66 lines
2.7 KiB
Vue
66 lines
2.7 KiB
Vue
<script setup lang="ts">
|
|
import { computed, ref, watch } from "vue";
|
|
import { useRoute } from "vue-router";
|
|
import { Building2, LayoutDashboard, ListChecks, Menu, Server, Workflow, Zap, type LucideIcon } from "@lucide/vue";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
|
import { activeNavPath, navTree, type NavEntry } from "@/lib/nav";
|
|
import Logo from "./Logo.vue";
|
|
|
|
/** The section list at phone width, where the strip has no room to show a
|
|
* label beside the current page. Sheet rather than a dropdown: it traps focus,
|
|
* takes the full height of a short screen, and holds rows a finger can hit. */
|
|
const props = defineProps<{ hidden: string[] }>();
|
|
|
|
const route = useRoute();
|
|
const open = ref(false);
|
|
let openedPath = route.path;
|
|
watch(open, (value) => { if (value) openedPath = route.path; });
|
|
function onCloseAutoFocus(event: Event): void {
|
|
if (route.path === openedPath) return;
|
|
event.preventDefault();
|
|
document.getElementById("main-content")?.focus({ preventScroll: true });
|
|
}
|
|
const links = computed(() =>
|
|
navTree(props.hidden).flatMap((node): NavEntry[] => (node.kind === "link" ? [node.entry] : [])),
|
|
);
|
|
const icons: Record<string, LucideIcon> = {
|
|
"/": LayoutDashboard,
|
|
"/tasks": ListChecks,
|
|
"/workflows": Workflow,
|
|
"/events": Zap,
|
|
"/org": Building2,
|
|
"/settings": Server,
|
|
};
|
|
const activePath = computed(() => activeNavPath(route.path));
|
|
|
|
watch(() => route.path, () => (open.value = false));
|
|
</script>
|
|
|
|
<template>
|
|
<Sheet v-model:open="open">
|
|
<SheetTrigger as-child>
|
|
<Button variant="ghost" size="icon" aria-label="Sections">
|
|
<Menu aria-hidden="true" />
|
|
</Button>
|
|
</SheetTrigger>
|
|
<SheetContent @close-auto-focus="onCloseAutoFocus" side="left" class="w-64 gap-0 p-0">
|
|
<SheetHeader class="border-b px-4 py-3">
|
|
<SheetTitle class="flex items-center"><Logo /></SheetTitle>
|
|
</SheetHeader>
|
|
<nav aria-label="Sections" class="flex flex-col gap-0.5 p-2">
|
|
<RouterLink
|
|
v-for="entry in links"
|
|
:key="entry.path"
|
|
:to="entry.path"
|
|
:aria-current="activePath === entry.path ? 'page' : undefined"
|
|
:data-current="activePath === entry.path ? '' : undefined"
|
|
class="text-fg-muted hover:text-foreground hover:bg-accent data-current:text-foreground data-current:bg-accent focus-visible:ring-ring/50 flex h-11 items-center gap-3 rounded-md px-3 text-label font-medium transition-colors outline-none focus-visible:ring-[3px]"
|
|
><component :is="icons[entry.path]" v-if="icons[entry.path]" class="size-4" aria-hidden="true" />{{ entry.label }}</RouterLink
|
|
>
|
|
</nav>
|
|
</SheetContent>
|
|
</Sheet>
|
|
</template>
|