# react-quill **Repository Path**: ekber/react-quill ## Basic Information - **Project Name**: react-quill - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-09-13 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README React-Quill [![Build Status](https://travis-ci.org/zenoamaro/react-quill.svg?branch=master)](https://travis-ci.org/zenoamaro/react-quill) [![npm](https://img.shields.io/npm/v/react-quill.svg)](https://www.npmjs.com/package/react-quill) [![npm downloads](https://img.shields.io/npm/dt/react-quill.svg?maxAge=2592000)](http://www.npmtrends.com/react-quill) ============================================================================== A [Quill] component for [React]. See a [live demo] or [Codepen](http://codepen.io/alexkrolick/pen/xgyOXQ/left?editors=0010#0). [Quill]: https://quilljs.com [React]: https://facebook.github.io/react/ [live demo]: https://zenoamaro.github.io/react-quill/ 1. [Quick start](#quick-start) 1. [Import the component](#import-the-component) 1. [Import the stylesheet](#import-the-stylesheet) 1. [Use the component](#use-the-component) 1. [Using Deltas](#using-deltas) 1. [Controlled vs Uncontrolled Mode](#controlled-vs-uncontrolled-mode) 1. [Options](#options) 1. [Theme](#theme) 1. [Custom Toolbar](#custom-toolbar) 1. [Custom Formats](#custom-formats) 1. [Custom Editing Area](#custom-editing-area) 1. [Mixin](#mixin) 1. [Upgrading to React-Quill v1.0.0](#upgrading-to-react-quill-v100) 1. [API reference](#api-reference) 1. [Exports](#exports) 1. [Props](#props) 1. [Methods](#methods) 1. [Browser support](#browser-support) 1. [Building and testing](#building-and-testing) 1. [Bundling with Webpack](#bundling-with-webpack) 1. [Changelog](./CHANGELOG.md) 1. [Contributors](#contributors) 1. [License](#license) --- 💯 **React Quill now supports Quill v1.0.0!** Thanks to @clemmy and @alexkrolick for landing this much-awaited change. There are many breaking changes, so be sure to read the [migration guide](#upgrading-to-react-quill-v100). --- ```sh npm install react-quill yarn add react-quill ``` Special thank you to everyone who contributed during the 1.0.0 release cycle! ## Quick Start ### Import the component ```jsx import ReactQuill from 'react-quill'; // ES6 import * as ReactQuill from 'react-quill'; // Typescript const ReactQuill = require('react-quill'); // CommonJS ``` ### Import the stylesheet _Two common examples are shown below. How stylesheets are included in your app depends on build system (Webpack, SCSS, LESS, etc). See the documentation on [Themes](#theme) for more information._ #### Fetching styles from the CDN ```html ``` #### Using `css-loader` with Webpack or `create-react-app` ```jsx require('react-quill/dist/quill.snow.css'); // CommonJS import 'react-quill/dist/quill.snow.css'; // ES6 ``` ### Use the component ```jsx class MyComponent extends React.Component { constructor(props) { super(props) this.state = { text: '' } // You can also pass a Quill Delta here this.handleChange = this.handleChange.bind(this) } handleChange(value) { this.setState({ text: value }) } render() { return ( ) } } ``` ### Using Deltas You can pass a [Quill Delta](https://quilljs.com/docs/delta/), instead of an HTML string, as the `value` and `defaultValue` properties. Deltas have a number of advantages over HTML strings, so you might want use them instead. Be aware, however, that comparing Deltas for changes is more expensive than comparing HTML strings, so it might be worth to profile your usage patterns. Note that switching `value` from an HTML string to a Delta, or vice-versa, will trigger a change, regardless of whether they represent the same document, so you might want to stick to a format and keep using it consistently throughout. ⚠️ Do not use the `delta` object you receive from the `onChange` event as `value`. This object does not contain the full document, but only the last modifications, and doing so will most likely trigger an infinite loop where the same changes are applied over and over again. Use `editor.getContents()` during the event to obtain a Delta of the full document instead. ReactQuill will prevent you from making such a mistake, however if you are absolutely sure that this is what you want, you can pass the object through `new Delta()` again to un-taint it. ### Controlled vs Uncontrolled Mode Pass `defaultValue` instead of `value` if you need to use DOM or [Quill API](https://quilljs.com/docs/api/)s to imperatively manipulate the editor state. In this "uncontrolled" mode ReactQuill uses the prop as the initial value but allows the element to deviate after that. The `onChange` callback still works normally. - Read more about uncontrolled components in the [React docs][defaultvalues]. - Read more about the available [props](#props). [defaultvalues]: https://facebook.github.io/react/docs/uncontrolled-components.html#default-values ## Options ### Theme The Quill editor supports [themes](http://quilljs.com/docs/themes/). It includes a full-fledged theme, called _snow_, that is Quill's standard appearance, a _bubble_ theme that is similar to the inline editor on Medium, and a _core_ theme containing only the bare essentials to allow modules like toolbars or tooltips to work. These stylesheets can be found in the Quill distribution, but for convenience they are also linked in React Quill's `dist` folder. In a common case you would activate a theme by setting the theme [prop](#props). Pass a falsy value (`null`) to disable the theme. ```jsx // or "bubble", null to use minimal core theme ``` And then link the appropriate stylesheet (only link the CSS for the themes you want to use): ```html ``` This may vary depending how application is structured, directories or otherwise. For example, if you use a CSS pre-processor like SASS, you may want to import that stylesheet inside your own. ### Custom Toolbar #### Default Toolbar Elements The [Quill Toolbar Module](http://quilljs.com/docs/modules/toolbar/) API provides an easy way to configure the default toolbar icons using an array of format names.
Example Code ```jsx var MyComponent = React.createClass({ modules: { toolbar: [ [{ 'header': [1, 2, false] }], ['bold', 'italic', 'underline','strike', 'blockquote'], [{'list': 'ordered'}, {'list': 'bullet'}, {'indent': '-1'}, {'indent': '+1'}], ['link', 'image'], ['clean'] ], }, formats: [ 'header', 'bold', 'italic', 'underline', 'strike', 'blockquote', 'list', 'bullet', 'indent', 'link', 'image' ], render: function() { return (
); }, }); ```
#### HTML Toolbar You can also supply your own HTML/JSX toolbar with custom elements that are not part of the Quill theme. See this example live on Codepen: [Custom Toolbar Example](https://codepen.io/alexkrolick/pen/gmroPj?editors=0010)
Example Code ```jsx /* * Custom "star" icon for the toolbar using an Octicon * https://octicons.github.io */ const CustomButton = () => /* * Event handler to be attached using Quill toolbar module * http://quilljs.com/docs/modules/toolbar/ */ function insertStar () { const cursorPosition = this.quill.getSelection().index this.quill.insertText(cursorPosition, "★") this.quill.setSelection(cursorPosition + 1) } /* * Custom toolbar component including insertStar button and dropdowns */ const CustomToolbar = () => (
) /* * Editor component with custom toolbar and content containers */ class Editor extends React.Component { constructor (props) { super(props) this.state = { editorHtml: '' } this.handleChange = this.handleChange.bind(this) } handleChange (html) { this.setState({ editorHtml: html }); } render() { return (
) } } /* * Quill modules to attach to editor * See http://quilljs.com/docs/modules/ for complete options */ Editor.modules = { toolbar: { container: "#toolbar", handlers: { "insertStar": insertStar, } } } /* * Quill editor formats * See http://quilljs.com/docs/formats/ */ Editor.formats = [ 'header', 'font', 'size', 'bold', 'italic', 'underline', 'strike', 'blockquote', 'list', 'bullet', 'indent', 'link', 'image', 'color', ] /* * PropType validation */ Editor.propTypes = { placeholder: React.PropTypes.string, } /* * Render component on page */ ReactDOM.render( , document.querySelector('.app') ) ```
### Custom Formats The component has two types of formats: 1. The default [Quill formats](http://quilljs.com/docs/formats/) that are enabled/disabled using the [`formats` prop](#props). All formats are enabled by default. 2. Custom formats created using Parchment and registered with your component's Quill instance
Example Code ```js const ReactQuill = require('react-quill'); // CommonJS import ReactQuill, { Quill } from 'react-quill'; // ES6 ``` ```jsx /* * Example Parchment format from * https://quilljs.com/guides/cloning-medium-with-parchment/ * See the video example in the guide for a complex format */ let Inline = Quill.import('blots/inline'); class BoldBlot extends Inline { } BoldBlot.blotName = 'bold'; BoldBlot.tagName = 'strong'; Quill.register('formats/bold', BoldBlot); const formats = ["bold"] // add custom format name + any built-in formats you need /* * Editor component with default and custom formats */ class MyComponent extends React.Component { constructor(props) { this.formats = formats this.state = { text: '' } } handleChange(value) { this.setState({text: value}) } render() { return ( ) } } ```
### Custom editing area If you instantiate ReactQuill without children, it will create a `
` for you, to be used as the editing area for Quill. If you prefer, you can specify your own element for ReactQuill to use. Note that `