|
| 1 | +export declare type InputType = TextInput | NumberInput | SelectInput | TextAreaInput | CheckboxInput | RadioInput | EmailInput | PasswordInput | RadioInput | ColorInput | UrlInput | CustomInput; |
| 2 | +export declare type MustHave<T, K extends keyof T> = Partial<T> & Pick<T, K>; |
| 3 | +export declare type FormFields = { |
| 4 | + [key: string]: InputType; |
| 5 | +}; |
| 6 | +export declare type FormChanges = { |
| 7 | + [key: string]: string | number | null | undefined; |
| 8 | +}; |
| 9 | +export interface DynamicForm { |
| 10 | + id: string; |
| 11 | + fields: FormFields; |
| 12 | + fieldOrder?: string[]; |
| 13 | + options?: FormOptions; |
| 14 | +} |
| 15 | +export declare enum ValidationTriggerTypes { |
| 16 | + BLUR = "blur", |
| 17 | + CHANGE = "change" |
| 18 | +} |
| 19 | +export interface ValidationTrigger { |
| 20 | + type: ValidationTriggerTypes; |
| 21 | + threshold: number; |
| 22 | +} |
| 23 | +export interface ErrorMessage { |
| 24 | + text: string; |
| 25 | + value: boolean | null; |
| 26 | +} |
| 27 | +export declare type ValidationErrors = { |
| 28 | + [key: string]: any; |
| 29 | +}; |
| 30 | +export declare type BindingObject = { |
| 31 | + [key: string]: never; |
| 32 | +}; |
| 33 | +export interface ValidatorFn { |
| 34 | + (value: ControlValue | undefined): ValidationErrors | null; |
| 35 | +} |
| 36 | +export declare type ControlValue = string | number | boolean; |
| 37 | +export interface FormValidator { |
| 38 | + validator: ValidatorFn; |
| 39 | + text: string; |
| 40 | + type?: string; |
| 41 | +} |
| 42 | +export interface InputEvent { |
| 43 | + name: string; |
| 44 | + value?: unknown; |
| 45 | +} |
| 46 | +export declare type ValidationEvent = InputEvent & { |
| 47 | + errors: ValidationErrors; |
| 48 | + valid: boolean; |
| 49 | +}; |
| 50 | +export interface InputBase { |
| 51 | + name?: string; |
| 52 | + label?: string; |
| 53 | + ariaLabel?: string; |
| 54 | + ariaLabelledBy?: string; |
| 55 | + disabled?: boolean; |
| 56 | + customClass?: string | string[] | BindingObject | BindingObject[] | unknown; |
| 57 | + customStyles?: string | string[] | BindingObject | BindingObject[] | unknown; |
| 58 | + placeholder?: string; |
| 59 | + autocomplete?: string; |
| 60 | + readonly?: boolean; |
| 61 | + validations?: FormValidator[]; |
| 62 | + validationTrigger?: ValidationTrigger; |
| 63 | +} |
| 64 | +export declare type TextInput = InputBase & { |
| 65 | + type: FieldTypes.TEXT; |
| 66 | + value?: string; |
| 67 | +}; |
| 68 | +export declare type NumberInput = InputBase & { |
| 69 | + type: FieldTypes.NUMBER; |
| 70 | + value: number; |
| 71 | + min: number; |
| 72 | + max: number; |
| 73 | + step: number; |
| 74 | +}; |
| 75 | +export declare type SelectInput<T = boolean | string> = InputBase & { |
| 76 | + type: FieldTypes.SELECT; |
| 77 | + value: T; |
| 78 | + optionValue: string; |
| 79 | + optionLabel: string; |
| 80 | + options?: { |
| 81 | + label: string; |
| 82 | + value: string; |
| 83 | + disabled?: boolean; |
| 84 | + }[]; |
| 85 | +}; |
| 86 | +export declare type TextAreaInput = InputBase & { |
| 87 | + type: FieldTypes.TEXTAREA; |
| 88 | + value: string; |
| 89 | + cols?: number; |
| 90 | + rows?: number; |
| 91 | +}; |
| 92 | +export declare type CheckboxInput = InputBase & { |
| 93 | + type: FieldTypes.CHECKBOX; |
| 94 | + value: boolean; |
| 95 | +}; |
| 96 | +export declare type CustomInput = InputBase & { |
| 97 | + type: FieldTypes.CUSTOM; |
| 98 | + value: boolean | string | number; |
| 99 | +}; |
| 100 | +export declare type EmailInput = InputBase & { |
| 101 | + type: FieldTypes.EMAIL; |
| 102 | + value: string; |
| 103 | +}; |
| 104 | +export declare type PasswordInput = InputBase & { |
| 105 | + type: FieldTypes.PASSWORD; |
| 106 | + value: string; |
| 107 | +}; |
| 108 | +export declare type ColorInput = InputBase & { |
| 109 | + type: FieldTypes.COLOR; |
| 110 | + value: string; |
| 111 | +}; |
| 112 | +export declare type UrlInput = InputBase & { |
| 113 | + type: FieldTypes.URL; |
| 114 | + value: string; |
| 115 | +}; |
| 116 | +export declare type RadioInput = InputBase & { |
| 117 | + type: FieldTypes.RADIO; |
| 118 | + value: string; |
| 119 | + options?: { |
| 120 | + key: string; |
| 121 | + value: string; |
| 122 | + disabled?: boolean; |
| 123 | + }[]; |
| 124 | +}; |
| 125 | +export declare type FormControl<T extends InputType> = T & { |
| 126 | + valid: boolean; |
| 127 | + dirty: boolean; |
| 128 | + touched: boolean; |
| 129 | + errors: ValidationErrors | null; |
| 130 | +}; |
| 131 | +export interface FormOptions { |
| 132 | + customClass?: string | string[] | BindingObject | BindingObject[] | unknown; |
| 133 | + customStyles?: string | string[] | BindingObject | BindingObject[] | unknown; |
| 134 | + method?: string; |
| 135 | + netlify?: boolean; |
| 136 | + netlifyHoneypot?: string; |
| 137 | + autocomplete?: boolean | string; |
| 138 | + resetAfterSubmit?: boolean; |
| 139 | +} |
| 140 | +export declare enum FieldTypes { |
| 141 | + TEXT = "text", |
| 142 | + TEXTAREA = "textarea", |
| 143 | + SELECT = "select", |
| 144 | + NUMBER = "number", |
| 145 | + EMAIL = "email", |
| 146 | + URL = "url", |
| 147 | + PASSWORD = "password", |
| 148 | + CHECKBOX = "checkbox", |
| 149 | + RADIO = "radio", |
| 150 | + CUSTOM = "custom-field", |
| 151 | + COLOR = "color" |
| 152 | +} |
0 commit comments