| 1 | "use client"; |
| 2 | |
| 3 | import { Redo2Icon, Undo2Icon } from "lucide-react"; |
| 4 | import { useEditorRef, useEditorSelector } from "platejs/react"; |
| 5 | import type * as React from "react"; |
| 6 | |
| 7 | import { ToolbarButton } from "./toolbar"; |
| 8 | |
| 9 | export function RedoToolbarButton( |
| 10 | props: React.ComponentProps<typeof ToolbarButton>, |
| 11 | ) { |
| 12 | const editor = useEditorRef(); |
| 13 | const disabled = useEditorSelector( |
| 14 | (editor) => editor.history.redos.length === 0, |
| 15 | [], |
| 16 | ); |
| 17 | |
| 18 | return ( |
| 19 | <ToolbarButton |
| 20 | {...props} |
| 21 | disabled={disabled} |
| 22 | onClick={() => editor.redo()} |
| 23 | onMouseDown={(e) => e.preventDefault()} |
| 24 | tooltip="Redo" |
| 25 | > |
| 26 | <Redo2Icon /> |
| 27 | </ToolbarButton> |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | export function UndoToolbarButton( |
| 32 | props: React.ComponentProps<typeof ToolbarButton>, |
| 33 | ) { |
| 34 | const editor = useEditorRef(); |
| 35 | const disabled = useEditorSelector( |
| 36 | (editor) => editor.history.undos.length === 0, |
| 37 | [], |
| 38 | ); |
| 39 | |
| 40 | return ( |
| 41 | <ToolbarButton |
| 42 | {...props} |
| 43 | disabled={disabled} |
| 44 | onClick={() => editor.undo()} |
| 45 | onMouseDown={(e) => e.preventDefault()} |
| 46 | tooltip="Undo" |
| 47 | > |
| 48 | <Undo2Icon /> |
| 49 | </ToolbarButton> |
| 50 | ); |
| 51 | } |
| 52 |