@ultraviolet/form 6.0.0-beta.14 → 6.0.0-beta.16
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/README.md +5 -6
- package/package.json +6 -10
- package/dist/components/CheckboxField/index.cjs +0 -55
- package/dist/components/CheckboxGroupField/index.cjs +0 -80
- package/dist/components/DateInputField/index.cjs +0 -85
- package/dist/components/Form/defaultErrors.cjs +0 -22
- package/dist/components/Form/index.cjs +0 -35
- package/dist/components/KeyValueField/index.cjs +0 -60
- package/dist/components/NumberInputField/index.cjs +0 -59
- package/dist/components/RadioField/index.cjs +0 -64
- package/dist/components/RadioGroupField/index.cjs +0 -45
- package/dist/components/SelectInputField/index.cjs +0 -50
- package/dist/components/SelectableCardField/index.cjs +0 -66
- package/dist/components/SelectableCardGroupField/index.cjs +0 -55
- package/dist/components/SelectableCardOptionGroupField/index.cjs +0 -59
- package/dist/components/SliderField/index.cjs +0 -76
- package/dist/components/Submit/index.cjs +0 -25
- package/dist/components/SubmitErrorAlert/index.cjs +0 -15
- package/dist/components/SwitchButtonField/index.cjs +0 -35
- package/dist/components/TagInputField/index.cjs +0 -51
- package/dist/components/TextAreaField/index.cjs +0 -84
- package/dist/components/TextInputField/index.cjs +0 -62
- package/dist/components/TimeInputField/index.cjs +0 -46
- package/dist/components/ToggleField/index.cjs +0 -55
- package/dist/components/ToggleGroupField/index.cjs +0 -56
- package/dist/components/UnitInputField/index.cjs +0 -58
- package/dist/components/VerificationCodeField/index.cjs +0 -48
- package/dist/hooks/useOnFieldChange.cjs +0 -21
- package/dist/index.cjs +0 -80
- package/dist/providers/ErrorContext/index.cjs +0 -34
- package/dist/utils/validateRegex.cjs +0 -4
- package/dist/validators/isInteger.cjs +0 -12
- package/dist/validators/maxDate.cjs +0 -4
- package/dist/validators/minDate.cjs +0 -4
package/README.md
CHANGED
|
@@ -8,17 +8,17 @@ It is using [React Hook Form](https://react-hook-form.com/) under the hood.
|
|
|
8
8
|
## Get Started
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
|
-
$ pnpm add @ultraviolet/ui @ultraviolet/form
|
|
11
|
+
$ pnpm add @ultraviolet/ui @ultraviolet/form @ultraviolet/themes
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
### Usage
|
|
15
15
|
|
|
16
|
-
To use the library you need to put a `ThemeProvider` from `@
|
|
16
|
+
To use the library you need to put a `ThemeProvider` from `@ultraviolet/themes` with the theme that comes from the same package or from `@ultraviolet/ui` then wrap all your fields inside a `Form`:
|
|
17
17
|
|
|
18
18
|
```tsx
|
|
19
|
-
import { ThemeProvider } from '@ultraviolet/
|
|
19
|
+
import { ThemeProvider } from '@ultraviolet/themes'
|
|
20
20
|
import { Form, TextInputField } from '@ultraviolet/form'
|
|
21
|
-
import { theme } from '@ultraviolet/ui'
|
|
21
|
+
import { theme } from '@ultraviolet/ui' // or import { theme } from "@ultraviolet/themes
|
|
22
22
|
import { useForm } from '@ultraviolet/form'
|
|
23
23
|
import '@ultraviolet/ui/styles'
|
|
24
24
|
|
|
@@ -167,9 +167,8 @@ pnpm add zod @hookform/resolvers
|
|
|
167
167
|
Here's how you can do it:
|
|
168
168
|
|
|
169
169
|
```tsx
|
|
170
|
-
import { ThemeProvider } from '@
|
|
170
|
+
import { ThemeProvider, theme } from '@ultraviolet/themes'
|
|
171
171
|
import { Form, TextInputField } from '@ultraviolet/form'
|
|
172
|
-
import { theme } from '@ultraviolet/ui'
|
|
173
172
|
import { useForm } from '@ultraviolet/form'
|
|
174
173
|
import { zodResolver } from "@hookform/resolvers/zod"
|
|
175
174
|
import * as z from "zod"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.16",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -51,29 +51,25 @@
|
|
|
51
51
|
}
|
|
52
52
|
],
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@emotion/react": "11.14.0",
|
|
55
|
-
"@emotion/styled": "11.14.1",
|
|
56
54
|
"react": "18.x || 19.x",
|
|
57
55
|
"react-dom": "18.x || 19.x",
|
|
58
|
-
"@ultraviolet/ui": "3.0.0-beta.
|
|
56
|
+
"@ultraviolet/ui": "3.0.0-beta.27"
|
|
59
57
|
},
|
|
60
58
|
"devDependencies": {
|
|
61
|
-
"@babel/core": "7.28.
|
|
62
|
-
"@emotion/react": "11.14.0",
|
|
63
|
-
"@emotion/styled": "11.14.1",
|
|
59
|
+
"@babel/core": "7.28.5",
|
|
64
60
|
"@types/final-form-focus": "1.1.7",
|
|
65
61
|
"@types/react": "19.2.2",
|
|
66
62
|
"@types/react-dom": "19.2.2",
|
|
67
63
|
"react": "19.2.0",
|
|
68
64
|
"react-dom": "19.2.0",
|
|
69
|
-
"@ultraviolet/ui": "3.0.0-beta.
|
|
65
|
+
"@ultraviolet/ui": "3.0.0-beta.27",
|
|
70
66
|
"@utils/test": "0.0.1"
|
|
71
67
|
},
|
|
72
68
|
"dependencies": {
|
|
73
69
|
"@babel/runtime": "7.28.4",
|
|
74
70
|
"react-hook-form": "7.55.0",
|
|
75
|
-
"@ultraviolet/icons": "5.0.0-beta.
|
|
76
|
-
"@ultraviolet/themes": "3.0.0-beta.
|
|
71
|
+
"@ultraviolet/icons": "5.0.0-beta.11",
|
|
72
|
+
"@ultraviolet/themes": "3.0.0-beta.4"
|
|
77
73
|
},
|
|
78
74
|
"scripts": {
|
|
79
75
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const reactHookForm = require("react-hook-form");
|
|
7
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
|
-
const CheckboxField = ({
|
|
9
|
-
control,
|
|
10
|
-
name,
|
|
11
|
-
label,
|
|
12
|
-
disabled,
|
|
13
|
-
required,
|
|
14
|
-
children,
|
|
15
|
-
onChange,
|
|
16
|
-
onBlur,
|
|
17
|
-
shouldUnregister = false,
|
|
18
|
-
validate,
|
|
19
|
-
"aria-label": ariaLabel,
|
|
20
|
-
...props
|
|
21
|
-
}) => {
|
|
22
|
-
const {
|
|
23
|
-
getError
|
|
24
|
-
} = index.useErrors();
|
|
25
|
-
const {
|
|
26
|
-
field,
|
|
27
|
-
fieldState: {
|
|
28
|
-
error
|
|
29
|
-
}
|
|
30
|
-
} = reactHookForm.useController({
|
|
31
|
-
control,
|
|
32
|
-
disabled,
|
|
33
|
-
name,
|
|
34
|
-
rules: {
|
|
35
|
-
required,
|
|
36
|
-
validate
|
|
37
|
-
},
|
|
38
|
-
shouldUnregister
|
|
39
|
-
});
|
|
40
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { ...props, checked: !!field.value, disabled: field.disabled, error: getError({
|
|
41
|
-
label: label ?? ariaLabel ?? name
|
|
42
|
-
}, error), name: field.name, onBlur: (event) => {
|
|
43
|
-
field.onBlur();
|
|
44
|
-
onBlur?.(event);
|
|
45
|
-
}, onChange: (event) => {
|
|
46
|
-
field.onChange(event.target.checked);
|
|
47
|
-
onChange?.(event.target.checked);
|
|
48
|
-
}, ref: field.ref, ...children ? {
|
|
49
|
-
"aria-label": void 0,
|
|
50
|
-
children
|
|
51
|
-
} : {
|
|
52
|
-
"aria-label": ariaLabel
|
|
53
|
-
} });
|
|
54
|
-
};
|
|
55
|
-
exports.CheckboxField = CheckboxField;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const reactHookForm = require("react-hook-form");
|
|
8
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
-
const arraysContainSameValues = (array1, array2) => {
|
|
10
|
-
if (array1.length === 0) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return array2.every((value) => array1.includes(value));
|
|
14
|
-
};
|
|
15
|
-
const CheckboxGroupField = ({
|
|
16
|
-
control,
|
|
17
|
-
children,
|
|
18
|
-
onChange,
|
|
19
|
-
error: customError,
|
|
20
|
-
name,
|
|
21
|
-
required = false,
|
|
22
|
-
shouldUnregister = false,
|
|
23
|
-
validate,
|
|
24
|
-
legend = "",
|
|
25
|
-
...props
|
|
26
|
-
}) => {
|
|
27
|
-
const {
|
|
28
|
-
getError
|
|
29
|
-
} = index.useErrors();
|
|
30
|
-
const checkboxValid = react.useCallback((value) => {
|
|
31
|
-
const requiredChildren = react.Children.map(children, (child) => {
|
|
32
|
-
if (react.isValidElement(child)) {
|
|
33
|
-
if (child.props.required) {
|
|
34
|
-
return child.props.name;
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
})?.filter(Boolean) ?? [];
|
|
40
|
-
if (requiredChildren.length === 0 && !required) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
if (!required && arraysContainSameValues(value, requiredChildren)) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
if (value.length >= react.Children.count(children)) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}, [children, required]);
|
|
51
|
-
const {
|
|
52
|
-
field,
|
|
53
|
-
fieldState: {
|
|
54
|
-
error
|
|
55
|
-
}
|
|
56
|
-
} = reactHookForm.useController({
|
|
57
|
-
control,
|
|
58
|
-
name,
|
|
59
|
-
rules: {
|
|
60
|
-
validate: {
|
|
61
|
-
checkboxValid,
|
|
62
|
-
...validate
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
shouldUnregister
|
|
66
|
-
});
|
|
67
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.CheckboxGroup, { ...props, error: getError({
|
|
68
|
-
label: legend
|
|
69
|
-
}, error) ?? customError, legend, name, onChange: (event) => {
|
|
70
|
-
const fieldValue = field.value;
|
|
71
|
-
if (fieldValue?.includes(event.currentTarget.value)) {
|
|
72
|
-
field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
|
|
73
|
-
} else {
|
|
74
|
-
field.onChange([...field.value, event.currentTarget.value]);
|
|
75
|
-
}
|
|
76
|
-
onChange?.(event.currentTarget.value);
|
|
77
|
-
}, required, value: field.value, children });
|
|
78
|
-
};
|
|
79
|
-
CheckboxGroupField.Checkbox = ui.CheckboxGroup.Checkbox;
|
|
80
|
-
exports.CheckboxGroupField = CheckboxGroupField;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const reactHookForm = require("react-hook-form");
|
|
7
|
-
const maxDate = require("../../validators/maxDate.cjs");
|
|
8
|
-
const minDate = require("../../validators/minDate.cjs");
|
|
9
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
10
|
-
const parseDate = (value) => typeof value === "string" ? new Date(value) : value;
|
|
11
|
-
const isEmpty = (value) => !value;
|
|
12
|
-
const DateInputField = ({
|
|
13
|
-
required,
|
|
14
|
-
name,
|
|
15
|
-
control,
|
|
16
|
-
label = "",
|
|
17
|
-
format,
|
|
18
|
-
minDate: minDate$1,
|
|
19
|
-
maxDate: maxDate$1,
|
|
20
|
-
onChange,
|
|
21
|
-
onBlur,
|
|
22
|
-
validate,
|
|
23
|
-
selectsRange,
|
|
24
|
-
showMonthYearPicker,
|
|
25
|
-
shouldUnregister = false,
|
|
26
|
-
...props
|
|
27
|
-
}) => {
|
|
28
|
-
const {
|
|
29
|
-
getError
|
|
30
|
-
} = index.useErrors();
|
|
31
|
-
const {
|
|
32
|
-
field,
|
|
33
|
-
fieldState: {
|
|
34
|
-
error
|
|
35
|
-
}
|
|
36
|
-
} = reactHookForm.useController({
|
|
37
|
-
control,
|
|
38
|
-
name,
|
|
39
|
-
rules: {
|
|
40
|
-
required,
|
|
41
|
-
validate: {
|
|
42
|
-
maxDate: maxDate.maxDateValidator(maxDate$1),
|
|
43
|
-
minDate: minDate.minDateValidator(minDate$1),
|
|
44
|
-
...validate
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
shouldUnregister
|
|
48
|
-
});
|
|
49
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.DateInput, { ...props, endDate: selectsRange && Array.isArray(field.value) ? field.value[1] : void 0, error: getError({
|
|
50
|
-
label,
|
|
51
|
-
maxDate: maxDate$1,
|
|
52
|
-
minDate: minDate$1
|
|
53
|
-
}, error), format: format || ((value) => {
|
|
54
|
-
if (!value) {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
const date = parseDate(value);
|
|
58
|
-
return showMonthYearPicker ? date.toLocaleDateString(void 0, {
|
|
59
|
-
month: "numeric",
|
|
60
|
-
year: "numeric"
|
|
61
|
-
}) : date.toLocaleDateString();
|
|
62
|
-
}), label, maxDate: maxDate$1, minDate: minDate$1, name: field.name, onBlur: (e) => {
|
|
63
|
-
field.onBlur();
|
|
64
|
-
onBlur?.(e);
|
|
65
|
-
}, onChange: (val) => {
|
|
66
|
-
if (val && val instanceof Date) {
|
|
67
|
-
onChange?.(val);
|
|
68
|
-
const newDate = parseDate(val);
|
|
69
|
-
if (isEmpty(field.value)) {
|
|
70
|
-
field.onChange(newDate);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const currentDate = parseDate(field.value);
|
|
74
|
-
newDate.setHours(currentDate.getHours(), currentDate.getMinutes());
|
|
75
|
-
field.onChange(newDate);
|
|
76
|
-
} else if (Array.isArray(val)) {
|
|
77
|
-
onChange?.(val);
|
|
78
|
-
field.onChange(val);
|
|
79
|
-
} else if (val === null) {
|
|
80
|
-
onChange?.(val);
|
|
81
|
-
field.onChange(val);
|
|
82
|
-
}
|
|
83
|
-
}, required, selectsRange, showMonthYearPicker, startDate: selectsRange && Array.isArray(field.value) ? field.value[0] : void 0, value: Array.isArray(field.value) ? void 0 : field.value });
|
|
84
|
-
};
|
|
85
|
-
exports.DateInputField = DateInputField;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const defaultErrors = {
|
|
4
|
-
deps: () => "",
|
|
5
|
-
disabled: () => "",
|
|
6
|
-
max: () => "",
|
|
7
|
-
maxDate: () => "",
|
|
8
|
-
maxLength: () => "",
|
|
9
|
-
min: () => "",
|
|
10
|
-
minLength: () => "",
|
|
11
|
-
onBlur: () => "",
|
|
12
|
-
onChange: () => "",
|
|
13
|
-
pattern: () => "",
|
|
14
|
-
required: () => "",
|
|
15
|
-
setValueAs: () => "",
|
|
16
|
-
shouldUnregister: () => "",
|
|
17
|
-
validate: () => "",
|
|
18
|
-
value: () => "",
|
|
19
|
-
valueAsDate: () => "",
|
|
20
|
-
valueAsNumber: () => ""
|
|
21
|
-
};
|
|
22
|
-
exports.defaultErrors = defaultErrors;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const reactHookForm = require("react-hook-form");
|
|
6
|
-
const defaultErrors = require("./defaultErrors.cjs");
|
|
7
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
|
-
const Form = ({
|
|
9
|
-
children,
|
|
10
|
-
methods,
|
|
11
|
-
errors,
|
|
12
|
-
onSubmit,
|
|
13
|
-
name
|
|
14
|
-
}) => {
|
|
15
|
-
const handleSubmit = methods.handleSubmit(async (values) => {
|
|
16
|
-
const result = await onSubmit(values);
|
|
17
|
-
if (result) {
|
|
18
|
-
methods.setError("root.submit", {
|
|
19
|
-
message: result,
|
|
20
|
-
type: "custom"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return /* @__PURE__ */ jsxRuntime.jsx(reactHookForm.FormProvider, { ...methods, children: /* @__PURE__ */ jsxRuntime.jsx(index.ErrorProvider, { errors: {
|
|
25
|
-
...defaultErrors.defaultErrors,
|
|
26
|
-
...errors
|
|
27
|
-
}, children: /* @__PURE__ */ jsxRuntime.jsx("form", { name, noValidate: true, onSubmit: async (e) => {
|
|
28
|
-
e.preventDefault();
|
|
29
|
-
e.stopPropagation();
|
|
30
|
-
await handleSubmit(e);
|
|
31
|
-
}, style: {
|
|
32
|
-
display: "contents"
|
|
33
|
-
}, children }) }) });
|
|
34
|
-
};
|
|
35
|
-
exports.Form = Form;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const icons = require("@ultraviolet/icons");
|
|
6
|
-
const ui = require("@ultraviolet/ui");
|
|
7
|
-
const reactHookForm = require("react-hook-form");
|
|
8
|
-
const index = require("../TextInputField/index.cjs");
|
|
9
|
-
const KeyValueField = ({
|
|
10
|
-
name,
|
|
11
|
-
inputKey,
|
|
12
|
-
inputValue,
|
|
13
|
-
addButton,
|
|
14
|
-
maxSize = 100,
|
|
15
|
-
readOnly = false,
|
|
16
|
-
control,
|
|
17
|
-
onChange,
|
|
18
|
-
onBlur
|
|
19
|
-
}) => {
|
|
20
|
-
const {
|
|
21
|
-
fields,
|
|
22
|
-
append,
|
|
23
|
-
remove
|
|
24
|
-
} = reactHookForm.useFieldArray({
|
|
25
|
-
control,
|
|
26
|
-
name
|
|
27
|
-
});
|
|
28
|
-
const {
|
|
29
|
-
getValues
|
|
30
|
-
} = reactHookForm.useFormContext();
|
|
31
|
-
const handleFieldChange = () => {
|
|
32
|
-
onChange?.(getValues(name));
|
|
33
|
-
};
|
|
34
|
-
const handleFieldBlur = () => {
|
|
35
|
-
onBlur?.(getValues(name));
|
|
36
|
-
};
|
|
37
|
-
const canAdd = fields.length !== void 0 && fields.length < maxSize;
|
|
38
|
-
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
39
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { gap: 3, children: [
|
|
40
|
-
fields.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { gap: 3, children: fields.map((field, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Row, { alignItems: "end", gap: 2, templateColumns: "1fr 1fr auto", children: [
|
|
41
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { label: inputKey.label, name: `${name}.${index$1}.key`, onBlur: handleFieldBlur, onChange: handleFieldChange, readOnly, regex: inputKey.regex, required: inputKey.required }),
|
|
42
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { autoComplete: "off", label: inputValue.label, name: `${name}.${index$1}.value`, onBlur: handleFieldBlur, onChange: handleFieldChange, placeholder: inputValue.placeholder, readOnly, regex: inputValue.regex, required: inputValue.required, type: inputValue.type }),
|
|
43
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { "data-testid": `remove-button-${index$1}`, disabled: readOnly, onClick: () => {
|
|
44
|
-
remove(index$1);
|
|
45
|
-
handleFieldChange();
|
|
46
|
-
}, sentiment: "danger", size: "large", variant: "outlined", children: /* @__PURE__ */ jsxRuntime.jsx(icons.DeleteIcon, {}) })
|
|
47
|
-
] }, field.id)) }) : null,
|
|
48
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { "data-testid": "add-button", disabled: !canAdd || readOnly, fullWidth: addButton.fullWidth, onClick: () => {
|
|
49
|
-
append({
|
|
50
|
-
key: "",
|
|
51
|
-
value: ""
|
|
52
|
-
});
|
|
53
|
-
handleFieldChange();
|
|
54
|
-
}, sentiment: "primary", tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip, variant: "outlined", children: [
|
|
55
|
-
/* @__PURE__ */ jsxRuntime.jsx(icons.PlusIcon, {}),
|
|
56
|
-
addButton.name
|
|
57
|
-
] }) })
|
|
58
|
-
] });
|
|
59
|
-
};
|
|
60
|
-
exports.KeyValueField = KeyValueField;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const reactHookForm = require("react-hook-form");
|
|
7
|
-
const isInteger = require("../../validators/isInteger.cjs");
|
|
8
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
-
const NumberInputField = ({
|
|
10
|
-
control,
|
|
11
|
-
max = Number.MAX_SAFE_INTEGER,
|
|
12
|
-
min = 0,
|
|
13
|
-
name,
|
|
14
|
-
onChange,
|
|
15
|
-
onBlur,
|
|
16
|
-
step,
|
|
17
|
-
label,
|
|
18
|
-
"aria-label": ariaLabel,
|
|
19
|
-
required,
|
|
20
|
-
shouldUnregister = false,
|
|
21
|
-
validate,
|
|
22
|
-
...props
|
|
23
|
-
}) => {
|
|
24
|
-
const {
|
|
25
|
-
getError
|
|
26
|
-
} = index.useErrors();
|
|
27
|
-
const {
|
|
28
|
-
field,
|
|
29
|
-
fieldState: {
|
|
30
|
-
error
|
|
31
|
-
}
|
|
32
|
-
} = reactHookForm.useController({
|
|
33
|
-
control,
|
|
34
|
-
name,
|
|
35
|
-
rules: {
|
|
36
|
-
max,
|
|
37
|
-
min,
|
|
38
|
-
required,
|
|
39
|
-
validate: {
|
|
40
|
-
...validate,
|
|
41
|
-
isInteger: isInteger.isInteger(step)
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
shouldUnregister
|
|
45
|
-
});
|
|
46
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.NumberInput, { ...props, "aria-label": ariaLabel, error: getError({
|
|
47
|
-
isInteger: step,
|
|
48
|
-
label: label ?? ariaLabel ?? name,
|
|
49
|
-
max,
|
|
50
|
-
min
|
|
51
|
-
}, error), label, max, min, name: field.name, onBlur: (event) => {
|
|
52
|
-
field.onBlur();
|
|
53
|
-
onBlur?.(event);
|
|
54
|
-
}, onChange: (newValue) => {
|
|
55
|
-
field.onChange(newValue);
|
|
56
|
-
onChange?.(newValue);
|
|
57
|
-
}, required, step, value: field.value });
|
|
58
|
-
};
|
|
59
|
-
exports.NumberInputField = NumberInputField;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const reactHookForm = require("react-hook-form");
|
|
8
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
-
const RadioField = ({
|
|
10
|
-
control,
|
|
11
|
-
disabled,
|
|
12
|
-
name,
|
|
13
|
-
onBlur,
|
|
14
|
-
label = "",
|
|
15
|
-
onChange,
|
|
16
|
-
onFocus,
|
|
17
|
-
required,
|
|
18
|
-
value,
|
|
19
|
-
shouldUnregister = false,
|
|
20
|
-
validate,
|
|
21
|
-
"aria-label": ariaLabel,
|
|
22
|
-
...props
|
|
23
|
-
}) => {
|
|
24
|
-
const {
|
|
25
|
-
getError
|
|
26
|
-
} = index.useErrors();
|
|
27
|
-
const {
|
|
28
|
-
field,
|
|
29
|
-
fieldState: {
|
|
30
|
-
error
|
|
31
|
-
}
|
|
32
|
-
} = reactHookForm.useController({
|
|
33
|
-
control,
|
|
34
|
-
name,
|
|
35
|
-
rules: {
|
|
36
|
-
required,
|
|
37
|
-
validate
|
|
38
|
-
},
|
|
39
|
-
shouldUnregister
|
|
40
|
-
});
|
|
41
|
-
const errorLabel = react.useMemo(() => {
|
|
42
|
-
if (label && typeof label === "string") {
|
|
43
|
-
return label;
|
|
44
|
-
}
|
|
45
|
-
if (ariaLabel) {
|
|
46
|
-
return ariaLabel;
|
|
47
|
-
}
|
|
48
|
-
return name;
|
|
49
|
-
}, [label, name, ariaLabel]);
|
|
50
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { ...props, checked: field.value === value, disabled, error: getError({
|
|
51
|
-
label: errorLabel
|
|
52
|
-
}, error), name: field.name, onBlur: (event) => {
|
|
53
|
-
field.onBlur();
|
|
54
|
-
onBlur?.(event);
|
|
55
|
-
}, onChange: () => {
|
|
56
|
-
field.onChange(value);
|
|
57
|
-
onChange?.(value);
|
|
58
|
-
}, onFocus, required, value: value ?? "", ...label ? {
|
|
59
|
-
label
|
|
60
|
-
} : {
|
|
61
|
-
"aria-label": ariaLabel
|
|
62
|
-
} });
|
|
63
|
-
};
|
|
64
|
-
exports.RadioField = RadioField;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const reactHookForm = require("react-hook-form");
|
|
7
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
8
|
-
const RadioGroupField = ({
|
|
9
|
-
control,
|
|
10
|
-
name,
|
|
11
|
-
onChange,
|
|
12
|
-
required,
|
|
13
|
-
children,
|
|
14
|
-
error: customError,
|
|
15
|
-
shouldUnregister = false,
|
|
16
|
-
validate,
|
|
17
|
-
legend = "",
|
|
18
|
-
...props
|
|
19
|
-
}) => {
|
|
20
|
-
const {
|
|
21
|
-
getError
|
|
22
|
-
} = index.useErrors();
|
|
23
|
-
const {
|
|
24
|
-
field,
|
|
25
|
-
fieldState: {
|
|
26
|
-
error
|
|
27
|
-
}
|
|
28
|
-
} = reactHookForm.useController({
|
|
29
|
-
control,
|
|
30
|
-
name,
|
|
31
|
-
rules: {
|
|
32
|
-
required,
|
|
33
|
-
validate
|
|
34
|
-
},
|
|
35
|
-
shouldUnregister
|
|
36
|
-
});
|
|
37
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { ...props, error: getError({
|
|
38
|
-
label: legend
|
|
39
|
-
}, error) ?? customError, legend, name: field.name, onChange: (event) => {
|
|
40
|
-
field.onChange(event);
|
|
41
|
-
onChange?.(event.target.value);
|
|
42
|
-
}, required, value: field.value, children });
|
|
43
|
-
};
|
|
44
|
-
RadioGroupField.Radio = ui.RadioGroup.Radio;
|
|
45
|
-
exports.RadioGroupField = RadioGroupField;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const ui = require("@ultraviolet/ui");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const reactHookForm = require("react-hook-form");
|
|
8
|
-
const index = require("../../providers/ErrorContext/index.cjs");
|
|
9
|
-
const SelectInputField = ({
|
|
10
|
-
label = "",
|
|
11
|
-
onBlur,
|
|
12
|
-
required,
|
|
13
|
-
name,
|
|
14
|
-
"aria-label": ariaLabel,
|
|
15
|
-
shouldUnregister = false,
|
|
16
|
-
control,
|
|
17
|
-
validate,
|
|
18
|
-
onChange,
|
|
19
|
-
multiselect,
|
|
20
|
-
...props
|
|
21
|
-
}) => {
|
|
22
|
-
const {
|
|
23
|
-
field,
|
|
24
|
-
fieldState: {
|
|
25
|
-
error
|
|
26
|
-
}
|
|
27
|
-
} = reactHookForm.useController({
|
|
28
|
-
control,
|
|
29
|
-
name,
|
|
30
|
-
rules: {
|
|
31
|
-
required,
|
|
32
|
-
validate
|
|
33
|
-
},
|
|
34
|
-
shouldUnregister
|
|
35
|
-
});
|
|
36
|
-
const {
|
|
37
|
-
getError
|
|
38
|
-
} = index.useErrors();
|
|
39
|
-
const handleChange = react.useCallback((value) => {
|
|
40
|
-
onChange?.(value);
|
|
41
|
-
field.onChange(value);
|
|
42
|
-
}, [onChange, field]);
|
|
43
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectInput, { "aria-label": ariaLabel, error: getError({
|
|
44
|
-
label: label ?? ariaLabel ?? name
|
|
45
|
-
}, error), label, multiselect, name: field.name, onBlur: (event) => {
|
|
46
|
-
field.onBlur();
|
|
47
|
-
onBlur?.(event);
|
|
48
|
-
}, onChange: handleChange, required, value: field.value, ...props });
|
|
49
|
-
};
|
|
50
|
-
exports.SelectInputField = SelectInputField;
|