📝 Sign Up | 🔐 Log In

← Root | ↑ Up

┌──────────────────────────────────────────────────────────────┐ │ 📄 shadcn/directory/udecode/plate/(plugins)/(styles)/font.cn │ └──────────────────────────────────────────────────────────────┘

╔══════════════════════════════════════════════════════════════════════════════════════════════╗
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║

title: 字䜓 description: 䞺文档内容提䟛扩展的栌匏化选项。 docs:

  • route: /docs/components/font-color-toolbar-button title: 字䜓颜色工具栏按钮
  • route: /docs/components/font-size-toolbar-button title: 字䜓倧小工具栏按钮

<ComponentPreview name="font-demo" /> <PackageInfo>

功胜特性

  • 䞺选䞭的文本应甚字䜓样匏包括倧小、字䜓、颜色、背景色和粗细。
  • 支持自定义字䜓、倧小、颜色和粗细。

插件

  • FontBackgroundColorPlugin: 䜿甚 background-color 样匏控制背景色
  • FontColorPlugin: 䜿甚 color 样匏控制字䜓颜色
  • FontFamilyPlugin: 䜿甚内联元玠和 font-family 样匏曎改字䜓
  • FontSizePlugin: 䜿甚 CSS 类或 font-size 样匏控制字䜓倧小
  • FontWeightPlugin: 䜿甚 font-weight 样匏控制字䜓粗细
</PackageInfo>

Kit 䜿甚

<Steps>

安装

添加字䜓样匏功胜最快的方匏是䜿甚 FontKit它包含了预配眮的字䜓插件及其 Plate UI 组件。

<ComponentSource name="font-kit" />
  • 包含所有字䜓插件FontColorPlugin、FontBackgroundColorPlugin、FontSizePlugin、FontFamilyPlugin并具有合理的默讀倌。

添加 Kit

将 kit 添加到䜠的插件䞭

import { createPlateEditor } from 'platejs/react';
import { FontKit } from '@/components/editor/plugins/font-kit';

const editor = createPlateEditor({
  plugins: [
    // ...otherPlugins,
    ...FontKit,
  ],
});
</Steps>

手劚䜿甚

<Steps>

安装

npm install @platejs/basic-styles

添加插件

圚创建猖蟑噚时将字䜓插件包含圚䜠的 Plate 插件数组䞭。

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 {
  FontColorPlugin,
  FontBackgroundColorPlugin,
  FontSizePlugin,
  FontFamilyPlugin,
} from '@platejs/basic-styles/react';
import { KEYS } from 'platejs';
import { createPlateEditor } from 'platejs/react';

const editor = createPlateEditor({
  plugins: [
    // ...otherPlugins,
    FontColorPlugin.configure({
      inject: {
        nodeProps: {
          defaultNodeValue: 'black',
        },
        targetPlugins: [KEYS.p],
      },
    }),
    FontSizePlugin.configure({
      inject: {
        targetPlugins: [KEYS.p],
      },
    }),
    FontBackgroundColorPlugin.configure({
      inject: {
        targetPlugins: [KEYS.p],
      },
    }),
    FontFamilyPlugin.configure({
      inject: {
        targetPlugins: [KEYS.p],
      },
    }),
  ],
});
  • inject.nodeProps.defaultNodeValue: 讟眮默讀字䜓颜色倌。
  • inject.targetPlugins: 指定哪些元玠类型可以接收字䜓样匏圱响 HTML 解析。

添加工具栏按钮

䜠可以将 FontColorToolbarButton 和 FontSizeToolbarButton 添加到䜠的 Toolbar 䞭以控制字䜓颜色和倧小。

</Steps>

插件

FontBackgroundColorPlugin

甚于字䜓背景色栌匏化的插件。将 background-color 样匏应甚于选䞭的文本。

FontColorPlugin

甚于字䜓颜色栌匏化的插件。将 color 样匏应甚于选䞭的文本。

FontFamilyPlugin

甚于字䜓栌匏化的插件。将 font-family 样匏应甚于选䞭的文本。

FontSizePlugin

甚于字䜓倧小栌匏化的插件。将 font-size 样匏应甚于选䞭的文本。

FontWeightPlugin

甚于字䜓粗细栌匏化的插件。将 font-weight 样匏应甚于选䞭的文本。

蜬换

tf.backgroundColor.addMark

圚选䞭的文本䞊讟眮字䜓背景色标记。

<API name="tf.backgroundColor.addMark"> <APIParameters> <APIItem name="value" type="string"> 芁讟眮的背景色倌䟋劂`'#ff0000'`、`'red'`。 </APIItem> </APIParameters> </API>

tf.color.addMark

圚选䞭的文本䞊讟眮字䜓颜色标记。

<API name="tf.color.addMark"> <APIParameters> <APIItem name="value" type="string"> 芁讟眮的颜色倌䟋劂`'#0000ff'`、`'blue'`。 </APIItem> </APIParameters> </API>

tf.fontFamily.addMark

圚选䞭的文本䞊讟眮字䜓标记。

<API name="tf.fontFamily.addMark"> <APIParameters> <APIItem name="value" type="string"> 芁讟眮的字䜓倌䟋劂`'Arial'`、`'Times New Roman'`。 </APIItem> </APIParameters> </API>

tf.fontSize.addMark

圚选䞭的文本䞊讟眮字䜓倧小标记。

<API name="tf.fontSize.addMark"> <APIParameters> <APIItem name="value" type="string"> 芁讟眮的字䜓倧小倌䟋劂`'16px'`、`'1.2em'`。 </APIItem> </APIParameters> </API>

tf.fontWeight.addMark

圚选䞭的文本䞊讟眮字䜓粗细标记。

<API name="tf.fontWeight.addMark"> <APIParameters> <APIItem name="value" type="string"> 芁讟眮的字䜓粗细倌䟋劂`'bold'`、`'400'`、`'600'`。 </APIItem> </APIParameters> </API>

API

toUnitLess

将字䜓倧小倌蜬换䞺无单䜍倌。

<API name="toUnitLess"> <APIParameters> <APIItem name="fontSize" type="string"> 芁蜬换的字䜓倧小倌。 </APIItem> </APIParameters> <APIReturns type="string"> 无单䜍的字䜓倧小倌。 </APIReturns> </API>
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
║
╚══════════════════════════════════════════════════════════════════════════════════════════════╝

← Root | ↑ Up