0.12.1 • Published 7 years ago

slate-editor-icons v0.12.1

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

slate-editor-icons NPM version Build Status Dependency Status

icons (quill-icons) for slate editors

Installation

$ npm install --save slate-editor-icons

Icons support

Blocks

  • Icons.blocks.Blockquote (blockquote)
    • icon: Blockquote
    • default slate type: blockquote
  • Icons.blocks.Heading (heading, \<h1/>, \<h2/> ..., this is a dropdown menu)
    • icon: Header
    • default slate type: h1 - heading1, h2 - heading2, h3 - heading3, h4 - heading4.
  • Icons.blocks.OlList (\<ol/> list)
    • icon: ListOrdered
    • default slate type: list-ol
  • Icons.blocks.UlList (\<ul/> list)
    • icon: ListBullet
    • default slate type: list-ul

Inlines

  • Icons.inlines.Link (link \<a/>)
    • icon: Link
    • default slate type: link

Marks

  • Icons.marks.Bold (\<b/>)
    • icon: Bold
    • default slate type: bold
  • Icons.marks.Code (\<code/>)
    • icon: Code
    • default slate type: code
  • Icons.marks.Italic (\<i/>)
    • icon: Italic
    • default slate type: italic
  • Icons.marks.StrikeThrough (\<s/>)
    • icon: Strike
    • default slate type: strikethrough
  • Icons.marks.Underline (\<u/>)
    • icon: Underline
    • default slate type: underline

Usage

Every icons in Icons support are React element, you can use it any where you like in your React component as below.

import React from 'react';
import ReactDOM from 'react-dom';
import {Editor, Raw} from 'slate';
import Icons from 'slate-editor-icons';

const initialState = Raw.deserialize({
  nodes: [
    {
      kind: 'block',
      type: 'paragraph',
      nodes: [
        {
          kind: 'text',
          text: 'A line of text in a paragraph.'
        }
      ]
    }
  ]
}, {terse: true});

const icons = [
  // load marks icons
  Icons.marks.Bold,
  Icons.marks.Italic,
  Icons.marks.Underline,
  Icons.marks.Code,
  Icons.marks.StrikeThrough,
  // load inlines icons
  Icons.inlines.Link,
  // load blocks icons
  Icons.blocks.Heading,
  Icons.blocks.Blockquote,
  Icons.blocks.OlList,
  Icons.blocks.UlList
];

class App extends React.Component {
  // Set the initial state when the app is first constructed.
  state = {
    state: initialState
  }

  render() {
    const {state} = this.state;
    const onChange = state => this.setState({state});

    return (
      <div style={{margin: '50px'}}>
        {icons.map((Type, i) => {
          return React.createElement(Type, {
            key: i,
            state: state,
            onChange: onChange
          });
        })}
        <Editor
          state={state}
          onChange={onChange}
        />
      </div>
    );
  }
}

ReactDOM.render(
  <App/>
, document.getElementById('root'));

example: https://github.com/Canner/slate-editor-icons/blob/master/docs/index.js

Props

propstyperequireddefaultdescription
stateobjecttruenullslate state
onChangefunctruenullonChange function usually state => this.setState({state}) to update slate state
iconstringfalseevery items have it's own icon see icons supportthe icon
typestringfalseevery items have it's own type see icons supportslate block, inline, mark type.

Start example server

node devServer.js

Maintainer

chilijung

License

MIT © Canner

0.12.1

7 years ago

0.12.0

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.3

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.6.6

7 years ago

0.6.5

7 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.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.0

8 years ago