UNPKG

@nutui/nutui-react-taro

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

224 lines (223 loc) 11.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "NumberKeyboard", { enumerable: true, get: function() { return NumberKeyboard; } }); var _interop_require_default = require("@swc/helpers/_/_interop_require_default"); var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); var _object_spread = require("@swc/helpers/_/_object_spread"); var _object_spread_props = require("@swc/helpers/_/_object_spread_props"); var _object_without_properties = require("@swc/helpers/_/_object_without_properties"); var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array"); var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array"); var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react")); var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames")); var _iconsreacttaro = require("@nutui/icons-react-taro"); var _components = require("@tarojs/components"); var _index = /*#__PURE__*/ _interop_require_default._(require("../popup/index")); var _index1 = require("../configprovider/index"); var _typings = require("../../utils/typings"); var _mergeprops = require("../../utils/merge-props"); var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), { visible: false, rightActions: '', type: 'default', custom: [], random: false, onClose: function onClose() {} }); var NumberKeyboard = function NumberKeyboard(props) { var locale = (0, _index1.useConfig)().locale; var _mergeProps = (0, _mergeprops.mergeProps)(defaultProps, props), title = _mergeProps.title, rightActions = _mergeProps.rightActions, confirmText = _mergeProps.confirmText, visible = _mergeProps.visible, type = _mergeProps.type, custom = _mergeProps.custom, random = _mergeProps.random, style = _mergeProps.style, className = _mergeProps.className, onChange = _mergeProps.onChange, onDelete = _mergeProps.onDelete, onClose = _mergeProps.onClose, onConfirm = _mergeProps.onConfirm, rest = (0, _object_without_properties._)(_mergeProps, [ "title", "rightActions", "confirmText", "visible", "type", "custom", "random", "style", "className", "onChange", "onDelete", "onClose", "onConfirm" ]); var classPrefix = 'nut-numberkeyboard'; var getBasicKeys = function getBasicKeys() { var keys = new Array(9).fill(0).map(function(_, index) { return { id: String(index + 1), type: 'num' }; }); return random ? keys.sort(function() { return Math.random() > 0.5 ? 1 : -1; }) : keys; }; var getCustomKeys = function getCustomKeys() { var customKeys = [ { id: 'close', type: 'close' }, { id: '0', type: 'num' }, { id: 'delete', type: 'delete' } ]; if (!custom) return customKeys; if (custom.length > 0) { customKeys[0] = { id: custom[0], type: 'custom' }; } if (custom.length > 1) { customKeys[2] = { id: custom[1], type: 'custom' }; } return customKeys; }; var keysList = (0, _react.useMemo)(function() { return (0, _to_consumable_array._)(getBasicKeys()).concat((0, _to_consumable_array._)(getCustomKeys())); }, [ type, random, custom ]); var DeleteIcon = function DeleteIcon() { var style = { background: "url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAnCAYAAABJ0cukAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyFpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDE0IDc5LjE1MTQ4MSwgMjAxMy8wMy8xMy0xMjowOToxNSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXN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r1iuENDPi5fDX4WG32WxeogL81NGRIEk3NBNAh10uS9IIY/oIbxR6vd4WLXmJAq9Ayl1kTAUmk8mNyJrUgDfK8hFPV9dnTQSCHiLkO/Ndb8jzrXqKawYJQg4gsu6srKyV4cC/7ujo1CqneRSPxNh74PligPdE3PYVIDHuY6PRWCxPTp7VC35KSvwjwBpwdPP4gXYc86ZdZnr6Pf7S9HqexUs9z0qBLprz8wn+PzWRFknaKGsgjwlvCdLGH42GQ0lg+dqkMP+Enj+lF/yMWYgnJD1qEhhphOWgS2E2yQZDJWa/lEgIvGIa0D2HKJZGA7yiBgaZqO9AermdFstGXQR8fn+BootW4wfPRBE8zXmXoia2SYLgpsJRVwqBBJ2N+pnueRVhPR8l8MGCnaWw8wDCDSWQoasGQCKJnpjGcwkkKqMBfo7ZyQklQCOxWVcRg4QDXmhkSJRjsGvRAD8HCTuNhNPpXKtLzHn9/n0orBqm052GvL2lcfepTMs8PwsJqyRJRbrlNFpBCUBcYWaKE2h4tampqUtV6pP60HNtapuUksTY2NidiLcWUQPnMOhlxvQoITGxxOPxDIVdR2dnb/V2dr7Umn50/Q31261JC4UhUQYSVUxdtPCCUAK10RuvZeQ0LRQ2tD7fddxdyuT3TijJehATF/yinqmJ2wB+jCGRA11TH9xiXAwEQpG4i0gcZHLPjHSqF0Vx76IgEIpEA9a7+3H5K2RK4jnuPvTToXgR0LW9Htpap71iAzPVNsUIMH0XMdXkfLrfD9BdanifksiKW/5w3Emj3mcHBgb6kpKTn6KYzfBCehzg10H6lHPzMdIWq9U8znEpsXE6N4rTO9TjSGgPanG/pfwjwABn1PZcM5XI0AAAAABJRU5ErkJggg0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTkwMjA5MzIyMjIxMzkzMzc2NzAwNjg0MC0tDQo=') no-repeat center", backgroundSize: '100% 100%', width: 28, height: 24 }; return /*#__PURE__*/ _react.default.createElement(_components.View, { style: style }); }; var NumberKeyboardKey = function NumberKeyboardKey(props) { var item = props.item; var _useState = (0, _sliced_to_array._)((0, _react.useState)(false), 2), active = _useState[0], setActive = _useState[1]; var onTouchStart = function onTouchStart() { setActive(true); }; var onTouchEnd = function onTouchEnd(item) { setActive(false); switch(item.type){ case 'num': case 'custom': onChange === null || onChange === void 0 ? void 0 : onChange(item.id); break; case 'close': onClose === null || onClose === void 0 ? void 0 : onClose(); break; case 'delete': onDelete === null || onDelete === void 0 ? void 0 : onDelete(); break; case 'confirm': onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(); break; default: break; } }; var renderContent = function renderContent(item) { switch(item.type){ case 'num': case 'custom': return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, item.id); case 'delete': return /*#__PURE__*/ _react.default.createElement(DeleteIcon, null); case 'close': return /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.ArrowDown, { size: 18 }); case 'confirm': return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, confirmText || locale.done); default: return null; } }; return /*#__PURE__*/ _react.default.createElement(_components.View, { key: item.id, className: "".concat(classPrefix, "-body-wrapper") }, /*#__PURE__*/ _react.default.createElement(_components.View, { className: (0, _classnames.default)({ key: true, active: active, close: item.type === 'close', delete: item.type === 'delete', confirm: item.type === 'confirm' }), onTouchStart: function onTouchStart1() { return onTouchStart(); }, onTouchEnd: function onTouchEnd1() { return onTouchEnd(item); }, onTouchCancel: function onTouchCancel() { return onTouchEnd(item); } }, renderContent(item))); }; return /*#__PURE__*/ _react.default.createElement(_index.default, (0, _object_spread_props._)((0, _object_spread._)({}, rest), { visible: visible, position: "bottom", onOverlayClick: onClose, onCloseIconClick: onClose, zIndex: 9999, style: { minHeight: 0 }, overlayStyle: { backgroundColor: 'rgba(0, 0, 0, 0)' } }), /*#__PURE__*/ _react.default.createElement(_components.View, { className: (0, _classnames.default)(classPrefix, className), style: style }, title && /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-header") }, /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-header-title") }, title), type === 'default' && /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-header-close"), onClick: onConfirm }, rightActions || locale.done)), /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-body") }, /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-body-keys") }, keysList === null || keysList === void 0 ? void 0 : keysList.map(function(item) { return /*#__PURE__*/ _react.default.createElement(NumberKeyboardKey, { key: item.id, item: item }); })), type === 'rightColumn' && /*#__PURE__*/ _react.default.createElement(_components.View, { className: "".concat(classPrefix, "-sidebar") }, /*#__PURE__*/ _react.default.createElement(NumberKeyboardKey, { key: "delete", item: { id: 'delete', type: 'delete' } }), /*#__PURE__*/ _react.default.createElement(NumberKeyboardKey, { key: "confirm", item: { id: 'confirm', type: 'confirm' } }))))); }; NumberKeyboard.displayName = 'NutNumberKeyboard';