1.0.1 • Published 2 years ago

@draft-js-enhance-plugins/clear-format v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

DraftJS Clear Format Plugin

This is a plugin for the @draft-js-plugins/editor.

Feature

Clear all inline styles, convert all block types to unstyled except AtomicBlock.

Usage

import { EditorState } from 'draft-js';
import Editor from '@draft-js-plugins/editor';
import createClearFormatPlugin from '@draft-js-enhance-plugins/clear-format';

const clearFormatPlugin = createClearFormatPlugin();

const plugins = [clearFormatPlugin];

function Example() {
  const [editorState, setEditorState] = useState(EditorState.createEmpty());

  const mapKeyToEditorCommand = (event: React.KeyboardEvent) => {
    if (event.key === '/' && KeyBindingUtil.hasCommandModifier(event)) {
      // cmd + '/'
      return 'clear-format';
    }

    return getDefaultKeyBinding(event);
  };

  return (
    <Editor
      editorState={editorState}
      onChange={setEditorState}
      keyBindingFn={mapKeyToEditorCommand}
      plugins={plugins}
    />
  );
}