import React, { type ComponentPropsWithRef, type ReactNode } from 'react'; import { NavLink } from 'react-router'; import { flexRender, useControllable, type FlexRenderable } from '@wener/reaction'; import { clsx } from 'clsx'; import { cn } from '../utils/cn'; export interface TitleTabItem { label: ReactNode; href?: string; icon?: FlexRenderable; action?: ReactNode; key?: string; } export function getTitleTabItemKey(item: TitleTabItem, index: number) { return item.key ?? String(index); } export const TitleTabList = ({ className, value, onValueChange, defaultValue, title, action, tabs, ref, ...props }: Omit, 'title'> & { title?: ReactNode; action?: ReactNode; tabs: Array; value?: string; defaultValue?: string; onValueChange?: (value: string) => void; }) => { const [current, setCurrent] = useControllable(value, onValueChange, defaultValue); return (

{title}

{tabs.map((item, index) => { const { label, href, icon } = item; const key = getTitleTabItemKey(item, index); const content = ( <> {flexRender(icon, { className: 'w-4 h-4' })} {label} ); let isActive = key === current; return href ? ( clsx('tab', isActive && 'tab-active')} key={index} > {content} ) : ( { setCurrent(key); }} > {content} ); })}
{action && (
{action}
)}
); };