|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 'use client'
-
- import { useSelectedLayoutSegment } from 'next/navigation'
- import Link from 'next/link'
- import classNames from '@/utils/classnames'
- import type { RemixiconComponentType } from '@remixicon/react'
-
- export type NavIcon = React.ComponentType<
- React.PropsWithoutRef<React.ComponentProps<'svg'>> & {
- title?: string | undefined
- titleId?: string | undefined
- }> | RemixiconComponentType
-
- export type NavLinkProps = {
- name: string
- href: string
- iconMap: {
- selected: NavIcon
- normal: NavIcon
- }
- mode?: string
- }
-
- export default function NavLink({
- name,
- href,
- iconMap,
- mode = 'expand',
- }: NavLinkProps) {
- const segment = useSelectedLayoutSegment()
- const formattedSegment = (() => {
- let res = segment?.toLowerCase()
- // logs and annotations use the same nav
- if (res === 'annotations')
- res = 'logs'
-
- return res
- })()
- const isActive = href.toLowerCase().split('/')?.pop() === formattedSegment
- const NavIcon = isActive ? iconMap.selected : iconMap.normal
-
- return (
- <Link
- key={name}
- href={href}
- className={classNames(
- isActive ? 'bg-state-accent-active font-semibold text-text-accent' : 'text-components-menu-item-text hover:bg-state-base-hover hover:text-components-menu-item-text-hover',
- 'group flex h-9 items-center rounded-md py-2 text-sm font-normal',
- mode === 'expand' ? 'px-3' : 'px-2.5',
- )}
- title={mode === 'collapse' ? name : ''}
- >
- <NavIcon
- className={classNames(
- 'h-4 w-4 shrink-0',
- mode === 'expand' ? 'mr-2' : 'mr-0',
- )}
- aria-hidden="true"
- />
- <span
- className={classNames(
- 'whitespace-nowrap transition-all duration-200 ease-in-out',
- mode === 'expand'
- ? 'w-auto opacity-100'
- : 'pointer-events-none w-0 overflow-hidden opacity-0',
- )}
- >
- {name}
- </span>
- </Link>
- )
- }
|