import * as React from 'react' ; import { Children , ReactElement , ReactNode } from 'react' ; import classnames from 'classnames' ; import FormInput from './FormInput' ; import PropTypes from 'prop-types' ; import { FormWithRedirectRenderProps , MutationMode , Record } from 'ra-core' ; import Toolbar from './Toolbar' ; import CardContentInner from '../layout/CardContentInner' ; export const SimpleFormView = ( { basePath , children , className , component : Component , handleSubmit , handleSubmitWithRedirect , invalid , margin , mutationMode , pristine , record , redirect , resource , saving , submitOnEnter , toolbar , undoable , variant , validating , ... rest } ) : ReactElement => ( < form className = { classnames ( 'simple-form' , className ) } { ... sanitizeRestProps ( rest ) } > < Component > { Children . map ( children , ( input ) => input && ( < FormInput basePath = { basePath } input = { input } record = { record } resource = { resource } variant = { input . props . variant || variant } margin = { input . props . margin || margin } / > ) ) } < /Component> { toolbar && React . cloneElement ( toolbar , { basePath , handleSubmitWithRedirect , handleSubmit , invalid , mutationMode , pristine , record , redirect , resource , saving , submitOnEnter , validating , undoable , } ) } < /form>); SimpleFormView . propTypes = { basePath : PropTypes . string , children : PropTypes . node , className : PropTypes . string , handleSubmit : PropTypes . func , invalid : PropTypes . bool , mutationMode : PropTypes . oneOf ( [ 'pessimistic' , 'optimistic' , 'undoable' ] ) , pristine : PropTypes . bool , record : PropTypes . object , resource : PropTypes . string , redirect : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . bool , PropTypes . func , ] ) , save : PropTypes . func , saving : PropTypes . bool , submitOnEnter : PropTypes . bool , toolbar : PropTypes . oneOfType ( [ PropTypes . element , PropTypes . oneOf ( [ false ] ) ] ) , undoable : PropTypes . bool , validate : PropTypes . func , } ; SimpleFormView . defaultProps = { submitOnEnter : true , toolbar : < Toolbar />, component : CardContentInner , } ; export interface SimpleFormViewProps extends FormWithRedirectRenderProps { basePath ? : string ; children ? : ReactNode ; className ? : string ; component ? : React . ComponentType < any > ; margin ? : 'none' | 'normal' | 'dense' ; mutationMode ? : MutationMode ; record ? : Partial < Record > ; resource ? : string ; toolbar ? : ReactElement | false ; deprecated undoable ? : boolean ; variant ? : 'standard' | 'outlined' | 'filled' ; submitOnEnter ? : boolean ; __versions ? : any ; } const sanitizeRestProps = ( { active , dirty , dirtyFields , dirtyFieldsSinceLastSubmit , dirtySinceLastSubmit , error , errors , form , hasSubmitErrors , hasValidationErrors , initialValues , modified = null , modifiedSinceLastSubmit , save = null , submitError , submitErrors , submitFailed , submitSucceeded , submitting , touched = null , valid , values , visited = null , __versions = null , ... props } ) => props ;