Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions resources/js/components/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetTrigger } from '@/co
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import UserMenuContent from '@/components/UserMenuContent.vue';
import { getInitials } from '@/composables/useInitials';
import { toUrl, urlIsActive } from '@/lib/utils';
import { dashboard } from '@/routes';
import type { BreadcrumbItem, NavItem } from '@/types';
import { InertiaLinkProps, Link, usePage } from '@inertiajs/vue3';
Expand All @@ -27,11 +28,11 @@ const props = withDefaults(defineProps<Props>(), {
const page = usePage();
const auth = computed(() => page.props.auth);

const isCurrentRoute = computed(() => (url: NonNullable<InertiaLinkProps['href']>) => page.url === (typeof url === 'string' ? url : url.url));
const isCurrentRoute = computed(() => (url: NonNullable<InertiaLinkProps['href']>) => urlIsActive(url, page.url));

const activeItemStyles = computed(
() => (url: NonNullable<InertiaLinkProps['href']>) =>
isCurrentRoute.value(typeof url === 'string' ? url : url.url) ? 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100' : '',
isCurrentRoute.value(toUrl(url)) ? 'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100' : '',
);

const mainNavItems: NavItem[] = [
Expand Down Expand Up @@ -90,7 +91,7 @@ const rightNavItems: NavItem[] = [
<a
v-for="item in rightNavItems"
:key="item.title"
:href="typeof item.href === 'string' ? item.href : item.href?.url"
:href="toUrl(item.href)"
target="_blank"
rel="noopener noreferrer"
class="flex items-center space-x-2 text-sm font-medium"
Expand Down Expand Up @@ -141,11 +142,7 @@ const rightNavItems: NavItem[] = [
<Tooltip>
<TooltipTrigger>
<Button variant="ghost" size="icon" as-child class="group h-9 w-9 cursor-pointer">
<a
:href="typeof item.href === 'string' ? item.href : item.href?.url"
target="_blank"
rel="noopener noreferrer"
>
<a :href="toUrl(item.href)" target="_blank" rel="noopener noreferrer">
<span class="sr-only">{{ item.title }}</span>
<component :is="item.icon" class="size-5 opacity-80 group-hover:opacity-100" />
</a>
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/NavFooter.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { SidebarGroup, SidebarGroupContent, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/components/ui/sidebar';
import { toUrl } from '@/lib/utils';
import { type NavItem } from '@/types';

interface Props {
Expand All @@ -16,7 +17,7 @@ defineProps<Props>();
<SidebarMenu>
<SidebarMenuItem v-for="item in items" :key="item.title">
<SidebarMenuButton class="text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100" as-child>
<a :href="typeof item.href === 'string' ? item.href : item.href.url" target="_blank" rel="noopener noreferrer">
<a :href="toUrl(item.href)" target="_blank" rel="noopener noreferrer">
<component :is="item.icon" />
<span>{{ item.title }}</span>
</a>
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/NavMain.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { SidebarGroup, SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/components/ui/sidebar';
import { urlIsActive } from '@/lib/utils';
import { type NavItem } from '@/types';
import { Link, usePage } from '@inertiajs/vue3';

Expand All @@ -15,7 +16,7 @@ const page = usePage();
<SidebarGroupLabel>Platform</SidebarGroupLabel>
<SidebarMenu>
<SidebarMenuItem v-for="item in items" :key="item.title">
<SidebarMenuButton as-child :is-active="item.href === page.url" :tooltip="item.title">
<SidebarMenuButton as-child :is-active="urlIsActive(item.href, page.url)" :tooltip="item.title">
<Link :href="item.href">
<component :is="item.icon" />
<span>{{ item.title }}</span>
Expand Down
8 changes: 3 additions & 5 deletions resources/js/layouts/settings/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Heading from '@/components/Heading.vue';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { toUrl, urlIsActive } from '@/lib/utils';
import { appearance } from '@/routes';
import { edit as editPassword } from '@/routes/password';
import { edit } from '@/routes/profile';
Expand Down Expand Up @@ -35,12 +36,9 @@ const currentPath = typeof window !== undefined ? window.location.pathname : '';
<nav class="flex flex-col space-y-1 space-x-0">
<Button
v-for="item in sidebarNavItems"
:key="typeof item.href === 'string' ? item.href : item.href?.url"
:key="toUrl(item.href)"
variant="ghost"
:class="[
'w-full justify-start',
{ 'bg-muted': currentPath === (typeof item.href === 'string' ? item.href : item.href?.url) },
]"
:class="['w-full justify-start', { 'bg-muted': urlIsActive(item.href, currentPath) }]"
as-child
>
<Link :href="item.href">
Expand Down
9 changes: 9 additions & 0 deletions resources/js/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { InertiaLinkProps } from '@inertiajs/vue3';
import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function urlIsActive(urlToCheck: NonNullable<InertiaLinkProps['href']>, currentUrl: string) {
return toUrl(urlToCheck) === currentUrl;
}

export function toUrl(href: NonNullable<InertiaLinkProps['href']>) {
return typeof href === 'string' ? href : href?.url;
}