1.1.4 • Published 1 month ago

@oecd-pac/ready-slate v1.1.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

ready-slate

Ready-to-use Slate-based RichText component for React.

Why?

The RichText component provided by this package is not meant to be extensible (e.g. allowing to add a new formatting features/buttons via plugins, etc.), it is actually quite the opposite.

The goal is to provide an API that can be used as simply and quickly as possible. Slate is great and offers a clean framework to build RichText components but since it is a "framework", it is not ready to use out of the box. It will take you hours (or more likely days) to build even a simple production-ready RichText.

On the other hand, if your requirements are basic like bold, italic, ... (see full feature list below, in the toolbar prop), you can use ready-slate in minutes; all you need to do is:

npm install @oecd-pac/ready-slate

and then use the component:

import React, { useState } from 'react';
import { RichText, richTextEmptyValue } from '@oecd-pac/ready-slate';

const App = () => {
  const [value, setValue] = useState(richTextEmptyValue);

  return (
    <RichText
      initialValue={value}
      setValue={setValue}
      toolbar={['bold', 'italic', 'separator', 'link']}
    />
  );
};

export default App;

API

RichText

PropsDescriptionTypeRequiredDefault
initialValueInitial value. You do not need to know the internal format and can pass richTextEmptyValue if you do not have an existing value to providearrayyes
setValueA function that will be called passing the current valuefuncyes
toolbarArray of formatting options for the toolbar. Possible values: 'bold', 'italic', 'underline', 'sup', 'sub', 'heading1', 'heading2', 'bulleted-list', 'numbered-list', 'link', 'align-left', 'align-right', 'align-center', 'align-justify', 'indent', 'outdent', 'separator',array[]
hoveringToolbarArray of formatting options for the hovering toolbar (same options than for toolbar)array[]
placeholderRichText placeholderstring''
singleLinePrevent user from creating new paragraph by pressing Enterboolfalse
onBlurA custom onBlur functionfuncnull
editorFooterContentCustom footer contentnode or array of nodesnull
disabledDisable the RichTextboolfalse
classNameRichText custom css class (mainly useful to override default style)string''
popperClassNamePopper (hovering toolbar, link form) custom css class (mainly useful to override default style)string''

On top of the RichText component, ready-slate exports a few useful helper functions and constants:

Functions:

  • slateToHtmlString: serialize internal value to HTML
  • htmlStringToSlate: deserialize HTML to internal value
  • slateToString: serialize internal value to string

Constants

  • richTextEmptyValue: internal empty value (can be compared against to know if the RichText is "empty")

Style

The RichText component comes with very neutral styling but if you wish to change certain details you can pass a custom className (or popperClassName) that will allow to have more precise css selectors. Then simply inspect the classes you want to override and declare your own classes.

Contributing

Even though ready-slate is not directly "extensible", feel free to add new features to the code base and propose PRs.

1.1.4

1 month ago

1.1.3

1 month ago

1.1.2

1 month ago

1.1.1

8 months ago

1.1.0

10 months ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago