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

89 lines
2.7 KiB
JavaScript
Raw Normal View History

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 OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
import Tooltip from 'react-bootstrap/lib/Tooltip';
2015-08-10 14:42:38 +02:00
import Panel from 'react-bootstrap/lib/Panel';
2015-07-09 11:56:54 +02:00
let PropertyCollapsile = React.createClass({
propTypes: {
children: React.PropTypes.arrayOf(React.PropTypes.element),
checkboxLabel: React.PropTypes.string,
tooltip: React.PropTypes.string
},
getInitialState() {
return {
show: false
};
},
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-08-10 14:42:38 +02:00
<Panel
collapsible
expanded={this.state.show}
className="bs-custom-panel">
<div className="ascribe-settings-property">
2015-07-14 00:12:33 +02:00
{this.renderChildren()}
2015-08-10 14:42:38 +02:00
</div>
</Panel>
2015-07-09 11:56:54 +02:00
</div>
);
}
});
export default PropertyCollapsile;