|
| 1 | +## Form Fields & Inputs |
| 2 | + |
| 3 | +### `FieldType` |
| 4 | + |
| 5 | +```ts |
| 6 | +export enum FieldTypes { |
| 7 | + TEXT = 'text', |
| 8 | + TEXTAREA = 'textarea', |
| 9 | + SELECT = 'select', |
| 10 | + NUMBER = 'number', |
| 11 | + EMAIL = 'email', |
| 12 | + URL = 'url', |
| 13 | + PASSWORD = 'password', |
| 14 | + CHECKBOX = 'checkbox', |
| 15 | + RADIO = 'radio', |
| 16 | + CUSTOM = 'custom-field', |
| 17 | + COLOR = 'color', |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +### `InputType` |
| 22 | + |
| 23 | +```ts |
| 24 | +export type InputType = |
| 25 | + | TextInput |
| 26 | + | NumberInput |
| 27 | + | SelectInput |
| 28 | + | TextAreaInput |
| 29 | + | CheckboxInput |
| 30 | + | RadioInput |
| 31 | + | EmailInput |
| 32 | + | PasswordInput |
| 33 | + | RadioInput |
| 34 | + | ColorInput |
| 35 | + | UrlInput |
| 36 | + | CustomInput |
| 37 | +``` |
| 38 | +
|
| 39 | +### `FormFields` |
| 40 | +
|
| 41 | +```ts |
| 42 | +export type FormFields = { |
| 43 | + [key: string]: InputType |
| 44 | +} |
| 45 | +``` |
| 46 | +
|
| 47 | +### `InputBase` |
| 48 | +
|
| 49 | +```ts |
| 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 | +``` |
| 65 | + |
| 66 | +### `TextInput` |
| 67 | + |
| 68 | +```ts |
| 69 | +export type TextInput = InputBase & { |
| 70 | + type: FieldTypes.TEXT |
| 71 | + value?: string |
| 72 | +} |
| 73 | +``` |
| 74 | +
|
| 75 | +### `TextInput` |
| 76 | +
|
| 77 | +```ts |
| 78 | +export type NumberInput = InputBase & { |
| 79 | + type: FieldTypes.NUMBER |
| 80 | + value: number |
| 81 | + min: number |
| 82 | + max: number |
| 83 | + step: number |
| 84 | +} |
| 85 | +``` |
| 86 | +
|
| 87 | +### `SelectInput` |
| 88 | +
|
| 89 | +```ts |
| 90 | +export type SelectInput<T = boolean | string> = InputBase & { |
| 91 | + type: FieldTypes.SELECT |
| 92 | + value: T |
| 93 | + optionValue: string |
| 94 | + optionLabel: string |
| 95 | + options?: { label: string; value: string; disabled?: boolean }[] |
| 96 | +} |
| 97 | +``` |
| 98 | +
|
| 99 | +### `TextAreaInput` |
| 100 | +
|
| 101 | +```ts |
| 102 | +export type TextAreaInput = InputBase & { |
| 103 | + type: FieldTypes.TEXTAREA |
| 104 | + value: string |
| 105 | + cols?: number |
| 106 | + rows?: number |
| 107 | +} |
| 108 | +``` |
| 109 | +
|
| 110 | +### `CheckboxInput` |
| 111 | +
|
| 112 | +```ts |
| 113 | +export type CheckboxInput = InputBase & { |
| 114 | + type: FieldTypes.CHECKBOX |
| 115 | + value: boolean |
| 116 | +} |
| 117 | +``` |
| 118 | +
|
| 119 | +### `RadioInput` |
| 120 | +
|
| 121 | +```ts |
| 122 | +export type RadioInput = InputBase & { |
| 123 | + type: FieldTypes.RADIO |
| 124 | + value: string |
| 125 | + options?: { key: string; value: string; disabled?: boolean }[] |
| 126 | +} |
| 127 | +``` |
| 128 | +
|
| 129 | +### `CustomInput` |
| 130 | +
|
| 131 | +```ts |
| 132 | +export type CustomInput = InputBase & { |
| 133 | + type: FieldTypes.CUSTOM |
| 134 | + value: boolean | string | number |
| 135 | +} |
| 136 | +``` |
| 137 | +
|
| 138 | +### `EmailInput` |
| 139 | +
|
| 140 | +```ts |
| 141 | +export type EmailInput = InputBase & { |
| 142 | + type: FieldTypes.EMAIL |
| 143 | + value: string |
| 144 | +} |
| 145 | +``` |
| 146 | +
|
| 147 | +### `PasswordInput` |
| 148 | +
|
| 149 | +```ts |
| 150 | +export type PasswordInput = InputBase & { |
| 151 | + type: FieldTypes.PASSWORD |
| 152 | + value: string |
| 153 | +} |
| 154 | +``` |
| 155 | +
|
| 156 | +### `ColorInput` |
| 157 | +
|
| 158 | +```ts |
| 159 | +export type ColorInput = InputBase & { |
| 160 | + type: FieldTypes.COLOR |
| 161 | + value: string |
| 162 | +} |
| 163 | +``` |
| 164 | +
|
| 165 | +### `UrlInput` |
| 166 | +
|
| 167 | +```ts |
| 168 | +export type UrlInput = InputBase & { |
| 169 | + type: FieldTypes.URL |
| 170 | + value: string |
| 171 | +} |
| 172 | +``` |
| 173 | +
|
| 174 | +## Form |
| 175 | +
|
| 176 | +### `FormOptions` |
| 177 | +
|
| 178 | +```ts |
| 179 | +export interface FormOptions { |
| 180 | + customClass?: string | string[] | BindingObject | BindingObject[] | unknown |
| 181 | + customStyles?: string | string[] | BindingObject | BindingObject[] | unknown |
| 182 | + method?: string |
| 183 | + netlify?: boolean |
| 184 | + netlifyHoneypot?: string |
| 185 | + autocomplete?: boolean | string |
| 186 | + resetAfterSubmit?: boolean |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +### `DynamicForm` |
| 191 | + |
| 192 | +```ts |
| 193 | +export interface DynamicForm { |
| 194 | + id: string |
| 195 | + fields: FormFields |
| 196 | + fieldOrder?: string[] |
| 197 | + options?: FormOptions |
| 198 | +} |
| 199 | +``` |
| 200 | + |
| 201 | +## Controls & Validation |
| 202 | + |
| 203 | +### `ValidationTrigger` |
| 204 | + |
| 205 | +```ts |
| 206 | +export enum ValidationTriggerTypes { |
| 207 | + BLUR = 'blur', |
| 208 | + CHANGE = 'change', |
| 209 | +} |
| 210 | +export interface ValidationTrigger { |
| 211 | + type: ValidationTriggerTypes |
| 212 | + threshold: number |
| 213 | +} |
| 214 | +``` |
| 215 | + |
| 216 | +### `ValidatorFn` |
| 217 | + |
| 218 | +```ts |
| 219 | +export interface ValidatorFn { |
| 220 | + (value: ControlValue | undefined): ValidationErrors | null |
| 221 | +} |
| 222 | +``` |
| 223 | + |
| 224 | +### `ValidationErrors` |
| 225 | + |
| 226 | +```ts |
| 227 | +export type ValidationErrors = { |
| 228 | + // eslint-disable-next-line |
| 229 | + [key: string]: any |
| 230 | +} |
| 231 | +``` |
| 232 | +
|
| 233 | +### `FormValidator` |
| 234 | +
|
| 235 | +```ts |
| 236 | +export interface FormValidator { |
| 237 | + validator: ValidatorFn |
| 238 | + text: string |
| 239 | + type?: string |
| 240 | +} |
| 241 | +``` |
| 242 | + |
| 243 | +### `ControlValue` |
| 244 | + |
| 245 | +```ts |
| 246 | +export type ControlValue = string | number | boolean |
| 247 | +``` |
| 248 | +
|
| 249 | +### `FormControl` |
| 250 | +
|
| 251 | +```ts |
| 252 | +export type FormControl<T extends InputType> = T & { |
| 253 | + valid: boolean |
| 254 | + dirty: boolean |
| 255 | + touched: boolean |
| 256 | + errors: ValidationErrors | null |
| 257 | +} |
| 258 | +``` |
0 commit comments