FontBackgroundColorPlugin: Control background color with background-color styleFontColorPlugin: Control font color with color styleFontFamilyPlugin: Change font family using inline elements with font-family styleFontSizePlugin: Control font size with CSS class or font-size styleFontWeightPlugin: Control font weight with font-weight styleThe fastest way to add font styling functionality is with the FontKit, which includes pre-configured font plugins with their Plate UI components.
'use client';
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from '@platejs/basic-styles/react';
export const FontKit = [
FontColorPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: 'black',
},
},
}),
FontBackgroundColorPlugin,
FontSizePlugin,
FontFamilyPlugin,
];'use client';
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from '@platejs/basic-styles/react';
export const FontKit = [
FontColorPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: 'black',
},
},
}),
FontBackgroundColorPlugin,
FontSizePlugin,
FontFamilyPlugin,
];FontColorPlugin, FontBackgroundColorPlugin, FontSizePlugin, FontFamilyPlugin) with sensible defaults.Add the kit to your plugins:
import { createPlateEditor } from "platejs/react";
import { FontKit } from "@/components/editor/font";
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...FontKit,
],
});import { createPlateEditor } from "platejs/react";
import { FontKit } from "@/components/editor/font";
const editor = createPlateEditor({
Include the font plugins in your Plate plugins array when creating the editor.
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from "@platejs/basic-styles/react";
import { createPlateEditor } from "platejs/react";
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
FontColorPlugin,
FontBackgroundColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
],
});import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
} from "@platejs/basic-styles/react";
import { createPlateEditor } from "platejs/react";
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
FontColorPlugin,
FontBackgroundColorPlugin,
FontFamilyPlugin,
FontSizePlugin,
],
});Font plugins register string-valued text marks, so they follow the selected text instead of a block target list. Configure render props only when your UI needs a different default.
import { FontColorPlugin } from "@platejs/basic-styles/react";
import { createPlateEditor } from "platejs/react";
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
FontColorPlugin.configure({
inject: {
nodeProps: {
defaultNodeValue: "currentColor",
},
},
}),
],
});
FontColorPlugin defaults to black. HTML parsers read font styles directly
onto text properties; block target injection does not constrain text marks.
You can add FontColorToolbarButton and FontSizeToolbarButton to your Toolbar to control font color and size.
Plugin for font background color formatting. Applies background-color style to selected text.
Plugin for font color formatting. Applies color style to selected text.
Plugin for font family formatting. Applies font-family style to selected text.
Plugin for font size formatting. Applies font-size style to selected text.
Plugin for font weight formatting. Applies font-weight style to selected text.
Set the font background color mark on the selected text.
Set the font color mark on the selected text.
Set the font family mark on the selected text.
Set the font size mark on the selected text.
Set the font weight mark on the selected text.
Convert a font size value to a unitless value.