UNPKG

fastlion-amis

Version:

一种MIS页面生成工具

76 lines (75 loc) 4.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberInput = void 0; var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importDefault)(require("react")); // @ts-ignore var rc_input_number_1 = (0, tslib_1.__importDefault)(require("rc-input-number")); var theme_1 = require("../theme"); var helper_1 = require("../utils/helper"); var NumberInput = /** @class */ (function (_super) { (0, tslib_1.__extends)(NumberInput, _super); // Jay function NumberInput(props) { var _this = _super.call(this, props) || this; _this.handleChange = function (value) { var _a = _this.props, min = _a.min, max = _a.max, onChange = _a.onChange; if (typeof value === 'number') { if (typeof min === 'number') { value = Math.max(value, min); } if (typeof max === 'number') { value = Math.min(value, max); } } _this.setState({ value: value }); onChange === null || onChange === void 0 ? void 0 : onChange(value); }; _this.state = { value: props.value }; return _this; } NumberInput.prototype.componentDidUpdate = function () { if (this.state.value !== this.props.value) { this.setState({ value: this.props.value }); } }; NumberInput.prototype.render = function () { var _a; var _this = this; var _b = this.props, className = _b.className, ns = _b.classPrefix, cx = _b.classnames, value = _b.value, step = _b.step, precision = _b.precision, max = _b.max, min = _b.min, disabled = _b.disabled, placeholder = _b.placeholder, onChange = _b.onChange, showSteps = _b.showSteps, formatter = _b.formatter, parser = _b.parser, borderMode = _b.borderMode, readOnly = _b.readOnly; var precisionProps = {}; if (typeof precision === 'number') { precisionProps.precision = precision; } return (react_1.default.createElement(rc_input_number_1.default, (0, tslib_1.__assign)({ className: cx(className, showSteps === false ? 'no-steps' : '', (_a = {}, _a["Number--border" + (0, helper_1.ucFirst)(borderMode)] = borderMode, _a)), "col-index": this.props.colIndex, readOnly: readOnly, prefixCls: ns + "Number", style: { textAlign: 'inherit', width: '100%' }, // value={value} // Jay 优化性能 value: this.state.value, step: step, max: max || 9999999999999.99, name: this.props.name, min: min, keyboard: this.props.keyboard || false, formatter: formatter, parser: parser, onChange: this.handleChange, disabled: disabled, onKeyDown: this.props.onKeyDown, placeholder: placeholder, onBlur: this.props.onBlur, onFocus: this.props.onFocus, inputMode: "decimal" }, precisionProps, { onInput: function (text) { var _a, _b, _c, _d; var isNaN = Number(text) !== Number(text); if (isNaN || text === '') { (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, text); } else if (typeof max === 'number' || typeof min === "number") { // 输入超过范围的数值的过程中也会校验 var v = Number(text); if ((max && v > max) || (min && v < min)) { (_d = (_c = _this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, v); } } } }))); }; NumberInput.defaultProps = { step: 1, readOnly: false, borderMode: 'full' }; return NumberInput; }(react_1.default.Component)); exports.NumberInput = NumberInput; exports.default = (0, theme_1.themeable)(NumberInput); //# sourceMappingURL=./components/NumberInput.js.map