UNPKG

shineout

Version:

Shein 前端组件库

73 lines (61 loc) 2.39 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import React, { PureComponent } from 'react'; import Input from './Input'; var DefaultValue = { value: '', point: '•' }; var Password = /*#__PURE__*/ function (_PureComponent) { _inheritsLoose(Password, _PureComponent); function Password(props) { var _this; _this = _PureComponent.call(this, props) || this; _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_assertThisInitialized(_this))); return _this; } var _proto = Password.prototype; _proto.handleChange = function handleChange(val) { var _this$props = this.props, _this$props$value = _this$props.value, value = _this$props$value === void 0 ? DefaultValue.value : _this$props$value, _this$props$point = _this$props.point, point = _this$props$point === void 0 ? DefaultValue.point : _this$props$point, clearToUndefined = _this$props.clearToUndefined; if (val === undefined && clearToUndefined) { this.props.onChange(undefined); return; } var newValue = []; val.split('').forEach(function (v, i) { newValue.push(v === point ? value[i] : v); }); this.props.onChange(newValue.join('')); }; _proto.render = function render() { var _this$props2 = this.props, _this$props2$point = _this$props2.point, point = _this$props2$point === void 0 ? DefaultValue.point : _this$props2$point, _this$props2$value = _this$props2.value, value = _this$props2$value === void 0 ? DefaultValue.value : _this$props2$value, others = _objectWithoutPropertiesLoose(_this$props2, ["point", "value"]); var transValue = Array.from({ length: (value || '').length }, function () { return point; }).join(''); return React.createElement(Input, _extends({}, others, { type: "text", value: transValue, onChange: this.handleChange })); }; return Password; }(PureComponent); _defineProperty(Password, "defaultProps", DefaultValue); export default Password;