Font
Provide extended formatting options for document content.
components/demo.tsx
'use client';
import React from 'react';
import { Plate } from '@udecode/plate/react';
import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';
import { DEMO_VALUES } from './values/demo-values';
export default function Demo({ id }: { id: string }) {
const editor = useCreateEditor({
plugins: [...editorPlugins],
value: DEMO_VALUES[id],
});
return (
<Plate editor={editor}>
<EditorContainer variant="demo">
<Editor />
</EditorContainer>
</Plate>
);
}
Features
- Font size, family, color, background color, and weight.
Plugins
FontFamilyPlugin
: Change font family using inline elements withfont-family
styleFontSizePlugin
: Control font size with CSS class orfont-size
styleFontColorPlugin
: Control font color withcolor
styleFontBackgroundColorPlugin
: Control background color withbackground-color
styleFontWeightPlugin
: Control font weight withfont-weight
style
Installation
npm install @udecode/plate-font
Usage
import {
FontBackgroundColorPlugin,
FontColorPlugin,
FontSizePlugin,
} from '@udecode/plate-font/react';
const plugins = [
// ...otherPlugins,
FontColorPlugin,
FontBackgroundColorPlugin,
FontSizePlugin,
];
Plugins
FontBackgroundColorPlugin
Plugin for font background color formatting.
FontColorPlugin
Plugin for font color formatting.
FontFamilyPlugin
Plugin for font family formatting.
FontSizePlugin
Plugin for font size formatting.
API
editor.api.fontSize.setMark
Utils
toUnitLess
FontWeightPlugin
Plugin for font weight formatting.