'use client' import { Slot } from '@radix-ui/react-slot' import type * as React from 'react' import { useActiveNavigation } from '../../hooks' import { NavTabs, NavTabsList, NavTabsTrigger } from './NavTabs' export type NavigationLink = { href: string name: string } type SimpleRenderLink = (args: { href: string children: React.ReactNode }) => React.ReactElement export type HeaderNavTabsProps = { /** * Current pathname (e.g., from useRouter().asPath or useLocation().pathname) */ path?: string /** * Array of navigation links */ links: NavigationLink[] /** * Custom link component renderer. Defaults to a regular anchor tag. * Only needs href and children - props are automatically merged by Slot. */ renderLink?: SimpleRenderLink /** * Additional className for the NavTabs root */ className?: string /** * Offset for the indicator in pixels. Defaults to 34. */ indicatorOffset?: number } /** * A composed navigation tabs component that automatically handles path-to-tab mapping * and renders links using the provided renderLink function. * * @example * ```tsx * // Next.js usage * const router = useRouter() * * ( * {children} * )} * /> * ``` * * @example * ```tsx * // React Router usage * const location = useLocation() * * ( * {children} * )} * /> * ``` * * @example * ```tsx * // Default anchor tag usage * * ``` */ type HeaderNavTabsPropsWithRef = HeaderNavTabsProps & { ref?: React.Ref> } export const HeaderNavTabs = ({ path, links, renderLink, className, indicatorOffset = 35, ref, ...props }: HeaderNavTabsPropsWithRef) => { const { activeItem, setActiveItem } = useActiveNavigation(path, links) const DefaultLink: SimpleRenderLink = ({ href, children }) => ( {children} ) const LinkComponent = renderLink ?? DefaultLink return ( {links.map((link) => { const linkEl = LinkComponent({ href: link.href, children: link.name, }) return ( {linkEl} ) })} ) } HeaderNavTabs.displayName = 'HeaderNavTabs'