返回 presentation-ai
font-color-picker-toolbar-button.tsx
根目录 / src / components / plate / ui / font-color-picker-toolbar-button.tsx
1 "use client";
2
3 import { KEYS } from "platejs";
4 import { useEditorRef, useEditorSelector } from "platejs/react";
5
6 import ColorPicker from "@/components/ui/color-picker";
7 import { ToolbarButton } from "./toolbar";
8
9 export function FontColorPickerToolbarButton() {
10 const editor = useEditorRef();
11
12 const color = useEditorSelector(
13 (editor) => (editor.api.mark(KEYS.color) as string) ?? "#000000",
14 [],
15 );
16
17 const handleColorChange = (newColor: string) => {
18 if (editor.selection) {
19 editor.tf.select(editor.selection);
20 editor.tf.focus();
21 editor.tf.addMarks({ [KEYS.color]: newColor });
22 }
23 };
24
25 return (
26 <ColorPicker value={color} onChange={handleColorChange}>
27 <ToolbarButton tooltip="Font color">
28 <div
29 className="size-5 rounded border border-border"
30 style={{ backgroundColor: color }}
31 />
32 </ToolbarButton>
33 </ColorPicker>
34 );
35 }
36
36 lines Plain Text