import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; // @todo: improve type definitions export const Tab = ({ title, selectedTab, onClick }: any) => { const selectTabHandler = () => { onClick(title); }; return (
  • {title}
  • ); }; export type TabsProps = { children: React.ReactNode | any; }; export const Tabs = ({ children }: TabsProps) => { const [selectedTab, setSelectedTab] = useState(null); useEffect(() => { setSelectedTab(children[0].props.title); }, [children]); const onClickTabItem = (tabtitle: any) => { setSelectedTab(tabtitle); }; return (
      {children.map((child: any) => { const { title } = child.props; return ( ); })}
    {children.map((child: any) => { if (child.props.title !== selectedTab) return undefined; return child.props.children; })}
    ); }; export default Tabs;