@sio-group/form-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/README.md +783 -0
- package/ROADMAP.md +21 -0
- package/dist/index.cjs +1919 -0
- package/dist/index.d.cts +284 -0
- package/dist/index.d.ts +284 -0
- package/dist/index.js +1878 -0
- package/dist/styles/components/button.css +244 -0
- package/dist/styles/components/button.css.map +1 -0
- package/dist/styles/components/checkbox.css +90 -0
- package/dist/styles/components/checkbox.css.map +1 -0
- package/dist/styles/components/color.css +31 -0
- package/dist/styles/components/color.css.map +1 -0
- package/dist/styles/components/form-field.css +36 -0
- package/dist/styles/components/form-field.css.map +1 -0
- package/dist/styles/components/form-states.css +80 -0
- package/dist/styles/components/form-states.css.map +1 -0
- package/dist/styles/components/grid.css +818 -0
- package/dist/styles/components/grid.css.map +1 -0
- package/dist/styles/components/input.css +112 -0
- package/dist/styles/components/input.css.map +1 -0
- package/dist/styles/components/link.css +113 -0
- package/dist/styles/components/link.css.map +1 -0
- package/dist/styles/components/radio.css +104 -0
- package/dist/styles/components/radio.css.map +1 -0
- package/dist/styles/components/range.css +54 -0
- package/dist/styles/components/range.css.map +1 -0
- package/dist/styles/components/select.css +37 -0
- package/dist/styles/components/select.css.map +1 -0
- package/dist/styles/components/upload.css +54 -0
- package/dist/styles/components/upload.css.map +1 -0
- package/dist/styles/index.css +1733 -0
- package/dist/styles/index.css.map +1 -0
- package/package.json +42 -0
- package/screenshots/contact-form.png +0 -0
- package/screenshots/file-input.png +0 -0
- package/screenshots/invalid-username.png +0 -0
- package/screenshots/number-field.png +0 -0
- package/screenshots/radio-field.png +0 -0
- package/screenshots/range-field.png +0 -0
- package/screenshots/registration-form.png +0 -0
- package/screenshots/select-field.png +0 -0
- package/screenshots/textarea-field.png +0 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +8 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { CSSProperties, ComponentType, ComponentPropsWithoutRef, HTMLAttributes } from 'react';
|
|
3
|
+
import { LayoutType, FormField, IconType, AcceptType, CaptureType, SpinnerVariant, SelectOption, Option, FieldConfigMap } from '@sio-group/form-types';
|
|
4
|
+
import { Properties } from 'csstype';
|
|
5
|
+
import { ValidationRule } from '@sio-group/form-types/src/core/valudation-rule';
|
|
6
|
+
|
|
7
|
+
interface FormLayout {
|
|
8
|
+
fields: string[];
|
|
9
|
+
layout?: LayoutType;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type ButtonType = 'button' | 'submit' | 'reset';
|
|
13
|
+
type Variant = 'primary' | 'secondary' | 'link';
|
|
14
|
+
type Color = 'default' | 'error' | 'success' | 'warning' | 'info';
|
|
15
|
+
type Size = 'sm' | 'md' | 'lg';
|
|
16
|
+
|
|
17
|
+
type BaseUiProps = {
|
|
18
|
+
variant?: Variant;
|
|
19
|
+
label?: string | React.ReactNode;
|
|
20
|
+
color?: Color;
|
|
21
|
+
size?: Size;
|
|
22
|
+
block?: boolean;
|
|
23
|
+
loading?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
ariaLabel?: string;
|
|
27
|
+
style?: React.CSSProperties;
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ButtonProps = BaseUiProps & {
|
|
32
|
+
type?: ButtonType;
|
|
33
|
+
onClick: (e: React.MouseEvent) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type LinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'onClick' | 'color'> &
|
|
37
|
+
BaseUiProps & {
|
|
38
|
+
to: string;
|
|
39
|
+
navigate?: () => void;
|
|
40
|
+
external?: boolean;
|
|
41
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type FormContainerProps = ComponentPropsWithoutRef<'form'>;
|
|
45
|
+
type ButtonContainerProps = HTMLAttributes<HTMLDivElement>;
|
|
46
|
+
|
|
47
|
+
interface FormConfig {
|
|
48
|
+
fields: FormField[];
|
|
49
|
+
layout?: FormLayout[];
|
|
50
|
+
|
|
51
|
+
submitShow?: boolean;
|
|
52
|
+
submitAction: (values: Record<string, any>) => void | Promise<void>;
|
|
53
|
+
submitLabel?: string;
|
|
54
|
+
cancelShow?: boolean;
|
|
55
|
+
cancelAction?: () => void;
|
|
56
|
+
cancelLabel?: string;
|
|
57
|
+
|
|
58
|
+
buttons?: (ButtonProps | LinkProps)[];
|
|
59
|
+
extraValidation?: (values: Record<string, any>) => boolean | Promise<boolean>
|
|
60
|
+
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
|
|
64
|
+
disableWhenOffline?: boolean;
|
|
65
|
+
|
|
66
|
+
container?: ComponentType<FormContainerProps>;
|
|
67
|
+
buttonContainer?: ComponentType<ButtonContainerProps>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const Form: ({ fields, layout, submitShow, submitAction, submitLabel, cancelShow, cancelAction, cancelLabel, buttons, extraValidation, className, style, disableWhenOffline, container: Container, buttonContainer: ButtonContainer, }: FormConfig) => react_jsx_runtime.JSX.Element;
|
|
71
|
+
|
|
72
|
+
type BaseFieldProps = {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
label?: string;
|
|
76
|
+
placeholder?: string;
|
|
77
|
+
value: unknown;
|
|
78
|
+
errors: string[];
|
|
79
|
+
required?: boolean;
|
|
80
|
+
autocomplete?: string;
|
|
81
|
+
touched: boolean;
|
|
82
|
+
focused: boolean;
|
|
83
|
+
readOnly?: boolean;
|
|
84
|
+
disabled: boolean;
|
|
85
|
+
icon?: IconType;
|
|
86
|
+
description?: string;
|
|
87
|
+
onChange: (value: unknown) => void;
|
|
88
|
+
setFocused: (focused: boolean) => void;
|
|
89
|
+
setTouched: (touched: boolean) => void;
|
|
90
|
+
className?: string;
|
|
91
|
+
style?: Properties;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type TextareaFieldProps = BaseFieldProps & {
|
|
95
|
+
type: "textarea";
|
|
96
|
+
rows?: number;
|
|
97
|
+
cols?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type FileFieldProps = BaseFieldProps & {
|
|
101
|
+
type: "file";
|
|
102
|
+
accept?: AcceptType;
|
|
103
|
+
multiple: boolean;
|
|
104
|
+
capture: CaptureType;
|
|
105
|
+
onError: (errors: string[]) => void;
|
|
106
|
+
filesize: number;
|
|
107
|
+
onFileRemove?: (file: File, index: number, files: File[]) => void;
|
|
108
|
+
onRemoveAll?: (files: File[]) => void;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type NumberFieldProps = BaseFieldProps & {
|
|
112
|
+
type: "number";
|
|
113
|
+
min: number;
|
|
114
|
+
max: number;
|
|
115
|
+
step: number;
|
|
116
|
+
spinner: boolean | SpinnerVariant;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type RangeFieldProps = BaseFieldProps & {
|
|
120
|
+
type: "range";
|
|
121
|
+
min: number;
|
|
122
|
+
max: number;
|
|
123
|
+
step: number;
|
|
124
|
+
showValue: boolean;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
type DateFieldProps = BaseFieldProps & {
|
|
128
|
+
type: "date" | "time" | "datetime-local";
|
|
129
|
+
min: string;
|
|
130
|
+
max: string;
|
|
131
|
+
step: number;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type UrlFieldProps = BaseFieldProps & {
|
|
135
|
+
type: "url";
|
|
136
|
+
allowLocalhost: boolean;
|
|
137
|
+
allowFtp: boolean;
|
|
138
|
+
secureOnly: boolean;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
type SelectFieldProps = BaseFieldProps & {
|
|
142
|
+
type: "select" | "creatable";
|
|
143
|
+
options: SelectOption[];
|
|
144
|
+
multiple: boolean;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type RadioFieldProps = BaseFieldProps & {
|
|
148
|
+
type: "radio";
|
|
149
|
+
options: string[] | Option[];
|
|
150
|
+
inline: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
type FieldProps =
|
|
154
|
+
| FileFieldProps
|
|
155
|
+
| TextareaFieldProps
|
|
156
|
+
| NumberFieldProps
|
|
157
|
+
| RangeFieldProps
|
|
158
|
+
| DateFieldProps
|
|
159
|
+
| UrlFieldProps
|
|
160
|
+
| SelectFieldProps
|
|
161
|
+
| RadioFieldProps
|
|
162
|
+
| (BaseFieldProps & { type: Exclude<FieldType, "file" | "textarea" | "range" | "date" | "time" | "datetime-local" | "url" | "select" | "creatable" | "radio"> });
|
|
163
|
+
|
|
164
|
+
type FieldType$1 = keyof FieldConfigMap;
|
|
165
|
+
|
|
166
|
+
type FieldState = {
|
|
167
|
+
[K in FieldType$1]: {
|
|
168
|
+
type: K;
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
value: FieldConfigMap[T]['defaultValue'];
|
|
172
|
+
|
|
173
|
+
validations: ValidationRule<T>[];
|
|
174
|
+
errors: string[];
|
|
175
|
+
|
|
176
|
+
touched: boolean;
|
|
177
|
+
focused: boolean;
|
|
178
|
+
} & FieldConfigMap[K]
|
|
179
|
+
}[FieldType$1];
|
|
180
|
+
|
|
181
|
+
interface UseFormOptions {
|
|
182
|
+
disableWhenOffline: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare const useForm: ({ disableWhenOffline }?: UseFormOptions) => {
|
|
186
|
+
register: (name: string, config: FormField, renderLayout?: boolean) => FieldProps;
|
|
187
|
+
unregister: (name: string) => void;
|
|
188
|
+
setValue: (name: string, value: unknown) => void;
|
|
189
|
+
getValues: () => Record<string, any>;
|
|
190
|
+
getValue: (name: string) => any;
|
|
191
|
+
reset: () => void;
|
|
192
|
+
isValid: () => boolean;
|
|
193
|
+
isDirty: () => boolean;
|
|
194
|
+
isBusy: () => boolean;
|
|
195
|
+
submit: (onSubmit: (values: Record<string, any>) => void | Promise<void>) => Promise<void>;
|
|
196
|
+
getField: (name: string) => FieldState | undefined;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Button component for user interaction.
|
|
201
|
+
*
|
|
202
|
+
* @component
|
|
203
|
+
* @example
|
|
204
|
+
* // Primaire button
|
|
205
|
+
* <Button label="Save" onClick={handleSave} />
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* // Submit button with loading state
|
|
209
|
+
* <Button
|
|
210
|
+
* type="submit"
|
|
211
|
+
* label="Send"
|
|
212
|
+
* variant="primary"
|
|
213
|
+
* loading
|
|
214
|
+
* />
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* // Button with icon and tekst
|
|
218
|
+
* <Button type="button" onClick={handleClick}>
|
|
219
|
+
* <Icon name="plus" />
|
|
220
|
+
* <span>Add</span>
|
|
221
|
+
* </Button>
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* // Error variant
|
|
225
|
+
* <Button
|
|
226
|
+
* type="button"
|
|
227
|
+
* label="Delete"
|
|
228
|
+
* variant="secondary"
|
|
229
|
+
* color="error"
|
|
230
|
+
* onClick={handleDelete}
|
|
231
|
+
* />
|
|
232
|
+
*/
|
|
233
|
+
declare const Button: React.FC<ButtonProps>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Custom Link component for internal or external navigation
|
|
237
|
+
*
|
|
238
|
+
* @component
|
|
239
|
+
* @example
|
|
240
|
+
* // Internal link
|
|
241
|
+
* <Link to="/dashboard" label="Dashboard" />
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* // External link
|
|
245
|
+
* // external property is optional
|
|
246
|
+
* // http(s), ftp, email and tel with automatically render as external
|
|
247
|
+
* <Link to="https://example.com" label="Visit website" external />
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* // Link with loading state
|
|
251
|
+
* <Link to="/profile" label="Profile" loading />
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* // Link with custom click handler en navigation
|
|
255
|
+
* <Link
|
|
256
|
+
* to="/settings"
|
|
257
|
+
* label="Settings"
|
|
258
|
+
* onClick={() => console.log('clicked')}
|
|
259
|
+
* navigate={customNavigate}
|
|
260
|
+
* />
|
|
261
|
+
*/
|
|
262
|
+
declare const Link: React.FC<LinkProps>;
|
|
263
|
+
|
|
264
|
+
declare const Checkbox: ({ value, onChange, name, id, label, required, setTouched, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FieldProps) => react_jsx_runtime.JSX.Element;
|
|
265
|
+
|
|
266
|
+
declare const Input: React.MemoExoticComponent<(props: FieldProps) => react_jsx_runtime.JSX.Element>;
|
|
267
|
+
|
|
268
|
+
declare const NumberInput: ({ value, min, max, step, spinner, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: NumberFieldProps) => react_jsx_runtime.JSX.Element;
|
|
269
|
+
|
|
270
|
+
declare const RangeInput: ({ value, min, max, step, showValue, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: RangeFieldProps) => react_jsx_runtime.JSX.Element;
|
|
271
|
+
|
|
272
|
+
declare const DateInput: ({ value, min, max, step, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: DateFieldProps) => react_jsx_runtime.JSX.Element;
|
|
273
|
+
|
|
274
|
+
declare const FileInput: ({ value, onChange, onError, accept, filesize, multiple, capture, onFileRemove, onRemoveAll, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FileFieldProps) => react_jsx_runtime.JSX.Element;
|
|
275
|
+
|
|
276
|
+
declare const TextInput: ({ value, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FieldProps) => react_jsx_runtime.JSX.Element;
|
|
277
|
+
|
|
278
|
+
declare const Radio: ({ value, onChange, options, inline, name, id, label, required, setTouched, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: RadioFieldProps) => react_jsx_runtime.JSX.Element;
|
|
279
|
+
|
|
280
|
+
declare const Select: ({ value, onChange, options, multiple, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: SelectFieldProps) => react_jsx_runtime.JSX.Element;
|
|
281
|
+
|
|
282
|
+
declare const Textarea: ({ value, onChange, rows, cols, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: TextareaFieldProps) => react_jsx_runtime.JSX.Element;
|
|
283
|
+
|
|
284
|
+
export { Button, type ButtonProps, Checkbox, DateInput, type FieldProps, FileInput, Form, type FormConfig, type FormLayout, Input, Link, type LinkProps, NumberInput, Radio, RangeInput, Select, TextInput, Textarea, useForm };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { CSSProperties, ComponentType, ComponentPropsWithoutRef, HTMLAttributes } from 'react';
|
|
3
|
+
import { LayoutType, FormField, IconType, AcceptType, CaptureType, SpinnerVariant, SelectOption, Option, FieldConfigMap } from '@sio-group/form-types';
|
|
4
|
+
import { Properties } from 'csstype';
|
|
5
|
+
import { ValidationRule } from '@sio-group/form-types/src/core/valudation-rule';
|
|
6
|
+
|
|
7
|
+
interface FormLayout {
|
|
8
|
+
fields: string[];
|
|
9
|
+
layout?: LayoutType;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type ButtonType = 'button' | 'submit' | 'reset';
|
|
13
|
+
type Variant = 'primary' | 'secondary' | 'link';
|
|
14
|
+
type Color = 'default' | 'error' | 'success' | 'warning' | 'info';
|
|
15
|
+
type Size = 'sm' | 'md' | 'lg';
|
|
16
|
+
|
|
17
|
+
type BaseUiProps = {
|
|
18
|
+
variant?: Variant;
|
|
19
|
+
label?: string | React.ReactNode;
|
|
20
|
+
color?: Color;
|
|
21
|
+
size?: Size;
|
|
22
|
+
block?: boolean;
|
|
23
|
+
loading?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
ariaLabel?: string;
|
|
27
|
+
style?: React.CSSProperties;
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type ButtonProps = BaseUiProps & {
|
|
32
|
+
type?: ButtonType;
|
|
33
|
+
onClick: (e: React.MouseEvent) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type LinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'onClick' | 'color'> &
|
|
37
|
+
BaseUiProps & {
|
|
38
|
+
to: string;
|
|
39
|
+
navigate?: () => void;
|
|
40
|
+
external?: boolean;
|
|
41
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type FormContainerProps = ComponentPropsWithoutRef<'form'>;
|
|
45
|
+
type ButtonContainerProps = HTMLAttributes<HTMLDivElement>;
|
|
46
|
+
|
|
47
|
+
interface FormConfig {
|
|
48
|
+
fields: FormField[];
|
|
49
|
+
layout?: FormLayout[];
|
|
50
|
+
|
|
51
|
+
submitShow?: boolean;
|
|
52
|
+
submitAction: (values: Record<string, any>) => void | Promise<void>;
|
|
53
|
+
submitLabel?: string;
|
|
54
|
+
cancelShow?: boolean;
|
|
55
|
+
cancelAction?: () => void;
|
|
56
|
+
cancelLabel?: string;
|
|
57
|
+
|
|
58
|
+
buttons?: (ButtonProps | LinkProps)[];
|
|
59
|
+
extraValidation?: (values: Record<string, any>) => boolean | Promise<boolean>
|
|
60
|
+
|
|
61
|
+
className?: string;
|
|
62
|
+
style?: CSSProperties;
|
|
63
|
+
|
|
64
|
+
disableWhenOffline?: boolean;
|
|
65
|
+
|
|
66
|
+
container?: ComponentType<FormContainerProps>;
|
|
67
|
+
buttonContainer?: ComponentType<ButtonContainerProps>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare const Form: ({ fields, layout, submitShow, submitAction, submitLabel, cancelShow, cancelAction, cancelLabel, buttons, extraValidation, className, style, disableWhenOffline, container: Container, buttonContainer: ButtonContainer, }: FormConfig) => react_jsx_runtime.JSX.Element;
|
|
71
|
+
|
|
72
|
+
type BaseFieldProps = {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
label?: string;
|
|
76
|
+
placeholder?: string;
|
|
77
|
+
value: unknown;
|
|
78
|
+
errors: string[];
|
|
79
|
+
required?: boolean;
|
|
80
|
+
autocomplete?: string;
|
|
81
|
+
touched: boolean;
|
|
82
|
+
focused: boolean;
|
|
83
|
+
readOnly?: boolean;
|
|
84
|
+
disabled: boolean;
|
|
85
|
+
icon?: IconType;
|
|
86
|
+
description?: string;
|
|
87
|
+
onChange: (value: unknown) => void;
|
|
88
|
+
setFocused: (focused: boolean) => void;
|
|
89
|
+
setTouched: (touched: boolean) => void;
|
|
90
|
+
className?: string;
|
|
91
|
+
style?: Properties;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type TextareaFieldProps = BaseFieldProps & {
|
|
95
|
+
type: "textarea";
|
|
96
|
+
rows?: number;
|
|
97
|
+
cols?: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type FileFieldProps = BaseFieldProps & {
|
|
101
|
+
type: "file";
|
|
102
|
+
accept?: AcceptType;
|
|
103
|
+
multiple: boolean;
|
|
104
|
+
capture: CaptureType;
|
|
105
|
+
onError: (errors: string[]) => void;
|
|
106
|
+
filesize: number;
|
|
107
|
+
onFileRemove?: (file: File, index: number, files: File[]) => void;
|
|
108
|
+
onRemoveAll?: (files: File[]) => void;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
type NumberFieldProps = BaseFieldProps & {
|
|
112
|
+
type: "number";
|
|
113
|
+
min: number;
|
|
114
|
+
max: number;
|
|
115
|
+
step: number;
|
|
116
|
+
spinner: boolean | SpinnerVariant;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type RangeFieldProps = BaseFieldProps & {
|
|
120
|
+
type: "range";
|
|
121
|
+
min: number;
|
|
122
|
+
max: number;
|
|
123
|
+
step: number;
|
|
124
|
+
showValue: boolean;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
type DateFieldProps = BaseFieldProps & {
|
|
128
|
+
type: "date" | "time" | "datetime-local";
|
|
129
|
+
min: string;
|
|
130
|
+
max: string;
|
|
131
|
+
step: number;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
type UrlFieldProps = BaseFieldProps & {
|
|
135
|
+
type: "url";
|
|
136
|
+
allowLocalhost: boolean;
|
|
137
|
+
allowFtp: boolean;
|
|
138
|
+
secureOnly: boolean;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
type SelectFieldProps = BaseFieldProps & {
|
|
142
|
+
type: "select" | "creatable";
|
|
143
|
+
options: SelectOption[];
|
|
144
|
+
multiple: boolean;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
type RadioFieldProps = BaseFieldProps & {
|
|
148
|
+
type: "radio";
|
|
149
|
+
options: string[] | Option[];
|
|
150
|
+
inline: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
type FieldProps =
|
|
154
|
+
| FileFieldProps
|
|
155
|
+
| TextareaFieldProps
|
|
156
|
+
| NumberFieldProps
|
|
157
|
+
| RangeFieldProps
|
|
158
|
+
| DateFieldProps
|
|
159
|
+
| UrlFieldProps
|
|
160
|
+
| SelectFieldProps
|
|
161
|
+
| RadioFieldProps
|
|
162
|
+
| (BaseFieldProps & { type: Exclude<FieldType, "file" | "textarea" | "range" | "date" | "time" | "datetime-local" | "url" | "select" | "creatable" | "radio"> });
|
|
163
|
+
|
|
164
|
+
type FieldType$1 = keyof FieldConfigMap;
|
|
165
|
+
|
|
166
|
+
type FieldState = {
|
|
167
|
+
[K in FieldType$1]: {
|
|
168
|
+
type: K;
|
|
169
|
+
id: string;
|
|
170
|
+
name: string;
|
|
171
|
+
value: FieldConfigMap[T]['defaultValue'];
|
|
172
|
+
|
|
173
|
+
validations: ValidationRule<T>[];
|
|
174
|
+
errors: string[];
|
|
175
|
+
|
|
176
|
+
touched: boolean;
|
|
177
|
+
focused: boolean;
|
|
178
|
+
} & FieldConfigMap[K]
|
|
179
|
+
}[FieldType$1];
|
|
180
|
+
|
|
181
|
+
interface UseFormOptions {
|
|
182
|
+
disableWhenOffline: boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare const useForm: ({ disableWhenOffline }?: UseFormOptions) => {
|
|
186
|
+
register: (name: string, config: FormField, renderLayout?: boolean) => FieldProps;
|
|
187
|
+
unregister: (name: string) => void;
|
|
188
|
+
setValue: (name: string, value: unknown) => void;
|
|
189
|
+
getValues: () => Record<string, any>;
|
|
190
|
+
getValue: (name: string) => any;
|
|
191
|
+
reset: () => void;
|
|
192
|
+
isValid: () => boolean;
|
|
193
|
+
isDirty: () => boolean;
|
|
194
|
+
isBusy: () => boolean;
|
|
195
|
+
submit: (onSubmit: (values: Record<string, any>) => void | Promise<void>) => Promise<void>;
|
|
196
|
+
getField: (name: string) => FieldState | undefined;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Button component for user interaction.
|
|
201
|
+
*
|
|
202
|
+
* @component
|
|
203
|
+
* @example
|
|
204
|
+
* // Primaire button
|
|
205
|
+
* <Button label="Save" onClick={handleSave} />
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* // Submit button with loading state
|
|
209
|
+
* <Button
|
|
210
|
+
* type="submit"
|
|
211
|
+
* label="Send"
|
|
212
|
+
* variant="primary"
|
|
213
|
+
* loading
|
|
214
|
+
* />
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* // Button with icon and tekst
|
|
218
|
+
* <Button type="button" onClick={handleClick}>
|
|
219
|
+
* <Icon name="plus" />
|
|
220
|
+
* <span>Add</span>
|
|
221
|
+
* </Button>
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* // Error variant
|
|
225
|
+
* <Button
|
|
226
|
+
* type="button"
|
|
227
|
+
* label="Delete"
|
|
228
|
+
* variant="secondary"
|
|
229
|
+
* color="error"
|
|
230
|
+
* onClick={handleDelete}
|
|
231
|
+
* />
|
|
232
|
+
*/
|
|
233
|
+
declare const Button: React.FC<ButtonProps>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Custom Link component for internal or external navigation
|
|
237
|
+
*
|
|
238
|
+
* @component
|
|
239
|
+
* @example
|
|
240
|
+
* // Internal link
|
|
241
|
+
* <Link to="/dashboard" label="Dashboard" />
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* // External link
|
|
245
|
+
* // external property is optional
|
|
246
|
+
* // http(s), ftp, email and tel with automatically render as external
|
|
247
|
+
* <Link to="https://example.com" label="Visit website" external />
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* // Link with loading state
|
|
251
|
+
* <Link to="/profile" label="Profile" loading />
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* // Link with custom click handler en navigation
|
|
255
|
+
* <Link
|
|
256
|
+
* to="/settings"
|
|
257
|
+
* label="Settings"
|
|
258
|
+
* onClick={() => console.log('clicked')}
|
|
259
|
+
* navigate={customNavigate}
|
|
260
|
+
* />
|
|
261
|
+
*/
|
|
262
|
+
declare const Link: React.FC<LinkProps>;
|
|
263
|
+
|
|
264
|
+
declare const Checkbox: ({ value, onChange, name, id, label, required, setTouched, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FieldProps) => react_jsx_runtime.JSX.Element;
|
|
265
|
+
|
|
266
|
+
declare const Input: React.MemoExoticComponent<(props: FieldProps) => react_jsx_runtime.JSX.Element>;
|
|
267
|
+
|
|
268
|
+
declare const NumberInput: ({ value, min, max, step, spinner, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: NumberFieldProps) => react_jsx_runtime.JSX.Element;
|
|
269
|
+
|
|
270
|
+
declare const RangeInput: ({ value, min, max, step, showValue, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: RangeFieldProps) => react_jsx_runtime.JSX.Element;
|
|
271
|
+
|
|
272
|
+
declare const DateInput: ({ value, min, max, step, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: DateFieldProps) => react_jsx_runtime.JSX.Element;
|
|
273
|
+
|
|
274
|
+
declare const FileInput: ({ value, onChange, onError, accept, filesize, multiple, capture, onFileRemove, onRemoveAll, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FileFieldProps) => react_jsx_runtime.JSX.Element;
|
|
275
|
+
|
|
276
|
+
declare const TextInput: ({ value, onChange, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: FieldProps) => react_jsx_runtime.JSX.Element;
|
|
277
|
+
|
|
278
|
+
declare const Radio: ({ value, onChange, options, inline, name, id, label, required, setTouched, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: RadioFieldProps) => react_jsx_runtime.JSX.Element;
|
|
279
|
+
|
|
280
|
+
declare const Select: ({ value, onChange, options, multiple, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: SelectFieldProps) => react_jsx_runtime.JSX.Element;
|
|
281
|
+
|
|
282
|
+
declare const Textarea: ({ value, onChange, rows, cols, name, id, placeholder, label, required, autocomplete, setTouched, setFocused, readOnly, disabled, icon, description, focused, errors, touched, type, className, style, }: TextareaFieldProps) => react_jsx_runtime.JSX.Element;
|
|
283
|
+
|
|
284
|
+
export { Button, type ButtonProps, Checkbox, DateInput, type FieldProps, FileInput, Form, type FormConfig, type FormLayout, Input, Link, type LinkProps, NumberInput, Radio, RangeInput, Select, TextInput, Textarea, useForm };
|