import React, { useState, useEffect } from 'react' import PropTypes from 'prop-types' import classNames from 'classnames' import Link from './link' import classes from '../styles/accordion.module.sass' const Accordion = ({ title, id, expanded, spaced, children }) => { const [isExpanded, setIsExpanded] = useState(true) const rootClassNames = classNames(classes.root, { [classes.spaced]: !!spaced, }) const contentClassNames = classNames(classes.content, { [classes.hidden]: !isExpanded, }) const iconClassNames = classNames({ [classes.hidden]: isExpanded, }) // Make sure accordion is expanded if JS is disabled useEffect(() => setIsExpanded(expanded), []) return (

{children}
) } Accordion.defaultProps = { expanded: false, } Accordion.propTypes = { title: PropTypes.string, id: PropTypes.string, children: PropTypes.node.isRequired, } export default Accordion