1.5.0 • Published 6 years ago

slate-toolbar v1.5.0

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

slate-toolbar NPM version

Quick and easy way to implement medium like toolbar in your slate editor

demo

Installation

$ npm install --save slate-toolbar

Usage

slate-toolbar is the easiest way to implement a medium-like toolbar in your slate editor.

Just add a decorator @toolbar() on you editor component. The parent component of this component must pass two props value: Value and onChange: (change: Change) => void.

import toolbar from "slate-toolbar";

@toolbar() // ----> Add this line and your toolbar is implemented in your editor
class EditorContainer extends React.Component<Props> {
  // On change, update the app's React state with the new editor state.
  render() {
    return (
      <div className="editor">
        <Editor {...this.props} />
      </div>
    );
  }
}

class App extends React.Component<{}, { value: Value }> {
  // Set the initial state when the app is first constructed.
  state = {
    value: initialValue
  };

  render() {
    return (
      <div className="container markdown-body">
        <EditorContainer
          value={this.state.value}
          onChange={({ value }) => this.setState({ value })}
          plugins={plugins}
        />
      </div>
    );
  }
}

see codes for full implementation and demo

Options

slate-toolbar is fully customizable, so it allows you to pass options to setup items you want to implement in your toolbar.

NOTE: Remember to add certain plugin to your editor's plugins

Select your icons here

There's an example

const options = {
  // default icons are Bold, Undo, Italic
  icons: [
    Undo, // ----> this must be one of icon in https://github.com/Canner/slate-editor-icons#icon-packages
    Bold,
    Italic,
    Underline,
    Code,
    StrikeThrough,
    Clean,
    "divider", // ---> insert a divider to seperate icons
    AlignCenter,
    AlignLeft,
    AlignRight
  ],

  // position, where toolbar should show up.
  position: "bottom" | "top",

  // disabled in block types in the list
  disabledTypes: ["code_block", "code_line", "header_one", "header_two"]
};

Start example server

npm start
1.5.0

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.3-alpha.0

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.3

6 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.2

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.0

8 years ago