@ultraviolet/form 4.0.0-beta.9 → 4.0.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.
Files changed (80) hide show
  1. package/README.md +191 -3
  2. package/dist/components/CheckboxField/index.cjs +13 -13
  3. package/dist/components/CheckboxField/index.js +13 -13
  4. package/dist/components/CheckboxGroupField/index.cjs +7 -7
  5. package/dist/components/CheckboxGroupField/index.d.ts +1 -3
  6. package/dist/components/CheckboxGroupField/index.js +7 -7
  7. package/dist/components/{DateField → DateInputField}/index.cjs +18 -18
  8. package/dist/components/DateInputField/index.d.ts +7 -0
  9. package/dist/components/{DateField → DateInputField}/index.js +18 -18
  10. package/dist/components/Form/defaultErrors.cjs +10 -10
  11. package/dist/components/Form/defaultErrors.js +10 -10
  12. package/dist/components/Form/index.cjs +5 -5
  13. package/dist/components/Form/index.js +5 -5
  14. package/dist/components/KeyValueField/index.cjs +11 -11
  15. package/dist/components/KeyValueField/index.d.ts +6 -6
  16. package/dist/components/KeyValueField/index.js +11 -11
  17. package/dist/components/NumberInputField/index.cjs +26 -26
  18. package/dist/components/NumberInputField/index.d.ts +3 -9
  19. package/dist/components/NumberInputField/index.js +26 -26
  20. package/dist/components/RadioField/index.cjs +8 -8
  21. package/dist/components/RadioField/index.d.ts +1 -4
  22. package/dist/components/RadioField/index.js +8 -8
  23. package/dist/components/RadioGroupField/index.cjs +7 -7
  24. package/dist/components/RadioGroupField/index.d.ts +17 -7
  25. package/dist/components/RadioGroupField/index.js +7 -7
  26. package/dist/components/SelectInputField/index.cjs +21 -73
  27. package/dist/components/SelectInputField/index.d.ts +3 -81
  28. package/dist/components/SelectInputField/index.js +22 -74
  29. package/dist/components/SelectableCardField/index.cjs +8 -8
  30. package/dist/components/SelectableCardField/index.js +8 -8
  31. package/dist/components/SelectableCardGroupField/index.cjs +7 -7
  32. package/dist/components/SelectableCardGroupField/index.js +7 -7
  33. package/dist/components/SelectableCardOptionGroupField/index.cjs +9 -9
  34. package/dist/components/SelectableCardOptionGroupField/index.d.ts +3 -3
  35. package/dist/components/SelectableCardOptionGroupField/index.js +9 -9
  36. package/dist/components/SliderField/index.cjs +9 -9
  37. package/dist/components/SliderField/index.d.ts +1 -1
  38. package/dist/components/SliderField/index.js +9 -9
  39. package/dist/components/Submit/index.cjs +1 -1
  40. package/dist/components/Submit/index.js +1 -1
  41. package/dist/components/SwitchButtonField/index.cjs +8 -9
  42. package/dist/components/SwitchButtonField/index.d.ts +11 -2
  43. package/dist/components/SwitchButtonField/index.js +8 -9
  44. package/dist/components/TagInputField/index.cjs +6 -6
  45. package/dist/components/TagInputField/index.js +6 -6
  46. package/dist/components/TextAreaField/index.cjs +8 -8
  47. package/dist/components/TextAreaField/index.js +8 -8
  48. package/dist/components/TextInputField/index.cjs +23 -77
  49. package/dist/components/TextInputField/index.d.ts +5 -11
  50. package/dist/components/TextInputField/index.js +23 -77
  51. package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.cjs +6 -6
  52. package/dist/components/TimeInputField/index.d.ts +11 -0
  53. package/dist/components/{TimeInputFieldV2 → TimeInputField}/index.js +7 -7
  54. package/dist/components/ToggleField/index.cjs +7 -7
  55. package/dist/components/ToggleField/index.js +7 -7
  56. package/dist/components/UnitInputField/index.cjs +10 -10
  57. package/dist/components/UnitInputField/index.js +10 -10
  58. package/dist/components/VerificationCodeField/index.cjs +4 -4
  59. package/dist/components/VerificationCodeField/index.js +4 -4
  60. package/dist/components/index.d.ts +11 -15
  61. package/dist/index.cjs +45 -53
  62. package/dist/index.d.ts +5 -5
  63. package/dist/index.js +15 -23
  64. package/dist/providers/index.d.ts +1 -1
  65. package/dist/validators/index.d.ts +1 -1
  66. package/package.json +10 -10
  67. package/dist/components/DateField/index.d.ts +0 -7
  68. package/dist/components/NumberInputFieldV2/index.cjs +0 -59
  69. package/dist/components/NumberInputFieldV2/index.d.ts +0 -7
  70. package/dist/components/NumberInputFieldV2/index.js +0 -59
  71. package/dist/components/SelectInputFieldV2/index.cjs +0 -50
  72. package/dist/components/SelectInputFieldV2/index.d.ts +0 -7
  73. package/dist/components/SelectInputFieldV2/index.js +0 -50
  74. package/dist/components/TextInputFieldV2/index.cjs +0 -62
  75. package/dist/components/TextInputFieldV2/index.d.ts +0 -12
  76. package/dist/components/TextInputFieldV2/index.js +0 -62
  77. package/dist/components/TimeField/index.cjs +0 -68
  78. package/dist/components/TimeField/index.d.ts +0 -7
  79. package/dist/components/TimeField/index.js +0 -68
  80. package/dist/components/TimeInputFieldV2/index.d.ts +0 -11
@@ -1,85 +1,7 @@
1
- import type { CSSObject, Theme, css } from '@emotion/react';
2
1
  import { SelectInput } from '@ultraviolet/ui';
3
- import type { ComponentProps, ForwardedRef, ReactNode } from 'react';
2
+ import type { ComponentProps } from 'react';
4
3
  import type { FieldPath, FieldValues } from 'react-hook-form';
5
- import type { CommonProps, GroupBase, OptionProps, Props } from 'react-select';
6
- import type Select from 'react-select';
7
4
  import type { BaseFieldProps } from '../../types';
8
- export type SelectInputType = typeof SelectInput;
9
- type SelectOption = {
10
- value: string;
11
- label: ReactNode;
12
- disabled?: boolean;
13
- description?: string;
14
- inlineDescription?: string;
15
- };
16
- type WithSelectProps = {
17
- selectProps: SelectProps;
18
- };
19
- type SelectStyleProps = {
20
- error?: string;
21
- /**
22
- * Custom styles of the SelectInput. See [React select documentation](https://react-select.com/styles)
23
- */
24
- customStyle: (state: SelectProps & WithSelectProps) => Record<string, CSSObject>;
25
- animation?: string;
26
- /**
27
- * Time of the animation
28
- */
29
- animationDuration?: number;
30
- /**
31
- * Show/hide the label inside the component
32
- */
33
- noTopLabel?: boolean;
34
- theme: Theme;
35
- };
36
- type StyledContainerProps = {
37
- isDisabled?: boolean;
38
- additionalStyles?: Parameters<typeof css>[0];
39
- };
40
- type SelectProps = StyledContainerProps & Omit<Props<SelectOption>, 'value'> & CommonProps<SelectOption, boolean, GroupBase<SelectOption>> & {
41
- value?: string | SelectOption;
42
- checked?: boolean;
43
- error?: string;
44
- labelId?: string;
45
- required?: boolean;
46
- time?: boolean;
47
- };
48
- type StateManagedSelect = typeof Select;
49
- type SelectInputProps = Partial<SelectProps & SelectStyleProps & Pick<ComponentProps<typeof SelectInput>, 'data-testid'> & {
50
- /**
51
- * Name of the animation
52
- */
53
- animation?: string;
54
- /**
55
- * Play the animation when the value change
56
- */
57
- animationOnChange?: boolean;
58
- disabled?: boolean;
59
- readOnly?: boolean;
60
- innerRef?: ForwardedRef<StateManagedSelect>;
61
- /**
62
- * Custom components of the SelectInput. See [React select documentation](https://react-select.com/components)
63
- */
64
- customComponents?: SelectProps['components'];
65
- children: ReactNode;
66
- emptyState?: ComponentProps<Select>['noOptionsMessage'];
67
- }>;
68
- /**
69
- * @deprecated This component is deprecated, please use `SelectInputFieldV2` instead
70
- */
71
- export type SelectInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TFieldName>, 'onChange'> & Partial<Pick<SelectInputProps, 'animation' | 'animationDuration' | 'animationOnChange' | 'children' | 'className' | 'disabled' | 'error' | 'id' | 'inputId' | 'isClearable' | 'isLoading' | 'isSearchable' | 'menuPortalTarget' | 'onBlur' | 'onChange' | 'onFocus' | 'options' | 'placeholder' | 'readOnly' | 'required' | 'value' | 'noTopLabel' | 'emptyState' | 'customStyle' | 'data-testid'>> & {
72
- multiple?: boolean;
73
- parse?: (value: unknown, name?: string) => unknown;
74
- format?: (value: unknown, name: string) => unknown;
75
- maxLength?: number;
76
- minLength?: number;
77
- };
78
- /**
79
- * @deprecated use SelectInputFieldV2 component instead
80
- */
81
- export declare const SelectInputField: {
82
- <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ animation, animationDuration, animationOnChange, children, className, disabled, format: formatProp, id, inputId, isClearable, isLoading, isSearchable, label, maxLength, menuPortalTarget, minLength, multiple, name, onBlur, onChange, onFocus, options: optionsProp, parse: parseProp, placeholder, readOnly, required, noTopLabel, emptyState, customStyle, shouldUnregister, "data-testid": dataTestId, validate, }: SelectInputFieldProps<TFieldValues, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
83
- Option: (props: Partial<OptionProps<import("@ultraviolet/ui").SelectOption> & import("@ultraviolet/ui").SelectOption>) => import("react").JSX.Element;
84
- };
5
+ type SelectInputFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof SelectInput>, 'value' | 'onChange'>;
6
+ export declare const SelectInputField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ label, onBlur, required, name, "aria-label": ariaLabel, shouldUnregister, control, validate, onChange, multiselect, ...props }: SelectInputFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
85
7
  export {};
@@ -1,102 +1,50 @@
1
1
  "use client";
2
2
  import { jsx } from "@emotion/react/jsx-runtime";
3
3
  import { SelectInput } from "@ultraviolet/ui";
4
- import { useMemo, Children, useCallback } from "react";
4
+ import { useCallback } from "react";
5
5
  import { useController } from "react-hook-form";
6
6
  import { useErrors } from "../../providers/ErrorContext/index.js";
7
- const identity = (x) => x;
8
7
  const SelectInputField = ({
9
- animation,
10
- animationDuration,
11
- animationOnChange,
12
- children,
13
- className,
14
- disabled,
15
- // error: errorProp,
16
- format: formatProp = identity,
17
- // formatOnBlur,
18
- id,
19
- inputId,
20
- isClearable,
21
- isLoading,
22
- isSearchable,
23
8
  label = "",
24
- maxLength,
25
- menuPortalTarget,
26
- minLength,
27
- multiple,
28
- name,
29
9
  onBlur,
30
- onChange,
31
- onFocus,
32
- options: optionsProp,
33
- parse: parseProp = identity,
34
- placeholder,
35
- readOnly,
36
10
  required,
37
- noTopLabel,
38
- emptyState,
39
- customStyle,
11
+ name,
12
+ "aria-label": ariaLabel,
40
13
  shouldUnregister = false,
41
- "data-testid": dataTestId,
42
- validate
14
+ control,
15
+ validate,
16
+ onChange,
17
+ multiselect,
18
+ ...props
43
19
  }) => {
44
- const options = useMemo(() => optionsProp || Children.toArray(children).flat().filter(Boolean).map(({
45
- props: {
46
- children: labelChild,
47
- ...option
48
- }
49
- }) => ({
50
- ...option,
51
- label: labelChild
52
- })), [optionsProp, children]);
53
- const parse = useMemo(() => multiple ? parseProp : (option) => parseProp(option?.value ?? null, name), [multiple, parseProp, name]);
54
- const format = useCallback((val) => {
55
- if (multiple) return formatProp(val, name);
56
- const find = (opts, valueToFind) => opts?.find((option) => option.value === valueToFind);
57
- let selected = "";
58
- if (val && options) {
59
- selected = find(options, val);
60
- if (!selected) {
61
- selected = options.map((curr) => find(curr.options, val)).filter(identity);
62
- if (Array.isArray(selected) && selected.length === 0) {
63
- selected = "";
64
- }
65
- }
66
- }
67
- return formatProp(selected, name);
68
- }, [formatProp, multiple, name, options]);
69
- const {
70
- getError
71
- } = useErrors();
72
20
  const {
73
21
  field,
74
22
  fieldState: {
75
23
  error
76
24
  }
77
25
  } = useController({
26
+ control,
78
27
  name,
79
- shouldUnregister,
80
28
  rules: {
81
29
  required,
82
- minLength: minLength || required ? 1 : void 0,
83
- maxLength,
84
30
  validate
85
- }
31
+ },
32
+ shouldUnregister
86
33
  });
87
- return /* @__PURE__ */ jsx(SelectInput, { name: field.name, animation, animationDuration, animationOnChange, className, disabled, error: getError({
88
- label,
89
- minLength,
90
- maxLength
91
- }, error), id, inputId, isClearable, isLoading, isMulti: multiple, customStyle, isSearchable, menuPortalTarget, onBlur: (event) => {
34
+ const {
35
+ getError
36
+ } = useErrors();
37
+ const handleChange = useCallback((value) => {
38
+ onChange?.(value);
39
+ field.onChange(value);
40
+ }, [onChange, field]);
41
+ return /* @__PURE__ */ jsx(SelectInput, { "aria-label": ariaLabel, error: getError({
42
+ label: label ?? ariaLabel ?? name
43
+ }, error), label, multiselect, name: field.name, onBlur: (event) => {
92
44
  field.onBlur();
93
45
  onBlur?.(event);
94
- }, onChange: (event, action) => {
95
- field.onChange(parse(event));
96
- onChange?.(event, action);
97
- }, onFocus, options, placeholder, readOnly, noTopLabel, required, value: format(field.value), emptyState, "data-testid": dataTestId, children });
46
+ }, onChange: handleChange, required, value: field.value, ...props });
98
47
  };
99
- SelectInputField.Option = SelectInput.Option;
100
48
  export {
101
49
  SelectInputField
102
50
  };
@@ -27,13 +27,13 @@ const SelectableCardField = ({
27
27
  error
28
28
  }
29
29
  } = reactHookForm.useController({
30
- name,
31
30
  control,
32
- shouldUnregister,
31
+ name,
33
32
  rules: {
34
33
  required,
35
34
  validate
36
- }
35
+ },
36
+ shouldUnregister
37
37
  });
38
38
  const isChecked = type === "checkbox" && Array.isArray(field.value) && value ? (field.value ?? []).includes(value) : field.value === value;
39
39
  return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCard, { ...props, ...productIcon ? {
@@ -44,7 +44,10 @@ const SelectableCardField = ({
44
44
  label
45
45
  } : {
46
46
  "aria-label": ariaLabel
47
- }, isError: !!error, checked: isChecked, onChange: (event) => {
47
+ }, checked: isChecked, isError: !!error, name: field.name, onBlur: (event) => {
48
+ field.onBlur();
49
+ onBlur?.(event);
50
+ }, onChange: (event) => {
48
51
  if (type === "checkbox") {
49
52
  const fieldValue = field.value ?? [];
50
53
  if (fieldValue?.includes(event.currentTarget.value)) {
@@ -56,11 +59,8 @@ const SelectableCardField = ({
56
59
  field.onChange(event);
57
60
  }
58
61
  onChange?.(event.currentTarget.value);
59
- }, onBlur: (event) => {
60
- field.onBlur();
61
- onBlur?.(event);
62
62
  }, onFocus: (event) => {
63
63
  onFocus?.(event);
64
- }, type, value: value ?? "", name: field.name });
64
+ }, type, value: value ?? "" });
65
65
  };
66
66
  exports.SelectableCardField = SelectableCardField;
@@ -25,13 +25,13 @@ const SelectableCardField = ({
25
25
  error
26
26
  }
27
27
  } = useController({
28
- name,
29
28
  control,
30
- shouldUnregister,
29
+ name,
31
30
  rules: {
32
31
  required,
33
32
  validate
34
- }
33
+ },
34
+ shouldUnregister
35
35
  });
36
36
  const isChecked = type === "checkbox" && Array.isArray(field.value) && value ? (field.value ?? []).includes(value) : field.value === value;
37
37
  return /* @__PURE__ */ jsx(SelectableCard, { ...props, ...productIcon ? {
@@ -42,7 +42,10 @@ const SelectableCardField = ({
42
42
  label
43
43
  } : {
44
44
  "aria-label": ariaLabel
45
- }, isError: !!error, checked: isChecked, onChange: (event) => {
45
+ }, checked: isChecked, isError: !!error, name: field.name, onBlur: (event) => {
46
+ field.onBlur();
47
+ onBlur?.(event);
48
+ }, onChange: (event) => {
46
49
  if (type === "checkbox") {
47
50
  const fieldValue = field.value ?? [];
48
51
  if (fieldValue?.includes(event.currentTarget.value)) {
@@ -54,12 +57,9 @@ const SelectableCardField = ({
54
57
  field.onChange(event);
55
58
  }
56
59
  onChange?.(event.currentTarget.value);
57
- }, onBlur: (event) => {
58
- field.onBlur();
59
- onBlur?.(event);
60
60
  }, onFocus: (event) => {
61
61
  onFocus?.(event);
62
- }, type, value: value ?? "", name: field.name });
62
+ }, type, value: value ?? "" });
63
63
  };
64
64
  export {
65
65
  SelectableCardField
@@ -27,15 +27,17 @@ const SelectableCardGroupField = ({
27
27
  error
28
28
  }
29
29
  } = reactHookForm.useController({
30
- name,
31
30
  control,
32
- shouldUnregister,
31
+ name,
33
32
  rules: {
34
33
  required,
35
34
  validate
36
- }
35
+ },
36
+ shouldUnregister
37
37
  });
38
- return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCardGroup, { ...props, legend, name, type, value: field.value, onChange: (event) => {
38
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCardGroup, { ...props, columns, error: getError({
39
+ label: legend
40
+ }, error) ?? customError, legend, name, onChange: (event) => {
39
41
  if (type === "checkbox") {
40
42
  const fieldValue = field.value ?? [];
41
43
  if (fieldValue?.includes(event.currentTarget.value)) {
@@ -47,9 +49,7 @@ const SelectableCardGroupField = ({
47
49
  field.onChange(event);
48
50
  }
49
51
  onChange?.(event.currentTarget.value);
50
- }, error: getError({
51
- label: legend
52
- }, error) ?? customError, columns, required });
52
+ }, required, type, value: field.value });
53
53
  };
54
54
  SelectableCardGroupField.Card = ui.SelectableCardGroup.Card;
55
55
  exports.SelectableCardGroupField = SelectableCardGroupField;
@@ -25,15 +25,17 @@ const SelectableCardGroupField = ({
25
25
  error
26
26
  }
27
27
  } = useController({
28
- name,
29
28
  control,
30
- shouldUnregister,
29
+ name,
31
30
  rules: {
32
31
  required,
33
32
  validate
34
- }
33
+ },
34
+ shouldUnregister
35
35
  });
36
- return /* @__PURE__ */ jsx(SelectableCardGroup, { ...props, legend, name, type, value: field.value, onChange: (event) => {
36
+ return /* @__PURE__ */ jsx(SelectableCardGroup, { ...props, columns, error: getError({
37
+ label: legend
38
+ }, error) ?? customError, legend, name, onChange: (event) => {
37
39
  if (type === "checkbox") {
38
40
  const fieldValue = field.value ?? [];
39
41
  if (fieldValue?.includes(event.currentTarget.value)) {
@@ -45,9 +47,7 @@ const SelectableCardGroupField = ({
45
47
  field.onChange(event);
46
48
  }
47
49
  onChange?.(event.currentTarget.value);
48
- }, error: getError({
49
- label: legend
50
- }, error) ?? customError, columns, required });
50
+ }, required, type, value: field.value });
51
51
  };
52
52
  SelectableCardGroupField.Card = SelectableCardGroup.Card;
53
53
  export {
@@ -28,32 +28,32 @@ const SelectableCardOptionGroupField = ({
28
28
  error
29
29
  }
30
30
  } = reactHookForm.useController({
31
- name,
32
31
  control,
33
- shouldUnregister,
32
+ name,
34
33
  rules: {
35
34
  required,
36
35
  validate
37
- }
36
+ },
37
+ shouldUnregister
38
38
  });
39
39
  const {
40
40
  field: optionField
41
41
  } = reactHookForm.useController({
42
42
  name: optionName ?? `${name}Option`,
43
- shouldUnregister,
44
43
  rules: {
45
44
  required
46
- }
45
+ },
46
+ shouldUnregister
47
47
  });
48
- return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCardOptionGroup, { legend, name, value: field.value, optionValue: String(optionField.value), onChange: (event) => {
48
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.SelectableCardOptionGroup, { error: getError({
49
+ label: legend
50
+ }, error) ?? customError, legend, name, onChange: (event) => {
49
51
  field.onChange(event);
50
52
  onChange?.(event);
51
53
  }, onChangeOption: (value) => {
52
54
  optionField.onChange(value);
53
55
  onChangeOption?.(value);
54
- }, error: getError({
55
- label: legend
56
- }, error) ?? customError, required, ...props, children });
56
+ }, optionValue: String(optionField.value), required, value: field.value, ...props, children });
57
57
  };
58
58
  SelectableCardOptionGroupField.Option = ui.SelectableCardOptionGroup.Option;
59
59
  exports.SelectableCardOptionGroupField = SelectableCardOptionGroupField;
@@ -11,9 +11,9 @@ export declare const SelectableCardOptionGroupField: {
11
11
  value: string;
12
12
  className?: string;
13
13
  children?: import("react").ReactNode;
14
- options: ComponentProps<typeof import("@ultraviolet/ui").SelectInputV2>["options"];
15
- optionValue?: ComponentProps<typeof import("@ultraviolet/ui").SelectInputV2>["value"];
16
- optionPlaceholder?: ComponentProps<typeof import("@ultraviolet/ui").SelectInputV2>["placeholder"];
14
+ options: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["options"];
15
+ optionValue?: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["value"];
16
+ optionPlaceholder?: ComponentProps<typeof import("@ultraviolet/ui").SelectInput>["placeholder"];
17
17
  image?: import("react").ReactNode;
18
18
  labelDescription?: ComponentProps<typeof import("@ultraviolet/ui").Label>["labelDescription"];
19
19
  id?: string;
@@ -26,32 +26,32 @@ const SelectableCardOptionGroupField = ({
26
26
  error
27
27
  }
28
28
  } = useController({
29
- name,
30
29
  control,
31
- shouldUnregister,
30
+ name,
32
31
  rules: {
33
32
  required,
34
33
  validate
35
- }
34
+ },
35
+ shouldUnregister
36
36
  });
37
37
  const {
38
38
  field: optionField
39
39
  } = useController({
40
40
  name: optionName ?? `${name}Option`,
41
- shouldUnregister,
42
41
  rules: {
43
42
  required
44
- }
43
+ },
44
+ shouldUnregister
45
45
  });
46
- return /* @__PURE__ */ jsx(SelectableCardOptionGroup, { legend, name, value: field.value, optionValue: String(optionField.value), onChange: (event) => {
46
+ return /* @__PURE__ */ jsx(SelectableCardOptionGroup, { error: getError({
47
+ label: legend
48
+ }, error) ?? customError, legend, name, onChange: (event) => {
47
49
  field.onChange(event);
48
50
  onChange?.(event);
49
51
  }, onChangeOption: (value) => {
50
52
  optionField.onChange(value);
51
53
  onChangeOption?.(value);
52
- }, error: getError({
53
- label: legend
54
- }, error) ?? customError, required, ...props, children });
54
+ }, optionValue: String(optionField.value), required, value: field.value, ...props, children });
55
55
  };
56
56
  SelectableCardOptionGroupField.Option = SelectableCardOptionGroup.Option;
57
57
  export {
@@ -32,15 +32,15 @@ const SliderField = ({
32
32
  error
33
33
  }
34
34
  } = reactHookForm.useController({
35
- name,
36
35
  control,
37
- shouldUnregister,
36
+ name,
38
37
  rules: {
39
38
  max,
40
39
  min,
41
40
  required,
42
41
  validate
43
- }
42
+ },
43
+ shouldUnregister
44
44
  });
45
45
  const finalValue = react.useMemo(() => {
46
46
  if (options && field.value) {
@@ -55,7 +55,11 @@ const SliderField = ({
55
55
  }
56
56
  return field.value;
57
57
  }, [field.value, options]);
58
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { name: field.name, value: finalValue, onBlur: (event) => {
58
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Slider, { "aria-label": ariaLabel, error: getError({
59
+ label: label ?? ariaLabel ?? name,
60
+ max,
61
+ min
62
+ }, error), label, max, min, name: field.name, onBlur: (event) => {
59
63
  field.onBlur();
60
64
  onBlur?.(event);
61
65
  }, onChange: (newValue) => {
@@ -67,10 +71,6 @@ const SliderField = ({
67
71
  field.onChange(newValue);
68
72
  onChange?.(newValue);
69
73
  }
70
- }, max, min, error: getError({
71
- label: label ?? ariaLabel ?? name,
72
- max,
73
- min
74
- }, error), label, required, options, "aria-label": ariaLabel, ...props });
74
+ }, options, required, value: finalValue, ...props });
75
75
  };
76
76
  exports.SliderField = SliderField;
@@ -1,5 +1,5 @@
1
1
  import { Slider } from '@ultraviolet/ui';
2
- import { type ComponentProps, type ReactNode } from 'react';
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
5
  type SliderFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof Slider>, 'value' | 'onChange'> & {
@@ -30,15 +30,15 @@ const SliderField = ({
30
30
  error
31
31
  }
32
32
  } = useController({
33
- name,
34
33
  control,
35
- shouldUnregister,
34
+ name,
36
35
  rules: {
37
36
  max,
38
37
  min,
39
38
  required,
40
39
  validate
41
- }
40
+ },
41
+ shouldUnregister
42
42
  });
43
43
  const finalValue = useMemo(() => {
44
44
  if (options && field.value) {
@@ -53,7 +53,11 @@ const SliderField = ({
53
53
  }
54
54
  return field.value;
55
55
  }, [field.value, options]);
56
- return /* @__PURE__ */ jsx(Slider, { name: field.name, value: finalValue, onBlur: (event) => {
56
+ return /* @__PURE__ */ jsx(Slider, { "aria-label": ariaLabel, error: getError({
57
+ label: label ?? ariaLabel ?? name,
58
+ max,
59
+ min
60
+ }, error), label, max, min, name: field.name, onBlur: (event) => {
57
61
  field.onBlur();
58
62
  onBlur?.(event);
59
63
  }, onChange: (newValue) => {
@@ -65,11 +69,7 @@ const SliderField = ({
65
69
  field.onChange(newValue);
66
70
  onChange?.(newValue);
67
71
  }
68
- }, max, min, error: getError({
69
- label: label ?? ariaLabel ?? name,
70
- max,
71
- min
72
- }, error), label, required, options, "aria-label": ariaLabel, ...props });
72
+ }, options, required, value: finalValue, ...props });
73
73
  };
74
74
  export {
75
75
  SliderField
@@ -20,6 +20,6 @@ const Submit = ({
20
20
  isValid
21
21
  } = reactHookForm.useFormState();
22
22
  const isDisabled = disabled || isSubmitting || !isValid;
23
- return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { className, disabled: isDisabled, isLoading: isSubmitting, size, type: "submit", variant, sentiment, tooltip, fullWidth, onClick, children });
23
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { className, disabled: isDisabled, fullWidth, isLoading: isSubmitting, onClick, sentiment, size, tooltip, type: "submit", variant, children });
24
24
  };
25
25
  exports.Submit = Submit;
@@ -18,7 +18,7 @@ const Submit = ({
18
18
  isValid
19
19
  } = useFormState();
20
20
  const isDisabled = disabled || isSubmitting || !isValid;
21
- return /* @__PURE__ */ jsx(Button, { className, disabled: isDisabled, isLoading: isSubmitting, size, type: "submit", variant, sentiment, tooltip, fullWidth, onClick, children });
21
+ return /* @__PURE__ */ jsx(Button, { className, disabled: isDisabled, fullWidth, isLoading: isSubmitting, onClick, sentiment, size, tooltip, type: "submit", variant, children });
22
22
  };
23
23
  export {
24
24
  Submit
@@ -6,8 +6,6 @@ const ui = require("@ultraviolet/ui");
6
6
  const reactHookForm = require("react-hook-form");
7
7
  const SwitchButtonField = ({
8
8
  name,
9
- leftButton,
10
- rightButton,
11
9
  size,
12
10
  control,
13
11
  shouldUnregister,
@@ -21,16 +19,17 @@ const SwitchButtonField = ({
21
19
  const {
22
20
  field
23
21
  } = reactHookForm.useController({
22
+ control,
24
23
  name,
25
- shouldUnregister,
26
- control
24
+ shouldUnregister
27
25
  });
28
- return /* @__PURE__ */ jsxRuntime.jsx(ui.SwitchButton, { ...props, name, leftButton, rightButton, onChange: (event) => {
29
- field.onChange(event);
30
- onChange?.(event.target);
31
- }, value: field.value, tooltip, size, className, onFocus, onBlur: (event) => {
26
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.SwitchButton, { ...props, className, name, onBlur: (event) => {
32
27
  field.onBlur();
33
28
  onBlur?.(event);
34
- } });
29
+ }, onChange: (event) => {
30
+ field.onChange(event);
31
+ onChange?.(event.target);
32
+ }, onFocus, size, tooltip, value: field.value });
35
33
  };
34
+ SwitchButtonField.Option = ui.SwitchButton.Option;
36
35
  exports.SwitchButtonField = SwitchButtonField;
@@ -5,5 +5,14 @@ import type { BaseFieldProps } from '../../types';
5
5
  type SwitchButtonFieldProps<TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TFieldName> & Omit<ComponentProps<typeof SwitchButton>, 'value' | 'name' | 'onChange'> & Partial<Pick<ComponentProps<typeof SwitchButton>, 'onChange'>> & {
6
6
  name: FieldPath<TFieldValues>;
7
7
  };
8
- export declare const SwitchButtonField: <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, leftButton, rightButton, size, control, shouldUnregister, onBlur, onChange, onFocus, tooltip, className, ...props }: SwitchButtonFieldProps<TFieldValues, TFieldName>) => import("@emotion/react/jsx-runtime").JSX.Element;
9
- export {};
8
+ declare const SwitchButtonField: {
9
+ <TFieldValues extends FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, size, control, shouldUnregister, onBlur, onChange, onFocus, tooltip, className, ...props }: SwitchButtonFieldProps<TFieldValues, TFieldName>): import("@emotion/react/jsx-runtime").JSX.Element;
10
+ Option: ({ value, children, "data-testid": dataTestId, disabled, tooltip, }: {
11
+ value: string;
12
+ children: import("react").ReactNode;
13
+ "data-testid"?: string;
14
+ disabled?: boolean;
15
+ tooltip?: string;
16
+ }) => import("@emotion/react/jsx-runtime").JSX.Element;
17
+ };
18
+ export { SwitchButtonField };
@@ -4,8 +4,6 @@ import { SwitchButton } from "@ultraviolet/ui";
4
4
  import { useController } from "react-hook-form";
5
5
  const SwitchButtonField = ({
6
6
  name,
7
- leftButton,
8
- rightButton,
9
7
  size,
10
8
  control,
11
9
  shouldUnregister,
@@ -19,18 +17,19 @@ const SwitchButtonField = ({
19
17
  const {
20
18
  field
21
19
  } = useController({
20
+ control,
22
21
  name,
23
- shouldUnregister,
24
- control
22
+ shouldUnregister
25
23
  });
26
- return /* @__PURE__ */ jsx(SwitchButton, { ...props, name, leftButton, rightButton, onChange: (event) => {
27
- field.onChange(event);
28
- onChange?.(event.target);
29
- }, value: field.value, tooltip, size, className, onFocus, onBlur: (event) => {
24
+ return /* @__PURE__ */ jsx(SwitchButton, { ...props, className, name, onBlur: (event) => {
30
25
  field.onBlur();
31
26
  onBlur?.(event);
32
- } });
27
+ }, onChange: (event) => {
28
+ field.onChange(event);
29
+ onChange?.(event.target);
30
+ }, onFocus, size, tooltip, value: field.value });
33
31
  };
32
+ SwitchButtonField.Option = SwitchButton.Option;
34
33
  export {
35
34
  SwitchButtonField
36
35
  };