UNPKG

react-forminate

Version:

React.js + Typescript package that creates dynamic UI forms based on the JSON schema

118 lines (117 loc) 5.63 kB
import { FieldPropContext } from './formTypes'; export type SupportedPrimitive = string | number | boolean | null; export type SupportedArray = Array<SupportedPrimitive | SupportedObject | SupportedArray>; export type SupportedObject = { [key: string]: SupportedPrimitive | SupportedArray | SupportedObject; }; export type SupportedTypes = SupportedPrimitive | SupportedArray | SupportedObject | React.ReactNode; export type ComputedValue<T> = { fn: (context: FieldPropContext) => T; dependsOn?: string[]; defaultValue?: T; isAsync?: boolean; }; export type FunctionOrValue<T extends SupportedTypes> = T | ComputedValue<T> | ((context: FieldPropContext) => T); export type TFieldLabel = string; export type TFieldRequired = boolean; export type TFieldDisabled = boolean; export type TFieldRequiredMessage = string; export type TFieldVisibility = boolean | { dependsOn: FieldIdType[] | FieldIdType; condition: VisibilityConditionType; value: string | number; }; export type TFunctionalChildrenType = React.ReactNode; export type FieldIdType = string; export type FieldTypeType = string; export type FieldLabelType = FunctionOrValue<TFieldLabel>; export type FieldRequiredType = FunctionOrValue<TFieldRequired>; export type FieldRequiredMessageType = FunctionOrValue<TFieldRequiredMessage>; export type VisibilityConditionType = "equals" | "not_equals" | "greater_than" | "greater_than_or_equal" | "less_than" | "less_than_or_equal" | "contains" | "not_contains" | "in" | "not_in"; export type FieldVisibilityType = FunctionOrValue<TFieldVisibility>; export type FieldClassNameType = string; export type FieldStyleType = React.CSSProperties; export type FieldDisableDefaultStyling = boolean; export type FieldSinglePositiveAnswerValue = string; export type FieldSingleNegativeAnswerValue = string; export type FieldLayout = "inline" | "column" | null; export type FieldDisabledType = FunctionOrValue<TFieldDisabled>; export type FieldDefaultValueType = SupportedTypes; export type BaseFieldParams = Record<string, unknown>; export type FieldPlaceholderType = string; export type FieldAutoCorrectType = "on" | "off"; export type FieldAutoCapitalizeType = "on" | "off" | "sentences" | "words" | "characters" | "none"; export type FieldSpellCheckType = boolean; export type FieldAutoFocusType = boolean; export type FieldStepType = number; export type FieldInputType = "text" | "number" | "email" | "password" | "url" | "tel" | "search"; export type FieldDatepickerType = "date"; export type FieldSelectType = "select" | "multiSelect"; export type FieldRadioType = "radio"; export type FieldCheckboxType = "checkbox"; export type FieldTextareaType = "textarea"; export type FieldGroupType = "group"; export type FieldGridViewType = "gridview"; export type FieldSpacerType = "spacer"; export type FieldContainerType = "container" | "content"; export type FieldInputFileType = "file"; export type FieldContentType = "content"; export type FieldTextareaRowsType = number; export type FieldTextareaColsType = number; export type FieldAsHTMLContainerTagType = "div" | "section" | "article" | "main" | "header" | "footer"; export type WidthType = string | number; export type HeightType = string | number; export type OptionsType = string | { value: string | number; label: string | number; }; export type ExtractFieldIds<T extends { fieldId: string; }[]> = T[number]["fieldId"]; export type FormIdType = string; export type TitleType = string; export type BaseUrlType = string; export type DescriptionType = string; export type APIEndpointType = string; export type APIMethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE"; export type APIDependsOnType = string | string[]; export type APIParamsType = Record<string, string>; export type APIHeadersType = Record<string, string>; export type APITransformResponseType = (response: any) => { label: string; value: any; }[] | string[]; export type APIResultPathType = string; export type APIfetchOnInitType = boolean; export type APIForceRefreshType = boolean; export type FormValuesType = Record<FieldIdType, any>; export type FormErrorsType = Record<FieldIdType, string>; export type FieldDynamicOptionsType = Record<FieldIdType, any[]>; export type ChildrenType = React.ReactNode; export type FunctionalChildrenType = FunctionOrValue<TFunctionalChildrenType>; export type ShowSkeletonLoadingType = boolean; export type ValidationPatternType = string; export type MessageType = string; export type MinType = number; export type MaxType = number; export type MinLengthType = number; export type MaxLengthType = number; export type ValidationCustomRuleType = ((value: SupportedTypes) => boolean | any) | ((value: SupportedTypes) => Promise<boolean | any>); export type ColumnsType = number; export type GapType = number; export type DependencyMap = Record<FieldIdType, Set<FieldIdType>>; export type DependencyMapTuple = [DependencyMap, DependencyMap]; export type FileAcceptType = string | string[]; export type FileMultipleType = boolean; export type FileMaxSizeMBType = number; export type FileMinFilesType = number; export type FilePreviewType = boolean; export type FileUploadUrlType = string; export type FileUploadHeadersType = string; export type FileUploadMethodType = "POST" | "PUT" | "PATCH"; export type FilePresignedUrlFnType = string; export type FileFileTypesType = string[]; export type FileRenameFileType = boolean; export type FileStoreLocallyType = boolean; export type FileStorageFormatType = "file" | "fileList" | "base64" | "blobUrl" | "arrayBuffer" | "remoteUrl" | "metadata"; export type FieldDescriptionType = string;