-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathshortcut.js
70 lines (64 loc) · 1.67 KB
/
shortcut.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* External dependencies
*/
import { castArray } from 'lodash';
/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import { displayShortcutList, shortcutAriaLabel } from '@wordpress/keycodes';
function KeyCombination( { keyCombination, forceAriaLabel } ) {
const shortcut = keyCombination.modifier
? displayShortcutList[ keyCombination.modifier ](
keyCombination.character
)
: keyCombination.character;
const ariaLabel = keyCombination.modifier
? shortcutAriaLabel[ keyCombination.modifier ](
keyCombination.character
)
: keyCombination.character;
return (
<kbd
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key-combination"
aria-label={ forceAriaLabel || ariaLabel }
>
{ castArray( shortcut ).map( ( character, index ) => {
if ( character === '+' ) {
return <Fragment key={ index }>{ character }</Fragment>;
}
return (
<kbd
key={ index }
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key"
>
{ character }
</kbd>
);
} ) }
</kbd>
);
}
function Shortcut( { description, keyCombination, aliases = [], ariaLabel } ) {
return (
<>
<div className="edit-widgets-keyboard-shortcut-help-modal__shortcut-description">
{ description }
</div>
<div className="edit-widgets-keyboard-shortcut-help-modal__shortcut-term">
<KeyCombination
keyCombination={ keyCombination }
forceAriaLabel={ ariaLabel }
/>
{ aliases.map( ( alias, index ) => (
<KeyCombination
keyCombination={ alias }
forceAriaLabel={ ariaLabel }
key={ index }
/>
) ) }
</div>
</>
);
}
export default Shortcut;