The Quill rich-text editor as a React component.
npm install react-quill-2React-Quill  

==============================================================================
A [Quill] component for [React].
See a [live demo] or Codepen.
[Quill]: https://quilljs.com
[React]: https://facebook.github.io/react/
[live demo]: https://zenoamaro.github.io/react-quill/
1. Quick start
1. Import the component
1. Import the stylesheet
1. Use the component
1. Using Deltas
1. Controlled vs Uncontrolled Mode
1. Options
1. Theme
1. Custom Toolbar
1. Custom Formats
1. Custom Editing Area
1. Mixin
1. Upgrading to React-Quill v1.0.0
1. API reference
1. Exports
1. Props
1. Methods
1. Browser support
1. Building and testing
1. Bundling with Webpack
1. Changelog
1. Contributors
1. 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.
---
``sh`
npm install react-quill
yarn add react-quill
Special thank you to everyone who contributed during the 1.0.0 release cycle!
`jsx`
import ReactQuill from 'react-quill'; // ES6
import * as ReactQuill from 'react-quill'; // Typescript
const ReactQuill = require('react-quill'); // CommonJS
_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 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
`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 (
)
}
}
`
You can pass a Quill 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.
Pass defaultValue instead of value if you need to use DOM or Quill APIs to imperatively manipulate the editor state.onChange
In this "uncontrolled" mode ReactQuill uses the prop as the initial value but allows the element to deviate after that. The callback still works normally.
- Read more about uncontrolled components in the [React docs][defaultvalues].
- Read more about the available props.
[defaultvalues]: https://facebook.github.io/react/docs/uncontrolled-components.html#default-values
The Quill editor supports 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. Pass a falsy value (null) to disable the theme.
`jsx`
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.
#### Default Toolbar Elements
The Quill Toolbar Module API provides an easy way to configure the default toolbar icons using an array of format names.
Example Code
`jsx
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {
text: "",
}
}
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() {
return (
export default MyComponent;
`
#### 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
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')
)
`
The component has two types of formats:
1. The default Quill formats that are enabled/disabled using the formats prop. 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 (
onChange={this.handleChange}
formats={this.formats}
/>
)
}
}
`
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