@fuf-stack/uniform 1.28.0 → 2.0.0-next.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 (148) hide show
  1. package/README.md +6 -35
  2. package/dist/Checkboxes/index.d.mts +192 -263
  3. package/dist/Checkboxes/index.d.mts.map +1 -1
  4. package/dist/Checkboxes/index.mjs +294 -90
  5. package/dist/Checkboxes/index.mjs.map +1 -1
  6. package/dist/DatePicker/index.d.mts +1278 -496
  7. package/dist/DatePicker/index.d.mts.map +1 -1
  8. package/dist/DatePicker/index.mjs +403 -83
  9. package/dist/DatePicker/index.mjs.map +1 -1
  10. package/dist/FieldArray/index.d.mts +105 -98
  11. package/dist/FieldArray/index.d.mts.map +1 -1
  12. package/dist/FieldArray/index.mjs +344 -195
  13. package/dist/FieldArray/index.mjs.map +1 -1
  14. package/dist/FieldCard/index.d.mts +37 -35
  15. package/dist/FieldCard/index.d.mts.map +1 -1
  16. package/dist/FieldCard/index.mjs +187 -128
  17. package/dist/FieldCard/index.mjs.map +1 -1
  18. package/dist/{FieldCopyTestIdButton-9xTF-DBW.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +4 -2
  19. package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
  20. package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
  21. package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
  22. package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
  23. package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
  24. package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
  25. package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
  26. package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
  27. package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
  28. package/dist/Form/index.d.mts +12 -12
  29. package/dist/Form/index.d.mts.map +1 -1
  30. package/dist/Form/index.mjs +9 -7
  31. package/dist/Form/index.mjs.map +1 -1
  32. package/dist/{FormContext-CB7Glm02.mjs → FormContext-CHctWFAP.mjs} +51 -8
  33. package/dist/FormContext-CHctWFAP.mjs.map +1 -0
  34. package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
  35. package/dist/Grid/index.mjs +1 -2
  36. package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
  37. package/dist/Grid-DfcZeuib.mjs.map +1 -0
  38. package/dist/Input/index.d.mts +638 -394
  39. package/dist/Input/index.d.mts.map +1 -1
  40. package/dist/Input/index.mjs +414 -165
  41. package/dist/Input/index.mjs.map +1 -1
  42. package/dist/RadioBoxes/index.d.mts +1588 -125
  43. package/dist/RadioBoxes/index.d.mts.map +1 -1
  44. package/dist/RadioBoxes/index.mjs +159 -114
  45. package/dist/RadioBoxes/index.mjs.map +1 -1
  46. package/dist/RadioTabs/index.d.mts +300 -81
  47. package/dist/RadioTabs/index.d.mts.map +1 -1
  48. package/dist/RadioTabs/index.mjs +277 -86
  49. package/dist/RadioTabs/index.mjs.map +1 -1
  50. package/dist/Radios/index.d.mts +1354 -109
  51. package/dist/Radios/index.d.mts.map +1 -1
  52. package/dist/Radios/index.mjs +105 -54
  53. package/dist/Radios/index.mjs.map +1 -1
  54. package/dist/Select/index.d.mts +554 -3009
  55. package/dist/Select/index.d.mts.map +1 -1
  56. package/dist/Select/index.mjs +319 -177
  57. package/dist/Select/index.mjs.map +1 -1
  58. package/dist/Slider/index.d.mts +416 -1328
  59. package/dist/Slider/index.d.mts.map +1 -1
  60. package/dist/Slider/index.mjs +276 -94
  61. package/dist/Slider/index.mjs.map +1 -1
  62. package/dist/SubmitButton/index.d.mts.map +1 -1
  63. package/dist/SubmitButton/index.mjs +4 -1
  64. package/dist/SubmitButton/index.mjs.map +1 -1
  65. package/dist/Switch/index.d.mts +2 -1248
  66. package/dist/Switch/index.mjs +167 -68
  67. package/dist/Switch/index.mjs.map +1 -1
  68. package/dist/Switch-CvPO8IF9.d.mts +601 -0
  69. package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
  70. package/dist/SwitchBox/index.d.mts +135 -39
  71. package/dist/SwitchBox/index.d.mts.map +1 -1
  72. package/dist/SwitchBox/index.mjs +142 -87
  73. package/dist/SwitchBox/index.mjs.map +1 -1
  74. package/dist/TextArea/index.d.mts +295 -411
  75. package/dist/TextArea/index.d.mts.map +1 -1
  76. package/dist/TextArea/index.mjs +200 -48
  77. package/dist/TextArea/index.mjs.map +1 -1
  78. package/dist/Time/index.d.mts +1170 -601
  79. package/dist/Time/index.d.mts.map +1 -1
  80. package/dist/Time/index.mjs +162 -74
  81. package/dist/Time/index.mjs.map +1 -1
  82. package/dist/helpers/index.d.mts +1 -1
  83. package/dist/helpers/index.mjs +1 -1
  84. package/dist/helpers/index.mjs.map +1 -1
  85. package/dist/hooks/useClientValidation/index.mjs +1 -1
  86. package/dist/hooks/useController/index.d.mts +31 -3
  87. package/dist/hooks/useController/index.d.mts.map +1 -0
  88. package/dist/hooks/useController/index.mjs +1 -2
  89. package/dist/hooks/useFormContext/index.d.mts +65 -3
  90. package/dist/hooks/useFormContext/index.d.mts.map +1 -0
  91. package/dist/hooks/useFormContext/index.mjs +1 -2
  92. package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
  93. package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
  94. package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
  95. package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
  96. package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
  97. package/dist/hooks/useInputValueTransform/index.mjs +1 -2
  98. package/dist/hooks/useWatchFormReset/index.mjs +1 -1
  99. package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
  100. package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
  101. package/dist/hooks/useWatchUserChange/index.mjs +1 -1
  102. package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
  103. package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
  104. package/dist/index-BS8IoBOn.d.mts.map +1 -0
  105. package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
  106. package/dist/partials/FieldValidationError/index.d.mts +637 -3
  107. package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
  108. package/dist/partials/FieldValidationError/index.mjs +1 -2
  109. package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
  110. package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
  111. package/dist/switchVariants-BaQw2DA7.mjs +67 -0
  112. package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
  113. package/dist/timeVariants-B9HDfNYt.mjs +58 -0
  114. package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
  115. package/dist/{useController-BBSbeKbn.mjs → useController-BCFeZbBZ.mjs} +2 -2
  116. package/dist/{useController-BBSbeKbn.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
  117. package/dist/{useFormContext-DNb_B8LQ.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
  118. package/dist/{useFormContext-DNb_B8LQ.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
  119. package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
  120. package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
  121. package/package.json +17 -29
  122. package/dist/FieldCopyTestIdButton-9xTF-DBW.mjs.map +0 -1
  123. package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
  124. package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
  125. package/dist/FormContext-CB7Glm02.mjs.map +0 -1
  126. package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
  127. package/dist/Switch/index.d.mts.map +0 -1
  128. package/dist/hooks/useInput/index.d.mts +0 -2
  129. package/dist/hooks/useInput/index.mjs +0 -7
  130. package/dist/hooks/useInput/index.mjs.map +0 -1
  131. package/dist/hooks/useUniformField/index.d.mts +0 -100
  132. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  133. package/dist/hooks/useUniformField/index.mjs +0 -139
  134. package/dist/hooks/useUniformField/index.mjs.map +0 -1
  135. package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
  136. package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
  137. package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
  138. package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
  139. package/dist/index-CAdGtKE_.d.mts +0 -1
  140. package/dist/index-CaxrMD1A.d.mts +0 -1
  141. package/dist/index-CwJo1b4Z.d.mts +0 -1
  142. package/dist/useController-DcK2YHbw.d.mts +0 -32
  143. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  144. package/dist/useFormContext-BegmYvGA.d.mts +0 -66
  145. package/dist/useFormContext-BegmYvGA.d.mts.map +0 -1
  146. package/dist/useInput-C0aJaAGe.mjs +0 -2
  147. package/dist/useInput-ClpHDPdr.d.mts +0 -2
  148. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1,81 +1,180 @@
1
- import { useUniformField } from "../hooks/useUniformField/index.mjs";
2
- import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
3
- import { useRef } from "react";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- import { VisuallyHidden } from "@react-aria/visually-hidden";
6
- import { Switch } from "@heroui/switch";
7
- //#region src/Switch/Switch.tsx
8
- const switchVariants = tv({ slots: {
9
- base: "",
10
- endContent: "",
11
- errorMessage: "ml-1 mt-1",
12
- label: "text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]",
13
- outerWrapper: "place-content-center",
14
- startContent: "",
15
- thumb: "",
16
- thumbIcon: "",
17
- wrapper: ""
18
- } });
1
+ import { n as useUniformField, t as FieldLabel } from "../FieldLabel-DKzqkuY1.mjs";
2
+ import { n as getFieldControlProps, t as FieldDescription } from "../FieldDescription-C4l0HKGL.mjs";
3
+ import { t as switchVariants } from "../switchVariants-BaQw2DA7.mjs";
4
+ import { cloneElement, isValidElement } from "react";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
7
+ import { useFocusRing } from "react-aria/useFocusRing";
8
+ import { useObjectRef } from "react-aria/useObjectRef";
9
+ import { useHover } from "react-aria/useHover";
10
+ import { mergeProps } from "react-aria/mergeProps";
11
+ import { useSwitch } from "react-aria/useSwitch";
12
+ import { VisuallyHidden } from "react-aria/VisuallyHidden";
13
+ import { useToggleState } from "react-stately/useToggleState";
14
+ //#region src/Switch/subcomponents/SwitchIcon.tsx
15
+ /** Applies switch icon dimensions and slot styling to an element */
16
+ const SwitchIcon = ({ children, className }) => {
17
+ return /* @__PURE__ */ jsx(Fragment, { children: isValidElement(children) ? cloneElement(children, {
18
+ width: "1em",
19
+ height: "1em",
20
+ className
21
+ }) : children });
22
+ };
23
+ //#endregion
24
+ //#region src/Switch/subcomponents/SwitchThumb.tsx
25
+ /** Thumb icon content, including the consumer's selection-aware render callback */
26
+ const SwitchThumb = ({ className, selected, thumbIcon = void 0 }) => {
27
+ return /* @__PURE__ */ jsx(Fragment, { children: typeof thumbIcon === "function" ? thumbIcon({
28
+ width: "1em",
29
+ height: "1em",
30
+ className,
31
+ "data-checked": String(selected),
32
+ isSelected: selected
33
+ }) : /* @__PURE__ */ jsx(SwitchIcon, {
34
+ className,
35
+ children: thumbIcon
36
+ }) });
37
+ };
38
+ //#endregion
39
+ //#region src/Switch/subcomponents/SwitchTrack.tsx
40
+ /** Visual switch track, thumb and optional leading and trailing icons */
41
+ const SwitchTrack = ({ className: classNames, endContent, selected, startContent, thumbIcon }) => {
42
+ return /* @__PURE__ */ jsxs("span", {
43
+ "aria-hidden": true,
44
+ className: classNames.wrapper,
45
+ "data-slot": "wrapper",
46
+ children: [
47
+ startContent ? /* @__PURE__ */ jsx(SwitchIcon, {
48
+ className: classNames.startContent,
49
+ children: startContent
50
+ }) : null,
51
+ /* @__PURE__ */ jsx("span", {
52
+ className: classNames.thumb,
53
+ "data-slot": "thumb",
54
+ children: /* @__PURE__ */ jsx(SwitchThumb, {
55
+ className: classNames.thumbIcon,
56
+ selected,
57
+ thumbIcon
58
+ })
59
+ }),
60
+ endContent ? /* @__PURE__ */ jsx(SwitchIcon, {
61
+ className: classNames.endContent,
62
+ children: endContent
63
+ }) : null
64
+ ]
65
+ });
66
+ };
67
+ //#endregion
68
+ //#region src/Switch/subcomponents/SwitchControl.tsx
19
69
  /**
20
- * Switch component based on [HeroUI Switch](https://www.heroui.com//docs/components/switch)
70
+ * Switch presentation with native input, focus and thumb content
71
+ *
72
+ * @see https://react-aria.adobe.com/useSwitch
21
73
  */
22
- const Switch$1 = ({ className = void 0, endContent = void 0, name, size = void 0, startContent = void 0, thumbIcon = void 0, ...uniformFieldProps }) => {
23
- const { ariaLabel, defaultValue, disabled, errorMessage, field, getErrorMessageProps, getHelperWrapperProps, invalid, label, onBlur, onChange, ref, required, testId } = useUniformField({
74
+ const SwitchControl = ({ field, className, size, thumbIcon, endContent, startContent }) => {
75
+ const { description, disabled, errorMessage, ids, ref: inputRef, invalid, label, name, onBlur, onChange: onValueChange, required, testId, value } = field;
76
+ const controlProps = getFieldControlProps(field);
77
+ const styling = useStyling();
78
+ const controlRef = useObjectRef(inputRef);
79
+ const state = useToggleState({
80
+ isSelected: !!value,
81
+ onChange: onValueChange
82
+ });
83
+ const { inputProps, labelProps, isPressed } = useSwitch({
84
+ ...controlProps,
85
+ children: label,
86
+ isDisabled: disabled,
87
+ isInvalid: invalid,
88
+ isRequired: required,
24
89
  name,
25
- ...uniformFieldProps
90
+ onBlur,
91
+ validationBehavior: "aria"
92
+ }, state, controlRef);
93
+ const { focusProps, isFocused, isFocusVisible } = useFocusRing();
94
+ const { hoverProps, isHovered } = useHover({ isDisabled: disabled });
95
+ const variants = styling.resolve(switchVariants, {
96
+ size,
97
+ disabled
26
98
  });
27
- const visualSwitchRef = useRef(null);
28
- const variants = switchVariants();
29
- const classNames = variantsToClassNames(variants, className, "outerWrapper");
99
+ const classNames = styling.variantsToClassNames(variants, className, "outerWrapper");
30
100
  return /* @__PURE__ */ jsxs("div", {
31
101
  className: classNames.outerWrapper,
32
- children: [
33
- /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
34
- ref,
35
- "aria-label": ariaLabel,
36
- checked: !!field.value,
37
- name,
38
- onBlur,
39
- onChange: (e) => {
40
- onChange(e.target.checked);
41
- },
42
- onFocus: () => {
43
- visualSwitchRef.current?.focus();
44
- },
45
- type: "checkbox"
46
- }) }),
47
- /* @__PURE__ */ jsx(Switch, {
48
- ref: visualSwitchRef,
49
- "aria-label": ariaLabel,
50
- classNames,
51
- "data-invalid": invalid,
52
- "data-required": required,
53
- "data-testid": testId,
54
- defaultSelected: !!defaultValue,
55
- endContent,
56
- isDisabled: disabled,
57
- isSelected: !!field.value,
58
- name: `${name}_switch`,
59
- onValueChange: onChange,
60
- size,
61
- startContent,
62
- thumbIcon,
63
- children: label
64
- }),
65
- invalid ? /* @__PURE__ */ jsx("div", {
66
- ...getHelperWrapperProps(),
67
- className: cn(getHelperWrapperProps()?.className, "ml-0 block"),
68
- children: /* @__PURE__ */ jsx("div", {
69
- ...getErrorMessageProps(),
70
- children: errorMessage
71
- })
72
- }) : null
73
- ]
102
+ "data-component": "switch",
103
+ "data-slot": "outer-wrapper",
104
+ children: [/* @__PURE__ */ jsxs("label", {
105
+ ...mergeProps(labelProps, hoverProps),
106
+ className: classNames.base,
107
+ "data-disabled": disabled ? true : void 0,
108
+ "data-focus": isFocused || void 0,
109
+ "data-focus-visible": isFocusVisible || void 0,
110
+ "data-hover": isHovered || void 0,
111
+ "data-invalid": invalid,
112
+ "data-pressed": isPressed || void 0,
113
+ "data-required": required,
114
+ "data-selected": state.isSelected || void 0,
115
+ "data-slot": "base",
116
+ "data-testid": testId,
117
+ htmlFor: ids.control,
118
+ children: [
119
+ /* @__PURE__ */ jsx(VisuallyHidden, {
120
+ elementType: "span",
121
+ children: /* @__PURE__ */ jsx("input", {
122
+ ...mergeProps(inputProps, focusProps, controlProps),
123
+ ref: controlRef,
124
+ "data-slot": "input"
125
+ })
126
+ }),
127
+ /* @__PURE__ */ jsx(SwitchTrack, {
128
+ className: classNames,
129
+ endContent,
130
+ selected: state.isSelected,
131
+ startContent,
132
+ thumbIcon
133
+ }),
134
+ label ? /* @__PURE__ */ jsx(FieldLabel, {
135
+ as: "span",
136
+ className: classNames.label,
137
+ id: ids.label,
138
+ required,
139
+ children: label
140
+ }) : null
141
+ ]
142
+ }), description || invalid ? /* @__PURE__ */ jsxs("div", {
143
+ className: classNames.helperWrapper,
144
+ "data-slot": "helper-wrapper",
145
+ children: [/* @__PURE__ */ jsx(FieldDescription, {
146
+ className: classNames.description,
147
+ id: ids.description,
148
+ children: description
149
+ }), invalid ? /* @__PURE__ */ jsx("div", {
150
+ className: classNames.errorMessage,
151
+ "data-slot": "error-message",
152
+ id: ids.error,
153
+ children: errorMessage
154
+ }) : null]
155
+ }) : null]
156
+ });
157
+ };
158
+ //#endregion
159
+ //#region src/Switch/Switch.tsx
160
+ /** Form toggle field for a boolean value */
161
+ const Switch = ({ className = void 0, endContent = void 0, name, size = "md", startContent = void 0, thumbIcon = void 0, ...uniformProps }) => {
162
+ const { field } = useUniformField({
163
+ ...uniformProps,
164
+ name
165
+ });
166
+ return /* @__PURE__ */ jsx(SwitchControl, {
167
+ className,
168
+ endContent,
169
+ field,
170
+ size,
171
+ startContent,
172
+ thumbIcon
74
173
  });
75
174
  };
76
175
  //#endregion
77
176
  //#region src/Switch/index.ts
78
- var Switch_default = Switch$1;
177
+ var Switch_default = Switch;
79
178
  //#endregion
80
179
  export { Switch_default as default, switchVariants };
81
180
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["Switch","HeroSwitch","Switch"],"sources":["../../src/Switch/Switch.tsx","../../src/Switch/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { SwitchProps as HeroSwitchProps } from '@heroui/switch';\nimport type { ReactNode } from 'react';\n\nimport { useRef } from 'react';\n\nimport { Switch as HeroSwitch } from '@heroui/switch';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../hooks/useUniformField';\n\nexport const switchVariants = tv({\n slots: {\n base: '',\n endContent: '',\n errorMessage: 'ml-1 mt-1',\n // see HeroUI styles for group-data condition,\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n outerWrapper: 'place-content-center',\n startContent: '',\n thumb: '',\n thumbIcon: '',\n wrapper: '',\n },\n});\n\ntype VariantProps = TVProps<typeof switchVariants>;\ntype ClassName = TVClassName<typeof switchVariants>;\n\nexport interface SwitchProps extends VariantProps {\n /** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** whether the select should be disabled */\n disabled?: boolean;\n /** Icon to be displayed at the end of the switch (when enabled) */\n endContent?: ReactNode;\n /** component displayed next to the switch */\n label?: ReactNode;\n /** name the field is registered under */\n name: string;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\n /** Icon to be displayed at the start of the switch (when disabled) */\n startContent?: ReactNode;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** Icon to be displayed inside the thumb */\n thumbIcon?: HeroSwitchProps['thumbIcon'];\n}\n\n/**\n * Switch component based on [HeroUI Switch](https://www.heroui.com//docs/components/switch)\n */\nconst Switch = ({\n className = undefined,\n endContent = undefined,\n name,\n size = undefined,\n startContent = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchProps) => {\n const {\n ariaLabel,\n defaultValue,\n disabled,\n errorMessage,\n field,\n getErrorMessageProps,\n getHelperWrapperProps,\n invalid,\n label,\n onBlur,\n onChange,\n ref,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Ref for the visual switch to forward focus\n const visualSwitchRef = useRef<HTMLInputElement>(null);\n\n // classNames from slots\n const variants = switchVariants();\n const classNames = variantsToClassNames(variants, className, 'outerWrapper');\n\n return (\n <div className={classNames.outerWrapper}>\n {/* Visually hidden input for form accessibility and focus management */}\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={ariaLabel}\n checked={!!field.value}\n name={name}\n onBlur={onBlur}\n onChange={(e) => {\n onChange(e.target.checked);\n }}\n onFocus={() => {\n // When RHF focuses this hidden input (e.g., on validation error),\n // forward focus to the visual switch to show focus ring\n visualSwitchRef.current?.focus();\n }}\n type=\"checkbox\"\n />\n </VisuallyHidden>\n {/* Visual HeroSwitch component */}\n <HeroSwitch\n ref={visualSwitchRef}\n aria-label={ariaLabel}\n classNames={classNames}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n defaultSelected={!!defaultValue}\n endContent={endContent}\n isDisabled={disabled}\n isSelected={!!field.value}\n name={`${name}_switch`}\n onValueChange={onChange}\n size={size}\n startContent={startContent}\n thumbIcon={thumbIcon}\n >\n {label}\n </HeroSwitch>\n {invalid ? (\n <div\n {...getHelperWrapperProps()}\n className={cn(\n getHelperWrapperProps()?.className,\n // force helper to be visible (for some reason it's hidden by default) and remove margin\n 'ml-0 block',\n )}\n >\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </div>\n );\n};\n\nexport default Switch;\n","import Switch from './Switch';\n\nexport type { SwitchProps } from './Switch';\n\nexport { switchVariants } from './Switch';\n\nexport default Switch;\n"],"mappings":";;;;;;;AAaA,MAAa,iBAAiB,GAAG,EAC/B,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s","names":[],"sources":["../../src/Switch/subcomponents/SwitchIcon.tsx","../../src/Switch/subcomponents/SwitchThumb.tsx","../../src/Switch/subcomponents/SwitchTrack.tsx","../../src/Switch/subcomponents/SwitchControl.tsx","../../src/Switch/Switch.tsx","../../src/Switch/index.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { cloneElement, isValidElement } from 'react';\n\ninterface SwitchIconProps {\n /** Icon content */\n children: ReactNode;\n /** CSS class name */\n className: string;\n}\n\n/** Applies switch icon dimensions and slot styling to an element */\nconst SwitchIcon = ({ children, className }: SwitchIconProps) => {\n return (\n <>\n {isValidElement<{ className?: string; width?: string; height?: string }>(\n children,\n )\n ? cloneElement(children, { width: '1em', height: '1em', className })\n : children}\n </>\n );\n};\n\nexport default SwitchIcon;\n","import type { ReactNode } from 'react';\n\nimport SwitchIcon from './SwitchIcon';\n\nexport interface SwitchThumbIconProps {\n /** CSS class name */\n className: string;\n /** Selected state as a string */\n 'data-checked': string;\n /** Icon height */\n height: string;\n /** Current toggle state */\n isSelected: boolean;\n /** Icon width */\n width: string;\n}\n\ninterface SwitchThumbProps {\n /** CSS class name */\n className: string;\n /** Current toggle state supplied to the icon callback */\n selected: boolean;\n /** Content or render callback inside the toggle thumb */\n thumbIcon?: ReactNode | ((props: SwitchThumbIconProps) => ReactNode);\n}\n\n/** Thumb icon content, including the consumer's selection-aware render callback */\nconst SwitchThumb = ({\n className,\n selected,\n thumbIcon = undefined,\n}: SwitchThumbProps) => {\n return (\n <>\n {typeof thumbIcon === 'function' ? (\n thumbIcon({\n width: '1em',\n height: '1em',\n className,\n 'data-checked': String(selected),\n isSelected: selected,\n })\n ) : (\n <SwitchIcon className={className}>{thumbIcon}</SwitchIcon>\n )}\n </>\n );\n};\n\nexport default SwitchThumb;\n","import type { SwitchProps } from '../Switch';\n\nimport SwitchIcon from './SwitchIcon';\nimport SwitchThumb from './SwitchThumb';\n\ninterface SwitchTrackProps extends Pick<\n SwitchProps,\n 'endContent' | 'startContent' | 'thumbIcon'\n> {\n /** CSS class name */\n className: Record<\n 'endContent' | 'startContent' | 'thumb' | 'thumbIcon' | 'wrapper',\n string\n >;\n /** Current toggle state supplied to the thumb */\n selected: boolean;\n}\n\n/** Visual switch track, thumb and optional leading and trailing icons */\nconst SwitchTrack = ({\n className: classNames,\n endContent,\n selected,\n startContent,\n thumbIcon,\n}: SwitchTrackProps) => {\n return (\n <span aria-hidden className={classNames.wrapper} data-slot=\"wrapper\">\n {startContent ? (\n <SwitchIcon className={classNames.startContent}>\n {startContent}\n </SwitchIcon>\n ) : null}\n <span className={classNames.thumb} data-slot=\"thumb\">\n <SwitchThumb\n className={classNames.thumbIcon}\n selected={selected}\n thumbIcon={thumbIcon}\n />\n </span>\n {endContent ? (\n <SwitchIcon className={classNames.endContent}>{endContent}</SwitchIcon>\n ) : null}\n </span>\n );\n};\n\nexport default SwitchTrack;\n","import type { UniformField } from '../../hooks/useUniformField/types';\nimport type { SwitchProps } from '../Switch';\n\nimport { mergeProps } from 'react-aria/mergeProps';\nimport { useFocusRing } from 'react-aria/useFocusRing';\nimport { useHover } from 'react-aria/useHover';\nimport { useObjectRef } from 'react-aria/useObjectRef';\nimport { useSwitch } from 'react-aria/useSwitch';\nimport { VisuallyHidden } from 'react-aria/VisuallyHidden';\nimport { useToggleState } from 'react-stately/useToggleState';\n\nimport { useStyling } from '@fuf-stack/pixels/StylingProvider';\n\nimport { getFieldControlProps } from '../../helpers/fieldProps/fieldProps';\nimport FieldDescription from '../../partials/FieldDescription/FieldDescription';\nimport FieldLabel from '../../partials/FieldLabel/FieldLabel';\nimport { switchVariants } from '../switchVariants';\nimport SwitchTrack from './SwitchTrack';\n\ninterface SwitchControlProps extends Pick<\n SwitchProps,\n 'className' | 'endContent' | 'size' | 'startContent' | 'thumbIcon'\n> {\n /** Bound field values, interactions and metadata */\n field: UniformField<unknown, boolean>;\n}\n\n/**\n * Switch presentation with native input, focus and thumb content\n *\n * @see https://react-aria.adobe.com/useSwitch\n */\nconst SwitchControl = ({\n field,\n className,\n size,\n thumbIcon,\n endContent,\n startContent,\n}: SwitchControlProps) => {\n const {\n description,\n disabled,\n errorMessage,\n ids,\n ref: inputRef,\n invalid,\n label,\n name,\n onBlur,\n onChange: onValueChange,\n required,\n testId,\n value,\n } = field;\n\n // associate the editable control with its label and messages\n const controlProps = getFieldControlProps(field);\n\n const styling = useStyling();\n const controlRef = useObjectRef<HTMLInputElement>(inputRef);\n const state = useToggleState({\n isSelected: !!value,\n onChange: onValueChange,\n });\n const { inputProps, labelProps, isPressed } = useSwitch(\n {\n ...controlProps,\n children: label,\n isDisabled: disabled,\n isInvalid: invalid,\n isRequired: required,\n name,\n onBlur,\n validationBehavior: 'aria',\n },\n state,\n controlRef,\n );\n const { focusProps, isFocused, isFocusVisible } = useFocusRing();\n const { hoverProps, isHovered } = useHover({ isDisabled: disabled });\n\n // classNames from slots\n const variants = styling.resolve(switchVariants, { size, disabled });\n const classNames = styling.variantsToClassNames(\n variants,\n className,\n 'outerWrapper',\n );\n\n return (\n <div\n className={classNames.outerWrapper}\n data-component=\"switch\"\n data-slot=\"outer-wrapper\"\n >\n <label\n {...mergeProps(labelProps, hoverProps)}\n className={classNames.base}\n data-disabled={disabled ? true : undefined}\n data-focus={isFocused || undefined}\n data-focus-visible={isFocusVisible || undefined}\n data-hover={isHovered || undefined}\n data-invalid={invalid}\n data-pressed={isPressed || undefined}\n data-required={required}\n data-selected={state.isSelected || undefined}\n data-slot=\"base\"\n data-testid={testId}\n htmlFor={ids.control}\n >\n {/* native toggle for keyboard and assistive technology */}\n <VisuallyHidden elementType=\"span\">\n <input\n {...mergeProps(inputProps, focusProps, controlProps)}\n ref={controlRef}\n data-slot=\"input\"\n />\n </VisuallyHidden>\n\n {/* toggle track and thumb */}\n <SwitchTrack\n className={classNames}\n endContent={endContent}\n selected={state.isSelected}\n startContent={startContent}\n thumbIcon={thumbIcon}\n />\n {label ? (\n <FieldLabel\n as=\"span\"\n className={classNames.label}\n id={ids.label}\n required={required}\n >\n {label}\n </FieldLabel>\n ) : null}\n </label>\n\n {/* help text and validation messages */}\n {description || invalid ? (\n <div className={classNames.helperWrapper} data-slot=\"helper-wrapper\">\n <FieldDescription\n className={classNames.description}\n id={ids.description}\n >\n {description}\n </FieldDescription>\n {invalid ? (\n <div\n className={classNames.errorMessage}\n data-slot=\"error-message\"\n id={ids.error}\n >\n {errorMessage}\n </div>\n ) : null}\n </div>\n ) : null}\n </div>\n );\n};\n\nexport default SwitchControl;\n","import type { ReactNode } from 'react';\nimport type { SwitchThumbIconProps } from './subcomponents/SwitchThumb';\nimport type { ClassName } from './switchVariants';\n\nimport useUniformField from '../hooks/useUniformField/useUniformField';\nimport SwitchControl from './subcomponents/SwitchControl';\n\nexport type { SwitchThumbIconProps } from './subcomponents/SwitchThumb';\n\nexport { switchVariants } from './switchVariants';\n\nexport interface SwitchProps {\n /** Custom accessible name */\n ariaLabel?: string;\n /** CSS class name */\n className?: ClassName;\n /** Help text associated with the field */\n description?: ReactNode;\n /** Disables the field */\n disabled?: boolean;\n /** Icon to be displayed at the end of the switch (when enabled) */\n endContent?: ReactNode;\n /** Field label */\n label?: ReactNode;\n /** Field name */\n name: string;\n /** Control size */\n size?: 'sm' | 'md' | 'lg';\n /** Icon to be displayed at the start of the switch (when disabled) */\n startContent?: ReactNode;\n /** HTML data-testid attribute for e2e tests */\n testId?: string;\n /** Content or render callback inside the toggle thumb */\n thumbIcon?: ReactNode | ((props: SwitchThumbIconProps) => ReactNode);\n}\n\n/** Form toggle field for a boolean value */\nconst Switch = ({\n className = undefined,\n endContent = undefined,\n name,\n size = 'md',\n startContent = undefined,\n thumbIcon = undefined,\n ...uniformProps\n}: SwitchProps) => {\n const { field } = useUniformField({\n ...uniformProps,\n name,\n });\n\n return (\n <SwitchControl\n className={className}\n endContent={endContent}\n field={field}\n size={size}\n startContent={startContent}\n thumbIcon={thumbIcon}\n />\n );\n};\n\nexport default Switch;\n","import Switch from './Switch';\n\nexport type { SwitchProps } from './Switch';\n\nexport { switchVariants } from './Switch';\n\nexport default Switch;\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAM,cAAc,EAAE,UAAU,gBAAiC;CAC/D,OACE,oBAAA,UAAA,EAAA,UACG,eACC,QACF,IACI,aAAa,UAAU;EAAE,OAAO;EAAO,QAAQ;EAAO;CAAU,CAAC,IACjE,SACJ,CAAA;AAEN;;;;ACKA,MAAM,eAAe,EACnB,WACA,UACA,YAAY,KAAA,QACU;CACtB,OACE,oBAAA,UAAA,EAAA,UACG,OAAO,cAAc,aACpB,UAAU;EACR,OAAO;EACP,QAAQ;EACR;EACA,gBAAgB,OAAO,QAAQ;EAC/B,YAAY;CACd,CAAC,IAED,oBAAC,YAAD;EAAuB;EAAY,UAAA;CAAsB,CAAA,EAE3D,CAAA;AAEN;;;;AC5BA,MAAM,eAAe,EACnB,WAAW,YACX,YACA,UACA,cACA,gBACsB;CACtB,OACE,qBAAC,QAAD;EAAM,eAAA;EAAY,WAAW,WAAW;EAAS,aAAU;EAA3D,UAAA;GACG,eACC,oBAAC,YAAD;IAAY,WAAW,WAAW;IAC/B,UAAA;GACS,CAAA,IACV;GACJ,oBAAC,QAAD;IAAM,WAAW,WAAW;IAAO,aAAU;IAC3C,UAAA,oBAAC,aAAD;KACE,WAAW,WAAW;KACZ;KACC;IACZ,CAAA;GACG,CAAA;GACL,aACC,oBAAC,YAAD;IAAY,WAAW,WAAW;IAAa,UAAA;GAAuB,CAAA,IACpE;EACA;;AAEV;;;;;;;;ACbA,MAAM,iBAAiB,EACrB,OACA,WACA,MACA,WACA,YACA,mBACwB;CACxB,MAAM,EACJ,aACA,UACA,cACA,KACA,KAAK,UACL,SACA,OACA,MACA,QACA,UAAU,eACV,UACA,QACA,UACE;CAGJ,MAAM,eAAe,qBAAqB,KAAK;CAE/C,MAAM,UAAU,WAAW;CAC3B,MAAM,aAAa,aAA+B,QAAQ;CAC1D,MAAM,QAAQ,eAAe;EAC3B,YAAY,CAAC,CAAC;EACd,UAAU;CACZ,C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