rehance-forms
Version:
Form utilities for React
43 lines (42 loc) • 1.43 kB
TypeScript
import * as React from "react";
import { FieldMap } from "./types";
import { ScopeContext } from "./ScopeContext";
import { FormEvent } from "./EventBus";
export declare type RenderProp = (scope: ScopeContext) => React.ReactNode;
export declare type FormProps = {
className?: string;
style?: React.CSSProperties;
initialValues?: FieldMap;
tag?: string;
mergeInitialStateOnSubmit?: boolean;
onMount?(scope: ScopeContext): void;
onEvent?(ev: FormEvent, scope: ScopeContext): void;
onSubmit?(values: FieldMap, scope: ScopeContext): void;
children?: React.ReactNode | RenderProp;
};
export declare class Form extends React.Component<FormProps> {
static defaultProps: Partial<FormProps>;
private formScope;
constructor(props: FormProps, context: any);
/**
* Provide the "onMount" prop (if any) with the form scope object for the form.
*/
componentWillMount(): void;
/**
* Handle scope updates for the the top level scope created by this component,
* including the call to submit the form.
*/
private handleScopeEvent;
/**
* The actual function that handles that calls the submit handler prop.
*/
private handleSubmit;
/**
* Invoke the onSubmit prop with the current form values when submitted.
*/
private handleFormSubmit;
/**
* Render the form and its contents.
*/
render(): JSX.Element;
}