1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2 | var _excluded = ["className", "cssModule", "tag", "innerRef"];
|
3 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
5 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
6 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
7 | function _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); } }
|
8 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
9 | function _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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
10 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
11 | 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); }; }
|
12 | function _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); }
|
13 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
14 | 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; } }
|
15 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
16 | import React, { Component } from 'react';
|
17 | import PropTypes from 'prop-types';
|
18 | import { mapToCssModules, tagPropType } from './utils';
|
19 | var propTypes = {
|
20 | children: PropTypes.node,
|
21 | tag: tagPropType,
|
22 | innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
|
23 | className: PropTypes.string,
|
24 | cssModule: PropTypes.object
|
25 | };
|
26 | var Form = function (_Component) {
|
27 | _inherits(Form, _Component);
|
28 | var _super = _createSuper(Form);
|
29 | function Form(props) {
|
30 | var _this;
|
31 | _classCallCheck(this, Form);
|
32 | _this = _super.call(this, props);
|
33 | _this.getRef = _this.getRef.bind(_assertThisInitialized(_this));
|
34 | _this.submit = _this.submit.bind(_assertThisInitialized(_this));
|
35 | return _this;
|
36 | }
|
37 | _createClass(Form, [{
|
38 | key: "getRef",
|
39 | value: function getRef(ref) {
|
40 | if (this.props.innerRef) {
|
41 | this.props.innerRef(ref);
|
42 | }
|
43 | this.ref = ref;
|
44 | }
|
45 | }, {
|
46 | key: "submit",
|
47 | value: function submit() {
|
48 | if (this.ref) {
|
49 | this.ref.submit();
|
50 | }
|
51 | }
|
52 | }, {
|
53 | key: "render",
|
54 | value: function render() {
|
55 | var _this$props = this.props,
|
56 | className = _this$props.className,
|
57 | cssModule = _this$props.cssModule,
|
58 | _this$props$tag = _this$props.tag,
|
59 | Tag = _this$props$tag === void 0 ? 'form' : _this$props$tag,
|
60 | innerRef = _this$props.innerRef,
|
61 | attributes = _objectWithoutProperties(_this$props, _excluded);
|
62 | var classes = mapToCssModules(className, cssModule);
|
63 | return React.createElement(Tag, _extends({}, attributes, {
|
64 | ref: innerRef,
|
65 | className: classes
|
66 | }));
|
67 | }
|
68 | }]);
|
69 | return Form;
|
70 | }(Component);
|
71 | Form.propTypes = propTypes;
|
72 | export default Form; |
\ | No newline at end of file |