feat: grouped list selected state

This commit is contained in:
Shibo Lyu 2024-10-15 03:03:30 +08:00
parent 3097b8a9dd
commit e3e3481739
3 changed files with 12 additions and 3 deletions

View file

@ -1,17 +1,26 @@
<script lang="ts"> <script lang="ts">
import { tw } from '$lib/tw';
import { Icon, type IconSource } from 'svelte-hero-icons'; import { Icon, type IconSource } from 'svelte-hero-icons';
export let href: string | undefined = undefined; export let href: string | undefined = undefined;
export let icon: IconSource | undefined = undefined; export let icon: IconSource | undefined = undefined;
export let selected: boolean = false;
</script> </script>
<svelte:element <svelte:element
this={href ? 'a' : 'div'} this={href ? 'a' : 'div'}
{href} {href}
class="flex items-center gap-2 px-4 py-3 font-medium text-sf-primary" class={tw(
'flex items-center gap-2 px-4 py-3 font-medium text-sf-primary first:rounded-t-lg last:rounded-b-lg',
selected && 'bg-accent-500 text-white shadow-inner dark:bg-accent-900 dark:text-sf-primary'
)}
> >
{#if icon} {#if icon}
<Icon src={icon} class="size-5 text-sf-secondary" mini /> <Icon
src={icon}
class={tw('size-5 text-sf-secondary', selected && 'text-white dark:text-sf-primary')}
mini
/>
{/if} {/if}
<slot /> <slot />
</svelte:element> </svelte:element>

View file

@ -26,7 +26,7 @@
<GroupedListItem icon={UserPlus}>Add Account</GroupedListItem> <GroupedListItem icon={UserPlus}>Add Account</GroupedListItem>
</GroupedListSection> </GroupedListSection>
<GroupedListSection> <GroupedListSection>
<GroupedListItem icon={Cog}>General</GroupedListItem> <GroupedListItem icon={Cog} selected>General</GroupedListItem>
<GroupedListItem icon={Bell}>Notifications</GroupedListItem> <GroupedListItem icon={Bell}>Notifications</GroupedListItem>
<GroupedListItem icon={LockClosed}>Privacy and Security</GroupedListItem> <GroupedListItem icon={LockClosed}>Privacy and Security</GroupedListItem>
<GroupedListItem icon={DevicePhoneMobile}>Devices</GroupedListItem> <GroupedListItem icon={DevicePhoneMobile}>Devices</GroupedListItem>