-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAccordion.jsx
45 lines (38 loc) · 1 KB
/
Accordion.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
38
39
40
41
42
43
44
45
const styles = () => ({
fontFamily: 'sans-serif',
heading: ({ context }) => ({
backgroundColor: '#1E90FF',
color: '#005A9C',
padding: '1em',
cursor: 'pointer',
':hover': {
backgroundColor: '#01BFFF',
color: '#FFFFFF'
},
...(context.panel.open && {
backgroundColor: '#00FFB2',
color: '#FFFFFF'
})
}),
content: ({ context }) => ({
padding: '1em',
color: '#444444',
display: context.panel.open ? 'block' : 'none'
})
});
const Accordion = ({ panels, ...props }) => {
const [current, toggle] = useState(0);
return (
<Module name='Accordion' styles={styles} { ...props }>
{panels.map(({ heading, content }, i) => (
<Component name='panel' open={i === current}>
<Component name='heading' onClick={() => toggle(i === current ? -1 : i)}>
{heading}
</Component>
<Component name='content' content={content} />
</Component>
))}
</Module>
);
}
export default Accordion;