@@ -8,41 +8,6 @@ interface TabConfig<TData> {
88 getFilter ?: ( row : TData ) => { field : string ; value : string } ;
99}
1010
11- interface TabButtonProps < TData > {
12- tab : TabConfig < TData > ;
13- isActive : boolean ;
14- itemCount : number ;
15- onTabChange : ( tabId : string ) => void ;
16- }
17-
18- const TabButton = < TData , > ( {
19- tab,
20- isActive,
21- itemCount,
22- onTabChange,
23- } : TabButtonProps < TData > ) => (
24- < button
25- aria-controls = { `tabpanel-${ tab . id } ` }
26- aria-selected = { isActive }
27- className = { cn (
28- 'cursor-pointer border-b-2 px-3 py-2 text-sm transition-all duration-100 hover:text-foreground' ,
29- isActive
30- ? 'border-foreground text-foreground'
31- : 'border-transparent text-muted-foreground'
32- ) }
33- onClick = { ( ) => onTabChange ( tab . id ) }
34- role = "tab"
35- type = "button"
36- >
37- { tab . label }
38- { itemCount > 0 && (
39- < span className = "ml-1 text-xs opacity-60" >
40- ({ itemCount > 999 ? '999+' : itemCount } )
41- </ span >
42- ) }
43- </ button >
44- ) ;
45-
4611interface TableTabsProps < TData > {
4712 tabs : TabConfig < TData > [ ] ;
4813 activeTab : string ;
@@ -54,25 +19,39 @@ export function TableTabs<TData>({
5419 activeTab,
5520 onTabChange,
5621} : TableTabsProps < TData > ) {
57- if ( ! tabs || tabs . length <= 1 ) {
22+ if ( ! tabs ?. length || tabs . length <= 1 ) {
5823 return null ;
5924 }
6025
6126 return (
62- < div className = "mt-3 px-3 " >
27+ < div className = "mt-3" >
6328 < div className = "flex gap-1 border-b" role = "tablist" >
6429 { tabs . map ( ( tab ) => {
6530 const isActive = activeTab === tab . id ;
66- const itemCount = tab ? .data ?. length || 0 ;
31+ const itemCount = tab . data ?. length || 0 ;
6732
6833 return (
69- < TabButton
70- isActive = { isActive }
71- itemCount = { itemCount }
34+ < button
35+ aria-controls = { `tabpanel-${ tab . id } ` }
36+ aria-selected = { isActive }
37+ className = { cn (
38+ 'cursor-pointer border-b-2 px-3 py-2 text-sm transition-all duration-100 hover:text-foreground' ,
39+ isActive
40+ ? 'border-foreground text-foreground'
41+ : 'border-transparent text-muted-foreground'
42+ ) }
7243 key = { tab . id }
73- onTabChange = { onTabChange }
74- tab = { tab }
75- />
44+ onClick = { ( ) => onTabChange ( tab . id ) }
45+ role = "tab"
46+ type = "button"
47+ >
48+ { tab . label }
49+ { itemCount > 0 && (
50+ < span className = "ml-1 text-xs opacity-60" >
51+ ({ itemCount > 999 ? '999+' : itemCount } )
52+ </ span >
53+ ) }
54+ </ button >
7655 ) ;
7756 } ) }
7857 </ div >
0 commit comments