1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_collapsible/collapsible_paragraph.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-06-18 19:03:03 +02:00
'use strict';
import React from 'react';
2015-08-10 14:42:38 +02:00
import Panel from 'react-bootstrap/lib/Panel';
2015-06-18 19:03:03 +02:00
const CollapsibleParagraph = React.createClass({
propTypes: {
title: React.PropTypes.string,
children: React.PropTypes.oneOfType([
React.PropTypes.object,
React.PropTypes.array
]),
iconName: React.PropTypes.string
},
2015-06-22 23:32:41 +02:00
getDefaultProps() {
return {
2015-08-10 14:42:38 +02:00
show: false
2015-06-22 23:32:41 +02:00
};
},
2015-08-10 14:42:38 +02:00
getInitialState() {
return {
2015-08-11 17:12:12 +02:00
expanded: this.props.defaultExpanded
2015-08-10 14:42:38 +02:00
};
2015-06-18 19:03:03 +02:00
},
handleToggle(e){
e.preventDefault();
this.setState({expanded: !this.state.expanded});
},
render() {
2015-08-10 14:42:38 +02:00
let text = this.state.expanded ? '-' : '+';
2015-07-08 14:37:20 +02:00
2015-06-22 23:32:41 +02:00
if(this.props.show) {
return (
<div className="ascribe-detail-header">
2015-09-01 14:00:06 +02:00
<div className="ascribe-collapsible-wrapper">
2015-06-22 23:32:41 +02:00
<div onClick={this.handleToggle}>
2015-07-08 14:37:20 +02:00
<span>{text} {this.props.title}</span>
2015-06-22 23:32:41 +02:00
</div>
2015-08-10 14:42:38 +02:00
<Panel
collapsible
expanded={this.state.expanded}
2015-09-01 14:00:06 +02:00
className="ascribe-collapsible-content">
2015-06-22 23:32:41 +02:00
{this.props.children}
2015-08-10 14:42:38 +02:00
</Panel>
2015-06-18 19:03:03 +02:00
</div>
</div>
2015-06-22 23:32:41 +02:00
);
} else {
return null;
}
2015-06-18 19:03:03 +02:00
}
});
export default CollapsibleParagraph;