@data-driven-forms/react-form-renderer
Version:
React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.
57 lines (56 loc) • 2.44 kB
TypeScript
import { Validator } from '../validators';
import { ConditionDefinition } from '../condition';
import { DataType } from '../data-types';
import { AnyObject } from './any-object';
import { FieldInputProps } from 'react-final-form';
import { FormOptions } from '../renderer-context';
import { Meta } from '../use-field-api';
import ComponentMapper, { ComponentPropsMap } from './component-mapper';
export type FieldAction = [string, ...any[]];
export interface FieldActions {
[key: string]: FieldAction;
}
export interface FieldApi<FieldValue, T extends HTMLElement = HTMLElement> {
meta: Meta<FieldValue>;
input: FieldInputProps<FieldValue, T>;
}
export type ResolvePropsFunction<FormValues = Record<string, any>, FieldValue = FormValues[keyof FormValues]> = (props: AnyObject, fieldApi: FieldApi<FieldValue>, formOptions: FormOptions<FormValues>) => AnyObject;
export { BaseFieldProps } from '../use-field-api';
export interface StrictBaseFieldProps<FormValues = Record<string, any>, FieldValue = FormValues[keyof FormValues]> {
name: string;
label?: string;
helperText?: string;
description?: string;
isRequired?: boolean;
isDisabled?: boolean;
isReadOnly?: boolean;
isVisible?: boolean;
hideField?: boolean;
validate?: Validator[];
condition?: ConditionDefinition | ConditionDefinition[];
initializeOnMount?: boolean;
dataType?: DataType;
initialValue?: FieldValue;
clearedValue?: FieldValue;
clearOnUnmount?: boolean;
actions?: FieldActions;
resolveProps?: ResolvePropsFunction<FormValues, FieldValue>;
}
export type TypedFieldProps<P = {}> = StrictBaseFieldProps & P;
export type Field<T extends ComponentMapper = ComponentMapper, C extends keyof T = keyof T, FormValues = Record<string, any>, FieldValue = FormValues[keyof FormValues]> = StrictBaseFieldProps<FormValues, FieldValue> & {
component: C;
} & ComponentPropsMap<T>[C];
interface LegacyField<FormValues = Record<string, any>, FieldValue = FormValues[keyof FormValues]> extends AnyObject {
name: string;
component: string;
validate?: Validator[];
condition?: ConditionDefinition | ConditionDefinition[];
initializeOnMount?: boolean;
dataType?: DataType;
initialValue?: FieldValue;
clearedValue?: FieldValue;
clearOnUnmount?: boolean;
actions?: FieldActions;
resolveProps?: ResolvePropsFunction<FormValues, FieldValue>;
}
export default LegacyField;