import PropTypes from 'prop-types' ; import React , { useCallback , ElementType } from 'react' ; import notify from './utils/notify' ; import useFormSubmit from './useFormSubmit' ; export interface FormSubmitProps < TAs extends ElementType = any > { as ? : TAs ; onClick ? : ( ... args : any [ ] ) => any ; triggers ? : string [ ] ; } memberof function Submit < TAs extends ElementType = 'button' > ( props ) { const { onClick , triggers , as : Component = 'button' , ... rest } = props ; const [ submit ] = useFormSubmit ( { triggers } ) ; const handleClick = useCallback ( ( ... args ) => { notify ( onClick , args ) ; submit ( args ) ; } , [ onClick , submit ] ) ; return ( < Component { ... rest } onClick = { handleClick } type = { triggers && triggers . length ? 'button' : 'submit' } />); } Submit . propTypes = { /**
     * Specify particular fields to validate in the related form. If empty the entire form will be validated.
     */ triggers : PropTypes . arrayOf ( PropTypes . string . isRequired ) , /**
     * Control the rendering of the Form Submit component when not using
     * the render prop form of `children`.
     *
     * ```jsx static
     * <Form.Submit as={MyButton}>
     *   Submit
     * </Form.Submit>
     * ```
     */ as : PropTypes . elementType , default onClick : PropTypes . func , } ; export default Submit ;