Skip to content

Instantly share code, notes, and snippets.

@theisof
Created August 12, 2015 12:16
Show Gist options
  • Save theisof/ccf3336384abebfcd177 to your computer and use it in GitHub Desktop.
Save theisof/ccf3336384abebfcd177 to your computer and use it in GitHub Desktop.
React component using Medium editor plugin
<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>
@theisof
Copy link
Author

theisof commented Aug 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment