Created
August 12, 2015 12:16
-
-
Save theisof/ccf3336384abebfcd177 to your computer and use it in GitHub Desktop.
React component using Medium editor plugin
This file contains 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
<Editor text={@props.image.description} options={{buttons: ['bold', 'italic', 'underline']}} /> | |
Editor = React.createClass | |
getInitialState: -> | |
text: this.props.text | |
getDefaultProps: -> | |
<div></div> | |
componentDidMount: -> | |
dom = @getDOMNode() | |
@medium = new MediumEditor(dom, @props.options) | |
@medium.subscribe 'editableInput', (e) => | |
@updated = true | |
@change(dom.innerHTML) | |
componentWillUnmount: -> | |
@medium.destroy() | |
componentWillReceiveProps: (nextProps) -> | |
if nextProps.text != this.state.textand ! @updated | |
@setState({ text: nextProps.text }) | |
if @updated then @updated = false | |
change: (text) -> | |
if @props.onChange then @props.onChange(text) | |
render: -> | |
<div contentEditable="true" dangerouslySetInnerHTML={__html: @state.text }></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rewrite of https://github.com/wangzuo/react-medium-editor