@@ -19,70 +19,58 @@ export function DemoContainer({
1919 codeTabs ?: CodeTab [ ] ;
2020} ) {
2121 const [ activeTab , setActiveTab ] = useState ( 0 ) ;
22- const [ showCode , setShowCode ] = useState ( true ) ;
2322
24- if ( ! codeTabs || codeTabs . length === 0 ) {
25- return (
26- < div className = "bg-zinc-900 border border-zinc-800 rounded-xl p-6" >
23+ const allTabs = [
24+ { label : 'Demo' , type : 'demo' as const } ,
25+ ...( codeTabs ?? [ ] ) . map ( ( t ) => ( { ...t , type : 'code' as const } ) ) ,
26+ ] ;
27+
28+ return (
29+ < div className = "bg-zinc-900 border border-zinc-800 rounded-xl overflow-hidden" >
30+ { /* Header */ }
31+ < div className = "px-6 pt-5 pb-0" >
2732 < h3 className = "text-lg font-semibold text-zinc-100 mb-1" > { title } </ h3 >
2833 { description && (
29- < p className = "text-sm text-zinc-400 mb-4 " > { description } </ p >
34+ < p className = "text-sm text-zinc-400 mb-0 " > { description } </ p >
3035 ) }
31- { children }
3236 </ div >
33- ) ;
34- }
3537
36- return (
37- < div className = "bg-zinc-900 border border-zinc-800 rounded-xl overflow-hidden" >
38- < div className = "flex flex-col lg:flex-row" >
39- { /* Live demo */ }
40- < div className = "flex-[3] p-6 min-w-0" >
41- < h3 className = "text-lg font-semibold text-zinc-100 mb-1" > { title } </ h3 >
42- { description && (
43- < p className = "text-sm text-zinc-400 mb-4" > { description } </ p >
44- ) }
45- { children }
46- </ div >
38+ { /* Tabs */ }
39+ < div className = "flex border-b border-zinc-800 px-6 mt-4" >
40+ { allTabs . map ( ( tab , i ) => (
41+ < button
42+ key = { tab . label }
43+ type = "button"
44+ onClick = { ( ) => setActiveTab ( i ) }
45+ className = { `px-3 py-2 text-xs font-medium transition-colors cursor-pointer -mb-px ${
46+ activeTab === i
47+ ? 'text-zinc-100 border-b-2 border-indigo-400'
48+ : 'text-zinc-500 hover:text-zinc-300'
49+ } `}
50+ >
51+ { tab . label }
52+ </ button >
53+ ) ) }
54+ </ div >
4755
48- { /* Code panel */ }
49- < div className = "flex-[2] border-t lg:border-t-0 lg:border-l border-zinc-800 bg-zinc-950 min-w-0" >
50- < div className = "flex items-center justify-between border-b border-zinc-800" >
51- < div className = "flex" >
52- { codeTabs . map ( ( tab , i ) => (
53- < button
54- key = { tab . label }
55- type = "button"
56- onClick = { ( ) => setActiveTab ( i ) }
57- className = { `px-3 py-2 text-xs font-medium transition-colors cursor-pointer ${
58- activeTab === i
59- ? 'text-zinc-100 bg-zinc-900/50 border-b-2 border-indigo-400'
60- : 'text-zinc-500 hover:text-zinc-300'
61- } `}
62- >
63- { tab . label }
64- </ button >
65- ) ) }
66- </ div >
67- < button
68- type = "button"
69- onClick = { ( ) => setShowCode ( ! showCode ) }
70- className = "px-2 py-1 mr-2 text-xs text-zinc-500 hover:text-zinc-300 cursor-pointer lg:hidden"
71- >
72- { showCode ? 'Hide' : 'Show' }
73- </ button >
74- </ div >
75- { showCode && codeTabs [ activeTab ] && (
76- < div className = "max-h-[500px] overflow-y-auto" >
56+ { /* Content */ }
57+ { activeTab === 0 ? (
58+ < div className = "p-6" > { children } </ div >
59+ ) : (
60+ ( ( ) => {
61+ const codeTab = codeTabs ?. [ activeTab - 1 ] ;
62+ if ( ! codeTab ) return null ;
63+ return (
64+ < div className = "max-h-[500px] overflow-y-auto bg-zinc-950" >
7765 < CodeBlock
78- code = { codeTabs [ activeTab ] . code }
79- language = { codeTabs [ activeTab ] . language ?? 'tsx' }
66+ code = { codeTab . code }
67+ language = { codeTab . language ?? 'tsx' }
8068 compact = { true }
8169 />
8270 </ div >
83- ) }
84- </ div >
85- </ div >
71+ ) ;
72+ } ) ( )
73+ ) }
8674 </ div >
8775 ) ;
8876}
0 commit comments