-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (26 loc) 路 717 Bytes
/
Copy pathindex.js
File metadata and controls
29 lines (26 loc) 路 717 Bytes
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
import React, { useState, Fragment } from "react";
import PropTypes from "prop-types";
const Accordion = ({ children, className = "", onToggle, title }) => {
const [visibility, setVisibility] = useState(true);
return (
<div className={className}>
<h2
className="title"
onClick={() => {
setVisibility(!visibility);
if (onToggle) onToggle(!visibility);
}}
>
{title}
</h2>
{visibility ? <Fragment>{children}</Fragment> : null}
</div>
);
};
Accordion.propTypes = {
className: PropTypes.string,
children: PropTypes.any.isRequired,
onToggle: PropTypes.func,
title: PropTypes.string.isRequired
};
export default Accordion;