返回 presentation-ai
print-toolbar-button.tsx
根目录 / src / components / plate / ui / print-toolbar-button.tsx
1 "use client";
2
3 import { PrinterIcon } from "lucide-react";
4 import { useEditorRef } from "platejs/react";
5
6 import { printEditorElement } from "@/lib/print-editor";
7 import { ToolbarButton } from "./toolbar";
8
9 export function PrintToolbarButton() {
10 const editor = useEditorRef();
11
12 return (
13 <ToolbarButton
14 tooltip="Print"
15 onClick={() => {
16 const editorNode = editor.api.toDOMNode(editor);
17 const printTarget =
18 editorNode?.closest<HTMLElement>(
19 "[data-print-editor-surface='true']",
20 ) ?? editorNode;
21
22 if (!printTarget) {
23 return;
24 }
25
26 printEditorElement(printTarget);
27 }}
28 >
29 <PrinterIcon className="size-4" />
30 </ToolbarButton>
31 );
32 }
33
33 lines Plain Text