89 lines
3.6 KiB
Vue
89 lines
3.6 KiB
Vue
<script setup lang="ts">
|
|
import { computed } from "vue";
|
|
import { useRoute } from "vue-router";
|
|
import { PanelLeftClose, PanelLeftOpen } from "@lucide/vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
|
import { useSidebar } from "@/components/ui/sidebar/utils";
|
|
import { activeNavPath, navTree } from "@/lib/nav";
|
|
import { navIcons } from "@/lib/nav-icons";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const props = defineProps<{ hidden: string[] }>();
|
|
|
|
const route = useRoute();
|
|
const { open, toggleSidebar, isMobile } = useSidebar();
|
|
|
|
const nodes = computed(() => navTree(props.hidden));
|
|
const activePath = computed(() =>
|
|
typeof route.meta.navPath === "string" ? route.meta.navPath : activeNavPath(route.path),
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<aside
|
|
v-if="!isMobile"
|
|
aria-label="Primary navigation"
|
|
:class="
|
|
cn(
|
|
'sticky top-0 flex h-dvh shrink-0 flex-col border-r border-border bg-card transition-[width] duration-150',
|
|
open ? 'w-56' : 'w-14',
|
|
)
|
|
"
|
|
>
|
|
<div class="flex h-14 items-center border-b border-border px-2.5" :class="open ? 'justify-between' : 'justify-center'">
|
|
<span v-if="open" class="px-1.5 text-caption font-semibold tracking-[0.06em] text-fg-subtle uppercase">Navigation</span>
|
|
<Tooltip>
|
|
<TooltipTrigger as-child>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
:aria-label="open ? 'Collapse navigation' : 'Expand navigation'"
|
|
:aria-expanded="open"
|
|
@click="toggleSidebar"
|
|
>
|
|
<PanelLeftClose v-if="open" class="size-4" aria-hidden="true" />
|
|
<PanelLeftOpen v-else class="size-4" aria-hidden="true" />
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="right">{{ open ? "Collapse navigation (⌘B)" : "Expand navigation (⌘B)" }}</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
|
|
<nav class="flex-1 overflow-y-auto px-2 py-3">
|
|
<div v-for="node in nodes" :key="node.kind === 'link' ? node.entry.path : node.label" class="mb-4 last:mb-0">
|
|
<template v-if="node.kind === 'group'">
|
|
<p v-if="open" class="mb-1 px-2.5 text-caption font-medium tracking-[0.06em] text-fg-subtle uppercase">
|
|
{{ node.label }}
|
|
</p>
|
|
<ul class="flex flex-col gap-0.5">
|
|
<li v-for="entry in node.items" :key="entry.path">
|
|
<Tooltip :disabled="open">
|
|
<TooltipTrigger as-child>
|
|
<RouterLink
|
|
:to="entry.path"
|
|
:aria-current="entry.path === activePath ? 'page' : undefined"
|
|
:aria-label="open ? undefined : entry.label"
|
|
:class="
|
|
cn(
|
|
'flex h-8 items-center gap-2.5 rounded-md px-2.5 text-label transition-colors hover:bg-secondary hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring',
|
|
!open && 'justify-center px-0',
|
|
entry.path === activePath && 'bg-secondary font-medium text-foreground',
|
|
)
|
|
"
|
|
>
|
|
<component :is="navIcons[entry.path]" v-if="navIcons[entry.path]" class="size-4 shrink-0" aria-hidden="true" />
|
|
<span v-if="open" class="truncate">{{ entry.label }}</span>
|
|
</RouterLink>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="right">{{ entry.label }}</TooltipContent>
|
|
</Tooltip>
|
|
</li>
|
|
</ul>
|
|
</template>
|
|
</div>
|
|
</nav>
|
|
</aside>
|
|
</template>
|