UNPKG

6.11 kBJavaScriptView Raw
1function _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); }
2var _excluded = ["className", "cssModule", "tag", "innerRef"];
3function _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); }
4function _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; }
5function _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; }
6function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7function _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); } }
8function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9function _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); }
10function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11function _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); }; }
12function _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); }
13function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14function _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; } }
15function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16import React, { Component } from 'react';
17import PropTypes from 'prop-types';
18import { mapToCssModules, tagPropType } from './utils';
19var 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};
26var Form = /*#__PURE__*/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 /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
64 ref: innerRef,
65 className: classes
66 }));
67 }
68 }]);
69 return Form;
70}(Component);
71Form.propTypes = propTypes;
72export default Form;
\No newline at end of file