react-medium-editor icon indicating copy to clipboard operation
react-medium-editor copied to clipboard

Custom Extensions

Open stanonyime opened this issue 9 years ago • 9 comments

How does one add custom extensions? I followed the custom button example on the medium editor website added to the options but nothing appeared.

stanonyime avatar Dec 22 '15 20:12 stanonyime

what's the error?

wangzuo avatar Dec 23 '15 02:12 wangzuo

There was no error but the custom button did not show

stanonyime avatar Dec 23 '15 10:12 stanonyime

Any code snippet?

wangzuo avatar Dec 23 '15 14:12 wangzuo

This is how I tried using them together:

import Editor from 'react-medium-editor'
import React from 'react'
import MediumEditor from 'medium-editor'
var HighlighterButton = MediumEditor.Extension.extend({
  name: 'highlighter',

  init: function () {
    this.button = this.document.createElement('button');
    this.button.classList.add('medium-editor-action');
    this.button.innerHTML = '<b>H</b>';
  },

  getButton: function () {
    return this.button;
  }
});
class EditorMedium extends React.Component {
  render(){
  const buttons  = ['bold', 'italic', 'underline']
    return ( <Editor
          {...this.props}
          tag="p"
          text="Sample text"
          onChange={this.props.onValue}
          options={{toolbar: {buttons: buttons,extensions:{'highlighter': new HighlighterButton()}}}}
        />)
  }
}

When I render the element and make a selection, I only see the buttons for Bold, Italic, and Underline

stanonyime avatar Dec 23 '15 16:12 stanonyime

@wangzuo, thanks for this library! An add-on question:

  • Can extensions be React Components, i.e., the element is a React Component instead of a native HTML element?

oyeanuj avatar Jan 06 '16 00:01 oyeanuj

@stanonyime Did you find a solution to your problem above?

@wangzuo Any thoughts on my question above?

oyeanuj avatar Feb 17 '16 06:02 oyeanuj

@oyeanuj No

stanonyime avatar Feb 18 '16 17:02 stanonyime

I've used MediumButton and it worked fine, the only thing is that clicking this button doesn't trigger onChange event of react component..

ilyadoroshin avatar Mar 24 '16 08:03 ilyadoroshin

Hello guys! Is there a way to add medium-editor-insert-plugin? For now I can't figure out how to do this and switch to dark side - write my own react component with medium-editor. I already see this issue, but I don't use class component

EugeneSnihovsky avatar Nov 21 '19 09:11 EugeneSnihovsky