-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathundo.js
40 lines (37 loc) · 1.22 KB
/
undo.js
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
34
35
36
37
38
39
40
/**
* WordPress dependencies
*/
import { __, isRTL } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { displayShortcut } from '@wordpress/keycodes';
import { undo as undoIcon, redo as redoIcon } from '@wordpress/icons';
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
function EditorHistoryUndo( props, ref ) {
const hasUndo = useSelect(
( select ) => select( editorStore ).hasEditorUndo(),
[]
);
const { undo } = useDispatch( editorStore );
return (
<Button
{ ...props }
ref={ ref }
icon={ ! isRTL() ? undoIcon : redoIcon }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Undo' ) }
shortcut={ displayShortcut.primary( 'z' ) }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
aria-disabled={ ! hasUndo }
onClick={ hasUndo ? undo : undefined }
className="editor-history__undo"
/>
);
}
export default forwardRef( EditorHistoryUndo );