1 | import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
2 | import _extends from "@babel/runtime/helpers/extends";
|
3 | import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
4 | import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
5 | import _createClass from "@babel/runtime/helpers/createClass";
|
6 | import _inherits from "@babel/runtime/helpers/inherits";
|
7 | import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
8 | import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
9 |
|
10 | function _createSuper(Derived) {
|
11 | function isNativeReflectConstruct() {
|
12 | if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
13 | if (Reflect.construct.sham) return false;
|
14 | if (typeof Proxy === "function") return true;
|
15 |
|
16 | try {
|
17 | Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
18 | return true;
|
19 | } catch (e) {
|
20 | return false;
|
21 | }
|
22 | }
|
23 |
|
24 | return function () {
|
25 | var Super = _getPrototypeOf(Derived),
|
26 | result;
|
27 |
|
28 | if (isNativeReflectConstruct()) {
|
29 | var NewTarget = _getPrototypeOf(this).constructor;
|
30 |
|
31 | result = Reflect.construct(Super, arguments, NewTarget);
|
32 | } else {
|
33 | result = Super.apply(this, arguments);
|
34 | }
|
35 |
|
36 | return _possibleConstructorReturn(this, result);
|
37 | };
|
38 | }
|
39 |
|
40 | import React, { Component } from 'react';
|
41 | import PropTypes from 'prop-types';
|
42 | import classNames from 'classnames';
|
43 | import omit from 'lodash/omit';
|
44 | import warning from '../_util/warning';
|
45 | import FormItem from './FormItem';
|
46 | import { FIELD_DATA_PROP, FIELD_META_PROP } from './constants';
|
47 | import { createFormField } from '../rc-components/form';
|
48 | import createDOMForm from '../rc-components/form/createDOMForm';
|
49 | import PureRenderMixin from '../rc-components/util/PureRenderMixin';
|
50 | import { FormLayout } from './enum';
|
51 | import { getPrefixCls } from '../configure';
|
52 |
|
53 | var Form =
|
54 |
|
55 | function (_Component) {
|
56 | _inherits(Form, _Component);
|
57 |
|
58 | var _super = _createSuper(Form);
|
59 |
|
60 | function Form(props) {
|
61 | var _this;
|
62 |
|
63 | _classCallCheck(this, Form);
|
64 |
|
65 | _this = _super.call(this, props);
|
66 | warning(!props.form, 'It is unnecessary to pass `form` to `Form`');
|
67 | return _this;
|
68 | }
|
69 |
|
70 | _createClass(Form, [{
|
71 | key: "shouldComponentUpdate",
|
72 | value: function shouldComponentUpdate() {
|
73 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
74 | args[_key] = arguments[_key];
|
75 | }
|
76 |
|
77 | return PureRenderMixin.shouldComponentUpdate.apply(this, args);
|
78 | }
|
79 | }, {
|
80 | key: "getChildContext",
|
81 | value: function getChildContext() {
|
82 | var layout = this.props.layout;
|
83 | return {
|
84 | vertical: layout === 'vertical'
|
85 | };
|
86 | }
|
87 | }, {
|
88 | key: "render",
|
89 | value: function render() {
|
90 | var _classNames;
|
91 |
|
92 | var _this$props = this.props,
|
93 | customizePrefixCls = _this$props.prefixCls,
|
94 | hideRequiredMark = _this$props.hideRequiredMark,
|
95 | _this$props$className = _this$props.className,
|
96 | className = _this$props$className === void 0 ? '' : _this$props$className,
|
97 | layout = _this$props.layout;
|
98 | var prefixCls = getPrefixCls('form', customizePrefixCls);
|
99 | var formClassName = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(layout), layout), _defineProperty(_classNames, "".concat(prefixCls, "-hide-required-mark"), hideRequiredMark), _classNames), className);
|
100 | var formProps = omit(this.props, ['prefixCls', 'className', 'layout', 'form', 'hideRequiredMark']);
|
101 | return React.createElement("form", _extends({}, formProps, {
|
102 | className: formClassName
|
103 | }));
|
104 | }
|
105 | }]);
|
106 |
|
107 | return Form;
|
108 | }(Component);
|
109 |
|
110 | export { Form as default };
|
111 | Form.displayName = 'Form';
|
112 | Form.defaultProps = {
|
113 | layout: FormLayout.horizontal,
|
114 | hideRequiredMark: false,
|
115 | onSubmit: function onSubmit(e) {
|
116 | e.preventDefault();
|
117 | }
|
118 | };
|
119 | Form.propTypes = {
|
120 | prefixCls: PropTypes.string,
|
121 | layout: PropTypes.oneOf([FormLayout.horizontal, FormLayout.inline, FormLayout.vertical]),
|
122 | children: PropTypes.any,
|
123 | onSubmit: PropTypes.func,
|
124 | hideRequiredMark: PropTypes.bool
|
125 | };
|
126 | Form.childContextTypes = {
|
127 | vertical: PropTypes.bool
|
128 | };
|
129 | Form.Item = FormItem;
|
130 | Form.createFormField = createFormField;
|
131 |
|
132 | Form.create = function () {
|
133 | var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
134 | return createDOMForm(_objectSpread({
|
135 | fieldNameProp: 'id'
|
136 | }, options, {
|
137 | fieldMetaProp: FIELD_META_PROP,
|
138 | fieldDataProp: FIELD_DATA_PROP
|
139 | }));
|
140 | };
|
141 |
|