|
| 1 | +import { ReactNode, useState } from "react"; |
| 2 | +import { ChevronDownIcon } from "@heroicons/react/24/outline"; |
| 3 | + |
| 4 | +interface Tab { |
| 5 | + id: string; |
| 6 | + title: string; |
| 7 | + content: ReactNode; |
| 8 | + linkUrl?: string; |
| 9 | + linkLabel?: string; |
| 10 | +} |
| 11 | + |
| 12 | +interface TerminalWindowProps { |
| 13 | + tabs: Tab[]; |
| 14 | + defaultTab?: string; |
| 15 | +} |
| 16 | + |
| 17 | +// Desktop version with tabs |
| 18 | +const DesktopTerminal = ({ |
| 19 | + tabs, |
| 20 | + activeTab, |
| 21 | + setActiveTab, |
| 22 | +}: { |
| 23 | + tabs: Tab[]; |
| 24 | + activeTab: string; |
| 25 | + setActiveTab: (id: string) => void; |
| 26 | +}) => { |
| 27 | + const activeContent = tabs.find(t => t.id === activeTab); |
| 28 | + |
| 29 | + return ( |
| 30 | + <div className="hidden md:block border border-neutral-600 rounded-lg overflow-hidden"> |
| 31 | + {/* Title bar */} |
| 32 | + <div className="flex items-stretch bg-neutral-700 border-b border-neutral-600"> |
| 33 | + {/* Window controls (decorative) */} |
| 34 | + <div className="flex items-center gap-2 px-3 py-2"> |
| 35 | + <span className="w-3 h-3 rounded-full bg-red-500" /> |
| 36 | + <span className="w-3 h-3 rounded-full bg-yellow-500" /> |
| 37 | + <span className="w-3 h-3 rounded-full bg-green-500" /> |
| 38 | + </div> |
| 39 | + |
| 40 | + {/* Tab headers */} |
| 41 | + {tabs.map(tab => ( |
| 42 | + <button |
| 43 | + key={tab.id} |
| 44 | + onClick={() => setActiveTab(tab.id)} |
| 45 | + className={`flex-1 min-w-0 flex items-center justify-center px-2 text-xs whitespace-nowrap border-l border-neutral-600 transition-all duration-200 ${ |
| 46 | + activeTab === tab.id ? "text-white font-medium" : "text-neutral-400 hover:text-neutral-200" |
| 47 | + }`} |
| 48 | + style={{ |
| 49 | + backgroundColor: activeTab === tab.id ? "#6b7280" : "transparent", |
| 50 | + }} |
| 51 | + title={tab.title} |
| 52 | + > |
| 53 | + {tab.title} |
| 54 | + </button> |
| 55 | + ))} |
| 56 | + </div> |
| 57 | + |
| 58 | + {/* Content area */} |
| 59 | + <div className="bg-black p-6"> |
| 60 | + <div className="animate-fadeIn"> |
| 61 | + {activeContent && ( |
| 62 | + <div> |
| 63 | + <div className="flex items-center gap-3 mb-4"> |
| 64 | + <div className="flex items-center gap-2 text-sm"> |
| 65 | + <span className="text-primary">$</span> |
| 66 | + <span className="text-primary">cat {activeContent.title.toLowerCase().replace(/\s+/g, "-")}.md</span> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + {activeContent.content} |
| 70 | + {activeContent.linkUrl && ( |
| 71 | + <div className="mt-6"> |
| 72 | + <a |
| 73 | + href={activeContent.linkUrl} |
| 74 | + target="_blank" |
| 75 | + rel="noopener noreferrer" |
| 76 | + className="text-primary-content hover:text-primary text-sm" |
| 77 | + > |
| 78 | + → {activeContent.linkLabel || "Link"} |
| 79 | + </a> |
| 80 | + </div> |
| 81 | + )} |
| 82 | + </div> |
| 83 | + )} |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + ); |
| 88 | +}; |
| 89 | + |
| 90 | +// Mobile version with accordion inside single terminal frame |
| 91 | +const MobileTerminal = ({ |
| 92 | + tabs, |
| 93 | + expandedTab, |
| 94 | + toggleTab, |
| 95 | +}: { |
| 96 | + tabs: Tab[]; |
| 97 | + expandedTab: string | null; |
| 98 | + toggleTab: (id: string) => void; |
| 99 | +}) => { |
| 100 | + return ( |
| 101 | + <div className="md:hidden border border-neutral-600 rounded-lg overflow-hidden"> |
| 102 | + {/* Title bar with window controls - only once */} |
| 103 | + <div className="flex items-center gap-2 px-3 py-2 bg-neutral-700 border-b border-neutral-600"> |
| 104 | + <span className="w-3 h-3 rounded-full bg-red-500" /> |
| 105 | + <span className="w-3 h-3 rounded-full bg-yellow-500" /> |
| 106 | + <span className="w-3 h-3 rounded-full bg-green-500" /> |
| 107 | + </div> |
| 108 | + |
| 109 | + {/* Accordion items */} |
| 110 | + <div className="bg-black"> |
| 111 | + {tabs.map((tab, index) => { |
| 112 | + const isExpanded = expandedTab === tab.id; |
| 113 | + const isLast = index === tabs.length - 1; |
| 114 | + return ( |
| 115 | + <div key={tab.id} className={!isLast ? "border-b border-neutral-700" : ""}> |
| 116 | + {/* Accordion header */} |
| 117 | + <button |
| 118 | + onClick={() => toggleTab(tab.id)} |
| 119 | + className="w-full flex items-center justify-between px-4 py-3 hover:bg-neutral-800/50 transition-colors" |
| 120 | + > |
| 121 | + <span className="text-sm text-white font-medium">{tab.title}</span> |
| 122 | + <ChevronDownIcon |
| 123 | + className={`w-5 h-5 text-neutral-400 transition-transform duration-200 ${ |
| 124 | + isExpanded ? "rotate-180" : "" |
| 125 | + }`} |
| 126 | + /> |
| 127 | + </button> |
| 128 | + |
| 129 | + {/* Accordion content */} |
| 130 | + <div |
| 131 | + className={`overflow-hidden transition-all duration-300 ease-in-out ${ |
| 132 | + isExpanded ? "max-h-[600px] opacity-100" : "max-h-0 opacity-0" |
| 133 | + }`} |
| 134 | + > |
| 135 | + <div className="px-4 pb-4"> |
| 136 | + <div className="flex items-center gap-2 text-xs mb-3"> |
| 137 | + <span className="text-primary">$</span> |
| 138 | + <span className="text-primary">cat {tab.title.toLowerCase().replace(/\s+/g, "-")}.md</span> |
| 139 | + </div> |
| 140 | + {tab.linkUrl && ( |
| 141 | + <a |
| 142 | + href={tab.linkUrl} |
| 143 | + target="_blank" |
| 144 | + rel="noopener noreferrer" |
| 145 | + className="text-primary-content hover:text-primary" |
| 146 | + > |
| 147 | + → {tab.linkLabel || "Link"} |
| 148 | + </a> |
| 149 | + )} |
| 150 | + {tab.content} |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + ); |
| 155 | + })} |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + ); |
| 159 | +}; |
| 160 | + |
| 161 | +export const TerminalWindow = ({ tabs, defaultTab }: TerminalWindowProps) => { |
| 162 | + const [activeTab, setActiveTab] = useState<string>(defaultTab || tabs[0]?.id); |
| 163 | + const [expandedTab, setExpandedTab] = useState<string | null>(defaultTab || tabs[0]?.id); |
| 164 | + |
| 165 | + const toggleTab = (id: string) => { |
| 166 | + setExpandedTab(expandedTab === id ? null : id); |
| 167 | + }; |
| 168 | + |
| 169 | + return ( |
| 170 | + <> |
| 171 | + <DesktopTerminal tabs={tabs} activeTab={activeTab} setActiveTab={setActiveTab} /> |
| 172 | + <MobileTerminal tabs={tabs} expandedTab={expandedTab} toggleTab={toggleTab} /> |
| 173 | + </> |
| 174 | + ); |
| 175 | +}; |
0 commit comments