const bindAll = require('lodash.bindall'); const classNames = require('classnames'); const PropTypes = require('prop-types'); const React = require('react'); require('./accordion.scss'); class Accordion extends React.Component { constructor (props) { super(props); bindAll(this, [ 'handleClick' ]); this.state = { isOpen: false }; } handleClick (e) { e.preventDefault(); this.setState({isOpen: !this.state.isOpen}); } render () { const classes = classNames({ content: true, open: this.state.isOpen }); return (
{this.props.title} {this.props.content}
); } } Accordion.propTypes = { content: PropTypes.node, title: PropTypes.string }; Accordion.defaultProps = { contentAs: 'div', titleAs: 'div' }; module.exports = Accordion;