import React, { useState } from 'react' import { cn } from '@/lib/utils' type TabProps = { name: string init?: boolean children: React.ReactNode } type Props = { children: React.ReactNode } export const Tab = ({ children }: TabProps) => <>{children} export default ({ children }: Props) => { const tabs = React.Children.toArray (children) as React.ReactElement[] const [current, setCurrent] = useState (() => { const i = tabs.findIndex (tab => tab.props.init) return i >= 0 ? i : 0 }) return (
{tabs.map ((tab, i) => ( { ev.preventDefault () setCurrent (i) }}> {tab.props.name} ))}
{tabs[current]}
) }