File tree Expand file tree Collapse file tree 3 files changed +70
-10
lines changed
Expand file tree Collapse file tree 3 files changed +70
-10
lines changed Original file line number Diff line number Diff line change 1- import React from 'react'
1+ import React , { useState } from "react" ;
2+
3+ const Accordion = ( { title, content } ) => {
4+ const [ isActive , setIsActive ] = useState ( false ) ;
25
3- function Accordion ( ) {
46 return (
5- < div >
6- Accordion
7- </ div >
8- )
7+ < section className = "accordion-card" key = { Math . random ( ) } >
8+ < div className = "header" onClick = { ( ) => setIsActive ( ! isActive ) } >
9+ < div > { title } </ div >
10+ < p className = "icon" > { isActive ? "-" : "+" } </ p >
11+ </ div >
12+
13+ < div className = "content" >
14+ { isActive && < p className = "card-info" > { content } </ p > }
15+ </ div >
16+ </ section >
17+ ) ;
918}
1019
11- export default Accordion
20+ export default Accordion ;
Original file line number Diff line number Diff line change 11import React from "react" ;
22import Accordion from "./Accordion" ;
3-
3+ import { accordionData } from "./utils/content" ;
44
55function App ( ) {
66 return (
7- < div >
8- < Accordion />
7+ < div className = "accordion" >
8+ { accordionData . map ( ( { title, content } ) => {
9+ return < Accordion title = { title } content = { content } /> ;
10+ } ) }
911 </ div >
1012 ) ;
1113}
Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ background : rgb (36 , 36 , 36 );
9+ color : # fff ;
10+ font-family : sans-serif;
11+ height : 100vh ;
12+ display : flex;
13+ flex-direction : column;
14+ justify-content : center;
15+ align-items : center;
16+ }
17+
18+ .container {
19+ border : 2px solid white;
20+ }
21+
22+ .accordion-card {
23+ margin : 20px ;
24+ padding : 20px ;
25+ background : rgb (73 , 73 , 73 );
26+ }
27+
28+ .header {
29+ display : flex;
30+ justify-content : space-between;
31+ width : 40rem ;
32+ }
33+
34+ .card-title {
35+ display : flex;
36+ justify-content : space-between;
37+ width : 50rem ;
38+ }
39+
40+ .icon {
41+ font-size : 1.5rem ;
42+ cursor : pointer;
43+ }
44+
45+ p .card-info {
46+ width : 30rem ;
47+ padding : 20px 0 ;
48+ line-height : 1.3 ;
49+ }
You can’t perform that action at this time.
0 commit comments