@ultraviolet/form 2.13.3 → 2.13.4
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/dist/components/CheckboxField/index.js +15 -32
- package/dist/components/CheckboxGroupField/index.js +31 -48
- package/dist/components/DateField/index.js +27 -42
- package/dist/components/Form/index.js +25 -33
- package/dist/components/KeyValueField/index.js +14 -48
- package/dist/components/NumberInputField/index.js +17 -32
- package/dist/components/NumberInputFieldV2/index.js +17 -37
- package/dist/components/RadioField/index.js +15 -27
- package/dist/components/RadioGroupField/index.js +12 -22
- package/dist/components/SelectInputField/index.js +41 -78
- package/dist/components/SelectInputFieldV2/index.js +16 -50
- package/dist/components/SelectableCardField/index.js +20 -42
- package/dist/components/SelectableCardGroupField/index.js +20 -34
- package/dist/components/Submit/index.js +5 -19
- package/dist/components/SubmitErrorAlert/index.js +6 -2
- package/dist/components/TagInputField/index.js +12 -27
- package/dist/components/TextAreaField/index.js +22 -50
- package/dist/components/TextInputField/index.js +31 -71
- package/dist/components/TextInputFieldV2/index.js +22 -59
- package/dist/components/TimeField/index.js +17 -42
- package/dist/components/ToggleField/index.js +10 -24
- package/dist/hooks/useField.js +10 -3
- package/dist/hooks/useFieldArray.js +13 -3
- package/dist/hooks/useForm.js +6 -1
- package/dist/hooks/useFormState.js +3 -1
- package/dist/hooks/useOnFieldChange.js +5 -4
- package/dist/providers/ErrorContext/index.js +17 -20
- package/package.json +3 -3
|
@@ -36,19 +36,21 @@ const TextInputField = ({
|
|
|
36
36
|
"aria-label": ariaLabel,
|
|
37
37
|
autoComplete
|
|
38
38
|
}) => {
|
|
39
|
-
const {
|
|
39
|
+
const {
|
|
40
|
+
getError
|
|
41
|
+
} = useErrors();
|
|
40
42
|
const {
|
|
41
43
|
field,
|
|
42
|
-
fieldState: {
|
|
44
|
+
fieldState: {
|
|
45
|
+
error
|
|
46
|
+
}
|
|
43
47
|
} = useController({
|
|
44
48
|
name,
|
|
45
49
|
rules: {
|
|
46
50
|
required,
|
|
47
51
|
validate: {
|
|
48
52
|
...regexes ? {
|
|
49
|
-
pattern: (value) => regexes.every(
|
|
50
|
-
(regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value))
|
|
51
|
-
)
|
|
53
|
+
pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
|
|
52
54
|
} : {},
|
|
53
55
|
...validate
|
|
54
56
|
},
|
|
@@ -56,60 +58,21 @@ const TextInputField = ({
|
|
|
56
58
|
maxLength
|
|
57
59
|
}
|
|
58
60
|
});
|
|
59
|
-
return /* @__PURE__ */ jsx(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
error
|
|
76
|
-
),
|
|
77
|
-
helper,
|
|
78
|
-
label,
|
|
79
|
-
loading,
|
|
80
|
-
labelDescription,
|
|
81
|
-
minLength,
|
|
82
|
-
maxLength,
|
|
83
|
-
name,
|
|
84
|
-
onBlur: (event) => {
|
|
85
|
-
onBlur?.(event);
|
|
86
|
-
field.onBlur();
|
|
87
|
-
},
|
|
88
|
-
onChange: (event) => {
|
|
89
|
-
field.onChange(event);
|
|
90
|
-
onChange?.(event);
|
|
91
|
-
},
|
|
92
|
-
onFocus: (event) => {
|
|
93
|
-
onFocus?.(event);
|
|
94
|
-
},
|
|
95
|
-
placeholder,
|
|
96
|
-
readOnly,
|
|
97
|
-
required,
|
|
98
|
-
success,
|
|
99
|
-
tabIndex,
|
|
100
|
-
tooltip,
|
|
101
|
-
type,
|
|
102
|
-
value: field.value,
|
|
103
|
-
id,
|
|
104
|
-
prefix,
|
|
105
|
-
suffix,
|
|
106
|
-
size,
|
|
107
|
-
onRandomize,
|
|
108
|
-
"aria-label": ariaLabel,
|
|
109
|
-
"aria-labelledby": ariaLabelledBy,
|
|
110
|
-
autoComplete
|
|
111
|
-
}
|
|
112
|
-
);
|
|
61
|
+
return /* @__PURE__ */ jsx(TextInputV2, { autoFocus, className, clearable, "data-testid": dataTestId, disabled, error: getError({
|
|
62
|
+
regex: regexes,
|
|
63
|
+
// minLength,
|
|
64
|
+
// maxLength,
|
|
65
|
+
label: label ?? "",
|
|
66
|
+
value: field.value
|
|
67
|
+
}, error), helper, label, loading, labelDescription, minLength, maxLength, name, onBlur: (event) => {
|
|
68
|
+
onBlur?.(event);
|
|
69
|
+
field.onBlur();
|
|
70
|
+
}, onChange: (event) => {
|
|
71
|
+
field.onChange(event);
|
|
72
|
+
onChange?.(event);
|
|
73
|
+
}, onFocus: (event) => {
|
|
74
|
+
onFocus?.(event);
|
|
75
|
+
}, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete });
|
|
113
76
|
};
|
|
114
77
|
export {
|
|
115
78
|
TextInputField
|
|
@@ -35,7 +35,9 @@ const TimeField = ({
|
|
|
35
35
|
}) => {
|
|
36
36
|
const {
|
|
37
37
|
field,
|
|
38
|
-
fieldState: {
|
|
38
|
+
fieldState: {
|
|
39
|
+
error
|
|
40
|
+
}
|
|
39
41
|
} = useController({
|
|
40
42
|
name,
|
|
41
43
|
shouldUnregister,
|
|
@@ -44,47 +46,20 @@ const TimeField = ({
|
|
|
44
46
|
...rules
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
|
-
return /* @__PURE__ */ jsx(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
date.setHours(Number(hours), Number(minutes), 0);
|
|
62
|
-
field.onChange(date);
|
|
63
|
-
},
|
|
64
|
-
onBlur: (event) => {
|
|
65
|
-
field.onBlur();
|
|
66
|
-
onBlur?.(event);
|
|
67
|
-
},
|
|
68
|
-
onFocus: (event) => {
|
|
69
|
-
onFocus?.(event);
|
|
70
|
-
},
|
|
71
|
-
error: error?.message,
|
|
72
|
-
disabled,
|
|
73
|
-
readOnly,
|
|
74
|
-
animation,
|
|
75
|
-
animationDuration,
|
|
76
|
-
animationOnChange,
|
|
77
|
-
className,
|
|
78
|
-
isLoading,
|
|
79
|
-
isClearable,
|
|
80
|
-
isSearchable,
|
|
81
|
-
inputId,
|
|
82
|
-
id,
|
|
83
|
-
options,
|
|
84
|
-
"data-testid": dataTestId,
|
|
85
|
-
noTopLabel
|
|
86
|
-
}
|
|
87
|
-
);
|
|
49
|
+
return /* @__PURE__ */ jsx(TimeInput, { name: field.name, placeholder, schedule, required, value: parseTime(field.value), onChange: (val) => {
|
|
50
|
+
if (!val)
|
|
51
|
+
return;
|
|
52
|
+
onChange?.(val);
|
|
53
|
+
const [hours, minutes] = val.value.split(":");
|
|
54
|
+
const date = field.value ? new Date(field.value) : /* @__PURE__ */ new Date();
|
|
55
|
+
date.setHours(Number(hours), Number(minutes), 0);
|
|
56
|
+
field.onChange(date);
|
|
57
|
+
}, onBlur: (event) => {
|
|
58
|
+
field.onBlur();
|
|
59
|
+
onBlur?.(event);
|
|
60
|
+
}, onFocus: (event) => {
|
|
61
|
+
onFocus?.(event);
|
|
62
|
+
}, error: error?.message, disabled, readOnly, animation, animationDuration, animationOnChange, className, isLoading, isClearable, isSearchable, inputId, id, options, "data-testid": dataTestId, noTopLabel });
|
|
88
63
|
};
|
|
89
64
|
export {
|
|
90
65
|
TimeField
|
|
@@ -17,7 +17,9 @@ const ToggleField = ({
|
|
|
17
17
|
"data-testid": dataTestId,
|
|
18
18
|
shouldUnregister = false
|
|
19
19
|
}) => {
|
|
20
|
-
const {
|
|
20
|
+
const {
|
|
21
|
+
field
|
|
22
|
+
} = useController({
|
|
21
23
|
name,
|
|
22
24
|
shouldUnregister,
|
|
23
25
|
rules: {
|
|
@@ -31,30 +33,14 @@ const ToggleField = ({
|
|
|
31
33
|
}
|
|
32
34
|
return field.value;
|
|
33
35
|
};
|
|
34
|
-
return /* @__PURE__ */ jsx(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
checked: transformedValue(),
|
|
40
|
-
tooltip,
|
|
41
|
-
onChange: (event) => {
|
|
42
|
-
if (parse) {
|
|
43
|
-
field.onChange(parse(event.target.checked));
|
|
44
|
-
} else {
|
|
45
|
-
field.onChange(event);
|
|
46
|
-
}
|
|
47
|
-
onChange?.(event);
|
|
48
|
-
},
|
|
49
|
-
label,
|
|
50
|
-
size,
|
|
51
|
-
disabled,
|
|
52
|
-
labelPosition,
|
|
53
|
-
className,
|
|
54
|
-
required,
|
|
55
|
-
"data-testid": dataTestId
|
|
36
|
+
return /* @__PURE__ */ jsx(Toggle, { name: field.name, ref: field.ref, checked: transformedValue(), tooltip, onChange: (event) => {
|
|
37
|
+
if (parse) {
|
|
38
|
+
field.onChange(parse(event.target.checked));
|
|
39
|
+
} else {
|
|
40
|
+
field.onChange(event);
|
|
56
41
|
}
|
|
57
|
-
|
|
42
|
+
onChange?.(event);
|
|
43
|
+
}, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId });
|
|
58
44
|
};
|
|
59
45
|
export {
|
|
60
46
|
ToggleField
|
package/dist/hooks/useField.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { useFormContext, useController } from "react-hook-form";
|
|
2
2
|
const useFieldDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
getValues
|
|
5
|
+
} = useFormContext();
|
|
6
|
+
const {
|
|
7
|
+
field,
|
|
8
|
+
fieldState
|
|
9
|
+
} = useController({
|
|
5
10
|
name,
|
|
6
|
-
rules: {
|
|
11
|
+
rules: {
|
|
12
|
+
validate: options?.validate
|
|
13
|
+
}
|
|
7
14
|
});
|
|
8
15
|
return {
|
|
9
16
|
input: {
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { useFieldArray, useWatch } from "react-hook-form";
|
|
2
2
|
const useFieldArrayDeprecated = (name, options) => {
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
fields,
|
|
5
|
+
append,
|
|
6
|
+
remove,
|
|
7
|
+
update,
|
|
8
|
+
move
|
|
9
|
+
} = useFieldArray({
|
|
4
10
|
name,
|
|
5
|
-
rules: {
|
|
11
|
+
rules: {
|
|
12
|
+
validate: options?.validate
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
const value = useWatch({
|
|
16
|
+
name
|
|
6
17
|
});
|
|
7
|
-
const value = useWatch({ name });
|
|
8
18
|
return {
|
|
9
19
|
fields: {
|
|
10
20
|
push: append,
|
package/dist/hooks/useForm.js
CHANGED
|
@@ -2,7 +2,12 @@ import { useContext } from "react";
|
|
|
2
2
|
import { useFormContext } from "react-hook-form";
|
|
3
3
|
import { FormSubmitContext } from "../components/Form/index.js";
|
|
4
4
|
const useFormDeprecated = () => {
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
setValue,
|
|
7
|
+
resetField,
|
|
8
|
+
getFieldState,
|
|
9
|
+
reset
|
|
10
|
+
} = useFormContext();
|
|
6
11
|
const formSubmitContext = useContext(FormSubmitContext);
|
|
7
12
|
return {
|
|
8
13
|
change: setValue,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useFormContext, useWatch } from "react-hook-form";
|
|
2
2
|
const useFormStateDeprecated = (_params) => {
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
formState
|
|
5
|
+
} = useFormContext();
|
|
4
6
|
return {
|
|
5
7
|
dirtySinceLastSubmit: formState.isDirty,
|
|
6
8
|
submitErrors: formState.errors.root,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useRef, useEffect } from "react";
|
|
2
2
|
import { useFormContext } from "react-hook-form";
|
|
3
3
|
const useOnFieldChange = (fieldName, callback, enabled = true) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
getValues
|
|
7
|
-
);
|
|
4
|
+
const {
|
|
5
|
+
watch,
|
|
6
|
+
getValues
|
|
7
|
+
} = useFormContext();
|
|
8
|
+
const previousValues = useRef(getValues(fieldName));
|
|
8
9
|
useEffect(() => {
|
|
9
10
|
const subscription = watch((value) => {
|
|
10
11
|
if (previousValues.current !== value[fieldName] && enabled) {
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useMemo, useContext } from "react";
|
|
3
3
|
const ErrorContext = createContext(void 0);
|
|
4
|
-
const ErrorProvider = ({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
[
|
|
16
|
-
);
|
|
17
|
-
const value = useMemo(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}),
|
|
22
|
-
[errors, getError]
|
|
23
|
-
);
|
|
4
|
+
const ErrorProvider = ({
|
|
5
|
+
children,
|
|
6
|
+
errors
|
|
7
|
+
}) => {
|
|
8
|
+
const getError = useCallback((meta, error) => {
|
|
9
|
+
if (!error) {
|
|
10
|
+
return void 0;
|
|
11
|
+
}
|
|
12
|
+
if (error.message) {
|
|
13
|
+
return error.message;
|
|
14
|
+
}
|
|
15
|
+
return errors?.[error.type]?.(meta);
|
|
16
|
+
}, [errors]);
|
|
17
|
+
const value = useMemo(() => ({
|
|
18
|
+
errors,
|
|
19
|
+
getError
|
|
20
|
+
}), [errors, getError]);
|
|
24
21
|
return /* @__PURE__ */ jsx(ErrorContext.Provider, { value, children });
|
|
25
22
|
};
|
|
26
23
|
const useErrors = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.4",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -52,14 +52,14 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@babel/runtime": "7.24.5",
|
|
55
|
-
"@emotion/babel-plugin": "11.11.0",
|
|
56
55
|
"@emotion/react": "11.11.4",
|
|
57
56
|
"@emotion/styled": "11.11.5",
|
|
58
57
|
"react-select": "5.8.0",
|
|
59
58
|
"react-hook-form": "7.51.3",
|
|
60
|
-
"@ultraviolet/ui": "1.51.
|
|
59
|
+
"@ultraviolet/ui": "1.51.3"
|
|
61
60
|
},
|
|
62
61
|
"scripts": {
|
|
62
|
+
"prebuild": "shx rm -rf dist",
|
|
63
63
|
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
64
64
|
"build": "vite build --config vite.config.ts && pnpm run type:generate",
|
|
65
65
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|