@ultraviolet/form 3.3.1 → 3.5.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.
@@ -5,24 +5,18 @@ const ui = require("@ultraviolet/ui");
5
5
  const reactHookForm = require("react-hook-form");
6
6
  const index = require("../../providers/ErrorContext/index.cjs");
7
7
  const CheckboxField = ({
8
- id,
9
8
  control,
10
9
  name,
11
10
  label,
12
- size,
13
- progress,
14
11
  disabled,
15
12
  required,
16
- className,
17
13
  children,
18
14
  onChange,
19
15
  onBlur,
20
- onFocus,
21
- helper,
22
- tooltip,
23
16
  "data-testid": dataTestId,
24
17
  shouldUnregister = false,
25
- validate
18
+ validate,
19
+ ...props
26
20
  }) => {
27
21
  const {
28
22
  getError
@@ -42,14 +36,14 @@ const CheckboxField = ({
42
36
  validate
43
37
  }
44
38
  });
45
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { id, name: field.name, onChange: (event) => {
39
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Checkbox, { ...props, name: field.name, onChange: (event) => {
46
40
  field.onChange(event.target.checked);
47
41
  onChange?.(event.target.checked);
48
42
  }, onBlur: (event) => {
49
43
  field.onBlur();
50
44
  onBlur?.(event);
51
- }, onFocus, size, progress, disabled: field.disabled, checked: !!field.value, error: getError({
45
+ }, disabled: field.disabled, checked: !!field.value, error: getError({
52
46
  label: label ?? ""
53
- }, error), ref: field.ref, className, required, "data-testid": dataTestId, helper, tooltip, children });
47
+ }, error), ref: field.ref, children });
54
48
  };
55
49
  exports.CheckboxField = CheckboxField;
@@ -2,9 +2,9 @@ import { Checkbox } from '@ultraviolet/ui';
2
2
  import type { ComponentProps, ReactNode } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type CheckboxFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'value'> & Partial<Pick<ComponentProps<typeof Checkbox>, 'id' | 'disabled' | 'onBlur' | 'onFocus' | 'progress' | 'size' | 'data-testid' | 'helper' | 'tooltip'>> & {
5
+ type CheckboxFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'value'> & Omit<ComponentProps<typeof Checkbox>, 'value' | 'onChange' | 'aria-label'> & {
6
6
  className?: string;
7
7
  children?: ReactNode;
8
8
  };
9
- export declare const CheckboxField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ id, control, name, label, size, progress, disabled, required, className, children, onChange, onBlur, onFocus, helper, tooltip, "data-testid": dataTestId, shouldUnregister, validate, }: CheckboxFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
9
+ export declare const CheckboxField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, label, disabled, required, children, onChange, onBlur, "data-testid": dataTestId, shouldUnregister, validate, ...props }: CheckboxFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
10
10
  export {};
@@ -3,24 +3,18 @@ import { Checkbox } from "@ultraviolet/ui";
3
3
  import { useController } from "react-hook-form";
4
4
  import { useErrors } from "../../providers/ErrorContext/index.js";
5
5
  const CheckboxField = ({
6
- id,
7
6
  control,
8
7
  name,
9
8
  label,
10
- size,
11
- progress,
12
9
  disabled,
13
10
  required,
14
- className,
15
11
  children,
16
12
  onChange,
17
13
  onBlur,
18
- onFocus,
19
- helper,
20
- tooltip,
21
14
  "data-testid": dataTestId,
22
15
  shouldUnregister = false,
23
- validate
16
+ validate,
17
+ ...props
24
18
  }) => {
25
19
  const {
26
20
  getError
@@ -40,15 +34,15 @@ const CheckboxField = ({
40
34
  validate
41
35
  }
42
36
  });
43
- return /* @__PURE__ */ jsx(Checkbox, { id, name: field.name, onChange: (event) => {
37
+ return /* @__PURE__ */ jsx(Checkbox, { ...props, name: field.name, onChange: (event) => {
44
38
  field.onChange(event.target.checked);
45
39
  onChange?.(event.target.checked);
46
40
  }, onBlur: (event) => {
47
41
  field.onBlur();
48
42
  onBlur?.(event);
49
- }, onFocus, size, progress, disabled: field.disabled, checked: !!field.value, error: getError({
43
+ }, disabled: field.disabled, checked: !!field.value, error: getError({
50
44
  label: label ?? ""
51
- }, error), ref: field.ref, className, required, "data-testid": dataTestId, helper, tooltip, children });
45
+ }, error), ref: field.ref, children });
52
46
  };
53
47
  export {
54
48
  CheckboxField
@@ -12,11 +12,7 @@ const arraysContainSameValues = (array1, array2) => {
12
12
  return array2.every((value) => array1.includes(value));
13
13
  };
14
14
  const CheckboxGroupField = ({
15
- legend,
16
- className,
17
15
  control,
18
- helper,
19
- direction,
20
16
  children,
21
17
  onChange,
22
18
  label = "",
@@ -24,7 +20,8 @@ const CheckboxGroupField = ({
24
20
  name,
25
21
  required = false,
26
22
  shouldUnregister = false,
27
- validate
23
+ validate,
24
+ ...props
28
25
  }) => {
29
26
  const {
30
27
  getError
@@ -63,7 +60,7 @@ const CheckboxGroupField = ({
63
60
  }
64
61
  }
65
62
  });
66
- return /* @__PURE__ */ jsxRuntime.jsx(ui.CheckboxGroup, { legend, name, value: field.value, onChange: (event) => {
63
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.CheckboxGroup, { ...props, value: field.value, onChange: (event) => {
67
64
  const fieldValue = field.value;
68
65
  if (fieldValue?.includes(event.currentTarget.value)) {
69
66
  field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
@@ -73,7 +70,7 @@ const CheckboxGroupField = ({
73
70
  onChange?.(event.currentTarget.value);
74
71
  }, error: getError({
75
72
  label
76
- }, error) ?? customError, className, direction, helper, required, children });
73
+ }, error) ?? customError, name, children });
77
74
  };
78
75
  CheckboxGroupField.Checkbox = ui.CheckboxGroup.Checkbox;
79
76
  exports.CheckboxGroupField = CheckboxGroupField;
@@ -2,9 +2,9 @@ import { CheckboxGroup } 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 CheckboxGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Partial<Pick<ComponentProps<typeof CheckboxGroup>, 'className' | 'helper' | 'required' | 'direction' | 'children' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof CheckboxGroup>, 'legend'>>;
5
+ type CheckboxGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof CheckboxGroup>, 'value' | 'onChange'>;
6
6
  export declare const CheckboxGroupField: {
7
- <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ legend, className, control, helper, direction, children, onChange, label, error: customError, name, required, shouldUnregister, validate, }: CheckboxGroupFieldProps<TFieldValues, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
7
+ <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, children, onChange, label, error: customError, name, required, shouldUnregister, validate, ...props }: CheckboxGroupFieldProps<TFieldValues, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
8
8
  Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, required, }: Omit<({
9
9
  error?: string | import("react").ReactNode;
10
10
  size?: number;
@@ -10,11 +10,7 @@ const arraysContainSameValues = (array1, array2) => {
10
10
  return array2.every((value) => array1.includes(value));
11
11
  };
12
12
  const CheckboxGroupField = ({
13
- legend,
14
- className,
15
13
  control,
16
- helper,
17
- direction,
18
14
  children,
19
15
  onChange,
20
16
  label = "",
@@ -22,7 +18,8 @@ const CheckboxGroupField = ({
22
18
  name,
23
19
  required = false,
24
20
  shouldUnregister = false,
25
- validate
21
+ validate,
22
+ ...props
26
23
  }) => {
27
24
  const {
28
25
  getError
@@ -61,7 +58,7 @@ const CheckboxGroupField = ({
61
58
  }
62
59
  }
63
60
  });
64
- return /* @__PURE__ */ jsx(CheckboxGroup, { legend, name, value: field.value, onChange: (event) => {
61
+ return /* @__PURE__ */ jsx(CheckboxGroup, { ...props, value: field.value, onChange: (event) => {
65
62
  const fieldValue = field.value;
66
63
  if (fieldValue?.includes(event.currentTarget.value)) {
67
64
  field.onChange(fieldValue?.filter((currentValue) => currentValue !== event.currentTarget.value));
@@ -71,7 +68,7 @@ const CheckboxGroupField = ({
71
68
  onChange?.(event.currentTarget.value);
72
69
  }, error: getError({
73
70
  label
74
- }, error) ?? customError, className, direction, helper, required, children });
71
+ }, error) ?? customError, name, children });
75
72
  };
76
73
  CheckboxGroupField.Checkbox = CheckboxGroup.Checkbox;
77
74
  export {
@@ -5,11 +5,9 @@ const ui = require("@ultraviolet/ui");
5
5
  const reactHookForm = require("react-hook-form");
6
6
  const index = require("../../providers/ErrorContext/index.cjs");
7
7
  const RadioField = ({
8
- className,
9
8
  control,
10
9
  "data-testid": dataTestId,
11
10
  disabled,
12
- id,
13
11
  name,
14
12
  onBlur,
15
13
  label = "",
@@ -17,9 +15,9 @@ const RadioField = ({
17
15
  onFocus,
18
16
  required,
19
17
  value,
20
- tooltip,
21
18
  shouldUnregister = false,
22
- validate
19
+ validate,
20
+ ...props
23
21
  }) => {
24
22
  const {
25
23
  getError
@@ -38,14 +36,14 @@ const RadioField = ({
38
36
  validate
39
37
  }
40
38
  });
41
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { name: field.name, checked: field.value === value, className, "data-testid": dataTestId, disabled, error: getError({
39
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Radio, { ...props, name: field.name, checked: field.value === value, "data-testid": dataTestId, disabled, error: getError({
42
40
  label: typeof label === "string" ? label : ""
43
- }, error), id, onChange: () => {
41
+ }, error), onChange: () => {
44
42
  field.onChange(value);
45
43
  onChange?.(value);
46
44
  }, onBlur: (event) => {
47
45
  field.onBlur();
48
46
  onBlur?.(event);
49
- }, onFocus, required, value: value ?? "", label, tooltip });
47
+ }, onFocus, required, value: value ?? "", label });
50
48
  };
51
49
  exports.RadioField = RadioField;
@@ -2,11 +2,9 @@ import { Radio } 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 RadioFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Partial<Pick<ComponentProps<typeof Radio>, 'disabled' | 'id' | 'onBlur' | 'onFocus' | 'data-testid' | 'tooltip' | 'label'>> & {
6
- className?: string;
7
- };
5
+ type RadioFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'label'> & Omit<ComponentProps<typeof Radio>, 'value' | 'onChange' | 'aria-label'>;
8
6
  /**
9
7
  * @deprecated This component is deprecated, use `RadioGroupField` instead.
10
8
  */
11
- export declare const RadioField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, control, "data-testid": dataTestId, disabled, id, name, onBlur, label, onChange, onFocus, required, value, tooltip, shouldUnregister, validate, }: RadioFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
9
+ export declare const RadioField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, "data-testid": dataTestId, disabled, name, onBlur, label, onChange, onFocus, required, value, shouldUnregister, validate, ...props }: RadioFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
12
10
  export {};
@@ -3,11 +3,9 @@ import { Radio } from "@ultraviolet/ui";
3
3
  import { useController } from "react-hook-form";
4
4
  import { useErrors } from "../../providers/ErrorContext/index.js";
5
5
  const RadioField = ({
6
- className,
7
6
  control,
8
7
  "data-testid": dataTestId,
9
8
  disabled,
10
- id,
11
9
  name,
12
10
  onBlur,
13
11
  label = "",
@@ -15,9 +13,9 @@ const RadioField = ({
15
13
  onFocus,
16
14
  required,
17
15
  value,
18
- tooltip,
19
16
  shouldUnregister = false,
20
- validate
17
+ validate,
18
+ ...props
21
19
  }) => {
22
20
  const {
23
21
  getError
@@ -36,15 +34,15 @@ const RadioField = ({
36
34
  validate
37
35
  }
38
36
  });
39
- return /* @__PURE__ */ jsx(Radio, { name: field.name, checked: field.value === value, className, "data-testid": dataTestId, disabled, error: getError({
37
+ return /* @__PURE__ */ jsx(Radio, { ...props, name: field.name, checked: field.value === value, "data-testid": dataTestId, disabled, error: getError({
40
38
  label: typeof label === "string" ? label : ""
41
- }, error), id, onChange: () => {
39
+ }, error), onChange: () => {
42
40
  field.onChange(value);
43
41
  onChange?.(value);
44
42
  }, onBlur: (event) => {
45
43
  field.onBlur();
46
44
  onBlur?.(event);
47
- }, onFocus, required, value: value ?? "", label, tooltip });
45
+ }, onFocus, required, value: value ?? "", label });
48
46
  };
49
47
  export {
50
48
  RadioField
@@ -5,19 +5,17 @@ const ui = require("@ultraviolet/ui");
5
5
  const reactHookForm = require("react-hook-form");
6
6
  const index = require("../../providers/ErrorContext/index.cjs");
7
7
  const RadioGroupField = ({
8
- className,
9
8
  control,
10
- legend = "",
11
9
  name,
12
10
  onChange,
13
11
  required,
14
12
  children,
15
13
  label = "",
16
14
  error: customError,
17
- helper,
18
- direction,
19
15
  shouldUnregister = false,
20
- validate
16
+ validate,
17
+ legend,
18
+ ...props
21
19
  }) => {
22
20
  const {
23
21
  getError
@@ -36,12 +34,12 @@ const RadioGroupField = ({
36
34
  validate
37
35
  }
38
36
  });
39
- return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { className, name: field.name, onChange: (event) => {
37
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.RadioGroup, { ...props, name: field.name, onChange: (event) => {
40
38
  field.onChange(event);
41
39
  onChange?.(event.target.value);
42
- }, required, value: field.value, legend, error: getError({
40
+ }, required, value: field.value, error: getError({
43
41
  label
44
- }, error) ?? customError, helper, direction, children });
42
+ }, error) ?? customError, legend: legend ?? "", children });
45
43
  };
46
44
  RadioGroupField.Radio = ui.RadioGroup.Radio;
47
45
  exports.RadioGroupField = RadioGroupField;
@@ -2,11 +2,9 @@ import { RadioGroup } from '@ultraviolet/ui';
2
2
  import type { ComponentProps, JSX } from 'react';
3
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
4
4
  import type { BaseFieldProps } from '../../types';
5
- type RadioGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'legend' | 'children' | 'error' | 'helper' | 'direction'>> & {
6
- className?: string;
7
- };
5
+ type RadioGroupFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof RadioGroup>, 'value' | 'onChange' | 'legend'> & Partial<Pick<ComponentProps<typeof RadioGroup>, 'legend'>>;
8
6
  export declare const RadioGroupField: {
9
- <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, control, legend, name, onChange, required, children, label, error: customError, helper, direction, shouldUnregister, validate, }: RadioGroupFieldProps<TFieldValues, TFieldName>): JSX.Element;
7
+ <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ control, name, onChange, required, children, label, error: customError, shouldUnregister, validate, legend, ...props }: RadioGroupFieldProps<TFieldValues, TFieldName>): JSX.Element;
10
8
  Radio: ({ onFocus, onBlur, disabled, error, name, value, label, helper, className, autoFocus, onKeyDown, tooltip, "data-testid": dataTestId, }: Omit<({
11
9
  error?: import("react").ReactNode;
12
10
  checked?: boolean;
@@ -3,19 +3,17 @@ import { RadioGroup } from "@ultraviolet/ui";
3
3
  import { useController } from "react-hook-form";
4
4
  import { useErrors } from "../../providers/ErrorContext/index.js";
5
5
  const RadioGroupField = ({
6
- className,
7
6
  control,
8
- legend = "",
9
7
  name,
10
8
  onChange,
11
9
  required,
12
10
  children,
13
11
  label = "",
14
12
  error: customError,
15
- helper,
16
- direction,
17
13
  shouldUnregister = false,
18
- validate
14
+ validate,
15
+ legend,
16
+ ...props
19
17
  }) => {
20
18
  const {
21
19
  getError
@@ -34,12 +32,12 @@ const RadioGroupField = ({
34
32
  validate
35
33
  }
36
34
  });
37
- return /* @__PURE__ */ jsx(RadioGroup, { className, name: field.name, onChange: (event) => {
35
+ return /* @__PURE__ */ jsx(RadioGroup, { ...props, name: field.name, onChange: (event) => {
38
36
  field.onChange(event);
39
37
  onChange?.(event.target.value);
40
- }, required, value: field.value, legend, error: getError({
38
+ }, required, value: field.value, error: getError({
41
39
  label
42
- }, error) ?? customError, helper, direction, children });
40
+ }, error) ?? customError, legend: legend ?? "", children });
43
41
  };
44
42
  RadioGroupField.Radio = RadioGroup.Radio;
45
43
  export {
@@ -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.1",
3
+ "version": "3.5.0",
4
4
  "description": "Ultraviolet Form",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {
@@ -72,7 +72,7 @@
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.62.0",
75
+ "@ultraviolet/ui": "1.64.0",
76
76
  "@ultraviolet/themes": "1.12.2"
77
77
  },
78
78
  "scripts": {