āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/udecode/plate/(plugins)/(styles)/text-align ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
title: Text Align docs:
align prop into targeted block elements.The fastest way to add text alignment functionality is with the AlignKit, which includes pre-configured TextAlignPlugin targeting paragraph, heading, image, and media elements.
Paragraph, Heading, Image, and Media elements to support the align property.start, left, center, right, end, justify.Add the kit to your plugins:
import { createPlateEditor } from 'platejs/react';
import { AlignKit } from '@/components/editor/plugins/align-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...AlignKit,
],
});
</Steps>
npm install @platejs/basic-styles
Include TextAlignPlugin in your Plate plugins array when creating the editor.
import { TextAlignPlugin } from '@platejs/basic-styles/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
TextAlignPlugin,
],
});
You can configure the TextAlignPlugin to target specific elements and define alignment options.
import { TextAlignPlugin } from '@platejs/basic-styles/react';
import { KEYS } from 'platejs';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
TextAlignPlugin.configure({
inject: {
nodeProps: {
nodeKey: 'align',
defaultNodeValue: 'start',
styleKey: 'textAlign',
validNodeValues: ['start', 'left', 'center', 'right', 'end', 'justify'],
},
targetPlugins: [...KEYS.heading, KEYS.p],
},
}),
],
});
inject.nodeProps.nodeKey: The property name injected into target elements (align by default). Set to 'textAlign' if you prefer that prop name.inject.nodeProps.defaultNodeValue: Sets the default alignment (start).inject.nodeProps.styleKey: Maps the injected prop to the CSS textAlign property.inject.nodeProps.validNodeValues: Defines valid alignment values for UI controls.inject.targetPlugins: An array of plugin keys indicating which element types will receive the alignment prop.You can add AlignToolbarButton to your Toolbar to control text alignment.
TextAlignPluginPlugin for aligning text within block elements. It injects an align prop into the elements specified by inject.targetPlugins.
tf.textAlign.setNodesSets the alignment for the selected block nodes that are configured as targets for this plugin.
<API name="tf.textAlign.setNodes"> <APIParameters> <APIItem name="value" type="string"> The alignment value (e.g., `'left'`, `'center'`, `'right'`, `'justify'`). </APIItem> <APIItem name="options" type="SetNodesOptions" optional> Options for the `setNodes` function. </APIItem> </APIParameters> </API>ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā