Add Form component to wrap forms with some default props

This commit is contained in:
Kimmo Puputti 2017-10-04 16:19:02 +03:00
parent 1bf7cc9963
commit cfae14105e
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import React, { PropTypes } from 'react';
const Form = props => {
const { children, ...restProps } = props;
const formProps = {
// These are mainly default values for the server
// rendering. Otherwise the form would submit potentially
// sensitive data with the default GET method until the client
// side code is loaded.
method: 'post',
action: '/',
...restProps,
};
return (
<form {...formProps}>
{children}
</form>
);
};
Form.defaultProps = {
children: null,
};
const { node } = PropTypes;
Form.propTypes = {
children: node,
};
export default Form;

View file

@ -15,6 +15,7 @@ import EditListingWizard from './EditListingWizard/EditListingWizard';
import ExpandingTextarea from './ExpandingTextarea/ExpandingTextarea';
import ExternalLink from './ExternalLink/ExternalLink';
import FilterPanel from './FilterPanel/FilterPanel';
import Form from './Form/Form';
import HeroSection from './HeroSection/HeroSection';
import IconBannedUser from './IconBannedUser/IconBannedUser';
import IconCheckmark from './IconCheckmark/IconCheckmark';
@ -96,6 +97,7 @@ export {
ExpandingTextarea,
ExternalLink,
FilterPanel,
Form,
HeroSection,
IconBannedUser,
IconCheckmark,