5.1.0 • Published 6 years ago

@slate-editor/color-plugin v5.1.0

Weekly downloads
251
License
MIT
Repository
github
Last release
6 years ago

SlateJS color plugin.

npm package npm downloads

Installation

The @slate-editor/color-plugin is available as an npm package.

yarn add @slate-editor/color-plugin

Usage

Here is a quick example to get you started:

import React from 'react'
import { SlateEditor, SlateToolbar, SlateContent } from 'slate-editor'
import { ColorPlugin, ColorButton, ColorStateModel } from '@slate-editor/color-plugin'

const colorPluginOptions = new ColorStateModel().rgba({ r: 100, g: 100, b: 100, a: 1 }).gen()

const plugins = [
  ColorPlugin()
]

const SlateRichTextEditor = () => (
  <SlateEditor plugins={plugins}>
    <SlateToolbar>
      <ColorButton
        initialState={colorPluginOptions}
        pickerDefaultPosition={{ x: -520, y: 17 }}
      />
    </SlateToolbar>

    <SlateContent />
  </SlateEditor>
)

export default SlateRichTextEditor

Keyboard Shortcut

OSActionShortcut
Apple LogoToggle Color Picker^ + alt + l
Windows LogoToggle Color Picker^ + alt + l

API

NameDescription
ColorMarkComponent that holds the html that will wrap the content with color style.
ColorUtilsGeneric file that holds the util common functions.
ColorButtonButton component that have behaviour to wrap content with color style.
ColorKeyboardShortcutKeyboard shortcut file that manipulates onKeyDown event inside SlateJS.
ColorStateModelClass that knows the state structure of the plugin

TODO

  • Make keyboard shortcut accepts customization;
  • Add keyboard shortcut to apply color to expanded selection;
  • Add keyboard shortcut to remove color from expanded selection;
  • Add button to apply color to expanded selection;
  • Add button to remove color from expanded selection;
  • Add handle to manipulates collapsed selection to remove color to anchor word;
  • Add behaviour to show which color have applied to collapsed selection;
  • Add behaviour to show which color have applied to expanded selection;