labo-components
Version:
46 lines (37 loc) • 923 B
JSX
import React from 'react';
import PropTypes from 'prop-types';
import IDUtil from '../util/IDUtil';
//TODO the header sucks a bit, make it better
class FlexBox extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: props.isVisible !== undefined ? props.isVisible : true
};
}
toggle() {
this.setState({
visible: !this.state.visible
});
}
render() {
const header = (
<div className={this.state.visible ? 'box-toggle open' : 'box-toggle closed'} onClick={this.toggle.bind(this)}>
<label>{this.props.title} </label>
</div>
);
return (
<div className={IDUtil.cssClassName('flex-box')}>
{header}
<div style={{display : this.state.visible ? 'block' : 'none'}}>
{this.props.children}
</div>
</div>
)
}
}
FlexBox.propTypes = {
title : PropTypes.string.isRequired,
isVisible : PropTypes.bool
};
export default FlexBox;