feat(KAN-19): add responsive permission-aware navigation
This commit is contained in:
@@ -1,19 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { Link, usePage } from '@inertiajs/vue3';
|
||||
import {
|
||||
BookOpen,
|
||||
Folder,
|
||||
FolderGit2,
|
||||
LayoutGrid,
|
||||
Layers3,
|
||||
Shield,
|
||||
Users,
|
||||
} from 'lucide-vue-next';
|
||||
import { computed } from 'vue';
|
||||
import { Link, router } from '@inertiajs/vue3';
|
||||
import { Settings2, X } from 'lucide-vue-next';
|
||||
import { computed, 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 { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
@@ -22,93 +13,98 @@ import {
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
useSidebar,
|
||||
} from '@/components/ui/sidebar';
|
||||
import { useAppNavigation } from '@/composables/useAppNavigation';
|
||||
import { useCurrentUrl } from '@/composables/useCurrentUrl';
|
||||
import { useLocalization } from '@/composables/useLocalization';
|
||||
import { dashboard } from '@/routes';
|
||||
import { index as adminUsers } from '@/routes/admin/users';
|
||||
import { index as projectTemplatesIndex } from '@/routes/project-templates';
|
||||
import { index as projectsIndex } from '@/routes/projects';
|
||||
import { index as teamsIndex } from '@/routes/teams';
|
||||
import type { NavItem } from '@/types';
|
||||
import { edit as profile } from '@/routes/profile';
|
||||
import { show } from '@/routes/projects';
|
||||
|
||||
const page = usePage();
|
||||
|
||||
const mainNavItems = computed<NavItem[]>(() => {
|
||||
const items: NavItem[] = [
|
||||
{
|
||||
title: 'Dashboard',
|
||||
href: dashboard(),
|
||||
icon: LayoutGrid,
|
||||
},
|
||||
{
|
||||
title: 'Projects',
|
||||
href: projectsIndex(),
|
||||
icon: Folder,
|
||||
},
|
||||
];
|
||||
|
||||
if (page.props.auth.permissions.projectCreate) {
|
||||
items.push({
|
||||
title: 'Project templates',
|
||||
href: projectTemplatesIndex(),
|
||||
icon: Layers3,
|
||||
});
|
||||
}
|
||||
|
||||
if (page.props.auth.permissions.globalAdmin) {
|
||||
items.push({
|
||||
title: 'Users',
|
||||
href: adminUsers(),
|
||||
icon: Shield,
|
||||
});
|
||||
}
|
||||
|
||||
if (page.props.auth.permissions.canManageTeams) {
|
||||
items.push({
|
||||
title: 'Teams',
|
||||
href: teamsIndex(),
|
||||
icon: Users,
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
const { t } = useLocalization();
|
||||
const { currentUrl } = useCurrentUrl();
|
||||
const { project, workspaceItems, projectItems, projectSettingsItems } =
|
||||
useAppNavigation();
|
||||
const { isMobile, setOpenMobile } = useSidebar();
|
||||
const accountItems = computed(() => [
|
||||
{
|
||||
title: t('navigation.settings'),
|
||||
href: profile(),
|
||||
icon: Settings2,
|
||||
isActive: currentUrl.value.startsWith('/settings/'),
|
||||
},
|
||||
]);
|
||||
let removeNavigationListener: (() => void) | undefined;
|
||||
onMounted(() => {
|
||||
removeNavigationListener = router.on('navigate', () =>
|
||||
setOpenMobile(false),
|
||||
);
|
||||
});
|
||||
|
||||
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,
|
||||
},
|
||||
];
|
||||
onUnmounted(() => removeNavigationListener?.());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Sidebar collapsible="icon" variant="inset">
|
||||
<SidebarHeader>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton size="lg" as-child>
|
||||
<Link :href="dashboard()">
|
||||
<AppLogo />
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
<Sidebar id="app-navigation" collapsible="icon" variant="sidebar">
|
||||
<SidebarHeader class="border-sidebar-border gap-4 border-b p-3">
|
||||
<div class="flex items-center gap-2">
|
||||
<SidebarMenu class="min-w-0">
|
||||
<SidebarMenuItem>
|
||||
<SidebarMenuButton
|
||||
size="lg"
|
||||
as-child
|
||||
tooltip="KanbanGit"
|
||||
>
|
||||
<Link :href="dashboard()" aria-label="KanbanGit"
|
||||
><AppLogo
|
||||
/></Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
<Button
|
||||
v-if="isMobile"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
:aria-label="t('navigation.close')"
|
||||
@click="setOpenMobile(false)"
|
||||
>
|
||||
<X aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
<Link
|
||||
v-if="project"
|
||||
:href="show(project.id)"
|
||||
class="bg-sidebar-accent flex min-w-0 items-center gap-3 rounded-md p-3 group-data-[collapsible=icon]:hidden"
|
||||
>
|
||||
<span
|
||||
class="text-label bg-brand/15 text-primary shrink-0 rounded-md px-2 py-1"
|
||||
>{{ project.key }}</span
|
||||
>
|
||||
<span class="truncate font-semibold" :title="project.name">{{
|
||||
project.name
|
||||
}}</span>
|
||||
</Link>
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<NavMain :items="mainNavItems" />
|
||||
<nav :aria-label="t('navigation.main')">
|
||||
<NavMain
|
||||
:items="workspaceItems"
|
||||
:label="t('navigation.workspace')"
|
||||
/>
|
||||
<NavMain
|
||||
v-if="projectItems.length"
|
||||
:items="projectItems"
|
||||
:label="t('navigation.project')"
|
||||
/>
|
||||
<NavMain
|
||||
v-if="projectSettingsItems.length"
|
||||
:items="projectSettingsItems"
|
||||
:label="t('navigation.projectSettings')"
|
||||
/>
|
||||
</nav>
|
||||
</SidebarContent>
|
||||
|
||||
<SidebarFooter>
|
||||
<NavFooter :items="footerNavItems" />
|
||||
<NavUser />
|
||||
<SidebarFooter class="border-sidebar-border border-t p-0">
|
||||
<NavMain :items="accountItems" :label="t('navigation.account')" />
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
<slot />
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user