-
Notifications
You must be signed in to change notification settings - Fork 471
/
Copy pathindex.tsx
33 lines (28 loc) · 872 Bytes
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React, { useEffect } from 'react';
import { UndoOutlined as UndoIcon } from '@mui/icons-material';
import { IconButton, Tooltip } from '@mui/material';
import { undo, useCanUndo } from '../../../documents/editor/EditorContext';
export default function Undo() {
const canUndo = useCanUndo();
useEffect(() => {
function handle(event: KeyboardEvent) {
if (event.ctrlKey && event.key.toLowerCase() === 'z') {
event.preventDefault();
undo();
}
}
document.addEventListener('keydown', handle);
return () => document.removeEventListener('keydown', handle);
}, []);
return (
<>
<Tooltip title="Undo (Ctrl + Z)">
<span>
<IconButton onClick={undo} disabled={canUndo === false}>
<UndoIcon fontSize="small" />
</IconButton>
</span>
</Tooltip>
</>
);
}