import { NavLink } from "@remix-run/react"; import { motion } from "framer-motion"; import { type ReactNode, useRef } from "react"; import { type ShortcutDefinition, useShortcutKeys } from "~/hooks/useShortcutKeys"; import { cn } from "~/utils/cn"; import { ShortcutKey } from "./ShortcutKey"; export type Variants = "underline" | "pipe-divider" | "segmented"; export type TabsProps = { tabs: { label: string; to: string; end?: boolean; }[]; className?: string; layoutId: string; variant?: Variants; }; export function Tabs({ tabs, className, layoutId, variant = "underline" }: TabsProps) { return ( {tabs.map((tab, index) => ( {tab.label} ))} ); } export function TabContainer({ children, className, variant = "underline", }: { children: ReactNode; className?: string; variant?: Variants; }) { if (variant === "segmented") { return (
{children}
); } if (variant === "underline") { return (
{children}
); } return
{children}
; } export function TabLink({ to, children, layoutId, variant = "underline", end = true, }: { to: string; children: ReactNode; layoutId: string; variant?: Variants; end?: boolean; }) { if (variant === "segmented") { return ( {({ isActive, isPending }) => { const active = isActive || isPending; return ( <>
{children}
{active && ( )} ); }}
); } if (variant === "pipe-divider") { return ( {({ isActive, isPending }) => { const active = isActive || isPending; return ( {children} ); }} ); } // underline variant (default) return ( {({ isActive, isPending }) => { return ( <> {children} {isActive || isPending ? ( ) : (
)} ); }} ); } export function TabButton({ isActive, layoutId, shortcut, ...props }: { isActive: boolean; shortcut?: ShortcutDefinition; layoutId: string; } & React.ButtonHTMLAttributes) { const ref = useRef(null); if (shortcut) { useShortcutKeys({ shortcut: shortcut, action: () => { if (ref.current) { ref.current.click(); } }, disabled: props.disabled, }); } return ( ); }