@ultraviolet/form 2.13.2 → 2.13.3

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 (73) hide show
  1. package/dist/components/CheckboxField/index.d.ts +10 -0
  2. package/dist/components/CheckboxField/index.js +40 -41
  3. package/dist/components/CheckboxGroupField/index.d.ts +32 -0
  4. package/dist/components/CheckboxGroupField/index.js +59 -53
  5. package/dist/components/DateField/index.d.ts +16 -0
  6. package/dist/components/DateField/index.js +53 -58
  7. package/dist/components/Form/defaultErrors.d.ts +2 -0
  8. package/dist/components/Form/defaultErrors.js +20 -19
  9. package/dist/components/Form/index.d.ts +69 -0
  10. package/dist/components/Form/index.js +52 -57
  11. package/dist/components/KeyValueField/index.d.ts +33 -0
  12. package/dist/components/KeyValueField/index.js +61 -60
  13. package/dist/components/NumberInputField/index.d.ts +13 -0
  14. package/dist/components/NumberInputField/index.js +39 -45
  15. package/dist/components/NumberInputFieldV2/index.d.ts +11 -0
  16. package/dist/components/NumberInputFieldV2/index.js +45 -51
  17. package/dist/components/RadioField/index.d.ts +12 -0
  18. package/dist/components/RadioField/index.js +36 -42
  19. package/dist/components/RadioGroupField/index.d.ts +28 -0
  20. package/dist/components/RadioGroupField/index.js +31 -32
  21. package/dist/components/SelectInputField/index.d.ts +82 -0
  22. package/dist/components/SelectInputField/index.js +90 -83
  23. package/dist/components/SelectInputFieldV2/index.d.ts +7 -0
  24. package/dist/components/SelectInputFieldV2/index.js +60 -60
  25. package/dist/components/SelectableCardField/index.d.ts +9 -0
  26. package/dist/components/SelectableCardField/index.js +49 -44
  27. package/dist/components/SelectableCardGroupField/index.d.ts +42 -0
  28. package/dist/components/SelectableCardGroupField/index.js +42 -41
  29. package/dist/components/Submit/index.d.ts +17 -0
  30. package/dist/components/Submit/index.js +27 -27
  31. package/dist/components/SubmitErrorAlert/index.d.ts +3 -0
  32. package/dist/components/SubmitErrorAlert/index.js +9 -17
  33. package/dist/components/TagInputField/index.d.ts +6 -0
  34. package/dist/components/TagInputField/index.js +35 -38
  35. package/dist/components/TextAreaField/index.d.ts +11 -0
  36. package/dist/components/TextAreaField/index.js +57 -56
  37. package/dist/components/TextInputField/index.d.ts +18 -0
  38. package/dist/components/TextInputField/index.js +82 -81
  39. package/dist/components/TextInputFieldV2/index.d.ts +12 -0
  40. package/dist/components/TextInputFieldV2/index.js +73 -72
  41. package/dist/components/TimeField/index.d.ts +9 -0
  42. package/dist/components/TimeField/index.js +51 -49
  43. package/dist/components/ToggleField/index.d.ts +10 -0
  44. package/dist/components/ToggleField/index.js +32 -31
  45. package/dist/components/ToggleGroupField/index.d.ts +26 -0
  46. package/dist/components/index.d.ts +22 -0
  47. package/dist/constants.d.ts +1 -0
  48. package/dist/constants.js +4 -3
  49. package/dist/hooks/index.d.ts +5 -0
  50. package/dist/hooks/useField.d.ts +34 -0
  51. package/dist/hooks/useField.js +7 -30
  52. package/dist/hooks/useFieldArray.d.ts +21 -0
  53. package/dist/hooks/useFieldArray.js +9 -22
  54. package/dist/hooks/useForm.d.ts +23 -0
  55. package/dist/hooks/useForm.js +8 -25
  56. package/dist/hooks/useFormState.d.ts +39 -0
  57. package/dist/hooks/useFormState.js +6 -23
  58. package/dist/hooks/useOnFieldChange.d.ts +3 -0
  59. package/dist/hooks/useOnFieldChange.js +10 -11
  60. package/dist/index.d.ts +7 -555
  61. package/dist/index.js +66 -29
  62. package/dist/mocks/index.d.ts +1 -0
  63. package/dist/mocks/mockErrors.d.ts +3 -0
  64. package/dist/providers/ErrorContext/index.d.ts +14 -0
  65. package/dist/providers/ErrorContext/index.js +30 -29
  66. package/dist/providers/index.d.ts +1 -0
  67. package/dist/types.d.ts +32 -0
  68. package/dist/validators/index.d.ts +5 -0
  69. package/dist/validators/maxDate.d.ts +1 -0
  70. package/dist/validators/maxDate.js +4 -3
  71. package/dist/validators/minDate.d.ts +1 -0
  72. package/dist/validators/minDate.js +4 -3
  73. package/package.json +11 -5
@@ -0,0 +1,18 @@
1
+ import { TextInput } from '@ultraviolet/ui';
2
+ import type { ComponentProps, Ref } from 'react';
3
+ import type { FieldPath, FieldValues, Path, PathValue } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof TextInput>, 'autoCapitalize' | 'autoComplete' | 'autoCorrect' | 'autoFocus' | 'autoSave' | 'cols' | 'disabled' | 'fillAvailable' | 'generated' | 'id' | 'multiline' | 'notice' | 'onBlur' | 'onFocus' | 'onKeyDown' | 'onKeyUp' | 'placeholder' | 'random' | 'readOnly' | 'resizable' | 'rows' | 'type' | 'noTopLabel' | 'unit' | 'valid' | 'size' | 'maxLength' | 'minLength' | 'min' | 'max' | 'data-testid'>> & {
6
+ className?: string;
7
+ regex?: (RegExp | RegExp[])[];
8
+ format?: (value: unknown) => PathValue<TFieldValues, Path<TFieldValues>>;
9
+ parse?: (value: string) => PathValue<TFieldValues, Path<TFieldValues>>;
10
+ customError?: string;
11
+ formatOnBlur?: boolean;
12
+ innerRef?: Ref<HTMLInputElement>;
13
+ };
14
+ /**
15
+ * @deprecated This component is deprecated, please use `TextInputFieldV2` instead
16
+ */
17
+ export declare const TextInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ autoCapitalize, autoComplete, autoCorrect, autoFocus, autoSave, className, cols, disabled, fillAvailable, generated, id, label, multiline, name, noTopLabel, notice, onChange, onFocus, onKeyDown, onKeyUp, onBlur, placeholder, random, readOnly, required, resizable, rows, type, unit, size, rules, valid, parse, format, formatOnBlur, regex: regexes, min, max, minLength, maxLength, validate, defaultValue, customError, innerRef, shouldUnregister, "data-testid": dataTestId, }: TextInputFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -1,11 +1,7 @@
1
- import { TextInput } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { jsx } from '@emotion/react/jsx-runtime';
4
- import { useErrors } from '../../providers/ErrorContext/index.js';
5
-
6
- /**
7
- * @deprecated This component is deprecated, please use `TextInputFieldV2` instead
8
- */
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { TextInput } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
4
+ import { useErrors } from "../../providers/ErrorContext/index.js";
9
5
  const TextInputField = ({
10
6
  autoCapitalize,
11
7
  autoComplete,
@@ -18,7 +14,7 @@ const TextInputField = ({
18
14
  fillAvailable,
19
15
  generated,
20
16
  id,
21
- label = '',
17
+ label = "",
22
18
  multiline,
23
19
  name,
24
20
  noTopLabel,
@@ -52,16 +48,12 @@ const TextInputField = ({
52
48
  customError,
53
49
  innerRef,
54
50
  shouldUnregister = false,
55
- 'data-testid': dataTestId
51
+ "data-testid": dataTestId
56
52
  }) => {
57
- const {
58
- getError
59
- } = useErrors();
53
+ const { getError } = useErrors();
60
54
  const {
61
55
  field,
62
- fieldState: {
63
- error
64
- }
56
+ fieldState: { error }
65
57
  } = useController({
66
58
  name,
67
59
  defaultValue,
@@ -69,9 +61,11 @@ const TextInputField = ({
69
61
  rules: {
70
62
  required,
71
63
  validate: {
72
- ...(regexes ? {
73
- pattern: value => regexes.every(regex => value === undefined || value === '' || (Array.isArray(regex) ? regex.some(regexOr => regexOr.test(value)) : regex.test(value)))
74
- } : {}),
64
+ ...regexes ? {
65
+ pattern: (value) => regexes.every(
66
+ (regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value))
67
+ )
68
+ } : {},
75
69
  ...validate
76
70
  },
77
71
  minLength,
@@ -87,67 +81,74 @@ const TextInputField = ({
87
81
  }
88
82
  return field.value;
89
83
  };
90
- return jsx(TextInput, {
91
- name: field.name,
92
- autoCapitalize: autoCapitalize,
93
- autoComplete: autoComplete,
94
- autoCorrect: autoCorrect,
95
- autoFocus: autoFocus,
96
- autoSave: autoSave,
97
- className: className,
98
- cols: cols,
99
- disabled: disabled,
100
- error: customError ?? getError({
101
- regex: regexes,
102
- minLength,
103
- maxLength,
84
+ return /* @__PURE__ */ jsx(
85
+ TextInput,
86
+ {
87
+ name: field.name,
88
+ autoCapitalize,
89
+ autoComplete,
90
+ autoCorrect,
91
+ autoFocus,
92
+ autoSave,
93
+ className,
94
+ cols,
95
+ disabled,
96
+ error: customError ?? getError(
97
+ {
98
+ regex: regexes,
99
+ minLength,
100
+ maxLength,
101
+ label,
102
+ min,
103
+ max,
104
+ value: field.value
105
+ },
106
+ error
107
+ ),
108
+ fillAvailable,
109
+ generated,
110
+ id,
104
111
  label,
105
- min,
106
- max,
107
- value: field.value
108
- }, error),
109
- fillAvailable: fillAvailable,
110
- generated: generated,
111
- id: id,
112
- label: label,
113
- multiline: multiline,
114
- notice: notice,
115
- required: required,
116
- onBlur: event => {
117
- field.onBlur();
118
- onBlur?.(event);
119
- if (formatOnBlur && format) {
120
- field.onChange(format(field.value));
121
- }
122
- },
123
- onChange: event => {
124
- if (parse) {
125
- field.onChange(parse(event));
126
- onChange?.(parse(event));
127
- } else {
128
- field.onChange(event);
129
- onChange?.(event);
130
- }
131
- },
132
- onFocus: event => {
133
- onFocus?.(event);
134
- },
135
- onKeyUp: onKeyUp,
136
- onKeyDown: onKeyDown,
137
- placeholder: placeholder,
138
- random: random,
139
- readOnly: readOnly,
140
- resizable: resizable,
141
- rows: rows,
142
- type: type,
143
- noTopLabel: noTopLabel,
144
- unit: unit,
145
- valid: valid,
146
- size: size,
147
- value: transformedValue(),
148
- ref: innerRef,
149
- "data-testid": dataTestId
150
- });
112
+ multiline,
113
+ notice,
114
+ required,
115
+ onBlur: (event) => {
116
+ field.onBlur();
117
+ onBlur?.(event);
118
+ if (formatOnBlur && format) {
119
+ field.onChange(format(field.value));
120
+ }
121
+ },
122
+ onChange: (event) => {
123
+ if (parse) {
124
+ field.onChange(parse(event));
125
+ onChange?.(parse(event));
126
+ } else {
127
+ field.onChange(event);
128
+ onChange?.(event);
129
+ }
130
+ },
131
+ onFocus: (event) => {
132
+ onFocus?.(event);
133
+ },
134
+ onKeyUp,
135
+ onKeyDown,
136
+ placeholder,
137
+ random,
138
+ readOnly,
139
+ resizable,
140
+ rows,
141
+ type,
142
+ noTopLabel,
143
+ unit,
144
+ valid,
145
+ size,
146
+ value: transformedValue(),
147
+ ref: innerRef,
148
+ "data-testid": dataTestId
149
+ }
150
+ );
151
+ };
152
+ export {
153
+ TextInputField
151
154
  };
152
-
153
- export { TextInputField };
@@ -0,0 +1,12 @@
1
+ import { TextInputV2 } from '@ultraviolet/ui';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type TextInputFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TextInputV2>, 'value' | 'error' | 'name' | 'onChange'> & {
6
+ regex?: (RegExp | RegExp[])[];
7
+ };
8
+ /**
9
+ * This component offers a form field based on Ultraviolet UI TextInputV2 component
10
+ */
11
+ export declare const TextInputField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ validate, regex: regexes, id, className, tabIndex, onChange, placeholder, disabled, readOnly, success, helper, tooltip, label, autoFocus, required, "data-testid": dataTestId, name, onFocus, onBlur, clearable, labelDescription, type, prefix, suffix, size, loading, onRandomize, minLength, maxLength, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, autoComplete, }: TextInputFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -1,11 +1,7 @@
1
- import { TextInputV2 } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { jsx } from '@emotion/react/jsx-runtime';
4
- import { useErrors } from '../../providers/ErrorContext/index.js';
5
-
6
- /**
7
- * This component offers a form field based on Ultraviolet UI TextInputV2 component
8
- */
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { TextInputV2 } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
4
+ import { useErrors } from "../../providers/ErrorContext/index.js";
9
5
  const TextInputField = ({
10
6
  validate,
11
7
  regex: regexes,
@@ -22,94 +18,99 @@ const TextInputField = ({
22
18
  label,
23
19
  autoFocus,
24
20
  required = false,
25
- 'data-testid': dataTestId,
21
+ "data-testid": dataTestId,
26
22
  name,
27
23
  onFocus,
28
24
  onBlur,
29
25
  clearable = false,
30
26
  labelDescription,
31
- type = 'text',
27
+ type = "text",
32
28
  prefix,
33
29
  suffix,
34
- size = 'large',
30
+ size = "large",
35
31
  loading,
36
32
  onRandomize,
37
33
  minLength,
38
34
  maxLength,
39
- 'aria-labelledby': ariaLabelledBy,
40
- 'aria-label': ariaLabel,
35
+ "aria-labelledby": ariaLabelledBy,
36
+ "aria-label": ariaLabel,
41
37
  autoComplete
42
38
  }) => {
43
- const {
44
- getError
45
- } = useErrors();
39
+ const { getError } = useErrors();
46
40
  const {
47
41
  field,
48
- fieldState: {
49
- error
50
- }
42
+ fieldState: { error }
51
43
  } = useController({
52
44
  name,
53
45
  rules: {
54
46
  required,
55
47
  validate: {
56
- ...(regexes ? {
57
- pattern: value => regexes.every(regex => value === undefined || value === '' || (Array.isArray(regex) ? regex.some(regexOr => regexOr.test(value)) : regex.test(value)))
58
- } : {}),
48
+ ...regexes ? {
49
+ pattern: (value) => regexes.every(
50
+ (regex) => value === void 0 || value === "" || (Array.isArray(regex) ? regex.some((regexOr) => regexOr.test(value)) : regex.test(value))
51
+ )
52
+ } : {},
59
53
  ...validate
60
54
  },
61
55
  minLength,
62
56
  maxLength
63
57
  }
64
58
  });
65
- return jsx(TextInputV2, {
66
- autoFocus: autoFocus,
67
- className: className,
68
- clearable: clearable,
69
- "data-testid": dataTestId,
70
- disabled: disabled,
71
- error: getError({
72
- regex: regexes,
73
- // minLength,
74
- // maxLength,
75
- label: label ?? '',
76
- value: field.value
77
- }, error),
78
- helper: helper,
79
- label: label,
80
- loading: loading,
81
- labelDescription: labelDescription,
82
- minLength: minLength,
83
- maxLength: maxLength,
84
- name: name,
85
- onBlur: event => {
86
- onBlur?.(event);
87
- field.onBlur();
88
- },
89
- onChange: event => {
90
- field.onChange(event);
91
- onChange?.(event);
92
- },
93
- onFocus: event => {
94
- onFocus?.(event);
95
- },
96
- placeholder: placeholder,
97
- readOnly: readOnly,
98
- required: required,
99
- success: success,
100
- tabIndex: tabIndex,
101
- tooltip: tooltip,
102
- type: type,
103
- value: field.value,
104
- id: id,
105
- prefix: prefix,
106
- suffix: suffix,
107
- size: size,
108
- onRandomize: onRandomize,
109
- "aria-label": ariaLabel,
110
- "aria-labelledby": ariaLabelledBy,
111
- autoComplete: autoComplete
112
- });
59
+ return /* @__PURE__ */ jsx(
60
+ TextInputV2,
61
+ {
62
+ autoFocus,
63
+ className,
64
+ clearable,
65
+ "data-testid": dataTestId,
66
+ disabled,
67
+ error: getError(
68
+ {
69
+ regex: regexes,
70
+ // minLength,
71
+ // maxLength,
72
+ label: label ?? "",
73
+ value: field.value
74
+ },
75
+ error
76
+ ),
77
+ helper,
78
+ label,
79
+ loading,
80
+ labelDescription,
81
+ minLength,
82
+ maxLength,
83
+ name,
84
+ onBlur: (event) => {
85
+ onBlur?.(event);
86
+ field.onBlur();
87
+ },
88
+ onChange: (event) => {
89
+ field.onChange(event);
90
+ onChange?.(event);
91
+ },
92
+ onFocus: (event) => {
93
+ onFocus?.(event);
94
+ },
95
+ placeholder,
96
+ readOnly,
97
+ required,
98
+ success,
99
+ tabIndex,
100
+ tooltip,
101
+ type,
102
+ value: field.value,
103
+ id,
104
+ prefix,
105
+ suffix,
106
+ size,
107
+ onRandomize,
108
+ "aria-label": ariaLabel,
109
+ "aria-labelledby": ariaLabelledBy,
110
+ autoComplete
111
+ }
112
+ );
113
+ };
114
+ export {
115
+ TextInputField
113
116
  };
114
-
115
- export { TextInputField };
@@ -0,0 +1,9 @@
1
+ import { TimeInput } from '@ultraviolet/ui';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type TimeFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Omit<ComponentProps<typeof TimeInput>, 'onChange'> & {
6
+ name: string;
7
+ };
8
+ export declare const TimeField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ required, name, schedule, placeholder, disabled, readOnly, onBlur, onFocus, onChange, isLoading, isClearable, inputId, id, animation, animationDuration, animationOnChange, className, isSearchable, rules, options, "data-testid": dataTestId, shouldUnregister, noTopLabel, }: TimeFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -1,9 +1,8 @@
1
- import { TimeInput } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { jsx } from '@emotion/react/jsx-runtime';
4
-
5
- const parseTime = date => {
6
- const timeStr = date && typeof date !== 'string' ? date.toLocaleTimeString().slice(0, -3) : '';
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { TimeInput } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
4
+ const parseTime = (date) => {
5
+ const timeStr = date && typeof date !== "string" ? date.toLocaleTimeString().slice(0, -3) : "";
7
6
  return {
8
7
  label: timeStr,
9
8
  value: timeStr
@@ -30,15 +29,13 @@ const TimeField = ({
30
29
  isSearchable,
31
30
  rules,
32
31
  options,
33
- 'data-testid': dataTestId,
32
+ "data-testid": dataTestId,
34
33
  shouldUnregister = false,
35
34
  noTopLabel
36
35
  }) => {
37
36
  const {
38
37
  field,
39
- fieldState: {
40
- error
41
- }
38
+ fieldState: { error }
42
39
  } = useController({
43
40
  name,
44
41
  shouldUnregister,
@@ -47,43 +44,48 @@ const TimeField = ({
47
44
  ...rules
48
45
  }
49
46
  });
50
- return jsx(TimeInput, {
51
- name: field.name,
52
- placeholder: placeholder,
53
- schedule: schedule,
54
- required: required,
55
- value: parseTime(field.value),
56
- onChange: val => {
57
- if (!val) return;
58
- onChange?.(val);
59
- const [hours, minutes] = val.value.split(':');
60
- const date = field.value ? new Date(field.value) : new Date();
61
- date.setHours(Number(hours), Number(minutes), 0);
62
- field.onChange(date);
63
- },
64
- onBlur: event => {
65
- field.onBlur();
66
- onBlur?.(event);
67
- },
68
- onFocus: event => {
69
- onFocus?.(event);
70
- },
71
- error: error?.message,
72
- disabled: disabled,
73
- readOnly: readOnly,
74
- animation: animation,
75
- animationDuration: animationDuration,
76
- animationOnChange: animationOnChange,
77
- className: className,
78
- isLoading: isLoading,
79
- isClearable: isClearable,
80
- isSearchable: isSearchable,
81
- inputId: inputId,
82
- id: id,
83
- options: options,
84
- "data-testid": dataTestId,
85
- noTopLabel: noTopLabel
86
- });
47
+ return /* @__PURE__ */ jsx(
48
+ TimeInput,
49
+ {
50
+ name: field.name,
51
+ placeholder,
52
+ schedule,
53
+ required,
54
+ value: parseTime(field.value),
55
+ onChange: (val) => {
56
+ if (!val)
57
+ return;
58
+ onChange?.(val);
59
+ const [hours, minutes] = val.value.split(":");
60
+ const date = field.value ? new Date(field.value) : /* @__PURE__ */ new Date();
61
+ date.setHours(Number(hours), Number(minutes), 0);
62
+ field.onChange(date);
63
+ },
64
+ onBlur: (event) => {
65
+ field.onBlur();
66
+ onBlur?.(event);
67
+ },
68
+ onFocus: (event) => {
69
+ onFocus?.(event);
70
+ },
71
+ error: error?.message,
72
+ disabled,
73
+ readOnly,
74
+ animation,
75
+ animationDuration,
76
+ animationOnChange,
77
+ className,
78
+ isLoading,
79
+ isClearable,
80
+ isSearchable,
81
+ inputId,
82
+ id,
83
+ options,
84
+ "data-testid": dataTestId,
85
+ noTopLabel
86
+ }
87
+ );
88
+ };
89
+ export {
90
+ TimeField
87
91
  };
88
-
89
- export { TimeField };
@@ -0,0 +1,10 @@
1
+ import { Toggle } from '@ultraviolet/ui';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type ToggleFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = Omit<BaseFieldProps<TFieldValues, TName>, 'label'> & Pick<ComponentProps<typeof Toggle>, 'disabled' | 'label' | 'onChange' | 'size' | 'tooltip' | 'labelPosition' | 'className' | 'data-testid'> & {
6
+ parse?: (value: boolean) => any;
7
+ format?: (value: any) => boolean;
8
+ };
9
+ export declare const ToggleField: <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ className, disabled, label, name, onChange, required, size, tooltip, rules, labelPosition, parse, format, "data-testid": dataTestId, shouldUnregister, }: ToggleFieldProps<TFieldValues, TName>) => import("@emotion/react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -1,7 +1,6 @@
1
- import { Toggle } from '@ultraviolet/ui';
2
- import { useController } from 'react-hook-form';
3
- import { jsx } from '@emotion/react/jsx-runtime';
4
-
1
+ import { jsx } from "@emotion/react/jsx-runtime";
2
+ import { Toggle } from "@ultraviolet/ui";
3
+ import { useController } from "react-hook-form";
5
4
  const ToggleField = ({
6
5
  className,
7
6
  disabled,
@@ -15,12 +14,10 @@ const ToggleField = ({
15
14
  labelPosition,
16
15
  parse,
17
16
  format,
18
- 'data-testid': dataTestId,
17
+ "data-testid": dataTestId,
19
18
  shouldUnregister = false
20
19
  }) => {
21
- const {
22
- field
23
- } = useController({
20
+ const { field } = useController({
24
21
  name,
25
22
  shouldUnregister,
26
23
  rules: {
@@ -34,27 +31,31 @@ const ToggleField = ({
34
31
  }
35
32
  return field.value;
36
33
  };
37
- return jsx(Toggle, {
38
- name: field.name,
39
- ref: field.ref,
40
- checked: transformedValue(),
41
- tooltip: tooltip,
42
- onChange: event => {
43
- if (parse) {
44
- field.onChange(parse(event.target.checked));
45
- } else {
46
- field.onChange(event);
47
- }
48
- onChange?.(event);
49
- },
50
- label: label,
51
- size: size,
52
- disabled: disabled,
53
- labelPosition: labelPosition,
54
- className: className,
55
- required: required,
56
- "data-testid": dataTestId
57
- });
34
+ return /* @__PURE__ */ jsx(
35
+ Toggle,
36
+ {
37
+ name: field.name,
38
+ ref: field.ref,
39
+ checked: transformedValue(),
40
+ tooltip,
41
+ onChange: (event) => {
42
+ if (parse) {
43
+ field.onChange(parse(event.target.checked));
44
+ } else {
45
+ field.onChange(event);
46
+ }
47
+ onChange?.(event);
48
+ },
49
+ label,
50
+ size,
51
+ disabled,
52
+ labelPosition,
53
+ className,
54
+ required,
55
+ "data-testid": dataTestId
56
+ }
57
+ );
58
+ };
59
+ export {
60
+ ToggleField
58
61
  };
59
-
60
- export { ToggleField };
@@ -0,0 +1,26 @@
1
+ import { ToggleGroup } from '@ultraviolet/ui';
2
+ import type { ComponentProps } from 'react';
3
+ import type { FieldPath, FieldValues } from 'react-hook-form';
4
+ import type { BaseFieldProps } from '../../types';
5
+ type ToggleGroupFieldProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues>> = BaseFieldProps<TFieldValues, TName> & Partial<Pick<ComponentProps<typeof ToggleGroup>, 'className' | 'helper' | 'direction' | 'children' | 'error' | 'legend'>> & Required<Pick<ComponentProps<typeof ToggleGroup>, 'legend' | 'name'>>;
6
+ export declare const ToggleGroupField: {
7
+ <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ legend, className, helper, direction, children, onChange, label, error: customError, name, required, shouldUnregister, }: ToggleGroupFieldProps<TFieldValues, TName>): import("@emotion/react/jsx-runtime").JSX.Element;
8
+ Toggle: ({ disabled, name, value, label, helper, className, "data-testid": dataTestId, }: Omit<{
9
+ id?: string | undefined;
10
+ checked?: boolean | undefined;
11
+ name: string;
12
+ tooltip?: string | undefined;
13
+ onChange?: import("react").ChangeEventHandler<HTMLInputElement> | undefined;
14
+ size?: "small" | "large" | undefined;
15
+ labelPosition?: "left" | "right" | undefined;
16
+ label?: import("react").ReactNode;
17
+ helper?: import("react").ReactNode;
18
+ disabled?: boolean | undefined;
19
+ className?: string | undefined;
20
+ required?: boolean | undefined;
21
+ 'data-testid'?: string | undefined;
22
+ } & Pick<import("react").InputHTMLAttributes<HTMLInputElement>, "value"> & import("react").RefAttributes<HTMLInputElement>, "required" | "onChange" | "checked"> & {
23
+ value: string;
24
+ }) => import("@emotion/react/jsx-runtime").JSX.Element;
25
+ };
26
+ export {};