@fuf-stack/uniform 1.8.9 → 1.9.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.
- package/dist/Checkboxes/index.cjs +10 -10
- package/dist/Checkboxes/index.js +9 -9
- package/dist/FieldArray/index.cjs +10 -10
- package/dist/FieldArray/index.js +9 -9
- package/dist/Form/index.cjs +10 -10
- package/dist/Form/index.js +9 -9
- package/dist/Input/index.cjs +10 -10
- package/dist/Input/index.js +9 -9
- package/dist/{RadioBoxes-DpkI28l0.d.cts → RadioBox-B0s3q9g6.d.cts} +87 -37
- package/dist/{RadioBoxes-DpkI28l0.d.ts → RadioBox-B0s3q9g6.d.ts} +87 -37
- package/dist/RadioBoxes/index.cjs +12 -10
- package/dist/RadioBoxes/index.cjs.map +1 -1
- package/dist/RadioBoxes/index.d.cts +2 -2
- package/dist/RadioBoxes/index.d.ts +2 -2
- package/dist/RadioBoxes/index.js +13 -11
- package/dist/RadioTabs/index.cjs +10 -10
- package/dist/RadioTabs/index.d.cts +2 -2
- package/dist/RadioTabs/index.d.ts +2 -2
- package/dist/RadioTabs/index.js +9 -9
- package/dist/{RadioTabs-DTDcAZoH.d.cts → RadioTabs-D9Px3XEs.d.cts} +15 -0
- package/dist/{RadioTabs-DTDcAZoH.d.ts → RadioTabs-D9Px3XEs.d.ts} +15 -0
- package/dist/Radios/index.cjs +10 -10
- package/dist/Radios/index.js +9 -9
- package/dist/Select/index.cjs +10 -10
- package/dist/Select/index.js +9 -9
- package/dist/Slider/index.cjs +19 -0
- package/dist/Slider/index.cjs.map +1 -0
- package/dist/Slider/index.d.cts +10 -0
- package/dist/Slider/index.d.ts +10 -0
- package/dist/Slider/index.js +19 -0
- package/dist/Slider/index.js.map +1 -0
- package/dist/Slider-CIVhjJy1.d.cts +153 -0
- package/dist/Slider-CIVhjJy1.d.ts +153 -0
- package/dist/SubmitButton/index.cjs +10 -10
- package/dist/SubmitButton/index.js +9 -9
- package/dist/Switch/index.cjs +10 -10
- package/dist/Switch/index.d.cts +2 -2
- package/dist/Switch/index.d.ts +2 -2
- package/dist/Switch/index.js +9 -9
- package/dist/{Switch-Hr6PnK98.d.cts → Switch-CqBVdRJe.d.cts} +4 -4
- package/dist/{Switch-Hr6PnK98.d.ts → Switch-CqBVdRJe.d.ts} +4 -4
- package/dist/SwitchBox/index.cjs +26 -0
- package/dist/SwitchBox/index.cjs.map +1 -0
- package/dist/SwitchBox/index.d.cts +11 -0
- package/dist/SwitchBox/index.d.ts +11 -0
- package/dist/SwitchBox/index.js +26 -0
- package/dist/SwitchBox/index.js.map +1 -0
- package/dist/SwitchBox-q1I7a0NX.d.cts +146 -0
- package/dist/SwitchBox-q1I7a0NX.d.ts +146 -0
- package/dist/TextArea/index.cjs +10 -10
- package/dist/TextArea/index.js +9 -9
- package/dist/{chunk-T6G6NGLL.js → chunk-246OISWB.js} +2 -2
- package/dist/chunk-2OXNDD5W.cjs +162 -0
- package/dist/chunk-2OXNDD5W.cjs.map +1 -0
- package/dist/{chunk-2UQCRQEJ.cjs → chunk-6RZT2BKH.cjs} +5 -5
- package/dist/{chunk-2UQCRQEJ.cjs.map → chunk-6RZT2BKH.cjs.map} +1 -1
- package/dist/{chunk-OZQQSTVH.js → chunk-7FOSZV75.js} +8 -6
- package/dist/chunk-7FOSZV75.js.map +1 -0
- package/dist/{chunk-F5DISGJ4.cjs → chunk-7O6LAGV2.cjs} +9 -9
- package/dist/{chunk-F5DISGJ4.cjs.map → chunk-7O6LAGV2.cjs.map} +1 -1
- package/dist/{chunk-QLMUUXQO.cjs → chunk-7WKVH43M.cjs} +78 -46
- package/dist/chunk-7WKVH43M.cjs.map +1 -0
- package/dist/{chunk-RCLQ6NFK.js → chunk-A3PYIWG2.js} +2 -2
- package/dist/{chunk-O2XJNQQK.js → chunk-BOCYHTFE.js} +7 -1
- package/dist/chunk-BOCYHTFE.js.map +1 -0
- package/dist/{chunk-KE5DB3DZ.js → chunk-CEVS6WSG.js} +2 -2
- package/dist/{chunk-VIK6VTAZ.js → chunk-CG7GDQAP.js} +3 -3
- package/dist/{chunk-77OMBV7C.js → chunk-DQAZSXD6.js} +4 -4
- package/dist/chunk-FUMQULCR.cjs +215 -0
- package/dist/chunk-FUMQULCR.cjs.map +1 -0
- package/dist/{chunk-5MTIQ6WD.js → chunk-GE7HUIAK.js} +3 -3
- package/dist/{chunk-LO7UKHOS.js → chunk-IKOYYA75.js} +2 -2
- package/dist/{chunk-SG3JI5R3.cjs → chunk-IU4RL2D7.cjs} +3 -3
- package/dist/{chunk-SG3JI5R3.cjs.map → chunk-IU4RL2D7.cjs.map} +1 -1
- package/dist/{chunk-PHMEYG5F.js → chunk-IZZTVGEW.js} +78 -46
- package/dist/chunk-IZZTVGEW.js.map +1 -0
- package/dist/{chunk-F3WXUKZG.js → chunk-JICFOKDO.js} +2 -2
- package/dist/{chunk-ALI7JORZ.cjs → chunk-JQQ32JOD.cjs} +3 -3
- package/dist/{chunk-ALI7JORZ.cjs.map → chunk-JQQ32JOD.cjs.map} +1 -1
- package/dist/{chunk-YYLTLVIF.cjs → chunk-LTE7PW7F.cjs} +3 -3
- package/dist/{chunk-YYLTLVIF.cjs.map → chunk-LTE7PW7F.cjs.map} +1 -1
- package/dist/chunk-LUO4I3TW.js +162 -0
- package/dist/chunk-LUO4I3TW.js.map +1 -0
- package/dist/{chunk-JG7S3DEH.cjs → chunk-MEYGGRBQ.cjs} +7 -7
- package/dist/{chunk-JG7S3DEH.cjs.map → chunk-MEYGGRBQ.cjs.map} +1 -1
- package/dist/{chunk-YBLDWOOG.js → chunk-MHQ2V7UW.js} +2 -2
- package/dist/{chunk-HEPNEBRF.cjs → chunk-NKIZA3ZO.cjs} +3 -3
- package/dist/{chunk-HEPNEBRF.cjs.map → chunk-NKIZA3ZO.cjs.map} +1 -1
- package/dist/{chunk-6AWHOBNL.cjs → chunk-NV4YVZYX.cjs} +6 -6
- package/dist/{chunk-6AWHOBNL.cjs.map → chunk-NV4YVZYX.cjs.map} +1 -1
- package/dist/{chunk-D4AAQIY3.cjs → chunk-RRG5ZLVF.cjs} +5 -5
- package/dist/{chunk-D4AAQIY3.cjs.map → chunk-RRG5ZLVF.cjs.map} +1 -1
- package/dist/{chunk-NQ3KBYW6.cjs → chunk-SR76XJW4.cjs} +3 -3
- package/dist/{chunk-NQ3KBYW6.cjs.map → chunk-SR76XJW4.cjs.map} +1 -1
- package/dist/chunk-THCIT66I.cjs +217 -0
- package/dist/chunk-THCIT66I.cjs.map +1 -0
- package/dist/{chunk-OKJWLH7T.cjs → chunk-TKICOKNS.cjs} +9 -3
- package/dist/chunk-TKICOKNS.cjs.map +1 -0
- package/dist/{chunk-IV45K4WU.js → chunk-TUIK3MER.js} +2 -2
- package/dist/{chunk-AQJLKHAE.cjs → chunk-UBLASN6D.cjs} +5 -5
- package/dist/{chunk-AQJLKHAE.cjs.map → chunk-UBLASN6D.cjs.map} +1 -1
- package/dist/chunk-UUGSI3FD.js +215 -0
- package/dist/chunk-UUGSI3FD.js.map +1 -0
- package/dist/{chunk-FYN7ZWLW.cjs → chunk-UUGUQGMX.cjs} +10 -10
- package/dist/{chunk-FYN7ZWLW.cjs.map → chunk-UUGUQGMX.cjs.map} +1 -1
- package/dist/{chunk-H2PPUEUO.cjs → chunk-V65AMUKK.cjs} +5 -5
- package/dist/{chunk-H2PPUEUO.cjs.map → chunk-V65AMUKK.cjs.map} +1 -1
- package/dist/chunk-VIV3MSIX.cjs +129 -0
- package/dist/chunk-VIV3MSIX.cjs.map +1 -0
- package/dist/{chunk-26VE4IGU.js → chunk-WWRIMXSN.js} +3 -3
- package/dist/chunk-XBVXMQBW.js +217 -0
- package/dist/chunk-XBVXMQBW.js.map +1 -0
- package/dist/{chunk-LIW7KW2L.cjs → chunk-XC3C2W4M.cjs} +3 -3
- package/dist/{chunk-LIW7KW2L.cjs.map → chunk-XC3C2W4M.cjs.map} +1 -1
- package/dist/chunk-XMCL3F4W.js +129 -0
- package/dist/chunk-XMCL3F4W.js.map +1 -0
- package/dist/{chunk-REVHYI2O.js → chunk-XXLYUZY4.js} +4 -4
- package/dist/{chunk-4UR2T76K.js → chunk-Y7YEI6T2.js} +3 -3
- package/dist/{chunk-27MWGFXR.cjs → chunk-YCCBMAN2.cjs} +9 -7
- package/dist/chunk-YCCBMAN2.cjs.map +1 -0
- package/dist/{chunk-SJWL6EMI.js → chunk-ZZW7JZ2U.js} +3 -3
- package/dist/helpers/index.cjs +4 -2
- package/dist/helpers/index.cjs.map +1 -1
- package/dist/helpers/index.d.cts +25 -1
- package/dist/helpers/index.d.ts +25 -1
- package/dist/helpers/index.js +3 -1
- package/dist/hooks/index.cjs +14 -14
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +18 -18
- package/dist/hooks/useClientValidation/index.cjs +5 -5
- package/dist/hooks/useClientValidation/index.d.cts +2 -2
- package/dist/hooks/useClientValidation/index.d.ts +2 -2
- package/dist/hooks/useClientValidation/index.js +4 -4
- package/dist/hooks/useController/index.cjs +4 -4
- package/dist/hooks/useController/index.js +3 -3
- package/dist/hooks/useFormContext/index.cjs +4 -4
- package/dist/hooks/useFormContext/index.js +3 -3
- package/dist/hooks/useUniformField/index.cjs +6 -6
- package/dist/hooks/useUniformField/index.js +5 -5
- package/dist/hooks/useUniformFieldArray/index.cjs +7 -7
- package/dist/hooks/useUniformFieldArray/index.js +6 -6
- package/dist/hooks/useWatchUserChange/index.cjs +5 -5
- package/dist/hooks/useWatchUserChange/index.js +4 -4
- package/dist/index.cjs +38 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +45 -31
- package/package.json +13 -2
- package/dist/chunk-27MWGFXR.cjs.map +0 -1
- package/dist/chunk-DJKC3SR6.js +0 -105
- package/dist/chunk-DJKC3SR6.js.map +0 -1
- package/dist/chunk-HUDJU756.cjs +0 -170
- package/dist/chunk-HUDJU756.cjs.map +0 -1
- package/dist/chunk-NI3WUU7T.cjs +0 -105
- package/dist/chunk-NI3WUU7T.cjs.map +0 -1
- package/dist/chunk-O2XJNQQK.js.map +0 -1
- package/dist/chunk-OKJWLH7T.cjs.map +0 -1
- package/dist/chunk-OZQQSTVH.js.map +0 -1
- package/dist/chunk-PHMEYG5F.js.map +0 -1
- package/dist/chunk-QLMUUXQO.cjs.map +0 -1
- package/dist/chunk-U4D6YJ6Z.js +0 -170
- package/dist/chunk-U4D6YJ6Z.js.map +0 -1
- /package/dist/{chunk-T6G6NGLL.js.map → chunk-246OISWB.js.map} +0 -0
- /package/dist/{chunk-RCLQ6NFK.js.map → chunk-A3PYIWG2.js.map} +0 -0
- /package/dist/{chunk-KE5DB3DZ.js.map → chunk-CEVS6WSG.js.map} +0 -0
- /package/dist/{chunk-VIK6VTAZ.js.map → chunk-CG7GDQAP.js.map} +0 -0
- /package/dist/{chunk-77OMBV7C.js.map → chunk-DQAZSXD6.js.map} +0 -0
- /package/dist/{chunk-5MTIQ6WD.js.map → chunk-GE7HUIAK.js.map} +0 -0
- /package/dist/{chunk-LO7UKHOS.js.map → chunk-IKOYYA75.js.map} +0 -0
- /package/dist/{chunk-F3WXUKZG.js.map → chunk-JICFOKDO.js.map} +0 -0
- /package/dist/{chunk-YBLDWOOG.js.map → chunk-MHQ2V7UW.js.map} +0 -0
- /package/dist/{chunk-IV45K4WU.js.map → chunk-TUIK3MER.js.map} +0 -0
- /package/dist/{chunk-26VE4IGU.js.map → chunk-WWRIMXSN.js.map} +0 -0
- /package/dist/{chunk-REVHYI2O.js.map → chunk-XXLYUZY4.js.map} +0 -0
- /package/dist/{chunk-4UR2T76K.js.map → chunk-Y7YEI6T2.js.map} +0 -0
- /package/dist/{chunk-SJWL6EMI.js.map → chunk-ZZW7JZ2U.js.map} +0 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useUniformField
|
|
3
|
+
} from "./chunk-7FOSZV75.js";
|
|
4
|
+
import {
|
|
5
|
+
__objRest,
|
|
6
|
+
__spreadProps,
|
|
7
|
+
__spreadValues
|
|
8
|
+
} from "./chunk-K2V4ULA2.js";
|
|
9
|
+
|
|
10
|
+
// src/SwitchBox/SwitchBox.tsx
|
|
11
|
+
import { useRef } from "react";
|
|
12
|
+
import { useSwitch } from "@heroui/switch";
|
|
13
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
14
|
+
import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var switchBoxVariants = tv({
|
|
17
|
+
slots: {
|
|
18
|
+
box: "group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default hover:bg-content2 data-[selected=true]:border-focus",
|
|
19
|
+
description: "text-foreground opacity-70",
|
|
20
|
+
icon: "",
|
|
21
|
+
label: 'font-medium text-foreground group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-["*"]',
|
|
22
|
+
wrapper: "",
|
|
23
|
+
thumb: "",
|
|
24
|
+
thumbIcon: ""
|
|
25
|
+
},
|
|
26
|
+
variants: {
|
|
27
|
+
isDisabled: {
|
|
28
|
+
true: {
|
|
29
|
+
box: "pointer-events-none opacity-disabled"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
isInvalid: {
|
|
33
|
+
true: {
|
|
34
|
+
box: "!border-danger",
|
|
35
|
+
label: "!text-danger"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
size: {
|
|
39
|
+
sm: {
|
|
40
|
+
box: "gap-2 p-3",
|
|
41
|
+
description: "text-xs",
|
|
42
|
+
label: "text-xs"
|
|
43
|
+
},
|
|
44
|
+
md: {
|
|
45
|
+
box: "gap-4 p-4",
|
|
46
|
+
description: "text-small",
|
|
47
|
+
label: "text-sm"
|
|
48
|
+
},
|
|
49
|
+
lg: {
|
|
50
|
+
box: "gap-4 p-5",
|
|
51
|
+
description: "text-small",
|
|
52
|
+
label: "text-base"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaultVariants: {
|
|
57
|
+
size: "md"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var SwitchBox = (_a) => {
|
|
61
|
+
var _b = _a, {
|
|
62
|
+
className = void 0,
|
|
63
|
+
description = void 0,
|
|
64
|
+
icon = void 0,
|
|
65
|
+
name,
|
|
66
|
+
size = void 0,
|
|
67
|
+
thumbIcon = void 0
|
|
68
|
+
} = _b, uniformFieldProps = __objRest(_b, [
|
|
69
|
+
"className",
|
|
70
|
+
"description",
|
|
71
|
+
"icon",
|
|
72
|
+
"name",
|
|
73
|
+
"size",
|
|
74
|
+
"thumbIcon"
|
|
75
|
+
]);
|
|
76
|
+
var _a2;
|
|
77
|
+
const {
|
|
78
|
+
defaultValue,
|
|
79
|
+
disabled,
|
|
80
|
+
errorMessage,
|
|
81
|
+
field,
|
|
82
|
+
getErrorMessageProps,
|
|
83
|
+
getHelperWrapperProps,
|
|
84
|
+
invalid,
|
|
85
|
+
label,
|
|
86
|
+
onBlur,
|
|
87
|
+
onChange,
|
|
88
|
+
ref,
|
|
89
|
+
required,
|
|
90
|
+
testId
|
|
91
|
+
} = useUniformField(__spreadValues({
|
|
92
|
+
name
|
|
93
|
+
}, uniformFieldProps));
|
|
94
|
+
const visualSwitchRef = useRef(null);
|
|
95
|
+
const {
|
|
96
|
+
Component,
|
|
97
|
+
slots,
|
|
98
|
+
isSelected,
|
|
99
|
+
getBaseProps,
|
|
100
|
+
getInputProps,
|
|
101
|
+
getWrapperProps
|
|
102
|
+
} = useSwitch({
|
|
103
|
+
defaultSelected: !!defaultValue,
|
|
104
|
+
isDisabled: disabled,
|
|
105
|
+
isSelected: !!field.value,
|
|
106
|
+
name: `${name}_switch`,
|
|
107
|
+
onValueChange: onChange,
|
|
108
|
+
size,
|
|
109
|
+
thumbIcon
|
|
110
|
+
});
|
|
111
|
+
const variants = switchBoxVariants({
|
|
112
|
+
isDisabled: disabled,
|
|
113
|
+
isInvalid: invalid,
|
|
114
|
+
size
|
|
115
|
+
});
|
|
116
|
+
const classNames = variantsToClassNames(variants, className, "box");
|
|
117
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
118
|
+
/* @__PURE__ */ jsxs(
|
|
119
|
+
Component,
|
|
120
|
+
__spreadProps(__spreadValues({}, getBaseProps()), {
|
|
121
|
+
className: classNames.box,
|
|
122
|
+
"data-invalid": invalid,
|
|
123
|
+
"data-required": required,
|
|
124
|
+
"data-testid": testId,
|
|
125
|
+
children: [
|
|
126
|
+
/* @__PURE__ */ jsxs(VisuallyHidden, { children: [
|
|
127
|
+
/* @__PURE__ */ jsx(
|
|
128
|
+
"input",
|
|
129
|
+
{
|
|
130
|
+
ref,
|
|
131
|
+
"aria-label": typeof label === "string" ? label : name,
|
|
132
|
+
checked: !!field.value,
|
|
133
|
+
name,
|
|
134
|
+
tabIndex: -1,
|
|
135
|
+
type: "checkbox",
|
|
136
|
+
onChange: (e) => {
|
|
137
|
+
onChange(e.target.checked);
|
|
138
|
+
},
|
|
139
|
+
onFocus: () => {
|
|
140
|
+
var _a3;
|
|
141
|
+
(_a3 = visualSwitchRef.current) == null ? void 0 : _a3.focus();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
),
|
|
145
|
+
/* @__PURE__ */ jsx(
|
|
146
|
+
"input",
|
|
147
|
+
__spreadProps(__spreadValues({
|
|
148
|
+
ref: visualSwitchRef
|
|
149
|
+
}, getInputProps()), {
|
|
150
|
+
onBlur: (e) => {
|
|
151
|
+
var _a3, _b2;
|
|
152
|
+
(_b2 = (_a3 = getInputProps()).onBlur) == null ? void 0 : _b2.call(_a3, e);
|
|
153
|
+
onBlur();
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
)
|
|
157
|
+
] }),
|
|
158
|
+
!icon ? /* @__PURE__ */ jsx(
|
|
159
|
+
"span",
|
|
160
|
+
__spreadProps(__spreadValues({}, getWrapperProps()), {
|
|
161
|
+
className: cn(getWrapperProps().className, classNames.wrapper),
|
|
162
|
+
children: /* @__PURE__ */ jsx("span", { className: cn(slots.thumb({ class: classNames.thumb })), children: thumbIcon && typeof thumbIcon === "function" ? thumbIcon({
|
|
163
|
+
isSelected: !!isSelected,
|
|
164
|
+
className: slots.thumbIcon({ class: classNames.thumbIcon }),
|
|
165
|
+
width: "1em",
|
|
166
|
+
height: "1em",
|
|
167
|
+
"data-checked": isSelected ? "true" : "false"
|
|
168
|
+
}) : thumbIcon })
|
|
169
|
+
})
|
|
170
|
+
) : null,
|
|
171
|
+
icon ? /* @__PURE__ */ jsx("div", { className: classNames.icon, children: icon }) : null,
|
|
172
|
+
/* @__PURE__ */ jsxs("div", { className: "grow", children: [
|
|
173
|
+
label ? /* @__PURE__ */ jsx("div", { className: classNames.label, children: label }) : null,
|
|
174
|
+
description ? /* @__PURE__ */ jsx("div", { className: classNames.description, children: description }) : null
|
|
175
|
+
] }),
|
|
176
|
+
icon ? /* @__PURE__ */ jsx(
|
|
177
|
+
"span",
|
|
178
|
+
__spreadProps(__spreadValues({}, getWrapperProps()), {
|
|
179
|
+
className: cn(getWrapperProps().className, classNames.wrapper),
|
|
180
|
+
children: /* @__PURE__ */ jsx("span", { className: cn(slots.thumb({ class: classNames.thumb })), children: thumbIcon && typeof thumbIcon === "function" ? thumbIcon({
|
|
181
|
+
isSelected: !!isSelected,
|
|
182
|
+
className: slots.thumbIcon({ class: classNames.thumbIcon }),
|
|
183
|
+
width: "1em",
|
|
184
|
+
height: "1em",
|
|
185
|
+
"data-checked": isSelected ? "true" : "false"
|
|
186
|
+
}) : thumbIcon })
|
|
187
|
+
})
|
|
188
|
+
) : null
|
|
189
|
+
]
|
|
190
|
+
})
|
|
191
|
+
),
|
|
192
|
+
invalid ? /* @__PURE__ */ jsx(
|
|
193
|
+
"div",
|
|
194
|
+
__spreadProps(__spreadValues({}, getHelperWrapperProps()), {
|
|
195
|
+
className: cn(
|
|
196
|
+
(_a2 = getHelperWrapperProps()) == null ? void 0 : _a2.className,
|
|
197
|
+
// force helper to be visible (for some reason it's hidden by default) and remove margin
|
|
198
|
+
"ml-0 block"
|
|
199
|
+
),
|
|
200
|
+
children: /* @__PURE__ */ jsx("div", __spreadProps(__spreadValues({}, getErrorMessageProps()), { children: errorMessage }))
|
|
201
|
+
})
|
|
202
|
+
) : null
|
|
203
|
+
] });
|
|
204
|
+
};
|
|
205
|
+
var SwitchBox_default = SwitchBox;
|
|
206
|
+
|
|
207
|
+
// src/SwitchBox/index.ts
|
|
208
|
+
var SwitchBox_default2 = SwitchBox_default;
|
|
209
|
+
|
|
210
|
+
export {
|
|
211
|
+
switchBoxVariants,
|
|
212
|
+
SwitchBox_default,
|
|
213
|
+
SwitchBox_default2
|
|
214
|
+
};
|
|
215
|
+
//# sourceMappingURL=chunk-UUGSI3FD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SwitchBox/SwitchBox.tsx","../src/SwitchBox/index.ts"],"sourcesContent":["import type { TVClassName } 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 { useSwitch } 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';\n\nexport const switchBoxVariants = tv({\n slots: {\n box: 'group inline-flex w-full cursor-pointer items-center justify-between rounded-lg border-2 border-default hover:bg-content2 data-[selected=true]:border-focus',\n description: 'text-foreground opacity-70',\n icon: '',\n label:\n 'font-medium text-foreground group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n wrapper: '',\n thumb: '',\n thumbIcon: '',\n },\n variants: {\n isDisabled: {\n true: {\n box: 'pointer-events-none opacity-disabled',\n },\n },\n isInvalid: {\n true: {\n box: '!border-danger',\n label: '!text-danger',\n },\n },\n size: {\n sm: {\n box: 'gap-2 p-3',\n description: 'text-xs',\n label: 'text-xs',\n },\n md: {\n box: 'gap-4 p-4',\n description: 'text-small',\n label: 'text-sm',\n },\n lg: {\n box: 'gap-4 p-5',\n description: 'text-small',\n label: 'text-base',\n },\n },\n },\n defaultVariants: {\n size: 'md',\n },\n});\n\ntype ClassName = TVClassName<typeof switchBoxVariants>;\n\nexport interface SwitchBoxProps {\n /** CSS class name */\n className?: ClassName;\n /** Description text displayed below the label */\n description?: ReactNode;\n /** whether the switch should be disabled */\n disabled?: boolean;\n /** Icon to be displayed in the box */\n icon?: ReactNode;\n /** component displayed as the label */\n label?: ReactNode;\n /** name the field is registered under */\n name: string;\n /** whether the field is required */\n required?: boolean;\n /* Size of the switch */\n size?: 'sm' | 'md' | 'lg';\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 * SwitchBox component - A card-like box with a switch control\n */\nconst SwitchBox = ({\n className = undefined,\n description = undefined,\n icon = undefined,\n name,\n size = undefined,\n thumbIcon = undefined,\n ...uniformFieldProps\n}: SwitchBoxProps) => {\n const {\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 // Use the useSwitch hook to get access to all the necessary props\n const {\n Component,\n slots,\n isSelected,\n getBaseProps,\n getInputProps,\n getWrapperProps,\n } = useSwitch({\n defaultSelected: !!defaultValue,\n isDisabled: disabled,\n isSelected: !!field.value,\n name: `${name}_switch`,\n onValueChange: onChange,\n size,\n thumbIcon,\n });\n\n // classNames from slots\n const variants = switchBoxVariants({\n isDisabled: disabled,\n isInvalid: invalid,\n size,\n });\n const classNames = variantsToClassNames(variants, className, 'box');\n\n return (\n <div>\n <Component\n {...getBaseProps()}\n className={classNames.box}\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n >\n <VisuallyHidden>\n <input\n ref={ref}\n aria-label={typeof label === 'string' ? label : name}\n checked={!!field.value}\n name={name}\n tabIndex={-1}\n type=\"checkbox\"\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 />\n {/* Visual switch input for focus ring */}\n <input\n ref={visualSwitchRef}\n {...getInputProps()}\n onBlur={(e) => {\n // Call HeroUI's internal onBlur to clear focus state and remove focus ring\n getInputProps().onBlur?.(e);\n // Then call RHF's onBlur to mark field as touched\n onBlur();\n }}\n />\n </VisuallyHidden>\n {!icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n {icon ? <div className={classNames.icon}>{icon}</div> : null}\n <div className=\"grow\">\n {label ? <div className={classNames.label}>{label}</div> : null}\n {description ? (\n <div className={classNames.description}>{description}</div>\n ) : null}\n </div>\n {icon ? (\n <span\n {...getWrapperProps()}\n className={cn(getWrapperProps().className, classNames.wrapper)}\n >\n <span className={cn(slots.thumb({ class: classNames.thumb }))}>\n {thumbIcon && typeof thumbIcon === 'function'\n ? thumbIcon({\n isSelected: !!isSelected,\n className: slots.thumbIcon({ class: classNames.thumbIcon }),\n width: '1em',\n height: '1em',\n 'data-checked': isSelected ? 'true' : 'false',\n })\n : thumbIcon}\n </span>\n </span>\n ) : null}\n </Component>\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 SwitchBox;\n","import SwitchBox from './SwitchBox';\n\nexport type { SwitchBoxProps } from './SwitchBox';\n\nexport { switchBoxVariants } from './SwitchBox';\nexport { SwitchBox };\n\nexport default SwitchBox;\n"],"mappings":";;;;;;;;;;AAIA,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAE/B,SAAS,IAAI,IAAI,4BAA4B;AAgJrC,SACE,KADF;AA5ID,IAAM,oBAAoB,GAAG;AAAA,EAClC,OAAO;AAAA,IACL,KAAK;AAAA,IACL,aAAa;AAAA,IACb,MAAM;AAAA,IACN,OACE;AAAA,IACF,SAAS;AAAA,IACT,OAAO;AAAA,IACP,WAAW;AAAA,EACb;AAAA,EACA,UAAU;AAAA,IACR,YAAY;AAAA,MACV,MAAM;AAAA,QACJ,KAAK;AAAA,MACP;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,MAAM;AAAA,QACJ,KAAK;AAAA,QACL,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,IAAI;AAAA,QACF,KAAK;AAAA,QACL,aAAa;AAAA,QACb,OAAO;AAAA,MACT;AAAA,MACA,IAAI;AAAA,QACF,KAAK;AAAA,QACL,aAAa;AAAA,QACb,OAAO;AAAA,MACT;AAAA,MACA,IAAI;AAAA,QACF,KAAK;AAAA,QACL,aAAa;AAAA,QACb,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf,MAAM;AAAA,EACR;AACF,CAAC;AA8BD,IAAM,YAAY,CAAC,OAQG;AARH,eACjB;AAAA,gBAAY;AAAA,IACZ,cAAc;AAAA,IACd,OAAO;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,MAAM,EAAE,OAAO,WAAW,MAAM,CAAC,CAAC,GACzD,uBAAa,OAAO,cAAc,aAC/B,UAAU;AAAA,gBACR,YAAY,CAAC,CAAC;AAAA,gBACd,WAAW,MAAM,UAAU,EAAE,OAAO,WAAW,UAAU,CAAC;AAAA,gBAC1D,OAAO;AAAA,gBACP,QAAQ;AAAA,gBACR,gBAAgB,aAAa,SAAS;AAAA,cACxC,CAAC,IACD,WACN;AAAA;AAAA,UACF,IACE;AAAA;AAAA;AAAA,IACN;AAAA,IACC,UACC;AAAA,MAAC;AAAA,uCACK,sBAAsB,IAD3B;AAAA,QAEC,WAAW;AAAA,WACTA,MAAA,sBAAsB,MAAtB,gBAAAA,IAAyB;AAAA;AAAA,UAEzB;AAAA,QACF;AAAA,QAEA,8BAAC,wCAAQ,qBAAqB,IAA7B,EAAiC,yBAAa;AAAA;AAAA,IACjD,IACE;AAAA,KACN;AAEJ;AAEA,IAAO,oBAAQ;;;AC3Of,IAAOE,qBAAQ;","names":["_a","_b","SwitchBox_default"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkUBLASN6Dcjs = require('./chunk-UBLASN6D.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkTKICOKNScjs = require('./chunk-TKICOKNS.cjs');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -16,7 +16,7 @@ var _chunk555JRYCScjs = require('./chunk-555JRYCS.cjs');
|
|
|
16
16
|
var _react = require('react');
|
|
17
17
|
var _reacthookform = require('react-hook-form');
|
|
18
18
|
var checkFieldIsRequired = (validation, path) => {
|
|
19
|
-
const checkPath = path[path.length - 1] ===
|
|
19
|
+
const checkPath = path[path.length - 1] === _chunkTKICOKNScjs.flatArrayKey ? path.slice(0, -1) : path;
|
|
20
20
|
const checkRequired = (schema) => {
|
|
21
21
|
if (schema.type === "array") {
|
|
22
22
|
if (schema.isOptional || schema.isNullable) {
|
|
@@ -30,7 +30,7 @@ var checkFieldIsRequired = (validation, path) => {
|
|
|
30
30
|
};
|
|
31
31
|
var getValidationErrorsByName = (errors, name) => {
|
|
32
32
|
const keys = name.split(".").filter((k) => {
|
|
33
|
-
return k !==
|
|
33
|
+
return k !== _chunkTKICOKNScjs.flatArrayKey;
|
|
34
34
|
});
|
|
35
35
|
let current = errors;
|
|
36
36
|
keys.forEach((key) => {
|
|
@@ -57,7 +57,7 @@ var useFormContext = () => {
|
|
|
57
57
|
"watch",
|
|
58
58
|
"subscribe"
|
|
59
59
|
]);
|
|
60
|
-
const uniformContext = _react.useContext.call(void 0,
|
|
60
|
+
const uniformContext = _react.useContext.call(void 0, _chunkUBLASN6Dcjs.UniformContext);
|
|
61
61
|
const getFieldState = (name, testId) => {
|
|
62
62
|
var _a2, _b;
|
|
63
63
|
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
@@ -72,16 +72,16 @@ var useFormContext = () => {
|
|
|
72
72
|
error,
|
|
73
73
|
invalid: !!error,
|
|
74
74
|
required,
|
|
75
|
-
testId:
|
|
75
|
+
testId: _chunkTKICOKNScjs.nameToTestId.call(void 0, testId != null ? testId : name)
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
78
|
const getValues = ((...args) => {
|
|
79
79
|
const result = getValuesOrig(...args);
|
|
80
|
-
return
|
|
80
|
+
return _chunkTKICOKNScjs.toValidationFormat.call(void 0, result);
|
|
81
81
|
});
|
|
82
82
|
const watch = ((...args) => {
|
|
83
83
|
const result = watchOrig(...args);
|
|
84
|
-
return
|
|
84
|
+
return _chunkTKICOKNScjs.toValidationFormat.call(void 0, result);
|
|
85
85
|
});
|
|
86
86
|
const subscribe = ((...args) => {
|
|
87
87
|
const [options] = args;
|
|
@@ -90,7 +90,7 @@ var useFormContext = () => {
|
|
|
90
90
|
const wrappedOptions = _chunk555JRYCScjs.__spreadProps.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {}, options), {
|
|
91
91
|
callback: (subscribeFormState) => {
|
|
92
92
|
const convertedFormState = _chunk555JRYCScjs.__spreadValues.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {}, subscribeFormState), subscribeFormState.values && {
|
|
93
|
-
values:
|
|
93
|
+
values: _chunkTKICOKNScjs.toValidationFormat.call(void 0, subscribeFormState.values)
|
|
94
94
|
});
|
|
95
95
|
return originalCallback(convertedFormState);
|
|
96
96
|
}
|
|
@@ -112,4 +112,4 @@ var useFormContext = () => {
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
exports.checkFieldIsRequired = checkFieldIsRequired; exports.useFormContext = useFormContext;
|
|
115
|
-
//# sourceMappingURL=chunk-
|
|
115
|
+
//# sourceMappingURL=chunk-UUGUQGMX.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-FYN7ZWLW.cjs","../src/hooks/useFormContext/useFormContext.ts"],"names":["_a"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACTA,8BAA2B;AAC3B,gDAAqD;AAM9C,IAAM,qBAAA,EAAuB,CAClC,UAAA,EACA,IAAA,EAAA,GACY;AAGZ,EAAA,MAAM,UAAA,EACJ,IAAA,CAAK,IAAA,CAAK,OAAA,EAAS,CAAC,EAAA,IAAM,+BAAA,EAAe,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAA,CAAE,EAAA,EAAI,IAAA;AAE/D,EAAA,MAAM,cAAA,EAAgB,CAAC,MAAA,EAAA,GAAgB;AAErC,IAAA,GAAA,CAAI,MAAA,CAAO,KAAA,IAAS,OAAA,EAAS;AAE3B,MAAA,GAAA,CAAI,MAAA,CAAO,WAAA,GAAc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,EAFE;AAAA,IAGL,SAAA;AAAA,IACA,aAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,EACF,CAAA,CAAA;AACF,CAAA;ADtFA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-FYN7ZWLW.cjs","sourcesContent":[null,"/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { VetoFormattedError, VetoInstance } from '@fuf-stack/veto';\nimport type { FieldError, FieldValues, Path } from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { flatArrayKey, nameToTestId, toValidationFormat } from '../../helpers';\n\n/** Schema check whether a field is required or optional */\nexport const checkFieldIsRequired = (\n validation: VetoInstance,\n path: string[],\n): boolean => {\n // Handle flat array paths: strip the flatArrayKey to check the array element schema\n // e.g., ['arrayField', '0', '__FLAT__'] -> check schema at ['arrayField', '0']\n const checkPath =\n path[path.length - 1] === flatArrayKey ? path.slice(0, -1) : path;\n\n const checkRequired = (schema: any) => {\n // arrays ...\n if (schema.type === 'array') {\n // ... if array is optional or nullable it is not required\n if (schema.isOptional || schema.isNullable) {\n return false;\n }\n // ... otherwise arrays are required (display logic wise -> no asterisk in the label)\n return true;\n }\n\n // all other fields are required if they are\n // not optional and not nullable\n return !schema.isOptional && !schema.isNullable;\n };\n\n return validation.checkSchemaPath(checkRequired, checkPath);\n};\n\n/**\n * Resolve validation errors for a given field path.\n *\n * Traverses a nested `VetoFormattedError` structure using a dotted path\n * (for example: \"user.address.0.street\") and returns the matching\n * `FieldError[]` if present. If no error exists at the path, returns\n * `undefined`.\n *\n * @param errors - The formatted validation errors from Uniform's context\n * @param name - The dotted field path to resolve\n * @returns An array of `FieldError` entries for the field, or `undefined`\n */\nconst getValidationErrorsByName = (\n errors: VetoFormattedError,\n name: string,\n) => {\n // Traverse nested error structure; ignore flat array wrapper key\n const keys = name.split('.').filter((k) => {\n return k !== flatArrayKey;\n });\n let current: unknown = errors as unknown;\n keys.forEach((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n } else {\n current = undefined;\n }\n });\n return current as FieldError[] | undefined;\n};\n\n/**\n * Custom hook that extends react-hook-form's useFormContext to add validation and state management.\n *\n * Key features:\n * - Enhanced `getFieldState` that includes validation schema-based \"required\" status and testId generation\n * - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:\n * - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)\n * - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)\n * - Filters out empty/null values\n */\nexport const useFormContext = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>() => {\n const {\n formState,\n // some methods that will be enhanced below\n getFieldState: getFieldStateOrig,\n getValues: getValuesOrig,\n watch: watchOrig,\n subscribe: subscribeOrig,\n // the rest of the methods pass through unchanged\n ...otherMethods\n } = useHookFormContext<TFieldValues, TContext, TTransformedValues>();\n\n const uniformContext = useContext(UniformContext);\n\n /**\n * Updated getFieldState method which returns:\n * - Whether the field is required by checking the validation schema\n * - Existing field state information (errors, etc.)\n * - A testId generated from the field name (with flat array keys removed and slugified)\n *\n * @param name - The field path (string or array)\n * @param testId - Optional explicit testId. If provided, will be slugified. If not provided, generated from name.\n */\n const getFieldState = (name: Path<TFieldValues>, testId?: string) => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n\n // Use base validation instance for checking \"required\" status\n // Client validation often uses .nullish() which would incorrectly mark fields as optional\n const validationInstance =\n uniformContext?.validation.baseInstance ??\n uniformContext?.validation.instance;\n\n // Check if the field is required using the validation schema\n const required = validationInstance\n ? checkFieldIsRequired(validationInstance, fieldPath)\n : false;\n\n const error = getValidationErrorsByName(\n uniformContext?.validation.errors ?? {},\n name,\n ) as unknown as FieldError[] | undefined;\n\n // Get everything but the error from the original field state\n const fieldState = getFieldStateOrig(name, formState);\n\n return {\n ...fieldState,\n error,\n invalid: !!error,\n required,\n testId: nameToTestId(testId ?? name),\n };\n };\n\n /**\n * Wrap form value accessor methods to automatically convert from internal storage format\n * to component-friendly format:\n *\n * - Unwrap flat array wrappers: `{ __FLAT__: value }` → `value`\n * - Convert nullish string markers: `__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`\n * - Filter out empty/null values: fields with converted null/empty values are removed entirely\n *\n * This ensures components receive clean, predictable data without needing to handle\n * the internal nullish string conversion system or flat array wrapping manually.\n */\n const getValues = ((...args: any[]) => {\n const result = (getValuesOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof getValuesOrig;\n\n const watch = ((...args: any[]) => {\n const result = (watchOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof watchOrig;\n\n const subscribe = ((...args: any[]) => {\n // For subscribe, we need to wrap the callback to convert the values property\n const [options] = args;\n if (options?.callback) {\n const originalCallback = options.callback;\n const wrappedOptions = {\n ...options,\n callback: (subscribeFormState: any) => {\n // Convert the values property if it exists\n const convertedFormState = {\n ...subscribeFormState,\n ...(subscribeFormState.values && {\n values: toValidationFormat(subscribeFormState.values),\n }),\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalCallback(convertedFormState);\n },\n };\n return subscribeOrig(wrappedOptions);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (subscribeOrig as any)(...args);\n }) as typeof subscribeOrig;\n\n return {\n ...otherMethods,\n ...uniformContext,\n formState,\n getFieldState,\n getValues,\n subscribe,\n watch,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-UUGUQGMX.cjs","../src/hooks/useFormContext/useFormContext.ts"],"names":["_a"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B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AAA,CAAA,EACtB,kBAAA,CAAA,EACC,kBAAA,CAAmB,OAAA,GAAU;AAAA,YAC/B,MAAA,EAAQ,kDAAA,kBAAmB,CAAmB,MAAM;AAAA,UACtD,CAAA,CAAA;AAGF,UAAA,OAAO,gBAAA,CAAiB,kBAAkB,CAAA;AAAA,QAC5C;AAAA,MACF,CAAA,CAAA;AACA,MAAA,OAAO,aAAA,CAAc,cAAc,CAAA;AAAA,IACrC;AAEA,IAAA,OAAQ,aAAA,CAAsB,GAAG,IAAI,CAAA;AAAA,EACvC,CAAA,CAAA;AAEA,EAAA,OAAO,6CAAA,8CAAA,8CAAA,CAAA,CAAA,EACF,YAAA,CAAA,EACA,cAAA,CAAA,EAFE;AAAA,IAGL,SAAA;AAAA,IACA,aAAA;AAAA,IACA,SAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,EACF,CAAA,CAAA;AACF,CAAA;ADtFA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-UUGUQGMX.cjs","sourcesContent":[null,"/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { VetoFormattedError, VetoInstance } from '@fuf-stack/veto';\nimport type { FieldError, FieldValues, Path } from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { flatArrayKey, nameToTestId, toValidationFormat } from '../../helpers';\n\n/** Schema check whether a field is required or optional */\nexport const checkFieldIsRequired = (\n validation: VetoInstance,\n path: string[],\n): boolean => {\n // Handle flat array paths: strip the flatArrayKey to check the array element schema\n // e.g., ['arrayField', '0', '__FLAT__'] -> check schema at ['arrayField', '0']\n const checkPath =\n path[path.length - 1] === flatArrayKey ? path.slice(0, -1) : path;\n\n const checkRequired = (schema: any) => {\n // arrays ...\n if (schema.type === 'array') {\n // ... if array is optional or nullable it is not required\n if (schema.isOptional || schema.isNullable) {\n return false;\n }\n // ... otherwise arrays are required (display logic wise -> no asterisk in the label)\n return true;\n }\n\n // all other fields are required if they are\n // not optional and not nullable\n return !schema.isOptional && !schema.isNullable;\n };\n\n return validation.checkSchemaPath(checkRequired, checkPath);\n};\n\n/**\n * Resolve validation errors for a given field path.\n *\n * Traverses a nested `VetoFormattedError` structure using a dotted path\n * (for example: \"user.address.0.street\") and returns the matching\n * `FieldError[]` if present. If no error exists at the path, returns\n * `undefined`.\n *\n * @param errors - The formatted validation errors from Uniform's context\n * @param name - The dotted field path to resolve\n * @returns An array of `FieldError` entries for the field, or `undefined`\n */\nconst getValidationErrorsByName = (\n errors: VetoFormattedError,\n name: string,\n) => {\n // Traverse nested error structure; ignore flat array wrapper key\n const keys = name.split('.').filter((k) => {\n return k !== flatArrayKey;\n });\n let current: unknown = errors as unknown;\n keys.forEach((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n } else {\n current = undefined;\n }\n });\n return current as FieldError[] | undefined;\n};\n\n/**\n * Custom hook that extends react-hook-form's useFormContext to add validation and state management.\n *\n * Key features:\n * - Enhanced `getFieldState` that includes validation schema-based \"required\" status and testId generation\n * - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:\n * - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)\n * - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)\n * - Filters out empty/null values\n */\nexport const useFormContext = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>() => {\n const {\n formState,\n // some methods that will be enhanced below\n getFieldState: getFieldStateOrig,\n getValues: getValuesOrig,\n watch: watchOrig,\n subscribe: subscribeOrig,\n // the rest of the methods pass through unchanged\n ...otherMethods\n } = useHookFormContext<TFieldValues, TContext, TTransformedValues>();\n\n const uniformContext = useContext(UniformContext);\n\n /**\n * Updated getFieldState method which returns:\n * - Whether the field is required by checking the validation schema\n * - Existing field state information (errors, etc.)\n * - A testId generated from the field name (with flat array keys removed and slugified)\n *\n * @param name - The field path (string or array)\n * @param testId - Optional explicit testId. If provided, will be slugified. If not provided, generated from name.\n */\n const getFieldState = (name: Path<TFieldValues>, testId?: string) => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n\n // Use base validation instance for checking \"required\" status\n // Client validation often uses .nullish() which would incorrectly mark fields as optional\n const validationInstance =\n uniformContext?.validation.baseInstance ??\n uniformContext?.validation.instance;\n\n // Check if the field is required using the validation schema\n const required = validationInstance\n ? checkFieldIsRequired(validationInstance, fieldPath)\n : false;\n\n const error = getValidationErrorsByName(\n uniformContext?.validation.errors ?? {},\n name,\n ) as unknown as FieldError[] | undefined;\n\n // Get everything but the error from the original field state\n const fieldState = getFieldStateOrig(name, formState);\n\n return {\n ...fieldState,\n error,\n invalid: !!error,\n required,\n testId: nameToTestId(testId ?? name),\n };\n };\n\n /**\n * Wrap form value accessor methods to automatically convert from internal storage format\n * to component-friendly format:\n *\n * - Unwrap flat array wrappers: `{ __FLAT__: value }` → `value`\n * - Convert nullish string markers: `__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`\n * - Filter out empty/null values: fields with converted null/empty values are removed entirely\n *\n * This ensures components receive clean, predictable data without needing to handle\n * the internal nullish string conversion system or flat array wrapping manually.\n */\n const getValues = ((...args: any[]) => {\n const result = (getValuesOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof getValuesOrig;\n\n const watch = ((...args: any[]) => {\n const result = (watchOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof watchOrig;\n\n const subscribe = ((...args: any[]) => {\n // For subscribe, we need to wrap the callback to convert the values property\n const [options] = args;\n if (options?.callback) {\n const originalCallback = options.callback;\n const wrappedOptions = {\n ...options,\n callback: (subscribeFormState: any) => {\n // Convert the values property if it exists\n const convertedFormState = {\n ...subscribeFormState,\n ...(subscribeFormState.values && {\n values: toValidationFormat(subscribeFormState.values),\n }),\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalCallback(convertedFormState);\n },\n };\n return subscribeOrig(wrappedOptions);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (subscribeOrig as any)(...args);\n }) as typeof subscribeOrig;\n\n return {\n ...otherMethods,\n ...uniformContext,\n formState,\n getFieldState,\n getValues,\n subscribe,\n watch,\n };\n};\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkYCCBMAN2cjs = require('./chunk-YCCBMAN2.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUUGUQGMXcjs = require('./chunk-UUGUQGMX.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -109,10 +109,10 @@ var Select = (_a) => {
|
|
|
109
109
|
label,
|
|
110
110
|
required,
|
|
111
111
|
testId
|
|
112
|
-
} =
|
|
112
|
+
} = _chunkYCCBMAN2cjs.useUniformField.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {
|
|
113
113
|
name
|
|
114
114
|
}, uniformFieldProps));
|
|
115
|
-
const { getFieldState } =
|
|
115
|
+
const { getFieldState } = _chunkUUGUQGMXcjs.useFormContext.call(void 0, );
|
|
116
116
|
const [isFocused, setIsFocused] = _react.useState.call(void 0, false);
|
|
117
117
|
const variants = selectVariants();
|
|
118
118
|
const classNames = _pixelutils.variantsToClassNames.call(void 0, variants, className, "base");
|
|
@@ -287,4 +287,4 @@ var Select_default2 = Select_default;
|
|
|
287
287
|
|
|
288
288
|
|
|
289
289
|
exports.Select_default = Select_default; exports.Select_default2 = Select_default2;
|
|
290
|
-
//# sourceMappingURL=chunk-
|
|
290
|
+
//# sourceMappingURL=chunk-V65AMUKK.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-H2PPUEUO.cjs","../src/Select/Select.tsx","../src/Select/index.ts"],"names":["_a","Select_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACTA,8BAAyB;AACzB,qGAAwC;AAExC,wCAA0B;AAE1B,oDAAsD;AAgG7C,+CAAA;AA5FF,IAAM,eAAA,EAAiB,4BAAA;AAAG,EAC/B,KAAA,EAAO;AAAA,IACL,IAAA,EAAM,sBAAA;AAAA,IACN,cAAA,EACE,wGAAA;AAAA,IACF,OAAA,EACE,qOAAA;AAAA,IACF,eAAA,EAAiB,cAAA;AAAA,IACjB,SAAA,EAAW,EAAA;AAAA,IACX,WAAA,EAAa,EAAA;AAAA,IACb,iBAAA,EACE,+FAAA;AAAA,IACF,KAAA,EAAO,EAAA;AAAA,IACP,YAAA,EAAc,4CAAA;AAAA,IACd,mBAAA,EAAqB,WAAA;AAAA,IACrB,kBAAA,EAAoB,gBAAA;AAAA,IACpB,KAAA,EAAO,aAAA;AAAA;AAAA;AAAA,IAGP,KAAA,EACE,yPAAA;AAAA,IACF,gBAAA,EAAkB,EAAA;AAAA,IAClB,cAAA,EAAgB,oCAAA;AAAA,IAChB,IAAA,EAAM,qEAAA;AAAA,IACN,QAAA,EAAU,EAAA;AAAA;AAAA;AAAA,IAGV,UAAA,EAAY,OAAA;AAAA,IACZ,UAAA,EAAY,8DAAA;AAAA,IACZ,mBAAA,EAAqB,EAAA;AAAA,IACrB,eAAA,EAAiB,kBAAA;AAAA,IACjB,gBAAA,EACE,+FAAA;AAAA,IACF,gBAAA,EAAkB,oCAAA;AAAA,IAClB,cAAA,EAAgB,sCAAA;AAAA,IAChB,eAAA,EAAiB,gBAAA;AAAA,IACjB,MAAA,EAAQ,wCAAA;AAAA,IACR,WAAA,EAAa,8CAAA;AAAA,IACb,eAAA,EAAiB,EAAA;AAAA,I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AA;AAEA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AAIA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACE,cAAA;AACE,gBAAA;AACE,kBAAA;AACD,gBAAA;AACH,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACE,kBAAA;AACA,kBAAA;AACF,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACA,gBAAA;AACF,cAAA;AACE,gBAAA;AACE,kBAAA;AACA,kBAAA;AACD,gBAAA;AACH,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACA,cAAA;AACA,cAAA;AACA,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACA,cAAA;AACF,YAAA;AACA,YAAA;AACM,cAAA;AACF,gBAAA;AACG,kBAAA;AACC,oBAAA;AACF,kBAAA;AACF,gBAAA;AACF,cAAA;AACE,gBAAA;AACF,cAAA;AAKA,cAAA;AACI,cAAA;AACF,gBAAA;AACF,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACF,YAAA;AAEA,YAAA;AACE,cAAA;AACD,YAAA;AAAA,UAAA;AACH,QAAA;AAEE,QAAA;AAGE,MAAA;AAAA,IAAA;AACN,EAAA;AAEJ;AAEO;ADhFW;AACA;AEpRXC;AFsRW;AACA;AACA;AACA;AACA","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-H2PPUEUO.cjs","sourcesContent":[null,"import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { Props } from 'react-select';\n\nimport { useState } from 'react';\nimport ReactSelect, { components } from 'react-select';\n\nimport { useSelect } from '@heroui/select';\n\nimport { cn, slugify, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext, useUniformField } from '../hooks';\n\nexport const selectVariants = tv({\n slots: {\n base: 'group leading-normal',\n clearIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-foreground-800',\n control:\n 'duration-150! rounded-lg border-2 border-default-200 bg-content1 transition-background hover:border-default-400 group-data-[invalid=true]:border-danger group-data-[invalid=true]:hover:border-danger motion-reduce:transition-none',\n control_focused: 'border-focus',\n crossIcon: '',\n downChevron: '',\n dropdownIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-black',\n group: '',\n groupHeading: 'mb-1 ml-3 mt-2 text-sm text-foreground-500',\n indicatorsContainer: 'gap-1 p-1',\n indicatorSeparator: 'bg-default-300',\n input: 'py-0.5 pl-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 'pointer-events-auto relative bottom-1.5 ml-1 subpixel-antialiased text-small 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 loadingIndicator: '',\n loadingMessage: 'rounded-sm p-2 text-foreground-500',\n menu: 'mt-2 rounded-xl border border-default-200 bg-content1 p-1 shadow-lg',\n menuList: '',\n // ensure menu has same z-index as modal so it is visible when rendered in modal\n // see: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/modal.ts (see z-50)\n menuPortal: 'z-50!',\n multiValue: 'items-center gap-1.5 rounded bg-default-100 py-0.5 pl-2 pr-1',\n multiValueContainer: '',\n multiValueLabel: 'py-0.5 leading-6',\n multiValueRemove:\n 'rounded text-default-500 hover:cursor-pointer hover:border-default-300 hover:text-default-800',\n noOptionsMessage: 'rounded-sm p-2 text-foreground-500',\n option_focused: 'bg-default-100 active:bg-default-200',\n option_selected: 'bg-default-300',\n option: 'rounded px-3 py-2 hover:cursor-pointer',\n placeholder: 'ml-1 py-0.5 pl-1 text-sm text-foreground-500',\n selectContainer: '',\n singleValue: 'ml-1! leading-7!',\n valueContainer: 'gap-1 p-1',\n },\n});\n\ninterface SelectOption {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n}\n\ntype VariantProps = TVProps<typeof selectVariants>;\ntype ClassName = TVClassName<typeof selectVariants>;\n\nexport interface SelectProps extends VariantProps {\n /** CSS class name */\n className?: ClassName; // string;\n /** Determine if the */\n clearable?: boolean;\n /** Set the select to disabled state. */\n disabled?: boolean;\n /** Filter Select Options */\n filterOption?:\n | undefined\n | ((option?: SelectOption, inputValue?: string) => boolean);\n /** Format the label of the option */\n renderOptionLabel?: undefined | Props['formatOptionLabel'];\n /** The value of the search input */\n inputValue?: string;\n /** Label that should be associated with the select. */\n label?: React.ReactNode;\n /** Set the select to a loading state. */\n loading?: boolean;\n /** switch between single and multi select mode. */\n multiSelect?: boolean;\n /** The name for the Select component, used by react-hook-form */\n name: string;\n /** Placeholder that is displayed when nothing is selected */\n placeholder?: string;\n /** The options for the Select component */\n options: SelectOption[];\n /** Handle change events on the input */\n onInputChange?: Props['onInputChange'];\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\nconst InputComponent: typeof components.Input = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}`;\n\n return <components.Input data-testid={testId} {...props} />;\n};\n\nconst ControlComponent: typeof components.Control = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_select`;\n return (\n <div data-testid={testId}>\n {}\n <components.Control {...props} />\n </div>\n );\n};\n\nconst OptionComponent: typeof components.Option = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_select_option_${slugify(props?.data?.testId ?? props?.data?.value, { replaceDots: true })}`;\n return (\n <div data-testid={testId}>\n {}\n <components.Option {...props} />\n </div>\n );\n};\n\nconst DropdownIndicatorComponent: typeof components.DropdownIndicator = (\n props,\n) => {\n // @ts-expect-error data-testid is not a default prop\n\n const testId = props?.selectProps['data-testid'] as string;\n return (\n <div data-testid={`${testId}_select_dropdown`}>\n {}\n <components.DropdownIndicator {...props} />\n </div>\n );\n};\n\n/** Select component based on [HeroUI Select](https://www.heroui.com//docs/components/select) and [React-Select](https://react-select.com/home) */\nconst Select = ({\n className = undefined,\n clearable = true,\n filterOption = undefined,\n renderOptionLabel = undefined,\n inputValue = undefined,\n loading = false,\n multiSelect = false,\n name,\n onInputChange = undefined,\n options,\n placeholder = undefined,\n ...uniformFieldProps\n}: SelectProps) => {\n const {\n disabled,\n errorMessage,\n field: { onBlur, onChange, ref, value },\n getErrorMessageProps,\n getHelperWrapperProps,\n getLabelProps,\n invalid,\n label,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Get getFieldState to check isTouched in onChange callback\n const { getFieldState } = useFormContext();\n\n // Track if the select is focused\n const [isFocused, setIsFocused] = useState(false);\n\n // classNames from slots\n const variants = selectVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n const { getBaseProps, getTriggerProps, getValueProps } = useSelect({\n children: [],\n classNames,\n errorMessage,\n isDisabled: disabled,\n isInvalid: invalid,\n isLoading: loading,\n isRequired: required,\n label,\n labelPlacement: 'outside',\n });\n\n return (\n <div\n {...getBaseProps()}\n className={cn(classNames.base)}\n // see HeroUI styles for group-data condition (data-invalid),\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/components/select/src/use-select.ts\n data-required={required}\n data-testid={`${testId}_wrapper`}\n >\n {label ? (\n <label\n className={classNames.label}\n data-slot=\"label\"\n htmlFor={`react-select-${name}-input`}\n id={getLabelProps().id}\n >\n {label}\n </label>\n ) : null}\n <ReactSelect\n ref={ref}\n menuShouldBlockScroll\n unstyled\n aria-errormessage=\"\"\n aria-invalid={invalid}\n aria-labelledby={getTriggerProps()['aria-labelledby']?.split(' ')[1]}\n // Does not affect the testId of the select, but is needed to pass it to sub-components\n data-testid={testId}\n filterOption={filterOption}\n formatOptionLabel={renderOptionLabel}\n inputValue={inputValue}\n instanceId={name}\n isClearable={clearable}\n isDisabled={disabled}\n isLoading={loading}\n isMulti={multiSelect}\n // set menuPosition to fixed so that menu can be rendered\n // inside Card / Modal components, menuShouldBlockScroll\n // prevents container scroll when menu is open\n menuPosition=\"fixed\"\n name={name}\n onInputChange={onInputChange}\n options={options}\n placeholder={placeholder}\n classNames={{\n control: () => {\n return cn(classNames.control, {\n [classNames.control_focused]: isFocused && !invalid,\n });\n },\n clearIndicator: () => {\n return classNames.clearIndicator;\n },\n dropdownIndicator: () => {\n return classNames.dropdownIndicator;\n },\n groupHeading: () => {\n return classNames.groupHeading;\n },\n indicatorsContainer: () => {\n return classNames.indicatorsContainer;\n },\n indicatorSeparator: () => {\n return classNames.indicatorSeparator;\n },\n loadingIndicator: () => {\n return classNames.loadingIndicator;\n },\n loadingMessage: () => {\n return classNames.loadingMessage;\n },\n input: () => {\n return classNames.input;\n },\n menu: () => {\n return classNames.menu;\n },\n menuList: () => {\n return classNames.menuList;\n },\n menuPortal: () => {\n return classNames.menuPortal;\n },\n multiValue: () => {\n return classNames.multiValue;\n },\n multiValueLabel: () => {\n return cn(\n classNames.multiValueLabel,\n `${getValueProps().className}`,\n );\n },\n multiValueRemove: () => {\n return classNames.multiValueRemove;\n },\n noOptionsMessage: () => {\n return classNames.noOptionsMessage;\n },\n option: ({\n isFocused: optionIsFocused,\n isSelected: optionIsSelected,\n }) => {\n return cn(classNames.option, {\n [classNames.option_focused]: optionIsFocused,\n [classNames.option_selected]: optionIsSelected,\n });\n },\n placeholder: () => {\n return classNames.placeholder;\n },\n singleValue: () => {\n return cn(classNames.singleValue, `${getValueProps().className}`);\n },\n valueContainer: () => {\n return classNames.valueContainer;\n },\n }}\n components={{\n Input: InputComponent,\n Option: OptionComponent,\n DropdownIndicator: DropdownIndicatorComponent,\n Control: ControlComponent,\n }}\n onBlur={(_e) => {\n setIsFocused(false);\n onBlur();\n }}\n onChange={(option) => {\n if (multiSelect) {\n onChange(\n (option as SelectOption[])?.map((_option) => {\n return _option.value;\n }),\n );\n } else {\n onChange((option as SelectOption)?.value);\n }\n // Mark field as touched immediately when a selection is made if not already touched\n // This ensures validation errors show right away (isTouched becomes true)\n // For Select components, selecting an option is a complete user action\n // (unlike text inputs where typing is ongoing), so we mark as touched immediately\n const { isTouched: currentIsTouched } = getFieldState(name, testId);\n if (!currentIsTouched) {\n onBlur();\n }\n }}\n onFocus={(_e) => {\n setIsFocused(true);\n }}\n // set complete option as value by current field value\n value={options.find((option) => {\n return option.value === value;\n })}\n />\n {invalid ? (\n <div {...getHelperWrapperProps()}>\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </div>\n );\n};\n\nexport default Select;\n","import Select from './Select';\n\nexport type { SelectProps } from './Select';\n\nexport { Select };\n\nexport default Select;\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-V65AMUKK.cjs","../src/Select/Select.tsx","../src/Select/index.ts"],"names":["_a","Select_default"],"mappings":"AAAA;AACE;AACF,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;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA;AACE,cAAA;AACE,gBAAA;AACE,kBAAA;AACD,gBAAA;AACH,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACE,kBAAA;AACA,kBAAA;AACF,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACA,gBAAA;AACF,cAAA;AACE,gBAAA;AACE,kBAAA;AACA,kBAAA;AACD,gBAAA;AACH,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACA,cAAA;AACE,gBAAA;AACF,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACA,cAAA;AACA,cAAA;AACA,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACA,cAAA;AACF,YAAA;AACA,YAAA;AACM,cAAA;AACF,gBAAA;AACG,kBAAA;AACC,oBAAA;AACF,kBAAA;AACF,gBAAA;AACF,cAAA;AACE,gBAAA;AACF,cAAA;AAKA,cAAA;AACI,cAAA;AACF,gBAAA;AACF,cAAA;AACF,YAAA;AACA,YAAA;AACE,cAAA;AACF,YAAA;AAEA,YAAA;AACE,cAAA;AACD,YAAA;AAAA,UAAA;AACH,QAAA;AAEE,QAAA;AAGE,MAAA;AAAA,IAAA;AACN,EAAA;AAEJ;AAEO;ADhFW;AACA;AEpRXC;AFsRW;AACA;AACA;AACA;AACA","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-V65AMUKK.cjs","sourcesContent":[null,"import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { Props } from 'react-select';\n\nimport { useState } from 'react';\nimport ReactSelect, { components } from 'react-select';\n\nimport { useSelect } from '@heroui/select';\n\nimport { cn, slugify, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext, useUniformField } from '../hooks';\n\nexport const selectVariants = tv({\n slots: {\n base: 'group leading-normal',\n clearIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-foreground-800',\n control:\n 'duration-150! rounded-lg border-2 border-default-200 bg-content1 transition-background hover:border-default-400 group-data-[invalid=true]:border-danger group-data-[invalid=true]:hover:border-danger motion-reduce:transition-none',\n control_focused: 'border-focus',\n crossIcon: '',\n downChevron: '',\n dropdownIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-black',\n group: '',\n groupHeading: 'mb-1 ml-3 mt-2 text-sm text-foreground-500',\n indicatorsContainer: 'gap-1 p-1',\n indicatorSeparator: 'bg-default-300',\n input: 'py-0.5 pl-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 'pointer-events-auto relative bottom-1.5 ml-1 subpixel-antialiased text-small 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 loadingIndicator: '',\n loadingMessage: 'rounded-sm p-2 text-foreground-500',\n menu: 'mt-2 rounded-xl border border-default-200 bg-content1 p-1 shadow-lg',\n menuList: '',\n // ensure menu has same z-index as modal so it is visible when rendered in modal\n // see: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/modal.ts (see z-50)\n menuPortal: 'z-50!',\n multiValue: 'items-center gap-1.5 rounded bg-default-100 py-0.5 pl-2 pr-1',\n multiValueContainer: '',\n multiValueLabel: 'py-0.5 leading-6',\n multiValueRemove:\n 'rounded text-default-500 hover:cursor-pointer hover:border-default-300 hover:text-default-800',\n noOptionsMessage: 'rounded-sm p-2 text-foreground-500',\n option_focused: 'bg-default-100 active:bg-default-200',\n option_selected: 'bg-default-300',\n option: 'rounded px-3 py-2 hover:cursor-pointer',\n placeholder: 'ml-1 py-0.5 pl-1 text-sm text-foreground-500',\n selectContainer: '',\n singleValue: 'ml-1! leading-7!',\n valueContainer: 'gap-1 p-1',\n },\n});\n\ninterface SelectOption {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n}\n\ntype VariantProps = TVProps<typeof selectVariants>;\ntype ClassName = TVClassName<typeof selectVariants>;\n\nexport interface SelectProps extends VariantProps {\n /** CSS class name */\n className?: ClassName; // string;\n /** Determine if the */\n clearable?: boolean;\n /** Set the select to disabled state. */\n disabled?: boolean;\n /** Filter Select Options */\n filterOption?:\n | undefined\n | ((option?: SelectOption, inputValue?: string) => boolean);\n /** Format the label of the option */\n renderOptionLabel?: undefined | Props['formatOptionLabel'];\n /** The value of the search input */\n inputValue?: string;\n /** Label that should be associated with the select. */\n label?: React.ReactNode;\n /** Set the select to a loading state. */\n loading?: boolean;\n /** switch between single and multi select mode. */\n multiSelect?: boolean;\n /** The name for the Select component, used by react-hook-form */\n name: string;\n /** Placeholder that is displayed when nothing is selected */\n placeholder?: string;\n /** The options for the Select component */\n options: SelectOption[];\n /** Handle change events on the input */\n onInputChange?: Props['onInputChange'];\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\nconst InputComponent: typeof components.Input = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}`;\n\n return <components.Input data-testid={testId} {...props} />;\n};\n\nconst ControlComponent: typeof components.Control = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_select`;\n return (\n <div data-testid={testId}>\n {}\n <components.Control {...props} />\n </div>\n );\n};\n\nconst OptionComponent: typeof components.Option = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_select_option_${slugify(props?.data?.testId ?? props?.data?.value, { replaceDots: true })}`;\n return (\n <div data-testid={testId}>\n {}\n <components.Option {...props} />\n </div>\n );\n};\n\nconst DropdownIndicatorComponent: typeof components.DropdownIndicator = (\n props,\n) => {\n // @ts-expect-error data-testid is not a default prop\n\n const testId = props?.selectProps['data-testid'] as string;\n return (\n <div data-testid={`${testId}_select_dropdown`}>\n {}\n <components.DropdownIndicator {...props} />\n </div>\n );\n};\n\n/** Select component based on [HeroUI Select](https://www.heroui.com//docs/components/select) and [React-Select](https://react-select.com/home) */\nconst Select = ({\n className = undefined,\n clearable = true,\n filterOption = undefined,\n renderOptionLabel = undefined,\n inputValue = undefined,\n loading = false,\n multiSelect = false,\n name,\n onInputChange = undefined,\n options,\n placeholder = undefined,\n ...uniformFieldProps\n}: SelectProps) => {\n const {\n disabled,\n errorMessage,\n field: { onBlur, onChange, ref, value },\n getErrorMessageProps,\n getHelperWrapperProps,\n getLabelProps,\n invalid,\n label,\n required,\n testId,\n } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n // Get getFieldState to check isTouched in onChange callback\n const { getFieldState } = useFormContext();\n\n // Track if the select is focused\n const [isFocused, setIsFocused] = useState(false);\n\n // classNames from slots\n const variants = selectVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n const { getBaseProps, getTriggerProps, getValueProps } = useSelect({\n children: [],\n classNames,\n errorMessage,\n isDisabled: disabled,\n isInvalid: invalid,\n isLoading: loading,\n isRequired: required,\n label,\n labelPlacement: 'outside',\n });\n\n return (\n <div\n {...getBaseProps()}\n className={cn(classNames.base)}\n // see HeroUI styles for group-data condition (data-invalid),\n // e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/components/select/src/use-select.ts\n data-required={required}\n data-testid={`${testId}_wrapper`}\n >\n {label ? (\n <label\n className={classNames.label}\n data-slot=\"label\"\n htmlFor={`react-select-${name}-input`}\n id={getLabelProps().id}\n >\n {label}\n </label>\n ) : null}\n <ReactSelect\n ref={ref}\n menuShouldBlockScroll\n unstyled\n aria-errormessage=\"\"\n aria-invalid={invalid}\n aria-labelledby={getTriggerProps()['aria-labelledby']?.split(' ')[1]}\n // Does not affect the testId of the select, but is needed to pass it to sub-components\n data-testid={testId}\n filterOption={filterOption}\n formatOptionLabel={renderOptionLabel}\n inputValue={inputValue}\n instanceId={name}\n isClearable={clearable}\n isDisabled={disabled}\n isLoading={loading}\n isMulti={multiSelect}\n // set menuPosition to fixed so that menu can be rendered\n // inside Card / Modal components, menuShouldBlockScroll\n // prevents container scroll when menu is open\n menuPosition=\"fixed\"\n name={name}\n onInputChange={onInputChange}\n options={options}\n placeholder={placeholder}\n classNames={{\n control: () => {\n return cn(classNames.control, {\n [classNames.control_focused]: isFocused && !invalid,\n });\n },\n clearIndicator: () => {\n return classNames.clearIndicator;\n },\n dropdownIndicator: () => {\n return classNames.dropdownIndicator;\n },\n groupHeading: () => {\n return classNames.groupHeading;\n },\n indicatorsContainer: () => {\n return classNames.indicatorsContainer;\n },\n indicatorSeparator: () => {\n return classNames.indicatorSeparator;\n },\n loadingIndicator: () => {\n return classNames.loadingIndicator;\n },\n loadingMessage: () => {\n return classNames.loadingMessage;\n },\n input: () => {\n return classNames.input;\n },\n menu: () => {\n return classNames.menu;\n },\n menuList: () => {\n return classNames.menuList;\n },\n menuPortal: () => {\n return classNames.menuPortal;\n },\n multiValue: () => {\n return classNames.multiValue;\n },\n multiValueLabel: () => {\n return cn(\n classNames.multiValueLabel,\n `${getValueProps().className}`,\n );\n },\n multiValueRemove: () => {\n return classNames.multiValueRemove;\n },\n noOptionsMessage: () => {\n return classNames.noOptionsMessage;\n },\n option: ({\n isFocused: optionIsFocused,\n isSelected: optionIsSelected,\n }) => {\n return cn(classNames.option, {\n [classNames.option_focused]: optionIsFocused,\n [classNames.option_selected]: optionIsSelected,\n });\n },\n placeholder: () => {\n return classNames.placeholder;\n },\n singleValue: () => {\n return cn(classNames.singleValue, `${getValueProps().className}`);\n },\n valueContainer: () => {\n return classNames.valueContainer;\n },\n }}\n components={{\n Input: InputComponent,\n Option: OptionComponent,\n DropdownIndicator: DropdownIndicatorComponent,\n Control: ControlComponent,\n }}\n onBlur={(_e) => {\n setIsFocused(false);\n onBlur();\n }}\n onChange={(option) => {\n if (multiSelect) {\n onChange(\n (option as SelectOption[])?.map((_option) => {\n return _option.value;\n }),\n );\n } else {\n onChange((option as SelectOption)?.value);\n }\n // Mark field as touched immediately when a selection is made if not already touched\n // This ensures validation errors show right away (isTouched becomes true)\n // For Select components, selecting an option is a complete user action\n // (unlike text inputs where typing is ongoing), so we mark as touched immediately\n const { isTouched: currentIsTouched } = getFieldState(name, testId);\n if (!currentIsTouched) {\n onBlur();\n }\n }}\n onFocus={(_e) => {\n setIsFocused(true);\n }}\n // set complete option as value by current field value\n value={options.find((option) => {\n return option.value === value;\n })}\n />\n {invalid ? (\n <div {...getHelperWrapperProps()}>\n <div {...getErrorMessageProps()}>{errorMessage}</div>\n </div>\n ) : null}\n </div>\n );\n};\n\nexport default Select;\n","import Select from './Select';\n\nexport type { SelectProps } from './Select';\n\nexport { Select };\n\nexport default Select;\n"]}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkYCCBMAN2cjs = require('./chunk-YCCBMAN2.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk555JRYCScjs = require('./chunk-555JRYCS.cjs');
|
|
9
|
+
|
|
10
|
+
// src/Switch/Switch.tsx
|
|
11
|
+
var _react = require('react');
|
|
12
|
+
var _switch = require('@heroui/switch');
|
|
13
|
+
var _visuallyhidden = require('@react-aria/visually-hidden');
|
|
14
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
15
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
16
|
+
var switchVariants = _pixelutils.tv.call(void 0, {
|
|
17
|
+
slots: {
|
|
18
|
+
base: "",
|
|
19
|
+
endContent: "",
|
|
20
|
+
errorMessage: "ml-1 mt-1",
|
|
21
|
+
// see HeroUI styles for group-data condition,
|
|
22
|
+
// e.g.: https://github.com/heroui-inc/heroui/blob/main/packages/core/theme/src/components/select.ts
|
|
23
|
+
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-["*"]',
|
|
24
|
+
outerWrapper: "place-content-center",
|
|
25
|
+
startContent: "",
|
|
26
|
+
thumb: "",
|
|
27
|
+
thumbIcon: "",
|
|
28
|
+
wrapper: ""
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var Switch = (_a) => {
|
|
32
|
+
var _b = _a, {
|
|
33
|
+
className = void 0,
|
|
34
|
+
endContent = void 0,
|
|
35
|
+
name,
|
|
36
|
+
size = void 0,
|
|
37
|
+
startContent = void 0,
|
|
38
|
+
thumbIcon = void 0
|
|
39
|
+
} = _b, uniformFieldProps = _chunk555JRYCScjs.__objRest.call(void 0, _b, [
|
|
40
|
+
"className",
|
|
41
|
+
"endContent",
|
|
42
|
+
"name",
|
|
43
|
+
"size",
|
|
44
|
+
"startContent",
|
|
45
|
+
"thumbIcon"
|
|
46
|
+
]);
|
|
47
|
+
var _a2;
|
|
48
|
+
const {
|
|
49
|
+
defaultValue,
|
|
50
|
+
disabled,
|
|
51
|
+
errorMessage,
|
|
52
|
+
field,
|
|
53
|
+
getErrorMessageProps,
|
|
54
|
+
getHelperWrapperProps,
|
|
55
|
+
invalid,
|
|
56
|
+
label,
|
|
57
|
+
onBlur,
|
|
58
|
+
onChange,
|
|
59
|
+
ref,
|
|
60
|
+
required,
|
|
61
|
+
testId
|
|
62
|
+
} = _chunkYCCBMAN2cjs.useUniformField.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {
|
|
63
|
+
name
|
|
64
|
+
}, uniformFieldProps));
|
|
65
|
+
const visualSwitchRef = _react.useRef.call(void 0, null);
|
|
66
|
+
const variants = switchVariants();
|
|
67
|
+
const classNames = _pixelutils.variantsToClassNames.call(void 0, variants, className, "outerWrapper");
|
|
68
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: classNames.outerWrapper, children: [
|
|
69
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _visuallyhidden.VisuallyHidden, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
70
|
+
"input",
|
|
71
|
+
{
|
|
72
|
+
ref,
|
|
73
|
+
"aria-label": typeof label === "string" ? label : name,
|
|
74
|
+
checked: !!field.value,
|
|
75
|
+
name,
|
|
76
|
+
onBlur,
|
|
77
|
+
type: "checkbox",
|
|
78
|
+
onChange: (e) => {
|
|
79
|
+
onChange(e.target.checked);
|
|
80
|
+
},
|
|
81
|
+
onFocus: () => {
|
|
82
|
+
var _a3;
|
|
83
|
+
(_a3 = visualSwitchRef.current) == null ? void 0 : _a3.focus();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
) }),
|
|
87
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
88
|
+
_switch.Switch,
|
|
89
|
+
{
|
|
90
|
+
ref: visualSwitchRef,
|
|
91
|
+
classNames,
|
|
92
|
+
"data-invalid": invalid,
|
|
93
|
+
"data-required": required,
|
|
94
|
+
"data-testid": testId,
|
|
95
|
+
defaultSelected: !!defaultValue,
|
|
96
|
+
endContent,
|
|
97
|
+
isDisabled: disabled,
|
|
98
|
+
isSelected: !!field.value,
|
|
99
|
+
name: `${name}_switch`,
|
|
100
|
+
onValueChange: onChange,
|
|
101
|
+
size,
|
|
102
|
+
startContent,
|
|
103
|
+
thumbIcon,
|
|
104
|
+
children: label
|
|
105
|
+
}
|
|
106
|
+
),
|
|
107
|
+
invalid ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
108
|
+
"div",
|
|
109
|
+
_chunk555JRYCScjs.__spreadProps.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {}, getHelperWrapperProps()), {
|
|
110
|
+
className: _pixelutils.cn.call(void 0,
|
|
111
|
+
(_a2 = getHelperWrapperProps()) == null ? void 0 : _a2.className,
|
|
112
|
+
// force helper to be visible (for some reason it's hidden by default) and remove margin
|
|
113
|
+
"ml-0 block"
|
|
114
|
+
),
|
|
115
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", _chunk555JRYCScjs.__spreadProps.call(void 0, _chunk555JRYCScjs.__spreadValues.call(void 0, {}, getErrorMessageProps()), { children: errorMessage }))
|
|
116
|
+
})
|
|
117
|
+
) : null
|
|
118
|
+
] });
|
|
119
|
+
};
|
|
120
|
+
var Switch_default = Switch;
|
|
121
|
+
|
|
122
|
+
// src/Switch/index.ts
|
|
123
|
+
var Switch_default2 = Switch_default;
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
exports.Switch_default = Switch_default; exports.Switch_default2 = Switch_default2;
|
|
129
|
+
//# sourceMappingURL=chunk-VIV3MSIX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-VIV3MSIX.cjs","../src/Switch/Switch.tsx","../src/Switch/index.ts"],"names":["_a","Switch_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,8BAAuB;AAEvB,wCAAqC;AACrC,6DAA+B;AAE/B,oDAA6C;AAoFzC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A,QACpB,IAAA,EAAM,CAAA,EAAA;AACN,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AAEC,QAAA;AAAA,MAAA;AACH,IAAA;AAEE,IAAA;AAAC,MAAA;AAAA,MAAA;AAEC,QAAA;AACEA,UAAAA;AAAyB;AAEzB,UAAA;AACF,QAAA;AAEA,QAAA;AAA+C,MAAA;AAE/C,IAAA;AACN,EAAA;AAEJ;AAEO;AD5BQ;AACA;AEnHRC;AFqHQ;AACA;AACA;AACA;AACA","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-VIV3MSIX.cjs","sourcesContent":[null,"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';\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 /** 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 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={typeof label === 'string' ? label : name}\n checked={!!field.value}\n name={name}\n onBlur={onBlur}\n type=\"checkbox\"\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 />\n </VisuallyHidden>\n {/* Visual HeroSwitch component */}\n <HeroSwitch\n ref={visualSwitchRef}\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 { Switch };\n\nexport default Switch;\n"]}
|