import React, { cloneElement } from 'react'; import { type TabsProps } from '../../typings'; export const Tabs = ({ TabList, className, containerClassName, scrollControlsContainerClassName, scrollControlsButtonClassName, size, children, selectedId, scrollable, collapsedTabsIds, fullWidthScroll = false, keepMounted = false, dataTestId, onChange, breakpoint, client, defaultMatchMediaValue, tagShape, tagView, showSkeleton = false, skeletonProps, textStyle, style, titleProps, ...restProps }: Omit) => { const tabsArray = React.Children.toArray(children) as TabsProps['children']; const titles = tabsArray.map( ({ props: { title, id, rightAddons, disabled, hidden, toggleClassName, dataTestId: toggleTestId, toggleRef, }, }) => ({ title, id, disabled, rightAddons, hidden, toggleClassName, dataTestId: toggleTestId, toggleRef, ...titleProps, }), ); const tabs = tabsArray.filter( (tab) => tab.props.id === selectedId || tab.props.keepMounted || keepMounted, ); return (
{tabs.map((tab) => cloneElement(tab, { hidden: tab.props.id !== selectedId }))}
); };