Created
May 10, 2018 17:57
-
-
Save AmrAbdulrahman/2f08f7dc10b125e925fc440a75634534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import classnames from 'classnames'; | |
import { withStyles } from 'material-ui/styles'; | |
import Grid from 'material-ui/Grid'; | |
import Loading from '~/Components/Loading'; | |
import styles from './styles'; | |
@withStyles(styles) | |
class Form extends Component { | |
_onSubmit = e => { | |
e.preventDefault(); | |
this.props.onSubmit(); | |
}; | |
render() { | |
const { classes, className, loading, ...rest } = this.props; | |
return ( | |
<form | |
className={classnames(classes.form, className, { [classes.loading]: loading })} | |
onSubmit={this._onSubmit} | |
{...rest} | |
> | |
<If condition={loading}> | |
<div className={classes.loading}> | |
<Loading /> | |
</div> | |
</If> | |
<Grid container className={classes.formInnerGrid}> | |
{this.props.children} | |
</Grid> | |
</form> | |
); | |
} | |
} | |
Form.propTypes = { | |
classes: PropTypes.object, | |
className: PropTypes.string, | |
children: PropTypes.any, | |
onSubmit: PropTypes.func, | |
loading: PropTypes.bool, | |
}; | |
Form.defaultProps = { | |
className: '', | |
loading: false, | |
onSubmit() {}, | |
}; | |
export { Form }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment