UNPKG

8.09 kBJavaScriptView Raw
1function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
3function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
5function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
7function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
9function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
11function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
12
13function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
14
15function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
17function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
18
19function _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); }; }
20
21function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
22
23function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
24
25function _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; } }
26
27function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
29import * as React from 'react';
30import classNames from 'classnames';
31import createDOMForm from "rc-form/es/createDOMForm";
32import createFormField from "rc-form/es/createFormField";
33import omit from 'omit.js';
34import { tuple } from '../_util/types';
35import warning from '../_util/warning';
36import FormItem from './FormItem';
37import { FIELD_META_PROP, FIELD_DATA_PROP } from './constants';
38import FormContext from './context';
39import upgradeMessage from '../_util/upgradeMessage';
40import CompatibleConsumer from '../CompatibleConsumer';
41var FormLayouts = tuple('horizontal', 'inline', 'vertical');
42
43var Form = /*#__PURE__*/function (_React$Component) {
44 _inherits(Form, _React$Component);
45
46 var _super = _createSuper(Form);
47
48 function Form(props) {
49 var _this;
50
51 _classCallCheck(this, Form);
52
53 _this = _super.call(this, props);
54
55 _this.renderForm = function (_ref) {
56 var _classNames;
57
58 var getPrefixCls = _ref.getPrefixCls;
59 var _this$props = _this.props,
60 customizePrefixCls = _this$props.prefixCls,
61 hideRequiredMark = _this$props.hideRequiredMark,
62 _this$props$className = _this$props.className,
63 className = _this$props$className === void 0 ? '' : _this$props$className,
64 layout = _this$props.layout;
65 var prefixCls = getPrefixCls('legacy-form', customizePrefixCls);
66 var formClassName = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-horizontal"), layout === 'horizontal'), _defineProperty(_classNames, "".concat(prefixCls, "-vertical"), layout === 'vertical'), _defineProperty(_classNames, "".concat(prefixCls, "-inline"), layout === 'inline'), _defineProperty(_classNames, "".concat(prefixCls, "-hide-required-mark"), hideRequiredMark), _classNames), className);
67 var formProps = omit(_this.props, ['prefixCls', 'className', 'layout', 'form', 'hideRequiredMark', 'wrapperCol', 'labelAlign', 'labelCol', 'colon']);
68 return /*#__PURE__*/React.createElement("form", _objectSpread(_objectSpread({}, formProps), {}, {
69 className: formClassName
70 }));
71 };
72
73 warning(!props.form, 'Form', 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.');
74 upgradeMessage('Form');
75 return _this;
76 }
77
78 _createClass(Form, [{
79 key: "componentDidMount",
80 value: function componentDidMount() {
81 try {
82 warning(getComputedStyle(document.querySelector('.ant-col'), null).getPropertyValue('position') === 'relative', 'Form', 'If missing `Grid` style, you should import it, Please follow https://github.com/ant-design/compatible#faq.');
83 } catch (error) {
84 warning(false, 'Form', error);
85 }
86 }
87 }, {
88 key: "render",
89 value: function render() {
90 var _this$props2 = this.props,
91 wrapperCol = _this$props2.wrapperCol,
92 labelAlign = _this$props2.labelAlign,
93 labelCol = _this$props2.labelCol,
94 layout = _this$props2.layout,
95 colon = _this$props2.colon;
96 return /*#__PURE__*/React.createElement(FormContext.Provider, {
97 value: {
98 wrapperCol: wrapperCol,
99 labelAlign: labelAlign,
100 labelCol: labelCol,
101 vertical: layout === 'vertical',
102 colon: colon
103 }
104 }, /*#__PURE__*/React.createElement(CompatibleConsumer, null, this.renderForm));
105 }
106 }]);
107
108 return Form;
109}(React.Component);
110
111Form.defaultProps = {
112 colon: true,
113 layout: 'horizontal',
114 hideRequiredMark: false,
115 onSubmit: function onSubmit(e) {
116 e.preventDefault();
117 }
118};
119Form.Item = FormItem;
120Form.createFormField = createFormField;
121
122Form.create = function create() {
123 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
124 return createDOMForm(_objectSpread(_objectSpread({
125 fieldNameProp: 'id'
126 }, options), {}, {
127 fieldMetaProp: FIELD_META_PROP,
128 fieldDataProp: FIELD_DATA_PROP
129 }));
130};
131
132export { Form as default };
\No newline at end of file