File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import { ReactNode , useState } from 'react' ;
2+
3+ export function Tabs ( { children } : { children : ReactNode } ) {
4+ const tabList = Array . isArray ( children ) ? children : [ children ] ;
5+ const [ activeTab , setActiveTab ] = useState ( 0 ) ;
6+
7+ return (
8+ < div className = "mb-8" >
9+ < div className = "flex border-b mb-4" >
10+ { tabList . map ( ( child : any , idx ) => (
11+ < button
12+ key = { idx }
13+ className = { `px-4 py-2 text-sm ${
14+ idx === activeTab ? 'border-b-2 border-blue-500 font-semibold' : 'text-gray-500'
15+ } `}
16+ onClick = { ( ) => setActiveTab ( idx ) }
17+ >
18+ { child . props . label }
19+ </ button >
20+ ) ) }
21+ </ div >
22+ < div className = "mt-4" > { tabList [ activeTab ] } </ div >
23+ </ div >
24+ ) ;
25+ }
26+
27+ export function Tab ( { children } : { children : ReactNode } ) {
28+ return < div > { children } </ div > ;
29+ }
You can’t perform that action at this time.
0 commit comments