npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oecd-pac/ready-slate

v1.1.4

Published

Ready to use Slate based RichText

Downloads

22

Readme

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

| Props | Description | Type | Required | Default | | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------------ | ----------- | | initialValue | Initial value. You do not need to know the internal format and can pass richTextEmptyValue if you do not have an existing value to provide | array | yes | | | setValue | A function that will be called passing the current value | func | yes | | | toolbar | Array 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 | | [] | | hoveringToolbar | Array of formatting options for the hovering toolbar (same options than for toolbar) | array | | [] | | placeholder | RichText placeholder | string | | '' | | singleLine | Prevent user from creating new paragraph by pressing Enter | bool | | false | | onBlur | A custom onBlur function | func | | null | | editorFooterContent | Custom footer content | node or array of nodes | | null | | disabled | Disable the RichText | bool | | false | | className | RichText custom css class (mainly useful to override default style) | string | | '' | | popperClassName | Popper (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.