@gechiui/components
Version:
UI components for GeChiUI.
58 lines (51 loc) • 1.19 kB
JavaScript
import { createElement } from "@gechiui/element";
/**
* External dependencies
*/
import { map } from 'lodash';
/**
* GeChiUI dependencies
*/
import { useRef, Children } from '@gechiui/element';
import { useKeyboardShortcut } from '@gechiui/compose';
function KeyboardShortcut(_ref) {
let {
target,
callback,
shortcut,
bindGlobal,
eventName
} = _ref;
useKeyboardShortcut(shortcut, callback, {
bindGlobal,
target,
eventName
});
return null;
}
function KeyboardShortcuts(_ref2) {
let {
children,
shortcuts,
bindGlobal,
eventName
} = _ref2;
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