UNPKG

antd-mini

Version:

antd-mini 是支付宝小程序 UI 组件库,遵循 Ant Design 规范。

76 lines (75 loc) 2.35 kB
import { effect } from '@preact/signals-core'; import mixinValue from '../mixins/value'; import { ComponentWithSignalStoreImpl, getValueFromProps, triggerEvent, } from '../_util/simply'; import i18nController from '../_util/store'; import { InputDefaultProps } from './props'; import { formatNumberWithLimits, isNumber } from './utils'; ComponentWithSignalStoreImpl({ store: function () { return i18nController; }, updateHook: effect, mapState: { locale: function (_a) { var store = _a.store; return store.currentLocale.value; }, }, }, InputDefaultProps, { onChange: function (e) { var value = e.detail.value; if (!this.isControlled()) { this.update(value); } triggerEvent(this, 'change', value, e); }, onFocus: function (e) { var value = e.detail.value; this.setData({ selfFocus: true, }); triggerEvent(this, 'focus', value, e); }, onBlur: function (e) { var value = e.detail.value; this.setData({ selfFocus: false, }); var val = this.checkNumberValue(value); if (val !== null) { if (val !== value && !this.isControlled()) { this.update(val); } value = val; } console.log('onBlur', value); triggerEvent(this, 'blur', value, e); }, onConfirm: function (e) { var value = e.detail.value; triggerEvent(this, 'confirm', value, e); }, onClear: function (e) { if (!this.isControlled()) { this.update(''); } triggerEvent(this, 'change', '', e); }, checkNumberValue: function (value) { var _a = getValueFromProps(this, [ 'type', 'max', 'min', 'precision', ]), type = _a[0], max = _a[1], min = _a[2], precision = _a[3]; var NUMBER_KEYBOARD = ['number', 'digit', 'numberpad', 'digitpad']; if (NUMBER_KEYBOARD.indexOf(type) !== -1 && isNumber(value)) { return formatNumberWithLimits(value, max, min, precision); } return null; }, }, { selfFocus: false, }, [mixinValue({ scopeKey: 'state' })], { attached: function () { this.triggerEvent('ref', this); }, });