Color β
The Color extension allows you to add text color to your editor with support for custom colors, keyboard shortcuts, and synchronized color selection across toolbar and bubble menu.
- Based on TipTap's Color extension. @tiptap/extension-text-style
Usage β
import { Color } from 'reactjs-tiptap-editor/color';
const extensions = [
...,
// Import Extensions Here
Color,
// or with configuration
Color.configure({
colors: COLORS_LIST,
defaultColor: '#000000',
}),
];Features β
- π¨ Rich Color Palette: Choose from a wide range of predefined colors
- β¨οΈ Keyboard Shortcuts: Quick color application with
Mod-Shift-C - π Smart Toggle: Intelligent color toggling and replacement
- π― Synchronized Selection: Color picker syncs between toolbar and bubble menu
- π¨ Custom Colors: Add custom colors via color picker
- πΎ Recent Colors: Automatically tracks recently used colors
Options β
colors β
Type: string[]
Default: undefined
An array of color options to display in the color picker. If not provided, a default set of colors will be used.
import { COLORS_LIST } from 'reactjs-tiptap-editor'
Color.configure({
colors: COLORS_LIST,
// or custom colors
colors: ['#FF0000', '#00FF00', '#0000FF', '#FFFF00'],
})defaultColor β
Type: string
Default: undefined
The default color to use when the extension is initialized. This color will be used when applying color via keyboard shortcut for the first time.
import { DEFAULT_COLOR } from 'reactjs-tiptap-editor'
Color.configure({
defaultColor: DEFAULT_COLOR,
// or
defaultColor: '#000000',
})shortcutKeys β
Type: string[]
Default: ['β§', 'mod', 'C']
Keyboard shortcuts for applying the color. Default is Mod-Shift-C (Ctrl-Shift-C on Windows/Linux, Cmd-Shift-C on Mac).
Color.configure({
shortcutKeys: ['β§', 'mod', 'C'],
})Keyboard Shortcut Behavior β
The Mod-Shift-C keyboard shortcut has intelligent toggle behavior:
- No color applied: Applies the currently selected color
- Same color already applied: Removes the color (toggle off)
- Different color applied: Replaces with the currently selected color
- "No Fill" selected: Does nothing (prevents applying undefined color)
Color Selection Synchronization β
The extension maintains a shared color state across all instances:
- Selecting a color in the toolbar updates the bubble menu
- Selecting a color in the bubble menu updates the toolbar
- Keyboard shortcut uses the last selected color
- All color pickers show the same selected color
Examples β
Basic Usage β
import { Color } from 'reactjs-tiptap-editor/color';
const extensions = [
Color,
];With Custom Colors β
import { Color, COLORS_LIST } from 'reactjs-tiptap-editor';
const extensions = [
Color.configure({
colors: [
...COLORS_LIST,
'#FF69B4', // Hot Pink
'#8A2BE2', // Blue Violet
],
defaultColor: '#000000',
}),
];Programmatic Usage β
// Apply color
editor.chain().focus().setColor('#FF0000').run();
// Remove color
editor.chain().focus().unsetColor().run();
// Check if color is active
const isColorActive = editor.isActive('textStyle', { color: '#FF0000' });
// Get current color
const { color } = editor.getAttributes('textStyle');
Hung Hoang
Condor Hero