import React from 'react'; import cn from 'classnames'; import { Skeleton } from '@alfalab/core-components-skeleton'; import { useTabs } from '../../hooks/use-tabs'; import { type PlatformProps, type SecondaryTabListProps, type Styles } from '../../typings'; import { ScrollableContainer } from '../scrollable-container'; function getBorderRadius( shape?: SecondaryTabListProps['tagShape'], size?: SecondaryTabListProps['size'], isMobile?: boolean, ) { if (shape === 'rounded') { return 99; } if (size === 'xxs') return isMobile ? 8 : 6; if (size === 'xs' || size === 's') return isMobile ? 12 : 8; return isMobile ? 16 : 4; } export const SecondaryTabList = ({ styles = {}, className, containerClassName, scrollControlsContainerClassName, scrollControlsButtonClassName, size, titles = [], selectedId = titles.length ? titles[0].id : undefined, scrollable = true, fullWidthScroll, tagSize = 40, onChange, dataTestId, TagComponent, platform, tagShape = 'rounded', tagView, inlineStyle, showSkeleton, skeletonProps, }: SecondaryTabListProps & Styles & PlatformProps) => { const { focusedTab, selectedTab, getTabListItemProps } = useTabs({ titles, selectedId, onChange, }); const renderContent = () => { if (!TagComponent) return null; return (
{titles.map((item, index) => { if (item.hidden) return null; const renderTab = () => ( {item.title} ); return showSkeleton ? ( {renderTab()} ) : ( renderTab() ); })}
); }; return scrollable ? ( {renderContent()} ) : (
{renderContent()}
); };