UNPKG

@open-tender/store

Version:

A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API

39 lines (38 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var react_1 = require("react"); var hooks_1 = require("../app/hooks"); var slices_1 = require("../slices"); var utils_1 = require("../utils"); var Keypad = function (_a) { var children = _a.children, maxLength = _a.maxLength, type = _a.type, value = _a.value, handlers = _a.handlers, isEmail = _a.isEmail, _b = _a.autoCapitalize, autoCapitalize = _b === void 0 ? false : _b; var _c = (0, hooks_1.useAppSelector)(slices_1.selectKioskConfig), keypad = _c.keypad, numpad = _c.numpad; var isDollar = type === 'dollar'; var config = type === 'numeric' || isDollar ? numpad : keypad; var _d = (0, react_1.useState)(autoCapitalize), isShiftOn = _d[0], setIsShiftOn = _d[1]; var handleOnKeyPress = (0, react_1.useCallback)(function (key) { var isShiftKey = key === '\u21E7'; if (isShiftKey) { setIsShiftOn(function (prev) { return !prev; }); return; } var newValue = (0, utils_1.getKeyboardValue)(key, value, maxLength, isShiftOn); handlers.change(newValue); if (autoCapitalize) { setIsShiftOn(newValue.length === 0); } }, [handlers, value, maxLength, isShiftOn, autoCapitalize]); var viewHandlers = (0, react_1.useMemo)(function () { return ({ keyPress: handleOnKeyPress }); }, [handleOnKeyPress]); if (!config) return null; return children({ config: config, handlers: viewHandlers, value: value, type: type, isEmail: isEmail, isShiftOn: isShiftOn, autoCapitalize: autoCapitalize }); }; exports.default = Keypad;