@timmons-group/config-form
Version:
React Components and helpers to build a form via configuration with react-hook-form and MUI
157 lines (156 loc) • 4.6 kB
TypeScript
/**
* @fileoverview Legacy form model types
* @typedef {object} LegacyLayoutField
* @property {string} path - field path
*/
import { FIELD_TYPES, MAX_VALUE_ERROR_TEXT, MIN_VALUE_ERROR_TEXT } from '../constants';
import { When } from './formFields.model';
import { Schema } from 'yup';
export type FieldIntTypes = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 100 | 120 | 999;
export interface LegacyFormLayout {
id?: string | number;
type: 1;
sections: LegacySection[];
}
export interface LegacyParsedSection {
name?: string;
title?: string;
fields: string[];
editable?: boolean;
enabled?: boolean;
order?: number;
description?: string;
}
export interface LegacySection {
id?: string | number;
name?: string;
title?: string;
layout: LegacyLayoutField[];
editable?: boolean;
enabled?: boolean;
order?: number;
description?: string;
}
export type CustomValidationFunction = (field: LegacyParsedFormField) => Schema;
export interface LegacyLayoutField {
path: string;
type: FieldIntTypes;
label: string;
customValidation?: CustomValidationFunction;
model: {
id?: string | number;
name: string;
type: FieldIntTypes;
data?: Record<string, any>;
};
solitary?: boolean;
singleColumnSize?: string | number;
inline?: boolean;
emptyMessage?: string;
required?: boolean;
requiredErrorText?: string;
disableFuture?: boolean;
disableFutureErrorText?: string;
minValue?: number;
defaultValue?: any;
conditions?: Array<LegacyCondition | Condition>;
hidden?: boolean;
multiple?: boolean;
checkbox?: boolean;
radio?: boolean;
linkFormat?: string;
zip?: boolean;
email?: boolean;
phone?: boolean;
url?: string;
possibleChoices?: Array<Record<string, any>>;
addLabel?: string;
removeLabel?: string;
clusterColumnCount?: number;
layout?: Array<LegacyLayoutField>;
}
export interface LegacyParsedFormField {
id: string;
path: string;
label: string;
type: FieldIntTypes;
hidden: boolean;
conditions?: Array<LegacyCondition | Condition>;
specialProps?: Record<string, any>;
defaultValue?: Record<string, any>;
modelData?: Record<string, any>;
render: LegacyFieldRender;
subFields?: LegacyParsedFormField[];
validations?: Record<string, any>;
customValidation?: CustomValidationFunction;
}
export type LegacyFieldRender = LegacyBaseFieldRenderProps | LegacyDropdownRenderProps | LegacyDateRenderProps | LegacyLongTextRenderProps | LegacyTextRenderProps | LegacyClusterRenderProps;
export interface LegacyBaseFieldRenderProps {
type: FieldIntTypes;
label: string;
name: string;
placeholder?: string;
idField?: string;
hidden?: boolean;
required?: boolean;
disabled?: boolean;
readOnly?: boolean;
defaultValue?: any;
inline?: boolean;
solitary?: boolean;
singleColumnSize?: string | number;
choices?: Array<Record<string, any>>;
url?: string;
minValue?: number;
[MIN_VALUE_ERROR_TEXT]?: string;
maxValue?: number;
[MAX_VALUE_ERROR_TEXT]?: string;
minLength?: number;
maxLength?: number;
emptyMessage?: string;
iconHelperText?: string;
altHelperText?: string;
helperText?: string;
requiredErrorText?: string;
linkFormat?: string;
}
export interface LegacyDropdownRenderProps extends LegacyBaseFieldRenderProps {
type: typeof FIELD_TYPES['CHOICE'] | typeof FIELD_TYPES['OBJECT'];
multiple?: boolean;
checkbox?: boolean;
radio?: boolean;
}
export interface LegacyDateRenderProps extends LegacyBaseFieldRenderProps {
disableFuture?: boolean;
disableFutureErrorText?: string;
}
export interface LegacyLongTextRenderProps extends LegacyBaseFieldRenderProps {
isMultiLine?: boolean;
}
export interface LegacyTextRenderProps extends LegacyBaseFieldRenderProps {
email?: boolean;
phone?: boolean;
zip?: boolean;
}
export interface LegacyClusterRenderProps extends LegacyBaseFieldRenderProps {
type: typeof FIELD_TYPES['CLUSTER'];
addLabel?: string;
removeLabel?: string;
clusterColumnCount?: number;
}
export interface LegacyCondition {
when: string;
is: string | number;
isValid?: boolean;
then: Record<string, any>;
}
export interface Condition {
when: When;
then: Record<string, any>;
}
/**
* This is the format of a parsed condition created in useFormLayout and used in useConfigForm
*/
export interface ParsedCondition extends Condition {
conditionId: string;
}