UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

47 lines (46 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Keys = void 0; exports.isKeyCode = isKeyCode; /** * Dictionary contains popular key codes * * It should use with `code` property with native event, * but usually it will work with `key` property of react synthetic event */ var Keys = exports.Keys = { // Control ENTER: ['Enter', 'NumpadEnter'], SPACE: 'Space', ESC: 'Escape', // Navigation TAB: 'Tab', UP: 'ArrowUp', DOWN: 'ArrowDown', LEFT: 'ArrowLeft', RIGHT: 'ArrowRight', HOME: 'Home', END: 'End', PAGE_UP: 'PageUp', PAGE_DOWN: 'PageDown', // Other CAPS_LOCK: 'CapsLock' }; /** * Check key code to match * * It useful to abstract from real key codes and replace it to constants * * @example * isKeyCode(event.code, [Keys.ESC, Keys.ENTER]) * * @param code Key code. * @param keys List of keys as numbers or strings. */ function isKeyCode(code, keys) { return Array.isArray(keys) ? keys.some(function (value) { return isKeyCode(code, value); }) : keys === code; }