UNPKG

@jdcfe/yep-react

Version:

一套移动端的React组件库

103 lines (78 loc) 3.26 kB
import _extends from "@babel/runtime/helpers/extends"; 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; } } 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 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; var Input = /*#__PURE__*/function (_React$PureComponent) { _inherits(Input, _React$PureComponent); var _super = _createSuper(Input); function Input() { var _this; _classCallCheck(this, Input); _this = _super.apply(this, arguments); _this.onInputBlur = function (e) { var value = e.target.value; if (_this.props.onBlur) { _this.props.onBlur(value); } }; _this.onInputFocus = function (e) { var value = e.target.value; if (_this.props.onFocus) { _this.props.onFocus(value); } }; _this.focus = function () { if (_this.inputRef) { _this.inputRef.focus(); } }; _this.onClick = function (e) { var _this$props = _this.props, readOnly = _this$props.readOnly, onClick = _this$props.onClick; if (readOnly) { _this.inputRef.blur(); } if (onClick) { onClick(e); } }; return _this; } _createClass(Input, [{ key: "render", value: function render() { var _this2 = this; var _a = this.props, onBlur = _a.onBlur, onFocus = _a.onFocus, onClick = _a.onClick, restProps = __rest(_a, ["onBlur", "onFocus", "onClick"]); return /*#__PURE__*/React.createElement("input", _extends({}, restProps, { ref: function ref(el) { return _this2.inputRef = el; }, onBlur: this.onInputBlur, onFocus: this.onInputFocus, onClick: this.onClick })); } }]); return Input; }(React.PureComponent); export default Input;