import * as React from "react"; import { Tabs as BaseTabs, TabsContent, TabsList, TabsTrigger, } from "@/components/ui/tabs"; interface TabDefinition { content: React.ReactNode; key: string; title: React.ReactNode; } export interface TabsProps { "aria-label"?: string; children: React.ReactNode; disableCursorAnimation?: boolean; onSelectionChange?: (key: React.Key) => void; selectedKey?: React.Key; } export interface TabProps { children: React.ReactNode; title: React.ReactNode; } export function Tab(_props: TabProps) { return null; } Tab.displayName = "HeroTab"; function parseTabs(children: React.ReactNode) { const tabs: TabDefinition[] = []; React.Children.forEach(children, (child, index) => { if (!React.isValidElement(child) || child.type !== Tab) { return; } const key = child.key ? String(child.key) : `tab-${index}`; const props = child.props as TabProps; tabs.push({ content: props.children, key, title: props.title, }); }); return tabs; } export function Tabs({ children, onSelectionChange, selectedKey }: TabsProps) { const tabs = React.useMemo(() => parseTabs(children), [children]); const fallback = tabs[0]?.key ?? ""; const value = selectedKey ? String(selectedKey) : fallback; return ( { onSelectionChange?.(nextValue); }} > {tabs.map((item) => ( {item.title} ))} {tabs.map((item) => ( {item.content} ))} ); }