Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/webkom/lego-editor

📝 A React rich text editor written in TS with Slate.js for lego-webapp
https://github.com/webkom/lego-editor

hacktoberfest lego-webapp react slate vite wysiwyg

Last synced: about 2 months ago
JSON representation

📝 A React rich text editor written in TS with Slate.js for lego-webapp

Awesome Lists containing this project

README

        

# lego-editor

[![Build Status](https://ci.webkom.dev/api/badges/webkom/lego-editor/status.svg)](https://ci.webkom.dev/webkom/lego-editor) ![npm (scoped)](https://img.shields.io/npm/v/@webkom/lego-editor?style=flat-square) [![Dependabot](https://badgen.net/dependabot/webkom/lego-editor/?icon=dependabot)](https://github.com/webkom/lego-editor/pulls?q=is%3Aopen+is%3Apr+label%3Adependencies) ![Dependencies](https://badgen.net/david/dep/webkom/lego-editor/)

> Editor made for [lego-webapp](https://github.com/webkom/lego-webapp) written with [Slate.js](https://docs.slatejs.org)

## Installation

- Add the package
```sh
$ yarn add @webkom/lego-editor
```
- Import the component in your project

```JSX
import Editor from '@webkom/lego-editor'
// Add the stylesheet
import '@webkom/lego-editor/dist/style.css'
// Also add the stylesheet from react-image-crop
import 'react-image-crop/dist/ReactCrop.css'

const YourComponent = () => (




)
```

## Extending the editor

Lego-editor uses [Slate.js](https://github.com/ianstormtaylor/slate) version [0.81](https://docs.slatejs.org/general/changelog). You can therefore add any plugins as described in this version of Slate.
The `` component accepts the prop `plugins`, which takes an array of plugins
(`plugins: (Editor => Editor)[]`).

## Props

| name | Type | Default | Description |
| ------------- | ------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value` | `string` | | The editors value/default value |
| `disabled` | `Boolean` | `False` | Disables the ability to edit the content |
| `simple` | `Boolean` | `False` | Removes the toolbar. |
| `onChange` | `string => void` | | Handler called when the editor value changes. Takes the serialized value |
| `onBlur` | `event => void` | | Handler called on blur |
| `onFocus` | `event => void` | | Handler called on focus |
| `autoFocus` | `Boolean` | `False` | Enables autoFocus |
| `placeholder` | `string` | | A placeholder shown when the editor is empty |
| `imageUpload` | `Blob => Promise>` | | A function for uploading images. Should contain `src` in the promise object. |
| `plugins` | `(Editor => Editor)[]` | | An array of plugins to load. The first plugin will be applied first (the last one will override any other plugins) |
| `domParser` | `string => HTMLDocument` | | Custom function that the deserializer will use to parse the input value to a HTML document. Can be useful for environments where the browser API is not available, like Node.js |

> See type definitions for more detailed types

## Example app

To test out the editor using the development application:

```sh
$ yarn dev
```

## Development

#### Installing dependencies

```sh
$ yarn
```

#### Building the module

```sh
$ yarn build
```

#### Linting & formatting

To run the linter & check formatting

```sh
$ yarn lint
```

Formatting with prettier

```sh
$ yarn prettier
```