1+ import { useState } from "react" ;
2+ import { ChevronDown } from "lucide-react" ;
3+
4+ interface AccordionItemProps {
5+ title : string ;
6+ content : string ;
7+ isOpen : boolean ;
8+ onClick : ( ) => void ;
9+ }
10+
11+ const AccordionItem = ( { title, content, isOpen, onClick } : AccordionItemProps ) => {
12+ return (
13+ < div className = "border-b bg-black dark:bg-white border-gray-100 last:border-none" >
14+ < button
15+ onClick = { onClick }
16+ className = "flex w-full items-center justify-between py-3 px-4 text-left text-sm font-medium text-white dark:text-gray-700 transition-colors rounded-xl"
17+ >
18+ < span > { title } </ span >
19+ < ChevronDown
20+ className = { `h-4 w-4 text-gray-400 transition-transform duration-200 ${
21+ isOpen ? "rotate-180" : ""
22+ } `}
23+ />
24+ </ button >
25+ < div
26+ className = { `transition-all duration-300 ease-in-out overflow-hidden ${
27+ isOpen ? "max-h-96 opacity-100" : "max-h-0 opacity-0"
28+ } `}
29+ >
30+ < div className = "px-4 pb-3 dark:text-gray-600 text-gray-200 text-sm leading-relaxed" >
31+ { content }
32+ </ div >
33+ </ div >
34+ </ div >
35+ ) ;
36+ } ;
37+
38+ const Accordion = ( ) => {
39+ const [ openIndex , setOpenIndex ] = useState < number | null > ( null ) ;
40+
41+ const items = [
42+ {
43+ title : "✨ What is DevUI?" ,
44+ content :
45+ "DevUI is a modern, open-source component library to build beautiful apps faster." ,
46+ } ,
47+ {
48+ title : "🤝 Can I contribute?" ,
49+ content :
50+ "Yes! Fork our GitHub repo, submit your PR, and join our awesome community." ,
51+ } ,
52+ {
53+ title : "💜 Is it free?" ,
54+ content :
55+ "Absolutely! DevUI is free under the MIT license. Use it anywhere without limits." ,
56+ } ,
57+ ] ;
58+
59+ return (
60+ < div className = "w-full max-w-lg mx-auto p-6" >
61+ < div className = "rounded-2xl border border-gray-200 bg-white shadow-sm overflow-hidden" >
62+ { items . map ( ( item , i ) => (
63+ < AccordionItem
64+ key = { i }
65+ { ...item }
66+ isOpen = { openIndex === i }
67+ onClick = { ( ) => setOpenIndex ( openIndex === i ? null : i ) }
68+ />
69+ ) ) }
70+ </ div >
71+ </ div >
72+ ) ;
73+ } ;
74+
75+ export default Accordion ;
0 commit comments