# material-rte

> [![npm version](https://badge.fury.io/js/material-rte.svg)](https://badge.fury.io/js/material-rte)

Latest version **1.0.1** (published 2021-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install material-rte
pnpm add material-rte
yarn add material-rte
bun add material-rte
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-12-29 |
| First published | 2021-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 7 |
| Unpacked size | 542.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ali Nauman |
| Maintainers | ali60351 |
| Keywords | react, draft-js, material-ui, text-editor, rich-text-editor, rte |

## Links

- npm: https://www.npmjs.com/package/material-rte
- Repository: https://github.com/Ali60351/material-rte
- Homepage: https://github.com/Ali60351/material-rte#readme
- Issues: https://github.com/Ali60351/material-rte/issues
- npm.io page: https://npm.io/package/material-rte

## Dependencies (7)

- [formik](https://npm.io/package/formik.md) ^2.2.9
- [draft-js](https://npm.io/package/draft-js.md) ^0.11.7
- [classnames](https://npm.io/package/classnames.md) ^2.3.1
- [@material-ui/core](https://npm.io/package/@material-ui/core.md) ^4.11.0
- [@material-ui/icons](https://npm.io/package/@material-ui/icons.md) ^4.9.1
- [draft-js-export-html](https://npm.io/package/draft-js-export-html.md) ^1.4.1
- [draft-js-import-html](https://npm.io/package/draft-js-import-html.md) ^1.4.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-12-29
- 0.1.3 — 2021-12-29
- 0.1.2 — 2021-12-29
- 0.1.1 — 2021-12-29
- 0.1.0 — 2021-12-29
- 1.0.0 — 2021-12-23

## README

# Material RTE

[![npm version](https://badge.fury.io/js/material-rte.svg)](https://badge.fury.io/js/material-rte)

A Rich Text Editor made for applications built using React and using Material UI (v4). A potential alternative to [CKEditor][ckeditor], [TinyMCE][tinymce] and other [rich text "WYSIWYG" editors][rte]. Based on [Draft.js][draft-js] which is maintained by Facebook.

## Demo

Try the editor here: [Demo Site][material-rte-demo]

[![Screenshot 1](https://i.imgur.com/WRQHpez.png)][material-rte-demo]

## Getting Started

```sh
npm install --save material-rte
```

The main component of this package is the `Editor` one. It comprises of the base editor from Draft.js, a header which contains several button which you can use to modify selected text and a footer which provides extra info and can be used to toggle scroll.

The value of the editor is controller via the `value` prop which can be initialized using an empty value or a HTML string. The output of the editor can be obtained in HTML string form by transforming the value via included function.

### Example Usage

```javascript
import React from 'react';
import { Editor, importEditor, exportEditor, createEmptyEditor } from 'material-rte';

class ExampleEditor extends React.Component {
    constructor(props) {
        super(props);

        // INITIALIZE USING BLANK VALUE
        this.state = {
            value: createEmptyEditor(),
        };

        // INITIALIZE USING HTML STRING VALUE
        // this.state = {
        //     value: importEditor('<p>Lorem Ipsum</p>'),
        // };
    }

    handleChange = value => {
        console.log(exportEditor(value)); // PRINTS EDITOR VALUE IN HTML STRING FORM
        this.setState({ value });
    };

    render() {
        return <Editor value={this.state.value} onChange={this.handleChange} name="example-editor" />;
    }
}
```

## API

### Required Props

| Name  | Description                                                          | Type        |
| ----- | -------------------------------------------------------------------- | ----------- |
| value | Is the main prop responsible for controlling the value of the editor | EditorState |

### Other Props

| Name               | Description                                                                                                                                                                                                                                                                 | Type     |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| onChange           | Function triggered on every editor change. Useful for updating editor value.                                                                                                                                                                                                | function |
| onBlur             | Function trigger when editor loses focus. Useful for validation purposes.                                                                                                                                                                                                   | function |
| maxLength          | Number used to specify the maximum length allowed for value. Default value is `-1`.                                                                                                                                                                                         | number   |
| readOnly           | Toggle used to control if the value is editable or not. Also removes footer and header. Useful for displaying stored values. Default value is `false`.                                                                                                                      | number   |
| maxLength          | Number used to specify the maximum length allowed for value. Default value is `-1`.                                                                                                                                                                                         | number   |
| className          | String which can contain your CSS classes allowing for style customization                                                                                                                                                                                                  | string   |
| name               | Attribute applied to the root of the editor. Useful for selecting element via `querySelector`                                                                                                                                                                               | string   |
| error              | Toggle used to notify user if entered value is invalid                                                                                                                                                                                                                      | boolean  |
| error              | Toggle used to notify user if entered value is invalid                                                                                                                                                                                                                      | boolean  |
| removeScroll       | Removes maximum height limitation for the editor. Default value is `false`.                                                                                                                                                                                                 | boolean  |
| showHeadingButtons | Removes header from the editor. Default value is `false`.                                                                                                                                                                                                                   | boolean  |
| borderLess         | Removes border from the editor. Default value is `false`.                                                                                                                                                                                                                   | boolean  |
| variables          | Is an optional array of variables in the format of `{value: '{{ custom_variable }}', id: 1}`. Upon insertion of a variable the user will see the variable in a Material Chip with the text `Custom variable`. Useful for filling value with dynamic values after submission | array    |

[ckeditor]: http://ckeditor.com/
[draft-js]: https://facebook.github.io/draft-js/
[material-rte-demo]: https://ali60351.github.io/material-rte/
[rte]: https://www.google.com/search?q=web+based+rich+text+editor
[tinymce]: https://www.tinymce.com/

---
_Source: https://npm.io/package/material-rte · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
