UNPKG

@wordpress/components

Version:
56 lines (49 loc) 1.14 kB
import { createElement } from "@wordpress/element"; /** * External dependencies */ import { map } from 'lodash'; /** * WordPress dependencies */ import { useRef, Children } from '@wordpress/element'; import { useKeyboardShortcut } from '@wordpress/compose'; function KeyboardShortcut({ target, callback, shortcut, bindGlobal, eventName }) { useKeyboardShortcut(shortcut, callback, { bindGlobal, target, eventName }); return null; } function KeyboardShortcuts({ children, shortcuts, bindGlobal, eventName }) { const target = useRef(); const element = map(shortcuts, (callback, shortcut) => createElement(KeyboardShortcut, { key: shortcut, shortcut: shortcut, callback: callback, bindGlobal: bindGlobal, eventName: eventName, target: target })); // Render as non-visual if there are no children pressed. Keyboard // events will be bound to the document instead. if (!Children.count(children)) { return element; } return createElement("div", { ref: target }, element, children); } export default KeyboardShortcuts; //# sourceMappingURL=index.js.map