Renders the Quill Editor and returns its content on change.
id: 5, // unique ID for each block (and so also for each EditorQuill)
data: {
value: '<p>Hello World. <b>This is bold.</b></p>' // can be html or plain text
}
The Toolbar (see Custom Toolbar Docu) is handled by the Component itself but can be replaced by the User (see Customization).
The Editor Quill provides a snow
(see more here) and core
theme
(enables customization).
In order to display only numbers on each list-level of the order list, one has
to add the following code to the styles.scss
:
.ql-editor ol {
@for $i from 1 through 8 {
li.ql-indent-#{$i} {
&:before {
content: counter(list-#{$i}, decimal) '.' // eg. 1. instead of a.
}
}
}
}
One can customize the toolbar
component and other behavioural aspects of the
EditorQuill
component. All that is needed is a property called blockConfig
.
props.blockConfig = {
placeholderText: 'Enter text...',
... // see a list of more available properties below
}
The following data properties are allowed and can be used:
icons
: customize the icons quill renders for the format buttons (eg. forql-bold
)onBlur
,onFocus
,onKeyPress
,onKeyDown
,onKeyUp
: event listenersplaceholderText
: will overwrite the placeholder text when the editor is emptyscrollingContainer
: DOM Element or a CSS selector for a DOM Element, specifying which container has the scrollbars. Read more about it here and heretoolbar
: custom Toolbar componenttoolbarCallback
: this callback allows the developer to use a callback to get data from the custom Toolbar to the LovelyEditor (eg. onClick on a custom button in the custom Toolbar)toolbarSelector
: css selector of the new Toolbar component (tells Quill to use it)theme
: supports eithersnow
orcore
(Docs). Usecore
to customize the theme of the Editor. An example can be found in the Storybook with Font-Awesome icons.
import { EditorQuill } from './'
const exampleBlock = {
id: 5,
data: {
value: '<p>Hello World. <b>This is bold.</b></p>'
},
}
const blockConfig = {
theme: 'snow'
}
<EditorQuill
block={exampleBlock}
blockConfig={blockConfig}
onChange={this.onChange}
/>
The following example illustrates how to replace the button icons with FontAwesome ones. There are more formats available, beside the ones illustrated below.
import { EditorQuill } from './'
const exampleBlock = {
id: 5,
data: {
value: '<p>Hello World. <b>This is bold.</b></p>'
},
}
const blockConfig = {
icons: {
bold: '<i class="fa fa-bold" aria-hidden="true"></i>',
italic: '<i class="fa fa-italic" aria-hidden="true"></i>',
underline: '<i class="fa fa-underline" aria-hidden="true"></i>',
list: {
bullet: '<i class="fa fa-list-ul"></i>',
ordered: '<i class="fa fa-list-ol"></i>',
},
indent: {
'+1': '<i class="fa fa-indent" aria-hidden="true"></i>',
'-1': '<i class="fa fa-indent fa-rotate-180" style="padding-top: 2px;" />'
}
},
}
<EditorQuill
block={exampleBlock}
blockConfig={blockConfig}
onChange={this.onChange}
/>
Usually the toolbar of quill is handled by the itself, but one can decide to overwrite it and render a custom toolbar instead.
Attention: One needs to take care of applying the correct classNames (eg. ql-bold) for buttons, selects and other action items in the custom Toolbar. Only then will Quill recognize them as such.
The current implementation level of the customization allows only to replace the UI basically, but no deep integration in custom Toolbar actions are available (eg. custom formatting). One can add additional buttons (eg. Close-Button for the Block) which are not related to the Editor per se.
import { EditorQuill } from './'
const customQuillToolbar = (props) => {
const onClick = () => {
props.onToolbarClick('customQuillToolbar >> Toolbar clicked')
}
return (
<div className="ql-toolbar" id="customToolbar" >
<select className="ql-header" defaultValue="">
<option value="1" />
<option value="2" />
<option value="3" />
<option value="" />
</select>
<button onClick={onClick}>Click Me</button>
</div>
)
}
class Wrapper extends React.Component {
onToolbarAction(toolbarAction) {
// do something...
}
render() {
const exampleBlock = {
id: 5,
data: {
value: '<p>Hello World. <b>This is bold.</b></p>'
},
}
const blockConfig = {
toolbar: customQuillToolbar,
toolbarCallback: this.onToolbarAction,
toolbarSelector: '#customToolbar'
}
return (
<EditorQuill
block={exampleBlock}
blockConfig={blockConfig}
onChange={this.onChange}
/>
)
}
}
The Quill component can import html content (eg. <p><b>Hello World</b></p>
).
Quill is able to import a delta, html or plain text.
- Word
- (Basic) Copy & Paste Support
- not all Word-Styles can be imported and processed by Quill
- Pages
- (Basic) Copy & Paste Support
- Some Headings-Formates (like Title, Headings) are not processed as such. They are imported as bold text.
- PDF
- (Basic) Copy & Paste Support
- Some Headings-Formates (like Title, Headings) are not processed as such. They are imported as bold text.
Images are not supported by now and stripped away by not allowing the images
format. Read more here.
Quill handles nested lists differently. Imaging you import a list like this one:
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
Quill will import and handle it further on like this:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li class="ql-indent-1">Black tea</li>
<li class="ql-indent-1">Green tea</li>
<li>Milk </li>
</ul>
The Component emits changes to the Editor with the Help of Lodash's
debounce
feature. Lodash creates a debounced function that delays
invoking onChange
until after wait
milliseconds have elapsed since the last
time the debounced function was invoked. Currently this is set to 300ms. We wait
for max 1000ms before the delayed onChange
is invoked.
- React-Quill (1.1.0) and Android: One cannot add new empty lines to an Editor
with existing content, when the last chars have
strong
styling. Additionally, the cursor jumps to a new line, when there is more content after<strong>
-paragraph.- Issue Reports: React-Quill
import { EditorQuill } from './'
const exampleBlock = {
id: 5,
data: {
value: '<p>Hello World. <b>This is bold.</b></p>'
},
}
<EditorQuill
block={exampleBlock}
onChange={this.onChange}
/>
Custom Dropdown Examples (but with snow styling)
- https://quannt.github.io/programming/javascript/2017/05/11/adding-custom-toolbar-react-quill.html
- https://alan.fyi/create-custom-style-dropdowns-on-quill/
How to customize the Dropdown (with examples)
- react-quill: customize dropdown with custom values and styling: zenoamaro/react-quill#182
- example: change values dynamically in dropdown: https://codepen.io/anon/pen/dWyzvV
- register custom toolbar icons: slab/quill#1099
- example: https://codepen.io/anon/pen/NbWJGb
How to write custom modules
- https://quilljs.com/guides/how-to-customize-quill/
- https://quilljs.com/guides/building-a-custom-module/
- custom toolbar with custom handler: https://jsfiddle.net/natterstefan/p6eqmsx3/