Files
sign/apps/web/src/components/(dashboard)/layout/desktop-nav.tsx

96 lines
2.8 KiB
TypeScript
Raw Normal View History

2023-06-09 18:21:18 +10:00
'use client';
import type { HTMLAttributes } from 'react';
2023-11-23 13:57:08 +11:00
import { useEffect, useState } from 'react';
2023-11-09 14:38:26 +11:00
2023-10-06 22:54:24 +00:00
import Link from 'next/link';
import { useParams, usePathname } from 'next/navigation';
2023-10-06 22:54:24 +00:00
2023-11-09 14:38:26 +11:00
import { Search } from 'lucide-react';
2023-06-09 18:21:18 +10:00
import { getRootHref } from '@documenso/lib/utils/params';
2023-06-09 18:21:18 +10:00
import { cn } from '@documenso/ui/lib/utils';
2023-11-09 14:38:26 +11:00
import { Button } from '@documenso/ui/primitives/button';
import { CommandMenu } from '../common/command-menu';
2023-06-09 18:21:18 +10:00
2023-10-06 22:54:24 +00:00
const navigationLinks = [
{
href: '/documents',
label: 'Documents',
},
{
href: '/templates',
label: 'Templates',
},
];
2023-06-09 18:21:18 +10:00
export type DesktopNavProps = HTMLAttributes<HTMLDivElement>;
export const DesktopNav = ({ className, ...props }: DesktopNavProps) => {
2023-10-06 22:54:24 +00:00
const pathname = usePathname();
const params = useParams();
2023-10-06 22:54:24 +00:00
2023-11-09 14:38:26 +11:00
const [open, setOpen] = useState(false);
2023-11-23 13:57:08 +11:00
const [modifierKey, setModifierKey] = useState(() => 'Ctrl');
2023-08-07 23:10:27 +10:00
const rootHref = getRootHref(params, { returnEmptyRootString: true });
2023-11-23 13:57:08 +11:00
useEffect(() => {
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : 'unknown';
const isMacOS = /Macintosh|Mac\s+OS\s+X/i.test(userAgent);
2023-11-23 13:57:08 +11:00
setModifierKey(isMacOS ? '⌘' : 'Ctrl');
}, []);
2023-06-09 18:21:18 +10:00
return (
2023-11-09 14:38:26 +11:00
<div
2023-12-14 15:28:27 +11:00
className={cn(
'ml-8 hidden flex-1 items-center gap-x-12 md:flex md:justify-between',
className,
)}
2023-11-09 14:38:26 +11:00
{...props}
>
2023-12-14 15:28:27 +11:00
<div className="flex items-baseline gap-x-6">
{navigationLinks
.filter(({ href }) => href !== '/templates' || rootHref === '') // Remove templates for team pages.
.map(({ href, label }) => (
<Link
key={href}
href={`${rootHref}${href}`}
className={cn(
'text-muted-foreground dark:text-muted focus-visible:ring-ring ring-offset-background rounded-md font-medium leading-5 hover:opacity-80 focus-visible:outline-none focus-visible:ring-2',
{
'text-foreground dark:text-muted-foreground': pathname?.startsWith(
`${rootHref}${href}`,
),
},
)}
>
{label}
</Link>
))}
2023-12-14 15:28:27 +11:00
</div>
2023-11-09 14:38:26 +11:00
<CommandMenu open={open} onOpenChange={setOpen} />
<Button
variant="outline"
className="text-muted-foreground flex w-96 items-center justify-between rounded-lg"
onClick={() => setOpen((open) => !open)}
>
<div className="flex items-center">
<Search className="mr-2 h-5 w-5" />
Search
</div>
<div>
2023-11-23 13:57:08 +11:00
<div className="text-muted-foreground bg-muted flex items-center rounded-md px-1.5 py-0.5 text-xs tracking-wider">
{modifierKey}+K
2023-11-09 14:38:26 +11:00
</div>
</div>
</Button>
2023-06-09 18:21:18 +10:00
</div>
);
};