UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

101 lines (87 loc) 3.98 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import * as React from 'react'; import classNames from 'classnames'; import { suffixPx } from '../_utils/styleUtil'; var PasswordInput = /*#__PURE__*/function (_React$PureComponent) { _inherits(PasswordInput, _React$PureComponent); var _super = _createSuper(PasswordInput); function PasswordInput(props) { _classCallCheck(this, PasswordInput); return _super.call(this, props); } _createClass(PasswordInput, [{ key: "renderMessage", value: function renderMessage() { var _this$props = this.props, prefixCls = _this$props.prefixCls, message = _this$props.message; return /*#__PURE__*/React.createElement("div", { className: "".concat(prefixCls, "-message") }, message); } }, { key: "render", value: function render() { var _this$props2 = this.props, prefixCls = _this$props2.prefixCls, className = _this$props2.className, value = _this$props2.value, _this$props2$length = _this$props2.length, length = _this$props2$length === void 0 ? 6 : _this$props2$length, mask = _this$props2.mask, gutter = _this$props2.gutter, onFocus = _this$props2.onFocus, name = _this$props2.name; var containerCls = classNames(prefixCls, className); var ulCls = classNames("".concat(prefixCls, "-ul"), _defineProperty({}, "".concat(prefixCls, "-hairline-surround"), !gutter)); var points = []; var valueArray = String(value).split(''); for (var i = 0; i < length; i++) { var _char = valueArray[i]; var liCls = classNames(_defineProperty({}, "".concat(prefixCls, "-hairline-left"), i !== 0 && !gutter), "".concat(prefixCls, "-li")); var style = void 0; if (i !== 0 && gutter) { style = { marginLeft: suffixPx(gutter) }; } points.push( /*#__PURE__*/React.createElement("li", { className: liCls, style: style, key: "".concat(prefixCls, "-li-").concat(i) }, mask ? /*#__PURE__*/React.createElement("i", { style: { visibility: _char ? 'visible' : 'hidden' } }) : _char)); } return /*#__PURE__*/React.createElement("div", { className: containerCls }, /*#__PURE__*/React.createElement("ul", { className: ulCls, onClick: function onClick(e) { e.stopPropagation(); onFocus && onFocus(name); } }, points), this.renderMessage()); } }]); return PasswordInput; }(React.PureComponent); export { PasswordInput as default }; PasswordInput.defaultProps = { prefixCls: 'Yep-password-input', style: {}, name: 'default', value: '', length: 6, mask: true, gutter: 0 };