Rich text editor
Tiptap based rich text editor
Source
Docs
Package
License
Installation
Install with yarn:
After installation import package styles at the root of your application:
TipTap editor
@mantine/tiptap
provides a UI for Tiptap. RichTextEditor
component
works with Editor instance of tiptap.
This means that you have full control over the editor state and configuration
with useEditor hook.
In other words, RichTextEditor
component does not manage state for you,
controls just execute operations on the Editor
instance. If you want to
implement something that is related to state or component value (e.g. controlled mode, value transforms to HTML/Markdown),
you should look for documentation on tiptap.dev website.
Usage
Subtle variant
variant="subtle"
removes borders from the controls groups, makes controls
larger and reduces spacing of the toolbar:
Controlled
To control editor state, create a wrapper component and pass onChange
handler
to useEditor
hook:
Controls and extensions
Some controls require installation of additional Tiptap extensions.
For example, if you want to use RichTextEditor.Underline
control, you will need to install @tiptap/extension-underline
package:
Included with @tiptap/starter-kit
(should be installed by default):
RichTextEditor.H1
RichTextEditor.H2
RichTextEditor.H3
RichTextEditor.H4
RichTextEditor.H5
RichTextEditor.H6
RichTextEditor.BulletList
RichTextEditor.OrderedList
RichTextEditor.Bold
RichTextEditor.Italic
RichTextEditor.Strikethrough
RichTextEditor.ClearFormatting
RichTextEditor.Blockquote
RichTextEditor.Code
RichTextEditor.CodeBlock
RichTextEditor.Hr
RichTextEditor.Undo
RichTextEditor.Redo
Controls that require @tiptap/extension-link extension:
RichTextEditor.Link
RichTextEditor.Unlink
Controls that require @tiptap/extension-text-align extension:
RichTextEditor.AlignLeft
RichTextEditor.AlignRight
RichTextEditor.AlignCenter
RichTextEditor.AlignJustify
Controls that require @tiptap/extension-color and @tiptap/extension-text-style extensions:
RichTextEditor.ColorPicker
RichTextEditor.Color
RichTextEditor.UnsetColor
Other controls with required extensions:
RichTextEditor.Underline
requires @tiptap/extension-underlineRichTextEditor.Superscript
requires @tiptap/extension-superscriptRichTextEditor.Subscript
requires @tiptap/extension-subscriptRichTextEditor.Highlight
requires @tiptap/extension-highlight
Placeholder
To use placeholder you will need to install @tiptap/extension-placeholder package:
Link extension
@mantine/tiptap
provides custom Link
extension that is required to be used instead of
@tiptap/extension-link
in order for Ctrl + K
keyboard shortcut to work:
Text color
To use text color you will need to install additional packages:
You can use the following controls to change text color:
RichTextEditor.ColorPicker
– allows to pick colors from given predefined color swatches and with ColorPicker componentRichTextEditor.Color
– allows to apply given color with one clickRichTextEditor.UnsetColor
– clears color styles
Code highlight
To use code highlight you will need to install additional packages:
Tasks
To use tasks you will need to install additional packages:
Typography styles
By default, RichTextEditor
renders content with TypographyStylesProvider and some additional styles.
You can disable these styles by setting withTypographyStyles={false}
:
Then you will be able to add your own styles either with global styles or with Styles API:
Bubble menu
You can use BubbleMenu component
with any RichTextEditor
controls. Bubble menu will appear near a selection of text:
Floating menu
You can use FloatingMenu component
with any RichTextEditor
controls. Floating menu will appear in an empty line:
Sticky toolbar
Set sticky
prop on RichTextEditor.Toolbar
component to make toolbar sticky,
control top
property with stickyOffset
. For example, on mantine.dev documentation
website there is a header with 60px
height (converted to rem), in this case we will need to
set stickyOffset={60}
to make sticky position correctly with fixed positioned element.
Editor context
Use useRichTextEditorContext
hook to get Editor from
the context. This hook can be used to create custom control or run any operations supported
by the Tiptap editor API.
Custom controls
Use RichTextEditor.Control
component to create custom controls. It supports all
props supported by button
element and has active
prop to indicate active state.
Note that you will need to set aria-label
attribute to make control visible for screen readers.
Change icons
You can change icon of control by setting icon
prop. It accepts a component
that must handle size
prop:
Labels and localization
RichTextEditor
supports changing labels for all controls with labels
prop:
Most labels are used to add aria-label
and title
attributes to controls, some of the labels
can be a function that returns string. If you do not provide all labels, then they will be merged with
the default labels.
All available labels:
Default labels (can be imported from @mantine/tiptap
package):