import * as React from 'react'; import { TabTitleRow, TabContent, TabViewStyled, TabTitle } from './TabView.styled'; export type TabViewProps = { children: { [title: string]: React.ReactNode }; initialTab?: string; }; type TabProps = { children: () => React.ReactNode; }; export const TabView = (props: TabViewProps) => { const tabNames = Object.keys(props.children); if (tabNames.length === 0) { return null; } const [currentTab, setCurrentTab] = React.useState( props.initialTab ?? tabNames[0] ); return ( {tabNames.map((tabName, idx) => ( setCurrentTab(tabName)} key={`tab${tabName}${idx}`} > {tabName} ))} {props.children[currentTab] || ( setCurrentTab(tabNames[0])}> Tabs were misconfigured, resetting to zero. )} ); }; export const Tab = (props: TabProps) =>
{props.children()}
;