2018-01-30 11:53:12 -05:00
|
|
|
const bindAll = require('lodash.bindall');
|
|
|
|
const classNames = require('classnames');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const React = require('react');
|
2016-04-21 16:22:39 -04:00
|
|
|
|
|
|
|
require('./accordion.scss');
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
class Accordion extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
bindAll(this, [
|
|
|
|
'handleClick'
|
|
|
|
]);
|
|
|
|
this.state = {
|
2016-04-21 16:22:39 -04:00
|
|
|
isOpen: false
|
|
|
|
};
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
handleClick (e) {
|
|
|
|
e.preventDefault();
|
2016-04-21 16:22:39 -04:00
|
|
|
this.setState({isOpen: !this.state.isOpen});
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
render () {
|
|
|
|
const classes = classNames({
|
|
|
|
content: true,
|
|
|
|
open: this.state.isOpen
|
2016-04-21 16:22:39 -04:00
|
|
|
});
|
|
|
|
return (
|
|
|
|
<div className="accordion">
|
2018-01-30 11:53:12 -05:00
|
|
|
<this.props.titleAs
|
|
|
|
className="title"
|
|
|
|
onClick={this.handleClick}
|
|
|
|
>
|
2016-04-21 16:22:39 -04:00
|
|
|
{this.props.title}
|
|
|
|
</this.props.titleAs>
|
|
|
|
<this.props.contentAs className={classes}>
|
|
|
|
{this.props.content}
|
|
|
|
</this.props.contentAs>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Accordion.propTypes = {
|
|
|
|
content: PropTypes.node,
|
|
|
|
title: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
Accordion.defaultProps = {
|
|
|
|
contentAs: 'div',
|
|
|
|
titleAs: 'div'
|
|
|
|
};
|
2016-04-21 16:22:39 -04:00
|
|
|
|
|
|
|
module.exports = Accordion;
|