2015-07-09 11:56:54 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
2015-07-14 00:12:33 +02:00
|
|
|
import ReactAddons from 'react/addons';
|
2015-07-09 11:56:54 +02:00
|
|
|
|
|
|
|
import CollapsibleMixin from 'react-bootstrap/lib/CollapsibleMixin';
|
|
|
|
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
|
|
|
|
import Tooltip from 'react-bootstrap/lib/Tooltip';
|
|
|
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
|
|
|
|
let PropertyCollapsile = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
children: React.PropTypes.arrayOf(React.PropTypes.element),
|
|
|
|
checkboxLabel: React.PropTypes.string,
|
|
|
|
tooltip: React.PropTypes.string
|
|
|
|
},
|
|
|
|
|
|
|
|
mixins: [CollapsibleMixin],
|
|
|
|
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
show: false
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getCollapsibleDOMNode(){
|
|
|
|
return React.findDOMNode(this.refs.panel);
|
|
|
|
},
|
|
|
|
|
|
|
|
getCollapsibleDimensionValue(){
|
|
|
|
return React.findDOMNode(this.refs.panel).scrollHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleFocus() {
|
|
|
|
this.refs.checkboxCollapsible.getDOMNode().checked = !this.refs.checkboxCollapsible.getDOMNode().checked;
|
|
|
|
this.setState({
|
|
|
|
show: this.refs.checkboxCollapsible.getDOMNode().checked
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-14 00:12:33 +02:00
|
|
|
handleChange(event) {
|
|
|
|
this.setState({value: event.target.value});
|
|
|
|
},
|
|
|
|
|
2015-07-09 11:56:54 +02:00
|
|
|
renderChildren() {
|
|
|
|
if(this.state.show) {
|
2015-07-14 00:12:33 +02:00
|
|
|
return ReactAddons.Children.map(this.props.children, (child) => {
|
|
|
|
return ReactAddons.addons.cloneWithProps(child, {
|
|
|
|
onChange: this.handleChange
|
|
|
|
});
|
|
|
|
});
|
2015-07-09 11:56:54 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let tooltip = <span/>;
|
|
|
|
if (this.props.tooltip){
|
|
|
|
tooltip = (
|
|
|
|
<Tooltip>
|
|
|
|
{this.props.tooltip}
|
|
|
|
</Tooltip>);
|
|
|
|
}
|
|
|
|
|
|
|
|
let style = this.state.show ? {} : {paddingBottom: 0};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={'ascribe-settings-wrapper'}
|
|
|
|
style={style}>
|
|
|
|
<OverlayTrigger
|
|
|
|
delay={500}
|
|
|
|
placement="top"
|
|
|
|
overlay={tooltip}>
|
|
|
|
<div
|
|
|
|
className="ascribe-settings-property-collapsible-toggle"
|
|
|
|
onClick={this.handleFocus}
|
|
|
|
onFocus={this.handleFocus}>
|
|
|
|
<input
|
2015-07-14 00:12:33 +02:00
|
|
|
onChange={this.handleChange}
|
2015-07-09 11:56:54 +02:00
|
|
|
type="checkbox"
|
|
|
|
ref="checkboxCollapsible"/>
|
|
|
|
{/* PLEASE LEAVE THE SPACE BETWEEN LABEL and this.props.label */}
|
|
|
|
<span className="checkbox"> {this.props.checkboxLabel}</span>
|
|
|
|
</div>
|
|
|
|
</OverlayTrigger>
|
2015-07-14 00:12:33 +02:00
|
|
|
<div
|
|
|
|
className={classNames(this.getCollapsibleClassSet()) + ' ascribe-settings-property'}
|
|
|
|
ref="panel">
|
|
|
|
{this.renderChildren()}
|
|
|
|
</div>
|
2015-07-09 11:56:54 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PropertyCollapsile;
|