import React, { ReactNode } from 'react'; import classNames from 'classnames'; interface TabProps { label: string; identifier: T; icon?: ReactNode; children: ReactNode; } export const Tab = ({ children }: TabProps) => { // Wrapper component return <>{children}; }; interface TabViewProps { children: ReactNode; selectedTab: T; onTabChange: (tab: T) => void; } export const TabView = ({ children, selectedTab, onTabChange }: TabViewProps) => { // Filter and validate children to only get Tab components const tabs = React.Children.toArray(children).filter( (child) => React.isValidElement(child) && child.type === Tab ) as React.ReactElement>[]; return (
{tabs.map((tab, index) => { const isSelected = selectedTab === tab.props.identifier; const rowClassName = classNames( "flex flex-row items-center justify-center w-full gap-2 text-white", { "qc-highlighted": isSelected } ); return (
onTabChange(tab.props.identifier)} > {tab.props.icon}
{tab.props.label}
); })}
{tabs.map((tab, index) => (
{tab.props.children}
))}
); };