1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-26 03:06:28 +02:00
onion/js/components/ascribe_collapsible/collapsible_button.js
Brett Sun 2dba4d5156 Use display:none for CollapsibleButton's hidden panel
Using visibility:invisible is awkward due to the spacing it leaves when
the panel is invisible. The CollapsibleParagraph behaves similarly,
leaving no spacing behind when the paragraph is collapsed.
2015-11-10 10:32:08 +01:00

39 lines
918 B
JavaScript

'use strict';
import React from 'react';
let CollapsibleButton = React.createClass({
propTypes: {
panel: React.PropTypes.object,
button: React.PropTypes.object,
children: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
])
},
getInitialState() {
return {expanded: false};
},
handleToggle(e){
e.preventDefault();
this.setState({expanded: !this.state.expanded});
},
render() {
let isHidden = (this.state.expanded) ? '' : 'hidden';
return (
<span>
<span onClick={this.handleToggle}>
{this.props.button}
</span>
<div ref='panel' className={isHidden}>
{this.props.panel}
</div>
</span>
);
}
});
export default CollapsibleButton;