import { Activity, ReactNode, useId } from "react"; import clsx from "clsx"; /* TODO: fix stickyTabs with overflow: hidden */ export interface Tab { id: string | number; title: ReactNode; content?: ReactNode; disabled?: boolean; } interface Props { tabs: Tab[]; value: number | string; /** * Will make tabs stick to the top of the container when overflowing */ stickyTabs?: boolean; /** * Tabs will take the maximum width and divide equally */ fullWidth?: boolean; onChange: (id: number | string) => void; action?: ReactNode; className?: string; contentClassName?: string; listClassName?: string; preload?: boolean; } export function Tabs({ className, listClassName, contentClassName, tabs, value, onChange, fullWidth = false, stickyTabs = false, preload = false, action, }: Props) { const content = tabs.find((t) => t.id === value)?.content; const baseId = useId(); return (
{tabs.map(({ title, id, disabled }) => { const selected = value === id; return ( ); })}
{action &&
{action}
}
{preload ? tabs.map(({ id, content }) => ( {content} )) : content}
); }