UNPKG

shineout

Version:

Shein 前端组件库

76 lines (61 loc) 2.05 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import * as React from 'react'; import shallowEqual from '../utils/shallowEqual'; var Field = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(Field, _React$Component); function Field(props) { var _this; _this = _React$Component.call(this, props) || this; _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_assertThisInitialized(_this))); // this.cacheChildren = undefined // this.cacheElement = null return _this; } var _proto = Field.prototype; _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { var options = this.props.cache ? { skip: ['children'] } : {}; return !shallowEqual(this.props, nextProps, options); }; _proto.handleChange = function handleChange(value) { if (value && value.nativeEvent) { // eslint-disable-next-line value = value.target.value; } this.props.onChange(value); }; _proto.render = function render() { var _this$props = this.props, children = _this$props.children, value = _this$props.value, error = _this$props.error, disabled = _this$props.disabled; if (typeof children === 'function') { return children({ value: value, error: error, onChange: this.handleChange, disabled: disabled }); } if (React.isValidElement(children)) { return React.cloneElement(children, { value: value, error: error, onChange: this.handleChange, disabled: disabled || children.props && children.props.disabled }); } console.error(new Error('Form.Field expect a single ReactElement or a function.')); return null; }; return Field; }(React.Component); _defineProperty(Field, "defaultProps", { cache: false }); export default Field;