@ultraviolet/form 3.2.0 → 3.3.1
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/KeyValueField/index.cjs +5 -5
- package/dist/components/KeyValueField/index.d.ts +2 -2
- package/dist/components/KeyValueField/index.js +5 -5
- package/dist/components/SliderField/index.cjs +53 -0
- package/dist/components/SliderField/index.d.ts +9 -0
- package/dist/components/SliderField/index.js +53 -0
- package/dist/components/TextInputFieldV2/index.cjs +1 -1
- package/dist/components/TextInputFieldV2/index.d.ts +1 -1
- package/dist/components/TextInputFieldV2/index.js +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.js +2 -0
- package/package.json +6 -6
|
@@ -10,7 +10,7 @@ const KeyValueField = ({
|
|
|
10
10
|
inputValue,
|
|
11
11
|
addButton,
|
|
12
12
|
maxSize = 100,
|
|
13
|
-
|
|
13
|
+
readOnly = false,
|
|
14
14
|
control
|
|
15
15
|
}) => {
|
|
16
16
|
const {
|
|
@@ -25,9 +25,9 @@ const KeyValueField = ({
|
|
|
25
25
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
26
26
|
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { gap: 3, children: [
|
|
27
27
|
fields.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { gap: 3, children: fields.map((field, index$1) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Row, { templateColumns: "1fr 1fr auto", gap: 2, alignItems: "end", children: [
|
|
28
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly
|
|
29
|
-
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly
|
|
30
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled:
|
|
28
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly, required: inputKey.required, name: `${name}.${index$1}.key`, label: inputKey.label, regex: inputKey.regex }),
|
|
29
|
+
/* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly, required: inputValue.required, name: `${name}.${index$1}.value`, label: inputValue.label, placeholder: inputValue.placeholder, type: inputValue.type, autoComplete: "off", regex: inputValue.regex }),
|
|
30
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { disabled: readOnly, "data-testid": `remove-button-${index$1}`, icon: "delete", variant: "outlined", sentiment: "danger", size: "large", onClick: () => remove(index$1) })
|
|
31
31
|
] }, field.id)) }) : null,
|
|
32
32
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
33
|
ui.Button,
|
|
@@ -37,7 +37,7 @@ const KeyValueField = ({
|
|
|
37
37
|
variant: "filled",
|
|
38
38
|
sentiment: "neutral",
|
|
39
39
|
fullWidth: addButton.fullWidth,
|
|
40
|
-
disabled: !canAdd ||
|
|
40
|
+
disabled: !canAdd || readOnly,
|
|
41
41
|
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
42
42
|
onClick: () => append({
|
|
43
43
|
key: "",
|
|
@@ -23,11 +23,11 @@ type KeyValueFieldProps<TFieldValues extends FieldValues, TFieldArrayName extend
|
|
|
23
23
|
inputValue: InputValueProps;
|
|
24
24
|
addButton: AddButtonProps;
|
|
25
25
|
maxSize?: number;
|
|
26
|
-
|
|
26
|
+
readOnly?: boolean;
|
|
27
27
|
control?: Control<TFieldValues>;
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* A React component that allows users to manage key-value pairs
|
|
31
31
|
*/
|
|
32
|
-
export declare const KeyValueField: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>({ name, inputKey, inputValue, addButton, maxSize,
|
|
32
|
+
export declare const KeyValueField: <TFieldValues extends FieldValues = FieldValues, TFieldArrayName extends FieldArrayPath<TFieldValues> = FieldArrayPath<TFieldValues>>({ name, inputKey, inputValue, addButton, maxSize, readOnly, control, }: KeyValueFieldProps<TFieldValues, TFieldArrayName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
33
33
|
export {};
|
|
@@ -8,7 +8,7 @@ const KeyValueField = ({
|
|
|
8
8
|
inputValue,
|
|
9
9
|
addButton,
|
|
10
10
|
maxSize = 100,
|
|
11
|
-
|
|
11
|
+
readOnly = false,
|
|
12
12
|
control
|
|
13
13
|
}) => {
|
|
14
14
|
const {
|
|
@@ -23,9 +23,9 @@ const KeyValueField = ({
|
|
|
23
23
|
const maxSizeReachedTooltip = addButton.maxSizeReachedTooltip ?? `Cannot add more than ${maxSize} elements`;
|
|
24
24
|
return /* @__PURE__ */ jsxs(Stack, { gap: 3, children: [
|
|
25
25
|
fields.length ? /* @__PURE__ */ jsx(Stack, { gap: 3, children: fields.map((field, index) => /* @__PURE__ */ jsxs(Row, { templateColumns: "1fr 1fr auto", gap: 2, alignItems: "end", children: [
|
|
26
|
-
/* @__PURE__ */ jsx(TextInputField, { readOnly
|
|
27
|
-
/* @__PURE__ */ jsx(TextInputField, { readOnly
|
|
28
|
-
/* @__PURE__ */ jsx(Button, { disabled:
|
|
26
|
+
/* @__PURE__ */ jsx(TextInputField, { readOnly, required: inputKey.required, name: `${name}.${index}.key`, label: inputKey.label, regex: inputKey.regex }),
|
|
27
|
+
/* @__PURE__ */ jsx(TextInputField, { readOnly, required: inputValue.required, name: `${name}.${index}.value`, label: inputValue.label, placeholder: inputValue.placeholder, type: inputValue.type, autoComplete: "off", regex: inputValue.regex }),
|
|
28
|
+
/* @__PURE__ */ jsx(Button, { disabled: readOnly, "data-testid": `remove-button-${index}`, icon: "delete", variant: "outlined", sentiment: "danger", size: "large", onClick: () => remove(index) })
|
|
29
29
|
] }, field.id)) }) : null,
|
|
30
30
|
/* @__PURE__ */ jsx(Stack, { direction: "row", justifyContent: "flex-start", children: /* @__PURE__ */ jsx(
|
|
31
31
|
Button,
|
|
@@ -35,7 +35,7 @@ const KeyValueField = ({
|
|
|
35
35
|
variant: "filled",
|
|
36
36
|
sentiment: "neutral",
|
|
37
37
|
fullWidth: addButton.fullWidth,
|
|
38
|
-
disabled: !canAdd ||
|
|
38
|
+
disabled: !canAdd || readOnly,
|
|
39
39
|
tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
|
|
40
40
|
onClick: () => append({
|
|
41
41
|
key: "",
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const ui = require("@ultraviolet/ui");
|
|
5
|
+
const reactHookForm = require("react-hook-form");
|
|
6
|
+
const index = require("../../providers/ErrorContext/index.cjs");
|
|
7
|
+
const SliderField = ({
|
|
8
|
+
name,
|
|
9
|
+
control,
|
|
10
|
+
shouldUnregister,
|
|
11
|
+
max,
|
|
12
|
+
min,
|
|
13
|
+
required,
|
|
14
|
+
validate,
|
|
15
|
+
onBlur,
|
|
16
|
+
onChange,
|
|
17
|
+
label,
|
|
18
|
+
value,
|
|
19
|
+
defaultValue,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
getError
|
|
24
|
+
} = index.useErrors();
|
|
25
|
+
const {
|
|
26
|
+
field,
|
|
27
|
+
fieldState: {
|
|
28
|
+
error
|
|
29
|
+
}
|
|
30
|
+
} = reactHookForm.useController({
|
|
31
|
+
name,
|
|
32
|
+
control,
|
|
33
|
+
shouldUnregister,
|
|
34
|
+
rules: {
|
|
35
|
+
max,
|
|
36
|
+
min,
|
|
37
|
+
required,
|
|
38
|
+
validate
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { name: field.name, value: field.value, onBlur: (event) => {
|
|
42
|
+
field.onBlur();
|
|
43
|
+
onBlur?.(event);
|
|
44
|
+
}, onChange: (newValue) => {
|
|
45
|
+
field.onChange(newValue);
|
|
46
|
+
onChange?.(newValue);
|
|
47
|
+
}, max, min, error: getError({
|
|
48
|
+
label: label ?? "",
|
|
49
|
+
max,
|
|
50
|
+
min
|
|
51
|
+
}, error), label, required, ...props });
|
|
52
|
+
};
|
|
53
|
+
exports.SliderField = SliderField;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Slider } from '@ultraviolet/ui';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
|
+
import type { BaseFieldProps } from '../../types';
|
|
5
|
+
type SliderFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof Slider>, 'value' | 'onChange'> & {
|
|
6
|
+
suffix?: string | ReactNode[];
|
|
7
|
+
};
|
|
8
|
+
export declare const SliderField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, control, shouldUnregister, max, min, required, validate, onBlur, onChange, label, value, defaultValue, ...props }: SliderFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Slider } from "@ultraviolet/ui";
|
|
3
|
+
import { useController } from "react-hook-form";
|
|
4
|
+
import { useErrors } from "../../providers/ErrorContext/index.js";
|
|
5
|
+
const SliderField = ({
|
|
6
|
+
name,
|
|
7
|
+
control,
|
|
8
|
+
shouldUnregister,
|
|
9
|
+
max,
|
|
10
|
+
min,
|
|
11
|
+
required,
|
|
12
|
+
validate,
|
|
13
|
+
onBlur,
|
|
14
|
+
onChange,
|
|
15
|
+
label,
|
|
16
|
+
value,
|
|
17
|
+
defaultValue,
|
|
18
|
+
...props
|
|
19
|
+
}) => {
|
|
20
|
+
const {
|
|
21
|
+
getError
|
|
22
|
+
} = useErrors();
|
|
23
|
+
const {
|
|
24
|
+
field,
|
|
25
|
+
fieldState: {
|
|
26
|
+
error
|
|
27
|
+
}
|
|
28
|
+
} = useController({
|
|
29
|
+
name,
|
|
30
|
+
control,
|
|
31
|
+
shouldUnregister,
|
|
32
|
+
rules: {
|
|
33
|
+
max,
|
|
34
|
+
min,
|
|
35
|
+
required,
|
|
36
|
+
validate
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return /* @__PURE__ */ jsx(Slider, { name: field.name, value: field.value, onBlur: (event) => {
|
|
40
|
+
field.onBlur();
|
|
41
|
+
onBlur?.(event);
|
|
42
|
+
}, onChange: (newValue) => {
|
|
43
|
+
field.onChange(newValue);
|
|
44
|
+
onChange?.(newValue);
|
|
45
|
+
}, max, min, error: getError({
|
|
46
|
+
label: label ?? "",
|
|
47
|
+
max,
|
|
48
|
+
min
|
|
49
|
+
}, error), label, required, ...props });
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
SliderField
|
|
53
|
+
};
|
|
@@ -82,6 +82,6 @@ const TextInputField = ({
|
|
|
82
82
|
onChange?.(event);
|
|
83
83
|
}, onFocus: (event) => {
|
|
84
84
|
onFocus?.(event);
|
|
85
|
-
}, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
|
|
85
|
+
}, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value === void 0 ? "" : field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
|
|
86
86
|
};
|
|
87
87
|
exports.TextInputField = TextInputField;
|
|
@@ -2,7 +2,7 @@ import { TextInputV2 } from '@ultraviolet/ui';
|
|
|
2
2
|
import type { ComponentProps } from 'react';
|
|
3
3
|
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
4
4
|
import type { BaseFieldProps } from '../../types';
|
|
5
|
-
type TextInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name'
|
|
5
|
+
type TextInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name'> & {
|
|
6
6
|
regex?: (RegExp | RegExp[])[];
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
@@ -80,7 +80,7 @@ const TextInputField = ({
|
|
|
80
80
|
onChange?.(event);
|
|
81
81
|
}, onFocus: (event) => {
|
|
82
82
|
onFocus?.(event);
|
|
83
|
-
}, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
|
|
83
|
+
}, placeholder, readOnly, required, success, tabIndex, tooltip, type, value: field.value === void 0 ? "" : field.value, id, prefix, suffix, size, onRandomize, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, autoComplete, role, "aria-live": ariaLive, "aria-atomic": ariaAtomic });
|
|
84
84
|
};
|
|
85
85
|
export {
|
|
86
86
|
TextInputField
|
|
@@ -20,3 +20,4 @@ export { KeyValueField } from './KeyValueField';
|
|
|
20
20
|
export { SelectableCardGroupField } from './SelectableCardGroupField';
|
|
21
21
|
export { SelectInputFieldV2 } from './SelectInputFieldV2';
|
|
22
22
|
export { UnitInputField } from './UnitInputField';
|
|
23
|
+
export { SliderField } from './SliderField';
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ const index$j = require("./components/KeyValueField/index.cjs");
|
|
|
25
25
|
const index$k = require("./components/SelectableCardGroupField/index.cjs");
|
|
26
26
|
const index$l = require("./components/SelectInputFieldV2/index.cjs");
|
|
27
27
|
const index$m = require("./components/UnitInputField/index.cjs");
|
|
28
|
+
const index$n = require("./components/SliderField/index.cjs");
|
|
28
29
|
exports.ErrorProvider = index.ErrorProvider;
|
|
29
30
|
exports.useErrors = index.useErrors;
|
|
30
31
|
Object.defineProperty(exports, "useController", {
|
|
@@ -74,3 +75,4 @@ exports.KeyValueField = index$j.KeyValueField;
|
|
|
74
75
|
exports.SelectableCardGroupField = index$k.SelectableCardGroupField;
|
|
75
76
|
exports.SelectInputFieldV2 = index$l.SelectInputFieldV2;
|
|
76
77
|
exports.UnitInputField = index$m.UnitInputField;
|
|
78
|
+
exports.SliderField = index$n.SliderField;
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import { KeyValueField } from "./components/KeyValueField/index.js";
|
|
|
23
23
|
import { SelectableCardGroupField } from "./components/SelectableCardGroupField/index.js";
|
|
24
24
|
import { SelectInputFieldV2 } from "./components/SelectInputFieldV2/index.js";
|
|
25
25
|
import { UnitInputField } from "./components/UnitInputField/index.js";
|
|
26
|
+
import { SliderField } from "./components/SliderField/index.js";
|
|
26
27
|
export {
|
|
27
28
|
CheckboxField,
|
|
28
29
|
CheckboxGroupField,
|
|
@@ -38,6 +39,7 @@ export {
|
|
|
38
39
|
SelectInputFieldV2,
|
|
39
40
|
SelectableCardField,
|
|
40
41
|
SelectableCardGroupField,
|
|
42
|
+
SliderField,
|
|
41
43
|
Submit,
|
|
42
44
|
SubmitErrorAlert,
|
|
43
45
|
TagInputField,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/form",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Ultraviolet Form",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"react-hook-form": "7.52.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@babel/core": "7.24.
|
|
61
|
+
"@babel/core": "7.24.9",
|
|
62
62
|
"@types/final-form-focus": "1.1.7",
|
|
63
63
|
"@types/react": "18.3.3",
|
|
64
64
|
"@types/react-dom": "18.3.0",
|
|
@@ -67,19 +67,19 @@
|
|
|
67
67
|
"@utils/test": "0.0.1"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@babel/runtime": "7.24.
|
|
70
|
+
"@babel/runtime": "7.24.8",
|
|
71
71
|
"@emotion/react": "11.11.4",
|
|
72
72
|
"@emotion/styled": "11.11.5",
|
|
73
73
|
"react-select": "5.8.0",
|
|
74
74
|
"react-hook-form": "7.52.1",
|
|
75
|
-
"@ultraviolet/ui": "1.
|
|
76
|
-
"@ultraviolet/themes": "1.12.
|
|
75
|
+
"@ultraviolet/ui": "1.62.0",
|
|
76
|
+
"@ultraviolet/themes": "1.12.2"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
|
|
80
80
|
"build": "vite build --config vite.config.ts && pnpm run type:generate",
|
|
81
81
|
"prebuild": "shx rm -rf dist",
|
|
82
|
-
"size": "
|
|
82
|
+
"size": "size-limit",
|
|
83
83
|
"test:unit:coverage": "pnpm test:unit --coverage",
|
|
84
84
|
"test:unit": "LC_ALL=en_US.UTF-8 pnpm vitest --run --config vite.config.ts",
|
|
85
85
|
"type:generate": "tsc --declaration -p tsconfig.build.json",
|