@ultraviolet/form 3.3.0 → 3.4.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.
@@ -10,7 +10,7 @@ const KeyValueField = ({
10
10
  inputValue,
11
11
  addButton,
12
12
  maxSize = 100,
13
- readonly = false,
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: readonly, required: inputKey.required, name: `${name}.${index$1}.key`, label: inputKey.label, regex: inputKey.regex }),
29
- /* @__PURE__ */ jsxRuntime.jsx(index.TextInputField, { readOnly: 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) })
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 || readonly,
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
- readonly?: boolean;
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, readonly, control, }: KeyValueFieldProps<TFieldValues, TFieldArrayName>) => import("@emotion/react/jsx-runtime").JSX.Element;
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
- readonly = false,
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: readonly, required: inputKey.required, name: `${name}.${index}.key`, label: inputKey.label, regex: inputKey.regex }),
27
- /* @__PURE__ */ jsx(TextInputField, { readOnly: 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) })
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 || readonly,
38
+ disabled: !canAdd || readOnly,
39
39
  tooltip: !canAdd ? maxSizeReachedTooltip : addButton.tooltip,
40
40
  onClick: () => append({
41
41
  key: "",
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("@emotion/react/jsx-runtime");
4
4
  const ui = require("@ultraviolet/ui");
5
+ const react = require("react");
5
6
  const reactHookForm = require("react-hook-form");
6
7
  const index = require("../../providers/ErrorContext/index.cjs");
7
8
  const SliderField = ({
@@ -17,6 +18,7 @@ const SliderField = ({
17
18
  label,
18
19
  value,
19
20
  defaultValue,
21
+ options,
20
22
  ...props
21
23
  }) => {
22
24
  const {
@@ -38,16 +40,35 @@ const SliderField = ({
38
40
  validate
39
41
  }
40
42
  });
41
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { name: field.name, value: field.value, onBlur: (event) => {
43
+ const finalValue = react.useMemo(() => {
44
+ if (options && field.value) {
45
+ if (!Array.isArray(field.value)) {
46
+ const processedValue = options.map((option) => option.value).indexOf(field.value);
47
+ return processedValue;
48
+ }
49
+ if (Array.isArray(field.value)) {
50
+ const processedValue = field.value.map((val) => options.map((option) => option.value).indexOf(val));
51
+ return processedValue;
52
+ }
53
+ }
54
+ return field.value;
55
+ }, [field.value, options]);
56
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { name: field.name, value: finalValue, onBlur: (event) => {
42
57
  field.onBlur();
43
58
  onBlur?.(event);
44
59
  }, onChange: (newValue) => {
45
- field.onChange(newValue);
46
- onChange?.(newValue);
60
+ if (options) {
61
+ const processedValue = !Array.isArray(newValue) ? options[newValue].value : newValue.map((val) => val ? options[val].value : options[0].value);
62
+ field.onChange(processedValue);
63
+ onChange?.(processedValue);
64
+ } else {
65
+ field.onChange(newValue);
66
+ onChange?.(newValue);
67
+ }
47
68
  }, max, min, error: getError({
48
69
  label: label ?? "",
49
70
  max,
50
71
  min
51
- }, error), label, required, ...props });
72
+ }, error), label, required, options, ...props });
52
73
  };
53
74
  exports.SliderField = SliderField;
@@ -1,9 +1,9 @@
1
1
  import { Slider } from '@ultraviolet/ui';
2
- import type { ComponentProps, ReactNode } from 'react';
2
+ import { type ComponentProps, type ReactNode } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
5
  type SliderFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof Slider>, 'value' | 'onChange'> & {
6
6
  suffix?: string | ReactNode[];
7
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;
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, options, ...props }: SliderFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
9
9
  export {};
@@ -1,5 +1,6 @@
1
1
  import { jsx } from "@emotion/react/jsx-runtime";
2
2
  import { Slider } from "@ultraviolet/ui";
3
+ import { useMemo } from "react";
3
4
  import { useController } from "react-hook-form";
4
5
  import { useErrors } from "../../providers/ErrorContext/index.js";
5
6
  const SliderField = ({
@@ -15,6 +16,7 @@ const SliderField = ({
15
16
  label,
16
17
  value,
17
18
  defaultValue,
19
+ options,
18
20
  ...props
19
21
  }) => {
20
22
  const {
@@ -36,17 +38,36 @@ const SliderField = ({
36
38
  validate
37
39
  }
38
40
  });
39
- return /* @__PURE__ */ jsx(Slider, { name: field.name, value: field.value, onBlur: (event) => {
41
+ const finalValue = useMemo(() => {
42
+ if (options && field.value) {
43
+ if (!Array.isArray(field.value)) {
44
+ const processedValue = options.map((option) => option.value).indexOf(field.value);
45
+ return processedValue;
46
+ }
47
+ if (Array.isArray(field.value)) {
48
+ const processedValue = field.value.map((val) => options.map((option) => option.value).indexOf(val));
49
+ return processedValue;
50
+ }
51
+ }
52
+ return field.value;
53
+ }, [field.value, options]);
54
+ return /* @__PURE__ */ jsx(Slider, { name: field.name, value: finalValue, onBlur: (event) => {
40
55
  field.onBlur();
41
56
  onBlur?.(event);
42
57
  }, onChange: (newValue) => {
43
- field.onChange(newValue);
44
- onChange?.(newValue);
58
+ if (options) {
59
+ const processedValue = !Array.isArray(newValue) ? options[newValue].value : newValue.map((val) => val ? options[val].value : options[0].value);
60
+ field.onChange(processedValue);
61
+ onChange?.(processedValue);
62
+ } else {
63
+ field.onChange(newValue);
64
+ onChange?.(newValue);
65
+ }
45
66
  }, max, min, error: getError({
46
67
  label: label ?? "",
47
68
  max,
48
69
  min
49
- }, error), label, required, ...props });
70
+ }, error), label, required, options, ...props });
50
71
  };
51
72
  export {
52
73
  SliderField
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/form",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
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.7",
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,12 +67,12 @@
67
67
  "@utils/test": "0.0.1"
68
68
  },
69
69
  "dependencies": {
70
- "@babel/runtime": "7.24.7",
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.61.1",
75
+ "@ultraviolet/ui": "1.63.0",
76
76
  "@ultraviolet/themes": "1.12.2"
77
77
  },
78
78
  "scripts": {