UNPKG

1.04 kBJavaScriptView Raw
1import React, { Component } from 'react';
2import PropTypes from 'prop-types';
3import { mapToCssModules, tagPropType } from './utils';
4
5const propTypes = {
6 children: PropTypes.node,
7 tag: tagPropType,
8 innerRef: PropTypes.oneOfType([
9 PropTypes.object,
10 PropTypes.func,
11 PropTypes.string,
12 ]),
13 className: PropTypes.string,
14 cssModule: PropTypes.object,
15};
16
17class Form extends Component {
18 constructor(props) {
19 super(props);
20 this.getRef = this.getRef.bind(this);
21 this.submit = this.submit.bind(this);
22 }
23
24 getRef(ref) {
25 if (this.props.innerRef) {
26 this.props.innerRef(ref);
27 }
28 this.ref = ref;
29 }
30
31 submit() {
32 if (this.ref) {
33 this.ref.submit();
34 }
35 }
36
37 render() {
38 const {
39 className,
40 cssModule,
41 tag: Tag = 'form',
42 innerRef,
43 ...attributes
44 } = this.props;
45
46 const classes = mapToCssModules(className, cssModule);
47 return <Tag {...attributes} ref={innerRef} className={classes} />;
48 }
49}
50
51Form.propTypes = propTypes;
52
53export default Form;
54
\No newline at end of file