choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
141 lines (122 loc) • 4.68 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _extends from "@babel/runtime/helpers/extends";
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) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import omit from 'lodash/omit';
import warning from '../_util/warning';
import FormItem from './FormItem';
import { FIELD_DATA_PROP, FIELD_META_PROP } from './constants';
import { createFormField } from '../rc-components/form';
import createDOMForm from '../rc-components/form/createDOMForm';
import PureRenderMixin from '../rc-components/util/PureRenderMixin';
import { FormLayout } from './enum';
import ConfigContext from '../config-provider/ConfigContext';
import { FormContextProvider } from './FormContext';
var Form =
/*#__PURE__*/
function (_Component) {
_inherits(Form, _Component);
var _super = _createSuper(Form);
function Form(props) {
var _this;
_classCallCheck(this, Form);
_this = _super.call(this, props);
warning(!props.form, 'It is unnecessary to pass `form` to `Form`');
return _this;
}
_createClass(Form, [{
key: "shouldComponentUpdate",
value: function shouldComponentUpdate() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
}
}, {
key: "render",
value: function render() {
var _classNames;
var _this$props = this.props,
customizePrefixCls = _this$props.prefixCls,
hideRequiredMark = _this$props.hideRequiredMark,
_this$props$className = _this$props.className,
className = _this$props$className === void 0 ? '' : _this$props$className,
layout = _this$props.layout;
var getPrefixCls = this.context.getPrefixCls;
var prefixCls = getPrefixCls('form', customizePrefixCls);
var formClassName = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(layout), layout), _defineProperty(_classNames, "".concat(prefixCls, "-hide-required-mark"), hideRequiredMark), _classNames), className);
var formProps = omit(this.props, ['prefixCls', 'className', 'layout', 'form', 'hideRequiredMark']);
return React.createElement(FormContextProvider, {
vertical: layout === 'vertical',
getPrefixCls: getPrefixCls
}, React.createElement("form", _extends({}, formProps, {
className: formClassName
})));
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return Form;
}(Component);
export { Form as default };
Form.displayName = 'Form';
Form.defaultProps = {
layout: FormLayout.horizontal,
hideRequiredMark: false,
onSubmit: function onSubmit(e) {
e.preventDefault();
}
};
Form.propTypes = {
prefixCls: PropTypes.string,
layout: PropTypes.oneOf([FormLayout.horizontal, FormLayout.inline, FormLayout.vertical]),
children: PropTypes.any,
onSubmit: PropTypes.func,
hideRequiredMark: PropTypes.bool
};
Form.Item = FormItem;
Form.createFormField = createFormField;
Form.create = function () {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return createDOMForm(_objectSpread({
fieldNameProp: 'id'
}, options, {
fieldMetaProp: FIELD_META_PROP,
fieldDataProp: FIELD_DATA_PROP
}));
};
//# sourceMappingURL=Form.js.map