Daan Meijer b9d2988e8c
Some checks failed
linter / quality (push) Failing after 1m1s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m4s
tests / ci (8.5) (push) Failing after 1m4s
feat: Auto-close mobile navigation sidebar upon successful user navigation
2026-06-17 00:43:26 +02:00

93 lines
2.2 KiB
Vue

<script setup lang="ts">
import { Link, router } from '@inertiajs/vue3';
import { BookOpen, FolderGit2, LayoutGrid, Users } from '@lucide/vue';
import { onMounted, onUnmounted } from 'vue';
import AppLogo from '@/components/AppLogo.vue';
import NavFooter from '@/components/NavFooter.vue';
import NavMain from '@/components/NavMain.vue';
import NavUser from '@/components/NavUser.vue';
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
useSidebar,
} from '@/components/ui/sidebar';
import { dashboard } from '@/routes';
import { index as dynamics } from '@/routes/dynamics';
import type { NavItem } from '@/types';
const { isMobile, setOpenMobile } = useSidebar();
let unregister: () => void;
onMounted(() => {
unregister = router.on('navigate', () => {
if (isMobile.value) {
setOpenMobile(false);
}
});
});
onUnmounted(() => {
if (unregister) {
unregister();
}
});
const mainNavItems: NavItem[] = [
{
title: 'Dashboard',
href: dashboard(),
icon: LayoutGrid,
},
{
title: 'Dynamics',
href: dynamics(),
icon: Users,
},
];
const footerNavItems: NavItem[] = [
// {
// title: 'Repository',
// href: 'https://github.com/laravel/vue-starter-kit',
// icon: FolderGit2,
// },
// {
// title: 'Documentation',
// href: 'https://laravel.com/docs/starter-kits#vue',
// icon: BookOpen,
// },
];
</script>
<template>
<Sidebar collapsible="icon" variant="inset">
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" as-child>
<Link :href="dashboard()">
<AppLogo />
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<NavMain :items="mainNavItems" />
</SidebarContent>
<SidebarFooter>
<NavFooter :items="footerNavItems" />
<NavUser />
</SidebarFooter>
</Sidebar>
<slot />
</template>