import React, {Children, cloneElement, isValidElement, ReactNode} from 'react'; import clsx from 'clsx'; import {FocusScope} from '@react-aria/focus'; import {TabProps} from './tab'; import {TabLine} from './tab-line'; export interface TabListProps { children: ReactNode; // center tabs within tablist center?: boolean; // expand tabs to fill in tablist space fully. By default, tabs are only as wide as their content. expand?: boolean; className?: string; } export function TabList({children, center, expand, className}: TabListProps) { const childrenArray = Children.toArray(children); return (
{childrenArray.map((child, index) => { if (isValidElement(child)) { return cloneElement(child, { index, className: clsx( child.props.className, expand && 'flex-auto', center && index === 0 && 'ml-auto', center && index === childrenArray.length - 1 && 'mr-auto' ), }); } return null; })}
); }