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

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-06-18 19:03:03 +02:00
'use strict';
import React from 'react';
import CollapsibleMixin from 'react-bootstrap/lib/CollapsibleMixin';
import classNames from 'classnames';
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 {
show: true
};
},
2015-06-18 19:03:03 +02:00
mixins: [CollapsibleMixin],
getCollapsibleDOMNode(){
return React.findDOMNode(this.refs.panel);
},
getCollapsibleDimensionValue(){
return React.findDOMNode(this.refs.panel).scrollHeight;
},
handleToggle(e){
e.preventDefault();
this.setState({expanded: !this.state.expanded});
},
render() {
let styles = this.getCollapsibleClassSet();
2015-07-08 14:37:20 +02:00
let text = this.isExpanded() ? '-' : '+';
2015-06-22 23:32:41 +02:00
if(this.props.show) {
return (
<div className="ascribe-detail-header">
<div className="ascribe-edition-collapsible-wrapper">
<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>
<div ref='panel' className={classNames(styles) + ' ascribe-edition-collapible-content'}>
{this.props.children}
</div>
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;