@ultraviolet/form 2.13.2 → 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.d.ts +10 -0
- package/dist/components/CheckboxField/index.js +17 -35
- package/dist/components/CheckboxGroupField/index.d.ts +32 -0
- package/dist/components/CheckboxGroupField/index.js +24 -35
- package/dist/components/DateField/index.d.ts +16 -0
- package/dist/components/DateField/index.js +33 -53
- package/dist/components/Form/defaultErrors.d.ts +2 -0
- package/dist/components/Form/defaultErrors.js +20 -19
- package/dist/components/Form/index.d.ts +69 -0
- package/dist/components/Form/index.js +41 -54
- package/dist/components/KeyValueField/index.d.ts +33 -0
- package/dist/components/KeyValueField/index.js +23 -56
- package/dist/components/NumberInputField/index.d.ts +13 -0
- package/dist/components/NumberInputField/index.js +18 -39
- package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
- package/dist/components/NumberInputFieldV2/index.js +20 -46
- package/dist/components/RadioField/index.d.ts +12 -0
- package/dist/components/RadioField/index.js +18 -36
- package/dist/components/RadioGroupField/index.d.ts +28 -0
- package/dist/components/RadioGroupField/index.js +15 -26
- package/dist/components/SelectInputField/index.d.ts +82 -0
- package/dist/components/SelectInputField/index.js +31 -61
- package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
- package/dist/components/SelectInputFieldV2/index.js +18 -52
- package/dist/components/SelectableCardField/index.d.ts +9 -0
- package/dist/components/SelectableCardField/index.js +24 -41
- package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
- package/dist/components/SelectableCardGroupField/index.js +22 -35
- package/dist/components/Submit/index.d.ts +17 -0
- package/dist/components/Submit/index.js +9 -23
- package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
- package/dist/components/SubmitErrorAlert/index.js +7 -11
- package/dist/components/TagInputField/index.d.ts +6 -0
- package/dist/components/TagInputField/index.js +14 -32
- package/dist/components/TextAreaField/index.d.ts +11 -0
- package/dist/components/TextAreaField/index.js +25 -52
- package/dist/components/TextInputField/index.d.ts +18 -0
- package/dist/components/TextInputField/index.js +37 -76
- package/dist/components/TextInputFieldV2/index.d.ts +12 -0
- package/dist/components/TextInputFieldV2/index.js +30 -66
- package/dist/components/TimeField/index.d.ts +9 -0
- package/dist/components/TimeField/index.js +23 -46
- package/dist/components/ToggleField/index.d.ts +10 -0
- package/dist/components/ToggleField/index.js +15 -28
- package/dist/components/ToggleGroupField/index.d.ts +26 -0
- package/dist/components/index.d.ts +22 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -3
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/useField.d.ts +34 -0
- package/dist/hooks/useField.js +4 -20
- package/dist/hooks/useFieldArray.d.ts +21 -0
- package/dist/hooks/useFieldArray.js +6 -9
- package/dist/hooks/useForm.d.ts +23 -0
- package/dist/hooks/useForm.js +7 -19
- package/dist/hooks/useFormState.d.ts +39 -0
- package/dist/hooks/useFormState.js +5 -20
- package/dist/hooks/useOnFieldChange.d.ts +3 -0
- package/dist/hooks/useOnFieldChange.js +6 -6
- package/dist/index.d.ts +7 -555
- package/dist/index.js +66 -29
- package/dist/mocks/index.d.ts +1 -0
- package/dist/mocks/mockErrors.d.ts +3 -0
- package/dist/providers/ErrorContext/index.d.ts +14 -0
- package/dist/providers/ErrorContext/index.js +11 -13
- package/dist/providers/index.d.ts +1 -0
- package/dist/types.d.ts +32 -0
- package/dist/validators/index.d.ts +5 -0
- package/dist/validators/maxDate.d.ts +1 -0
- package/dist/validators/maxDate.js +4 -3
- package/dist/validators/minDate.d.ts +1 -0
- package/dist/validators/minDate.js +4 -3
- package/package.json +12 -6
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated This component is deprecated, please use `TextInputFieldV2` instead
|
|
8
|
-
*/
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { TextInput } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
9
5
|
const TextInputField = ({
|
|
10
6
|
autoCapitalize,
|
|
11
7
|
autoComplete,
|
|
@@ -18,7 +14,7 @@ const TextInputField = ({
|
|
|
18
14
|
fillAvailable,
|
|
19
15
|
generated,
|
|
20
16
|
id,
|
|
21
|
-
label =
|
|
17
|
+
label = "",
|
|
22
18
|
multiline,
|
|
23
19
|
name,
|
|
24
20
|
noTopLabel,
|
|
@@ -52,7 +48,7 @@ const TextInputField = ({
|
|
|
52
48
|
customError,
|
|
53
49
|
innerRef,
|
|
54
50
|
shouldUnregister = false,
|
|
55
|
-
|
|
51
|
+
"data-testid": dataTestId
|
|
56
52
|
}) => {
|
|
57
53
|
const {
|
|
58
54
|
getError
|
|
@@ -69,9 +65,9 @@ const TextInputField = ({
|
|
|
69
65
|
rules: {
|
|
70
66
|
required,
|
|
71
67
|
validate: {
|
|
72
|
-
...
|
|
73
|
-
pattern: value => regexes.every(regex => value ===
|
|
74
|
-
} : {}
|
|
68
|
+
...regexes ? {
|
|
69
|
+
pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
|
|
70
|
+
} : {},
|
|
75
71
|
...validate
|
|
76
72
|
},
|
|
77
73
|
minLength,
|
|
@@ -87,67 +83,32 @@ const TextInputField = ({
|
|
|
87
83
|
}
|
|
88
84
|
return field.value;
|
|
89
85
|
};
|
|
90
|
-
return jsx(TextInput, {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
onBlur?.(event);
|
|
119
|
-
if (formatOnBlur && format) {
|
|
120
|
-
field.onChange(format(field.value));
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
onChange: event => {
|
|
124
|
-
if (parse) {
|
|
125
|
-
field.onChange(parse(event));
|
|
126
|
-
onChange?.(parse(event));
|
|
127
|
-
} else {
|
|
128
|
-
field.onChange(event);
|
|
129
|
-
onChange?.(event);
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
onFocus: event => {
|
|
133
|
-
onFocus?.(event);
|
|
134
|
-
},
|
|
135
|
-
onKeyUp: onKeyUp,
|
|
136
|
-
onKeyDown: onKeyDown,
|
|
137
|
-
placeholder: placeholder,
|
|
138
|
-
random: random,
|
|
139
|
-
readOnly: readOnly,
|
|
140
|
-
resizable: resizable,
|
|
141
|
-
rows: rows,
|
|
142
|
-
type: type,
|
|
143
|
-
noTopLabel: noTopLabel,
|
|
144
|
-
unit: unit,
|
|
145
|
-
valid: valid,
|
|
146
|
-
size: size,
|
|
147
|
-
value: transformedValue(),
|
|
148
|
-
ref: innerRef,
|
|
149
|
-
"data-testid": dataTestId
|
|
150
|
-
});
|
|
86
|
+
return /* @__PURE__ */ jsx(TextInput, { name: field.name, autoCapitalize, autoComplete, autoCorrect, autoFocus, autoSave, className, cols, disabled, error: customError ?? getError({
|
|
87
|
+
regex: regexes,
|
|
88
|
+
minLength,
|
|
89
|
+
maxLength,
|
|
90
|
+
label,
|
|
91
|
+
min,
|
|
92
|
+
max,
|
|
93
|
+
value: field.value
|
|
94
|
+
}, error), fillAvailable, generated, id, label, multiline, notice, required, onBlur: (event) => {
|
|
95
|
+
field.onBlur();
|
|
96
|
+
onBlur?.(event);
|
|
97
|
+
if (formatOnBlur && format) {
|
|
98
|
+
field.onChange(format(field.value));
|
|
99
|
+
}
|
|
100
|
+
}, onChange: (event) => {
|
|
101
|
+
if (parse) {
|
|
102
|
+
field.onChange(parse(event));
|
|
103
|
+
onChange?.(parse(event));
|
|
104
|
+
} else {
|
|
105
|
+
field.onChange(event);
|
|
106
|
+
onChange?.(event);
|
|
107
|
+
}
|
|
108
|
+
}, onFocus: (event) => {
|
|
109
|
+
onFocus?.(event);
|
|
110
|
+
}, onKeyUp, onKeyDown, placeholder, random, readOnly, resizable, rows, type, noTopLabel, unit, valid, size, value: transformedValue(), ref: innerRef, "data-testid": dataTestId });
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
TextInputField
|
|
151
114
|
};
|
|
152
|
-
|
|
153
|
-
export { TextInputField };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TextInputV2 } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name' | 'onChange'> & {
|
|
6
|
+
regex?: (RegExp | RegExp[])[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* This component offers a form field based on Ultraviolet UI TextInputV2 component
|
|
10
|
+
*/
|
|
11
|
+
export declare const TextInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ validate, regex: regexes, id, className, tabIndex, onChange, placeholder, disabled, readOnly, success, helper, tooltip, label, autoFocus, required, "data-testid": dataTestId, name, onFocus, onBlur, clearable, labelDescription, type, prefix, suffix, size, loading, onRandomize, minLength, maxLength, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, autoComplete, }: TextInputFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useErrors } from
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This component offers a form field based on Ultraviolet UI TextInputV2 component
|
|
8
|
-
*/
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { TextInputV2 } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
9
5
|
const TextInputField = ({
|
|
10
6
|
validate,
|
|
11
7
|
regex: regexes,
|
|
@@ -22,22 +18,22 @@ const TextInputField = ({
|
|
|
22
18
|
label,
|
|
23
19
|
autoFocus,
|
|
24
20
|
required = false,
|
|
25
|
-
|
|
21
|
+
"data-testid": dataTestId,
|
|
26
22
|
name,
|
|
27
23
|
onFocus,
|
|
28
24
|
onBlur,
|
|
29
25
|
clearable = false,
|
|
30
26
|
labelDescription,
|
|
31
|
-
type =
|
|
27
|
+
type = "text",
|
|
32
28
|
prefix,
|
|
33
29
|
suffix,
|
|
34
|
-
size =
|
|
30
|
+
size = "large",
|
|
35
31
|
loading,
|
|
36
32
|
onRandomize,
|
|
37
33
|
minLength,
|
|
38
34
|
maxLength,
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
"aria-labelledby": ariaLabelledBy,
|
|
36
|
+
"aria-label": ariaLabel,
|
|
41
37
|
autoComplete
|
|
42
38
|
}) => {
|
|
43
39
|
const {
|
|
@@ -53,63 +49,31 @@ const TextInputField = ({
|
|
|
53
49
|
rules: {
|
|
54
50
|
required,
|
|
55
51
|
validate: {
|
|
56
|
-
...
|
|
57
|
-
pattern: value => regexes.every(regex => value ===
|
|
58
|
-
} : {}
|
|
52
|
+
...regexes ? {
|
|
53
|
+
pattern: (value) => regexes.every((regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value)))
|
|
54
|
+
} : {},
|
|
59
55
|
...validate
|
|
60
56
|
},
|
|
61
57
|
minLength,
|
|
62
58
|
maxLength
|
|
63
59
|
}
|
|
64
60
|
});
|
|
65
|
-
return jsx(TextInputV2, {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
maxLength: maxLength,
|
|
84
|
-
name: name,
|
|
85
|
-
onBlur: event => {
|
|
86
|
-
onBlur?.(event);
|
|
87
|
-
field.onBlur();
|
|
88
|
-
},
|
|
89
|
-
onChange: event => {
|
|
90
|
-
field.onChange(event);
|
|
91
|
-
onChange?.(event);
|
|
92
|
-
},
|
|
93
|
-
onFocus: event => {
|
|
94
|
-
onFocus?.(event);
|
|
95
|
-
},
|
|
96
|
-
placeholder: placeholder,
|
|
97
|
-
readOnly: readOnly,
|
|
98
|
-
required: required,
|
|
99
|
-
success: success,
|
|
100
|
-
tabIndex: tabIndex,
|
|
101
|
-
tooltip: tooltip,
|
|
102
|
-
type: type,
|
|
103
|
-
value: field.value,
|
|
104
|
-
id: id,
|
|
105
|
-
prefix: prefix,
|
|
106
|
-
suffix: suffix,
|
|
107
|
-
size: size,
|
|
108
|
-
onRandomize: onRandomize,
|
|
109
|
-
"aria-label": ariaLabel,
|
|
110
|
-
"aria-labelledby": ariaLabelledBy,
|
|
111
|
-
autoComplete: autoComplete
|
|
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 });
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
TextInputField
|
|
113
79
|
};
|
|
114
|
-
|
|
115
|
-
export { TextInputField };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TimeInput } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type TimeFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TimeInput>, 'onChange'> & {
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const TimeField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ required, name, schedule, placeholder, disabled, readOnly, onBlur, onFocus, onChange, isLoading, isClearable, inputId, id, animation, animationDuration, animationOnChange, className, isSearchable, rules, options, "data-testid": dataTestId, shouldUnregister, noTopLabel, }: TimeFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const timeStr = date && typeof date !== 'string' ? date.toLocaleTimeString().slice(0, -3) : '';
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { TimeInput } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
const parseTime = (date) => {
|
|
5
|
+
const timeStr = date && typeof date !== "string" ? date.toLocaleTimeString().slice(0, -3) : "";
|
|
7
6
|
return {
|
|
8
7
|
label: timeStr,
|
|
9
8
|
value: timeStr
|
|
@@ -30,7 +29,7 @@ const TimeField = ({
|
|
|
30
29
|
isSearchable,
|
|
31
30
|
rules,
|
|
32
31
|
options,
|
|
33
|
-
|
|
32
|
+
"data-testid": dataTestId,
|
|
34
33
|
shouldUnregister = false,
|
|
35
34
|
noTopLabel
|
|
36
35
|
}) => {
|
|
@@ -47,43 +46,21 @@ const TimeField = ({
|
|
|
47
46
|
...rules
|
|
48
47
|
}
|
|
49
48
|
});
|
|
50
|
-
return jsx(TimeInput, {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
value
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
onFocus: event => {
|
|
69
|
-
onFocus?.(event);
|
|
70
|
-
},
|
|
71
|
-
error: error?.message,
|
|
72
|
-
disabled: disabled,
|
|
73
|
-
readOnly: readOnly,
|
|
74
|
-
animation: animation,
|
|
75
|
-
animationDuration: animationDuration,
|
|
76
|
-
animationOnChange: animationOnChange,
|
|
77
|
-
className: className,
|
|
78
|
-
isLoading: isLoading,
|
|
79
|
-
isClearable: isClearable,
|
|
80
|
-
isSearchable: isSearchable,
|
|
81
|
-
inputId: inputId,
|
|
82
|
-
id: id,
|
|
83
|
-
options: options,
|
|
84
|
-
"data-testid": dataTestId,
|
|
85
|
-
noTopLabel: noTopLabel
|
|
86
|
-
});
|
|
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 });
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
TimeField
|
|
87
66
|
};
|
|
88
|
-
|
|
89
|
-
export { TimeField };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Toggle } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type ToggleFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'label'> & Pick<ComponentProps<typeof Toggle>, 'disabled' | 'label' | 'onChange' | 'size' | 'tooltip' | 'labelPosition' | 'className' | 'data-testid'> & {
|
|
6
|
+
parse?: (value: boolean) => any;
|
|
7
|
+
format?: (value: any) => boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const ToggleField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, disabled, label, name, onChange, required, size, tooltip, rules, labelPosition, parse, format, "data-testid": dataTestId, shouldUnregister, }: ToggleFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Toggle } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
5
4
|
const ToggleField = ({
|
|
6
5
|
className,
|
|
7
6
|
disabled,
|
|
@@ -15,7 +14,7 @@ const ToggleField = ({
|
|
|
15
14
|
labelPosition,
|
|
16
15
|
parse,
|
|
17
16
|
format,
|
|
18
|
-
|
|
17
|
+
"data-testid": dataTestId,
|
|
19
18
|
shouldUnregister = false
|
|
20
19
|
}) => {
|
|
21
20
|
const {
|
|
@@ -34,27 +33,15 @@ const ToggleField = ({
|
|
|
34
33
|
}
|
|
35
34
|
return field.value;
|
|
36
35
|
};
|
|
37
|
-
return jsx(Toggle, {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
onChange?.(event);
|
|
49
|
-
},
|
|
50
|
-
label: label,
|
|
51
|
-
size: size,
|
|
52
|
-
disabled: disabled,
|
|
53
|
-
labelPosition: labelPosition,
|
|
54
|
-
className: className,
|
|
55
|
-
required: required,
|
|
56
|
-
"data-testid": dataTestId
|
|
57
|
-
});
|
|
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);
|
|
41
|
+
}
|
|
42
|
+
onChange?.(event);
|
|
43
|
+
}, label, size, disabled, labelPosition, className, required, "data-testid": dataTestId });
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
ToggleField
|
|
58
47
|
};
|
|
59
|
-
|
|
60
|
-
export { ToggleField };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ToggleGroup } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type ToggleGroupFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof ToggleGroup>, 'className' | 'helper' | 'direction' | 'children' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof ToggleGroup>, 'legend' | 'name'>>;
|
|
6
|
+
export declare const ToggleGroupField: {
|
|
7
|
+
<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ legend, className, helper, direction, children, onChange, label, error: customError, name, required, shouldUnregister, }: ToggleGroupFieldProps<TFieldValues, TName>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
8
|
+
Toggle: ({ disabled, name, value, label, helper, className, "data-testid": dataTestId, }: Omit<{
|
|
9
|
+
id?: string | undefined;
|
|
10
|
+
checked?: boolean | undefined;
|
|
11
|
+
name: string;
|
|
12
|
+
tooltip?: string | undefined;
|
|
13
|
+
onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
|
|
14
|
+
size?: "small" | "large" | undefined;
|
|
15
|
+
labelPosition?: "left" | "right" | undefined;
|
|
16
|
+
label?: import("react").ReactNode;
|
|
17
|
+
helper?: import("react").ReactNode;
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
className?: string | undefined;
|
|
20
|
+
required?: boolean | undefined;
|
|
21
|
+
'data-testid'?: string | undefined;
|
|
22
|
+
} & Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value"> & import("react").RefAttributes<HTMLInputElement>, "required" | "onChange" | "checked"> & {
|
|
23
|
+
value: string;
|
|
24
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { CheckboxField } from './CheckboxField';
|
|
2
|
+
export { CheckboxGroupField } from './CheckboxGroupField';
|
|
3
|
+
export { DateField } from './DateField';
|
|
4
|
+
export type { FormProps } from './Form';
|
|
5
|
+
export { Form } from './Form';
|
|
6
|
+
export { RadioField } from './RadioField';
|
|
7
|
+
export { SelectInputField } from './SelectInputField';
|
|
8
|
+
export { SelectableCardField } from './SelectableCardField';
|
|
9
|
+
export { NumberInputField } from './NumberInputField';
|
|
10
|
+
export { NumberInputFieldV2 } from './NumberInputFieldV2';
|
|
11
|
+
export { SubmitErrorAlert } from './SubmitErrorAlert';
|
|
12
|
+
export { TagInputField } from './TagInputField';
|
|
13
|
+
export { TextAreaField } from './TextAreaField';
|
|
14
|
+
export { TextInputField } from './TextInputField';
|
|
15
|
+
export { TextInputField as TextInputFieldV2 } from './TextInputFieldV2';
|
|
16
|
+
export { TimeField } from './TimeField';
|
|
17
|
+
export { ToggleField } from './ToggleField';
|
|
18
|
+
export { Submit } from './Submit';
|
|
19
|
+
export { RadioGroupField } from './RadioGroupField';
|
|
20
|
+
export { KeyValueField } from './KeyValueField';
|
|
21
|
+
export { SelectableCardGroupField } from './SelectableCardGroupField';
|
|
22
|
+
export { SelectInputFieldV2 } from './SelectInputFieldV2';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FORM_ERROR = "FINAL_FORM/form-error";
|
package/dist/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
const FORM_ERROR =
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const FORM_ERROR = "FINAL_FORM/form-error";
|
|
2
|
+
export {
|
|
3
|
+
FORM_ERROR
|
|
4
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useOnFieldChange } from './useOnFieldChange';
|
|
2
|
+
export { useFormStateDeprecated } from './useFormState';
|
|
3
|
+
export { useFieldDeprecated } from './useField';
|
|
4
|
+
export { useFormDeprecated } from './useForm';
|
|
5
|
+
export { useFieldArrayDeprecated } from './useFieldArray';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FieldPath, FieldPathValue, FieldValues, Path, Validate } from 'react-hook-form';
|
|
2
|
+
type Options<TFieldValues extends FieldValues> = {
|
|
3
|
+
subscription?: Record<string, boolean>;
|
|
4
|
+
validate?: Validate<FieldPathValue<TFieldValues, Path<TFieldValues>>, TFieldValues>;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use [useForm](https://www.react-hook-form.com/api/useform/), [useFormContext](https://www.react-hook-form.com/api/useformcontext/) or [useWatch](https://www.react-hook-form.com/api/usewatch/) to get values. Use [useFormState](https://www.react-hook-form.com/api/useformstate/) to get fields states.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const Input = () {
|
|
12
|
+
* const username = useWatch({
|
|
13
|
+
* name: 'username'
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* const { errors } = useFormState()
|
|
17
|
+
*
|
|
18
|
+
* console.log(errors.username)
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const useFieldDeprecated: <T, TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(name: TFieldName, options?: Options<TFieldValues>) => {
|
|
23
|
+
input: {
|
|
24
|
+
value: T;
|
|
25
|
+
onChange: (...event: any[]) => void;
|
|
26
|
+
};
|
|
27
|
+
meta: {
|
|
28
|
+
error: string | undefined;
|
|
29
|
+
touched: boolean;
|
|
30
|
+
invalid: boolean;
|
|
31
|
+
dirty: boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export {};
|
package/dist/hooks/useField.js
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import { useFormContext, useController } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use [useForm](https://www.react-hook-form.com/api/useform/), [useFormContext](https://www.react-hook-form.com/api/useformcontext/) or [useWatch](https://www.react-hook-form.com/api/usewatch/) to get values. Use [useFormState](https://www.react-hook-form.com/api/useformstate/) to get fields states.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```tsx
|
|
8
|
-
* const Input = () {
|
|
9
|
-
* const username = useWatch({
|
|
10
|
-
* name: 'username'
|
|
11
|
-
* })
|
|
12
|
-
*
|
|
13
|
-
* const { errors } = useFormState()
|
|
14
|
-
*
|
|
15
|
-
* console.log(errors.username)
|
|
16
|
-
* }
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
1
|
+
import { useFormContext, useController } from "react-hook-form";
|
|
19
2
|
const useFieldDeprecated = (name, options) => {
|
|
20
3
|
const {
|
|
21
4
|
getValues
|
|
@@ -42,5 +25,6 @@ const useFieldDeprecated = (name, options) => {
|
|
|
42
25
|
}
|
|
43
26
|
};
|
|
44
27
|
};
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
export {
|
|
29
|
+
useFieldDeprecated
|
|
30
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ArrayPath, FieldArray, FieldValues, Validate } from 'react-hook-form';
|
|
3
|
+
type Options<TFieldValues extends FieldValues> = {
|
|
4
|
+
validate?: Validate<FieldArray<TFieldValues>[], TFieldValues>;
|
|
5
|
+
subscription?: Record<string, boolean>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use [useFieldArray](https://www.react-hook-form.com/api/usefieldarray/)
|
|
9
|
+
*/
|
|
10
|
+
export declare const useFieldArrayDeprecated: <T, TFieldValues extends FieldValues = FieldValues>(name: ArrayPath<TFieldValues>, options?: Options<TFieldValues>) => {
|
|
11
|
+
fields: {
|
|
12
|
+
push: import("react-hook-form").UseFieldArrayAppend<TFieldValues, ArrayPath<TFieldValues>>;
|
|
13
|
+
value: T[];
|
|
14
|
+
remove: import("react-hook-form").UseFieldArrayRemove;
|
|
15
|
+
update: import("react-hook-form").UseFieldArrayUpdate<TFieldValues, ArrayPath<TFieldValues>>;
|
|
16
|
+
map: (callback: (name: string, index: number) => ReactNode) => ReactNode[];
|
|
17
|
+
move: import("react-hook-form").UseFieldArrayMove;
|
|
18
|
+
length: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { useFieldArray, useWatch } from
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use [useFieldArray](https://www.react-hook-form.com/api/usefieldarray/)
|
|
5
|
-
*/
|
|
1
|
+
import { useFieldArray, useWatch } from "react-hook-form";
|
|
6
2
|
const useFieldArrayDeprecated = (name, options) => {
|
|
7
3
|
const {
|
|
8
4
|
fields,
|
|
@@ -22,14 +18,15 @@ const useFieldArrayDeprecated = (name, options) => {
|
|
|
22
18
|
return {
|
|
23
19
|
fields: {
|
|
24
20
|
push: append,
|
|
25
|
-
value
|
|
21
|
+
value,
|
|
26
22
|
remove,
|
|
27
23
|
update,
|
|
28
|
-
map: callback => fields.map((_, index) => callback(`${name}.${index}`, index)),
|
|
24
|
+
map: (callback) => fields.map((_, index) => callback(`${name}.${index}`, index)),
|
|
29
25
|
move,
|
|
30
26
|
length: fields.length
|
|
31
27
|
}
|
|
32
28
|
};
|
|
33
29
|
};
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
export {
|
|
31
|
+
useFieldArrayDeprecated
|
|
32
|
+
};
|