Skip to content

Commit df389b1

Browse files
committed
adjust NavItems to accept link href type properties
1 parent 9e5a0f9 commit df389b1

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

resources/js/components/AppHeader.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import UserMenuContent from '@/components/UserMenuContent.vue';
1212
import { getInitials } from '@/composables/useInitials';
1313
import { dashboard } from '@/routes';
1414
import type { BreadcrumbItem, NavItem } from '@/types';
15-
import { Link, usePage } from '@inertiajs/vue3';
15+
import { InertiaLinkProps, Link, usePage } from '@inertiajs/vue3';
1616
import { BookOpen, Folder, LayoutGrid, Menu, Search } from 'lucide-vue-next';
1717
import { computed } from 'vue';
1818
@@ -27,16 +27,17 @@ const props = withDefaults(defineProps<Props>(), {
2727
const page = usePage();
2828
const auth = computed(() => page.props.auth);
2929
30-
const isCurrentRoute = computed(() => (url: string) => page.url === url);
30+
const isCurrentRoute = computed(() => (url: NonNullable<InertiaLinkProps['href']>) => page.url === (typeof url === 'string' ? url : url.url));
3131
3232
const activeItemStyles = computed(
33-
() => (url: string) => (isCurrentRoute.value(url) ? 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100' : ''),
33+
() => (url: NonNullable<InertiaLinkProps['href']>) =>
34+
isCurrentRoute.value(typeof url === 'string' ? url : url.url) ? 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100' : '',
3435
);
3536
3637
const mainNavItems: NavItem[] = [
3738
{
3839
title: 'Dashboard',
39-
href: dashboard().url,
40+
href: dashboard(),
4041
icon: LayoutGrid,
4142
},
4243
];
@@ -89,7 +90,7 @@ const rightNavItems: NavItem[] = [
8990
<a
9091
v-for="item in rightNavItems"
9192
:key="item.title"
92-
:href="item.href"
93+
:href="typeof item.href === 'string' ? item.href : item.href?.url"
9394
target="_blank"
9495
rel="noopener noreferrer"
9596
class="flex items-center space-x-2 text-sm font-medium"
@@ -140,7 +141,11 @@ const rightNavItems: NavItem[] = [
140141
<Tooltip>
141142
<TooltipTrigger>
142143
<Button variant="ghost" size="icon" as-child class="group h-9 w-9 cursor-pointer">
143-
<a :href="item.href" target="_blank" rel="noopener noreferrer">
144+
<a
145+
:href="typeof item.href === 'string' ? item.href : item.href?.url"
146+
target="_blank"
147+
rel="noopener noreferrer"
148+
>
144149
<span class="sr-only">{{ item.title }}</span>
145150
<component :is="item.icon" class="size-5 opacity-80 group-hover:opacity-100" />
146151
</a>

resources/js/components/AppSidebar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import AppLogo from './AppLogo.vue';
1212
const mainNavItems: NavItem[] = [
1313
{
1414
title: 'Dashboard',
15-
href: dashboard().url,
15+
href: dashboard(),
1616
icon: LayoutGrid,
1717
},
1818
];

resources/js/layouts/settings/Layout.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import { Link } from '@inertiajs/vue3';
1111
const sidebarNavItems: NavItem[] = [
1212
{
1313
title: 'Profile',
14-
href: edit().url,
14+
href: edit(),
1515
},
1616
{
1717
title: 'Password',
18-
href: editPassword().url,
18+
href: editPassword(),
1919
},
2020
{
2121
title: 'Appearance',
22-
href: appearance().url,
22+
href: appearance(),
2323
},
2424
];
2525
@@ -35,9 +35,12 @@ const currentPath = typeof window !== undefined ? window.location.pathname : '';
3535
<nav class="flex flex-col space-y-1 space-x-0">
3636
<Button
3737
v-for="item in sidebarNavItems"
38-
:key="item.href"
38+
:key="typeof item.href === 'string' ? item.href : item.href?.url"
3939
variant="ghost"
40-
:class="['w-full justify-start', { 'bg-muted': currentPath === item.href }]"
40+
:class="[
41+
'w-full justify-start',
42+
{ 'bg-muted': currentPath === (typeof item.href === 'string' ? item.href : item.href?.url) },
43+
]"
4144
as-child
4245
>
4346
<Link :href="item.href">

resources/js/types/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { InertiaLinkProps } from '@inertiajs/vue3';
12
import type { LucideIcon } from 'lucide-vue-next';
23

34
export interface Auth {
@@ -11,7 +12,7 @@ export interface BreadcrumbItem {
1112

1213
export interface NavItem {
1314
title: string;
14-
href: string;
15+
href: NonNullable<InertiaLinkProps['href']>;
1516
icon?: LucideIcon;
1617
isActive?: boolean;
1718
}

0 commit comments

Comments
 (0)