import { useRef, type ReactNode } from "react"; import { useLocation, useNavigate } from "react-router"; type SystemTab = { id: string; label: string; content: ReactNode }; export function DesignSystemTabs({ tabs }: { tabs: SystemTab[] }) { const { hash } = useLocation(); const navigate = useNavigate(); const buttons = useRef>([]); const selected = tabs.findIndex((tab) => hash === `#${tab.id}`); const active = selected < 0 ? 0 : selected; function select(index: number) { navigate({ hash: `#${tabs[index]!.id}` }); } return (
{tabs.map((tab, index) => ( ))}
{/* Keep panels mounted so editors and examples retain their local state. */} {tabs.map((tab, index) => ( ))}
); }