UNPKG

@wordpress/edit-post

Version:
58 lines (52 loc) 1.77 kB
import { createElement } from "@wordpress/element"; /** * 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 createElement("kbd", { className: "edit-post-keyboard-shortcut-help-modal__shortcut-key-combination", "aria-label": forceAriaLabel || ariaLabel }, castArray(shortcut).map((character, index) => { if (character === '+') { return createElement(Fragment, { key: index }, character); } return createElement("kbd", { key: index, className: "edit-post-keyboard-shortcut-help-modal__shortcut-key" }, character); })); } function Shortcut({ description, keyCombination, aliases = [], ariaLabel }) { return createElement(Fragment, null, createElement("div", { className: "edit-post-keyboard-shortcut-help-modal__shortcut-description" }, description), createElement("div", { className: "edit-post-keyboard-shortcut-help-modal__shortcut-term" }, createElement(KeyCombination, { keyCombination: keyCombination, forceAriaLabel: ariaLabel }), aliases.map((alias, index) => createElement(KeyCombination, { keyCombination: alias, forceAriaLabel: ariaLabel, key: index })))); } export default Shortcut; //# sourceMappingURL=shortcut.js.map