UNPKG

@contensis/forms

Version:
287 lines (280 loc) 9.07 kB
import React, { ReactNode } from 'react'; type Nullable<T> = undefined | null | T; type Dictionary<T> = Record<string, T>; type DeepPartial<T> = { [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : null | T[P]; }; type VersionStatus = null | 'latest' | 'published'; type ApiParams = { apiUrl: string; projectId: string; formId: string; language: null | string; versionStatus: VersionStatus; }; type GetFormParams = ApiParams; type FormResponse = Dictionary<unknown>; type FormContentType = { id: string; name: string; description: string; fields: Field[]; groups?: Group[]; properties?: Nullable<FormProperties>; language: string; version?: { versionNo?: string; }; }; type Field = { id: string; name: string; dataType: FieldDataType; dataFormat?: Nullable<FieldDataFormat>; description?: Nullable<string>; default?: unknown; groupId: string; validations?: Nullable<FieldValidations>; editor?: Nullable<FieldEditor>; }; type Group = { id: string; name: string; description?: Nullable<string>; }; type CaptchaSettings = { enabled: boolean; siteKey?: Nullable<string>; }; type FormLocalizations$1 = { closedReasonMessage: Nullable<string>; disabledReasonMessage: Nullable<string>; submit: Nullable<string>; previous: Nullable<string>; next: Nullable<string>; requirePermissionToPostMessage: Nullable<string>; errorLabel: Nullable<string>; errorPageTitle: Nullable<string>; errorSummaryTitle: Nullable<string>; pageHeader: Nullable<string>; requiredLabel: Nullable<string>; dateInputDayLabel: Nullable<string>; dateInputMonthLabel: Nullable<string>; dateInputYearLabel: Nullable<string>; dateInputHourLabel: Nullable<string>; dateInputMinuteLabel: Nullable<string>; dateInputPeriodLabel: Nullable<string>; validationDataTypeBoolean: Nullable<string>; validationDataTypeDateTime: Nullable<string>; validationDataTypeDecimal: Nullable<string>; validationDataTypeInteger: Nullable<string>; validationDataTypeString: Nullable<string>; validationDataTypeStringArray: Nullable<string>; validationDataFormatEmail: Nullable<string>; validationDataFormatPhone: Nullable<string>; validationDataFormatTime: Nullable<string>; validationDataFormatUrl: Nullable<string>; validationMinCountZero: Nullable<string>; validationMinCountOne: Nullable<string>; validationMinCountTwo: Nullable<string>; validationMinCountFew: Nullable<string>; validationMinCountMany: Nullable<string>; validationMinCountOther: Nullable<string>; validationMaxCountZero: Nullable<string>; validationMaxCountOne: Nullable<string>; validationMaxCountTwo: Nullable<string>; validationMaxCountFew: Nullable<string>; validationMaxCountMany: Nullable<string>; validationMaxCountOther: Nullable<string>; validationRequired: Nullable<string>; validationAllowedValue: Nullable<string>; validationAllowedValues: Nullable<string>; validationRegEx: Nullable<string>; validationPastDateTime: Nullable<string>; validationMin: Nullable<string>; validationMax: Nullable<string>; validationMinMax: Nullable<string>; validationMinLength: Nullable<string>; validationMaxLength: Nullable<string>; validationMinMaxLength: Nullable<string>; validationMinMaxCount: Nullable<string>; characterCountRemainingZero: Nullable<string>; characterCountRemainingOne: Nullable<string>; characterCountRemainingTwo: Nullable<string>; characterCountRemainingFew: Nullable<string>; characterCountRemainingMany: Nullable<string>; characterCountRemainingOther: Nullable<string>; characterCountExceededZero: Nullable<string>; characterCountExceededOne: Nullable<string>; characterCountExceededTwo: Nullable<string>; characterCountExceededFew: Nullable<string>; characterCountExceededMany: Nullable<string>; characterCountExceededOther: Nullable<string>; }; type FormProperties = { captcha: CaptchaSettings; localizations: Nullable<FormLocalizations$1>; confirmationRules: FormRule<ConfirmationRuleReturn>[]; autoSaveProgress: boolean; mode?: 'survey'; }; type FieldDataType = 'boolean' | 'dateTime' | 'decimal' | 'integer' | 'string' | 'stringArray'; type FieldDataFormat = 'email' | 'phone' | 'reference' | 'time' | 'url'; type FieldEditorId = 'datetime' | 'datetimeparts' | 'date' | 'dateparts' | 'decimal' | 'integer' | 'list-dropdown' | 'list' | 'multiline' | 'text' | 'time' | 'timeparts'; type AllowedValues = { values?: Nullable<string[]>; labeledValues?: Nullable<{ value: string; label: string; }[]>; }; type FieldValidations = { required?: Nullable<FieldValidation>; min?: Nullable<FieldValidationWithValue<number>>; max?: Nullable<FieldValidationWithValue<number>>; minLength?: Nullable<FieldValidationWithValue<number>>; maxLength?: Nullable<FieldValidationWithValue<number>>; minCount?: Nullable<FieldValidationWithValue<number>>; maxCount?: Nullable<FieldValidationWithValue<number>>; regex?: Nullable<FieldValidation & { pattern: string; }>; allowedValue?: Nullable<FieldValidationWithValue<any>>; allowedValues?: Nullable<FieldValidation & AllowedValues>; pastDateTime?: Nullable<FieldValidation>; }; type FieldValidation = { message?: Nullable<string>; }; type FieldValidationWithValue<T> = FieldValidation & { value: T; }; type FieldEditor = { id?: Nullable<FieldEditorId>; instructions?: Nullable<string>; label?: Nullable<string>; properties?: FieldEditorProperties; }; type FieldLabelPosition = 'top' | 'leftAligned'; type DateFormat = 'dd-mm-yyyy' | 'mm-dd-yyyy' | 'yyyy-mm-dd'; type TimeFormat = '12h' | '24h'; type FieldEditorProperties = { autoFill?: string; rows?: number; labelPosition?: FieldLabelPosition; cssClass?: string; hidden?: boolean; placeholderText?: string; dateFormat?: DateFormat; dateSeparator?: string; timeFormat?: TimeFormat; timeSeparator?: string; }; type FormRule<TReturn> = { return: TReturn; }; type ConfirmationRuleReturnUri = { link: { sys: { uri: string; }; }; }; type ConfirmationRuleReturnContent = { content: string; }; type ConfirmationRuleReturn = ConfirmationRuleReturnUri | ConfirmationRuleReturnContent; type PluralLocalizations = { zero: string; one: string; two: string; few: string; many: string; other: string; }; type FormLocalizations = { buttons: { next: string; previous: string; submit: string; }; load: { loading: string; error: string; }; error: { label: string; pageTitle: string; summaryTitle: string; }; messages: { confirmation: string; page: string; }; labels: { required: string; selectPlaceholder: string; }; dates: { day: string; month: string; year: string; hour: string; minute: string; period: string; }; validation: { dataType: { boolean: string; dateTime: string; decimal: string; integer: string; string: string; stringArray: string; }; dataFormat: { email: string; phone: string; time: string; url: string; }; minCount: PluralLocalizations; maxCount: PluralLocalizations; required: string; allowedValue: string; allowedValues: string; pastDateTime: string; regEx: string; min: string; max: string; minMax: string; minLength: string; maxLength: string; minMaxLength: string; minMaxCount: string; }; characterCount: { remaining: PluralLocalizations; exceeded: PluralLocalizations; }; }; type FormProps = { apiUrl?: null | string; projectId: string; formId: string; language?: null | string; versionStatus?: VersionStatus; loading?: ReactNode; disabled?: ReactNode; headingLevel?: number; localizations?: DeepPartial<FormLocalizations>; showTitle?: boolean; error?: (error: unknown) => ReactNode; onPopulate?: (defaultValue: FormResponse, form: FormContentType) => FormResponse | Promise<FormResponse>; onSubmit?: (response: FormResponse, form: FormContentType) => false | FormResponse | Promise<false | FormResponse>; onSubmitSuccess?: (response: FormResponse, form: FormContentType) => boolean | Promise<boolean>; onSubmitError?: (error: unknown, form: FormContentType) => boolean | Promise<boolean>; onLoadError?: (error: unknown, params: GetFormParams) => void; }; declare function ContensisForm(props: FormProps): React.JSX.Element | null; export { ContensisForm, type FormProps };