1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_collapsible/collapsible_paragraph.js

62 lines
1.6 KiB
JavaScript
Raw Permalink 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
]),
2015-12-02 16:51:56 +01:00
iconName: React.PropTypes.string,
show: React.PropTypes.bool,
defaultExpanded: React.PropTypes.bool
2015-06-18 19:03:03 +02:00
},
2015-06-22 23:32:41 +02:00
getDefaultProps() {
return {
2015-09-25 15:33:01 +02:00
show: true
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;