Created
January 23, 2016 20:16
-
-
Save cbilgili/89cab4196a6018daef26 to your computer and use it in GitHub Desktop.
React Trix Editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrixEditor extends React.Component { | |
propTypes: { | |
value: PropTypes.string, | |
onChange: PropTypes.func | |
} | |
componentDidMount () { | |
this.trix = ReactDOM.findDOMNode(this) | |
this.changeListener = document.addEventListener( | |
'trix-change', this.onChange.bind(this)) | |
this.trix.editor.insertHTML(this.props.value) | |
} | |
componentWillDismount () { | |
this.changeListener() | |
} | |
onChange (event) { | |
if (event.target === this.trix) { | |
this.props.onChange(event) | |
} | |
} | |
render () { | |
return ( | |
<trix-editor {...this.props}></trix-editor> | |
) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TrixEditor value={this.props.tour_day.description} onChange={this.onTrixChanged} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment