-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSingleSelectAccordion.jsx
37 lines (32 loc) · 1008 Bytes
/
SingleSelectAccordion.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useState } from "react";
import data from "./AccordionData.js";
import styles from "./styles.module.css";
// add rotation to the expand icon
export default function SingleSelectAccordion() {
const [selected, setSelected] = useState(null);
function handleClick(currentId) {
setSelected(currentId === selected ? null : currentId);
}
console.log(selected);
return (
<div className={styles.wrapper}>
<div className={styles.accordion}>
{data && data.length > 0 ? (
data.map(({ id, cover, content }) => (
<div className={styles.item} key={id}>
<div onClick={() => handleClick(id)} className={styles.cover}>
<h3>{cover}</h3>
<span>+</span>
</div>
{selected === id && (
<div className={styles.content}>{content}</div>
)}
</div>
))
) : (
<div>No data found</div>
)}
</div>
</div>
);
}