Editor is rich text editor component based on Quill.
import { Editor } from 'primereact/editor';
<script src="https://unpkg.com/primereact/core/core.min.js"></script>
<script src="https://unpkg.com/primereact/editor/editor.min.js"></script>
Editor is used as a controlled component with value and onTextChange properties.
<Editor style={{height:'320px'}} value={text} onTextChange={(e) => setText(e.htmlValue)} />
Editor provides a default toolbar with common options, to customize it define your elements with the headerTemplate. Refer to Quill documentation for available controls.
const header = (
<span className="ql-formats">
<button className="ql-bold" aria-label="Bold"></button>
<button className="ql-italic" aria-label="Italic"></button>
<button className="ql-underline" aria-label="Underline"></button>
</span>
);
<Editor style={{height:'320px'}} value={text} onTextChange={(e) => setText(e.htmlValue)} headerTemplate={header}/>
Any valid attribute is passed to the root element implicitly, extended properties are as follows;
| Name | Type | Default | Description |
|---|---|---|---|
| id | string | null | Unique identifier of the element. |
| value | string | null | Value of the content. |
| style | object | null | Inline style of the container. |
| className | string | null | Style class of the container. |
| placeholder | string | null | Placeholder text to show when editor is empty. |
| readOnly | boolean | false | Whether to instantiate the editor to read-only mode. |
| modules | object | null | Modules configuration, see here for available options. |
| formats | string[] | null | Whitelist of formats to display, see here for available options. |
| headerTemplate | any | null | Style and modules of the toolbar. |
| maxLength | number | null | Maximum number of characters the editor will accept. |
| Name | Parameters | Description |
|---|---|---|
| onTextChange | event.delta: Representation of the change. event.source: Source of change. Will be either "user" or "api". event.htmlValue: Current value as html. event.textValue: Current value as text. | Callback to invoke when text of editor changes. |
| onSelectionChange | event.range: Object with index and length keys indicating where the selection exists. event.oldRange: Object with index and length keys indicating where the previous selection was. event.source: Source of change. Will be either "user" or "api". | Callback to invoke when selected text of editor changes. |
| onLoad | quill: Quill instance | Callback to invoke when the quill modules are loaded. |
Refer to Quill documentation for more information.
Following is the list of structural style classes, for theming classes visit theming page.
| Name | Element |
|---|---|
| p-editor-container | Container element |
| p-editor-toolbar | Toolbar of the editor |
| p-editor-content | Editable area |
This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.
Quill Editor 1.3+.
Resources of quill needs to be added to your application.
npm install quill
Built-in component themes created by the PrimeReact Theme Designer.
Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.
Beautifully crafted premium create-react-app application templates by the PrimeTek design team.