Text styling extension for TipTap rich text editor providing color, background, font family, font size, and line height capabilities.
—
The TextStyleKit is a convenience extension that bundles all text styling extensions together, providing a simple way to add comprehensive text styling capabilities to a TipTap editor.
Bundle extension that includes all text styling extensions (TextStyle, Color, BackgroundColor, FontFamily, FontSize, LineHeight) with individual configuration options.
/**
* Bundle extension containing all text styling capabilities
* Automatically configures and includes all styling extensions
*/
const TextStyleKit: Extension<TextStyleKitOptions>;
interface TextStyleKitOptions {
/** BackgroundColor extension config or false to disable */
backgroundColor: Partial<BackgroundColorOptions> | false;
/** Color extension config or false to disable */
color: Partial<ColorOptions> | false;
/** FontFamily extension config or false to disable */
fontFamily: Partial<FontFamilyOptions> | false;
/** FontSize extension config or false to disable */
fontSize: Partial<FontSizeOptions> | false;
/** LineHeight extension config or false to disable */
lineHeight: Partial<LineHeightOptions> | false;
/** TextStyle mark config or false to disable (not recommended) */
textStyle: Partial<TextStyleOptions> | false;
}Usage Example:
import { Editor } from "@tiptap/core";
import { TextStyleKit } from "@tiptap/extension-text-style/text-style-kit";
const editor = new Editor({
extensions: [
TextStyleKit.configure({
// All extensions enabled with default options
backgroundColor: {},
color: {},
fontFamily: {},
fontSize: {},
lineHeight: {},
textStyle: {}
})
]
});Enable all text styling capabilities with default settings:
import { TextStyleKit } from "@tiptap/extension-text-style/text-style-kit";
const editor = new Editor({
extensions: [
TextStyleKit.configure({
backgroundColor: {},
color: {},
fontFamily: {},
fontSize: {},
lineHeight: {},
textStyle: {}
})
]
});
// All commands are now available
editor.commands.setColor("#ff0000");
editor.commands.setBackgroundColor("#ffff00");
editor.commands.setFontFamily("Arial");
editor.commands.setFontSize("18px");
editor.commands.setLineHeight("1.5");Enable only specific styling capabilities:
const editor = new Editor({
extensions: [
TextStyleKit.configure({
// Enable only color and font styling
color: {},
fontFamily: {},
fontSize: {},
textStyle: {}, // Always include for foundation
// Disable background and line height
backgroundColor: false,
lineHeight: false
})
]
});
// Only color, font family, and font size commands available
editor.commands.setColor("#0066cc");
editor.commands.setFontFamily("Georgia");
editor.commands.setFontSize("16px");
// These commands would not be available:
// editor.commands.setBackgroundColor(); // Not available
// editor.commands.setLineHeight(); // Not availableConfigure individual extensions with custom options:
const editor = new Editor({
extensions: [
TextStyleKit.configure({
// Configure color for headings and paragraphs
color: {
types: ['textStyle', 'heading', 'paragraph']
},
// Configure background color for textStyle only
backgroundColor: {
types: ['textStyle']
},
// Standard font configuration
fontFamily: {},
fontSize: {},
lineHeight: {},
// TextStyle with custom HTML attributes
textStyle: {
HTMLAttributes: {
class: 'custom-text-style'
},
mergeNestedSpanStyles: true
}
})
]
});For basic text styling needs:
const editor = new Editor({
extensions: [
TextStyleKit.configure({
// Just color and basic styling
color: {},
textStyle: {},
// Disable other features
backgroundColor: false,
fontFamily: false,
fontSize: false,
lineHeight: false
})
]
});When TextStyleKit is configured, all enabled extension commands become available:
editor.commands.setColor(color: string);
editor.commands.unsetColor();editor.commands.setBackgroundColor(backgroundColor: string);
editor.commands.unsetBackgroundColor();editor.commands.setFontFamily(fontFamily: string);
editor.commands.unsetFontFamily();editor.commands.setFontSize(fontSize: string);
editor.commands.unsetFontSize();editor.commands.setLineHeight(lineHeight: string);
editor.commands.unsetLineHeight();editor.commands.toggleTextStyle(attributes?: TextStyleAttributes);
editor.commands.removeEmptyTextStyle();All enabled commands can be chained together:
// Apply multiple styles at once
editor.chain()
.setColor("#333333")
.setBackgroundColor("#f5f5f5")
.setFontFamily("Georgia")
.setFontSize("18px")
.setLineHeight("1.6")
.run();
// Remove all styling
editor.chain()
.unsetColor()
.unsetBackgroundColor()
.unsetFontFamily()
.unsetFontSize()
.unsetLineHeight()
.removeEmptyTextStyle()
.run();The TextStyleKit works by:
import { TextStyleKit } from "@tiptap/extension-text-style/text-style-kit";
const editor = new Editor({
extensions: [
TextStyleKit.configure({
color: {},
fontFamily: {},
fontSize: {}
})
]
});import { TextStyle } from "@tiptap/extension-text-style/text-style";
import { Color } from "@tiptap/extension-text-style/color";
import { FontFamily } from "@tiptap/extension-text-style/font-family";
import { FontSize } from "@tiptap/extension-text-style/font-size";
const editor = new Editor({
extensions: [
TextStyle,
Color,
FontFamily,
FontSize
]
});Both approaches are equivalent, but TextStyleKit provides more convenient configuration and ensures proper dependencies are included.
Install with Tessl CLI
npx tessl i tessl/npm-tiptap--extension-text-style