feat(ui): implement dropdown menu component with items and separators
This commit is contained in:
1 parent
cd72558db8
commit
9af1e0ce73
7 files changed
+100
-36
No files matched your search
@@ -15,11 +15,20 @@
|
||||
<script>
|
||||
import { page } from '$app/state';
|
||||
import { resolve } from '$app/paths';
|
||||
import { Menu, Table2, Settings, X } from '@lucide/svelte';
|
||||
import { LogOut, Menu, Table2, Settings, UserRound, X } from '@lucide/svelte';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import HealthWidget from '$lib/features/health/HealthWidget.svelte';
|
||||
import SettingsDialog from '$lib/features/layout/SettingsDialog.svelte';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '$lib/components/ui/dropdown-menu';
|
||||
import { useAuth } from '$lib/features/auth/auth.svelte.js';
|
||||
import CredentialsDialog from '$lib/features/auth/CredentialsDialog.svelte';
|
||||
|
||||
const navLinkClass = (active) =>
|
||||
cn(
|
||||
@@ -27,8 +36,11 @@
|
||||
active && 'bg-surface-hover text-primary',
|
||||
);
|
||||
|
||||
const auth = useAuth();
|
||||
|
||||
let navOpen = $state(false);
|
||||
let settingsOpen = $state(false);
|
||||
let credentialsOpen = $state(false);
|
||||
</script>
|
||||
|
||||
<header class="sticky top-0 z-40 flex h-14 items-center gap-2 border-b border-border bg-bg px-3">
|
||||
@@ -82,6 +94,29 @@
|
||||
<Button variant="ghost" size="icon" aria-label="Settings" onclick={() => (settingsOpen = true)}>
|
||||
<Settings class="size-5" />
|
||||
</Button>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger>
|
||||
{#snippet child({ props })}
|
||||
<Button variant="ghost" size="sm" class="max-[639px]:size-9 max-[639px]:p-0" aria-label="Account" {...props}>
|
||||
<UserRound class="size-5" />
|
||||
<span class="hidden min-[640px]:inline">{auth.status?.username ?? ''}</span>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem onSelect={() => (credentialsOpen = true)}>
|
||||
<UserRound class="size-4" />
|
||||
Profile
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onSelect={() => void auth.logout()}>
|
||||
<LogOut class="size-4" />
|
||||
Sign out
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</header>
|
||||
<CredentialsDialog bind:open={credentialsOpen} currentUsername={auth.status?.username ?? ''} />
|
||||
<SettingsDialog bind:open={settingsOpen} />
|
||||
Reference in new issue
Block a user