react-formal
Version:
Classy HTML form management for React
30 lines (29 loc) • 1.3 kB
TypeScript
/// <reference types="react" />
import PropTypes from 'prop-types';
import { AnyObjectSchema } from 'yup';
import { FormProps } from './Form';
export interface NestedFormProps<TSchema extends AnyObjectSchema> extends Omit<FormProps<TSchema>, 'onError' | 'onChange' | 'value' | 'defaultValue' | 'defaultErrors'> {
name: string;
}
/**
* A `Form` component that takes a `name` prop. Functions exactly like a normal
* Form, except that when a `name` is present it will defer errors up to the parent `<Form>`,
* functioning like a `<Form.Field>`.
*
* This is useful for encapsulating complex input groups into self-contained
* forms without having to worry about `"very.long[1].paths[4].to.fields"` for names.
*/
declare function NestedForm<T extends AnyObjectSchema>({ name, schema, errors, ...props }: NestedFormProps<T>): JSX.Element;
declare namespace NestedForm {
var propTypes: {
name: PropTypes.Validator<string>;
schema: PropTypes.Requireable<object>;
errors: PropTypes.Requireable<object>;
context: PropTypes.Requireable<object>;
meta: PropTypes.Requireable<PropTypes.InferProps<{
errors: PropTypes.Validator<object>;
onError: PropTypes.Validator<(...args: any[]) => any>;
}>>;
};
}
export default NestedForm;