mirror of
https://github.com/twisterarmy/twister-react.git
synced 2025-08-30 07:41:58 +00:00
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
var React = require('react');
|
|
var ContentEditable = require('../common/ContentEditable.js');
|
|
|
|
module.exports = TwistComposer = React.createClass({ displayName: "TwistComposer",
|
|
|
|
getInitialState: function () {
|
|
return {
|
|
html: 'default text',
|
|
placeholder: true,
|
|
editing: true
|
|
};
|
|
},
|
|
|
|
render: function () {
|
|
return React.createElement("div", null, React.createElement(ContentEditable, {
|
|
tagName: "textarea",
|
|
onChange: this.onChange,
|
|
html: this.state.html,
|
|
preventStyling: true,
|
|
noLinebreaks: true,
|
|
placeholder: this.state.placeholder,
|
|
placeholderText: "Your Name",
|
|
editing: this.state.editing }), React.createElement("button", { onClick: this.enableEditing }, "Enable Editing"));
|
|
},
|
|
|
|
onChange: function (textContent, setPlaceholder) {
|
|
if (setPlaceholder) {
|
|
this.setState({
|
|
placeholder: true,
|
|
html: ''
|
|
});
|
|
} else {
|
|
this.setState({
|
|
placeholder: false,
|
|
html: textContent
|
|
});
|
|
}
|
|
},
|
|
|
|
enableEditing: function () {
|
|
// set your contenteditable field into editing mode.
|
|
this.setState({ editing: true });
|
|
}
|
|
|
|
}); |