Created
November 9, 2015 09:55
-
-
Save mikker/8ace50104aa9b363ae03 to your computer and use it in GitHub Desktop.
Basecamp's Trix editor in a React component
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
import React, { Component, PropTypes } from 'react' | |
import { findDOMNode } from 'react-dom' | |
class TrixEditor extends Component { | |
static propTypes = { | |
value: PropTypes.string, | |
onChange: PropTypes.func | |
} | |
componentDidMount () { | |
this.trix = 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> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much, I have updated something for my need at https://gist.github.com/cbilgili/89cab4196a6018daef26