antd-mobile
Version:
基于 React 的移动设计规范实现
169 lines (154 loc) • 6.87 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
}return t;
};
import React from 'react';
import classNames from 'classnames';
import Touchable from 'rc-touchable';
export var KeyboardItem = function (_React$Component) {
_inherits(KeyboardItem, _React$Component);
function KeyboardItem() {
_classCallCheck(this, KeyboardItem);
return _possibleConstructorReturn(this, (KeyboardItem.__proto__ || Object.getPrototypeOf(KeyboardItem)).apply(this, arguments));
}
_createClass(KeyboardItem, [{
key: 'render',
value: function render() {
var _wrapCls;
var _a = this.props,
prefixCls = _a.prefixCls,
_onClick = _a.onClick,
className = _a.className,
disabled = _a.disabled,
children = _a.children,
restProps = __rest(_a, ["prefixCls", "onClick", "className", "disabled", "children"]);
var value = children;
if (className === 'keyboard-delete') {
value = 'delete';
} else if (className === 'keyboard-hide') {
value = 'hide';
} else if (className === 'keyboard-confirm') {
value = 'confirm';
}
var wrapCls = (_wrapCls = {}, _defineProperty(_wrapCls, className, className), _defineProperty(_wrapCls, prefixCls + '-item', true), _defineProperty(_wrapCls, prefixCls + '-item-disabled', disabled), _wrapCls);
return React.createElement(
Touchable,
{ activeClassName: prefixCls + '-item-active' },
React.createElement(
'td',
_extends({ onClick: function onClick(e) {
_onClick(e, value);
}, className: classNames(wrapCls) }, restProps),
children
)
);
}
}]);
return KeyboardItem;
}(React.Component);
KeyboardItem.defaultProps = {
prefixCls: 'am-number-keyboard',
onClick: function onClick() {},
disabled: false
};
var CustomKeyboard = function (_React$Component2) {
_inherits(CustomKeyboard, _React$Component2);
function CustomKeyboard() {
_classCallCheck(this, CustomKeyboard);
var _this2 = _possibleConstructorReturn(this, (CustomKeyboard.__proto__ || Object.getPrototypeOf(CustomKeyboard)).apply(this, arguments));
_this2.onKeyboardClick = function (e, value) {
e.nativeEvent.stopImmediatePropagation();
var confirmDisabled = _this2.props.confirmDisabled;
if (value === 'confirm' && confirmDisabled) {
return null;
} else {
_this2.props.onClick(value);
}
};
_this2.renderKetboardItem = function (item, index) {
return React.createElement(
KeyboardItem,
{ onClick: _this2.onKeyboardClick, key: 'item-' + item + '-' + index },
item
);
};
return _this2;
}
_createClass(CustomKeyboard, [{
key: 'render',
value: function render() {
var _classNames,
_this3 = this;
var _props = this.props,
prefixCls = _props.prefixCls,
confirmDisabled = _props.confirmDisabled,
hide = _props.hide,
confirmLabel = _props.confirmLabel;
var wrapperCls = classNames((_classNames = {}, _defineProperty(_classNames, prefixCls + '-wrapper', true), _defineProperty(_classNames, prefixCls + '-wrapper-hide', hide), _classNames));
return React.createElement(
'div',
{ className: wrapperCls },
React.createElement(
'table',
null,
React.createElement(
'tbody',
null,
React.createElement(
'tr',
null,
['1', '2', '3'].map(function (item, index) {
return _this3.renderKetboardItem(item, index);
}),
React.createElement(KeyboardItem, { className: 'keyboard-delete', rowSpan: 2, onClick: this.onKeyboardClick })
),
React.createElement(
'tr',
null,
['4', '5', '6'].map(function (item, index) {
return _this3.renderKetboardItem(item, index);
})
),
React.createElement(
'tr',
null,
['7', '8', '9'].map(function (item, index) {
return _this3.renderKetboardItem(item, index);
}),
React.createElement(
KeyboardItem,
{ className: 'keyboard-confirm', disabled: confirmDisabled, rowSpan: 2, onClick: this.onKeyboardClick },
confirmLabel
)
),
React.createElement(
'tr',
null,
['.', '0'].map(function (item, index) {
return _this3.renderKetboardItem(item, index);
}),
React.createElement(KeyboardItem, { className: 'keyboard-hide', onClick: this.onKeyboardClick })
)
)
)
);
}
}]);
return CustomKeyboard;
}(React.Component);
CustomKeyboard.defaultProps = {
prefixCls: 'am-number-keyboard',
onClick: function onClick() {},
confirmDisabled: false
};
export default CustomKeyboard;