import { ReactElement, HTMLInputTypeAttribute } from 'react';
type Values = {
[id: string]: string;
};
type Validator = (value: any) => string;
type ControlConfig = {
label?: string;
type?: HTMLInputTypeAttribute;
placeholder?: string;
multiple?: boolean;
optional?: boolean;
min?: number;
max?: number;
step?: number;
options?: Array<{
label: string;
value: string;
}>;
initialValue?: any;
validator?: Array | Validator;
[prop: string]: unknown;
};
type Config = {
[key: string]: ControlConfig;
};
type ControlProps = ControlConfig & {
id: string;
onChange: (value: any, id: string) => void;
validationError: string;
value: any;
};
type GetControlProps = (id: string) => ControlProps;
export interface FormProps {
config: Config;
renderForm: (getControlProps: GetControlProps, onSubmit: () => void) => ReactElement;
handleFormData: (controlValues: Values) => void;
onChange?: (data: Values) => void;
onCancel?: () => void;
}
declare function Form({ config, renderForm, handleFormData, onChange, onCancel }: FormProps): ReactElement;
declare namespace Form {
var propTypes: {
/** An object containing keys that correspond to control names. The value of each control name key are objects containing the configuration of a control. */
config: any;
/** Renders the form layout. When called a get argument is passed to return the configuration object of each control type. */
renderForm: any;
/** Called when the form has successfully passed validation and returns an object containing keys the coorespond to control names with values equalling the users inputted value. */
handleFormData: any;
/** Called when any control component registered with the form changes in value. */
onChange: any;
/** Called when ESC is pressed. */
onCancel: any;
};
}
export default Form;