React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/react-with-addons.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
JavaScript 1.7
var DisableableItem = React.createClass({
getInitialState: function() {
return {
disabled: false
};
},
_onclick: function() {
this.setState({disabled: !this.state.disabled});
},
render: function() {
return (
<div>
<button onClick={this._onclick}>Disable</button>
{
React.Children.map(this.props.children,
function(child) {
return React.cloneElement(
child,
{isDisabled: this.state.disabled}
);
}.bind(this)
)
}
</div>
);
}
});
var ParameterizedOption = React.createClass({
getInitialState: function() {
return {disabled: this.props.isDisabled};
},
componentWillReceiveProps: function(np) {
this.setState({disabled: np.isDisabled});
},
render: function() {
return (
<div className="parameterized-option">
<label>{this.props.text}</label>
<div className="input-group input-group-sm">
<input type={this.props.inputType || "text"} className="form-control"
placeholder={this.props.initialInput || "00.00"}
disabled={this.state.disabled}></input>
</div>
</div>
);
}
});
React.render(
<DisableableItem>
<ParameterizedOption text="hey" isDisabled={false} />
<ParameterizedOption text="hey" isDisabled={false} />
</DisableableItem>,
document.body
);