@fuf-stack/uniform 1.8.10 → 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 +8 -8
- package/dist/Checkboxes/index.js +7 -7
- package/dist/FieldArray/index.cjs +8 -8
- package/dist/FieldArray/index.js +7 -7
- package/dist/Form/index.cjs +6 -6
- package/dist/Form/index.js +6 -6
- package/dist/Input/index.cjs +8 -8
- package/dist/Input/index.js +7 -7
- 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 +10 -8
- 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 +11 -9
- package/dist/RadioTabs/index.cjs +8 -8
- package/dist/RadioTabs/index.d.cts +2 -2
- package/dist/RadioTabs/index.d.ts +2 -2
- package/dist/RadioTabs/index.js +7 -7
- 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 +8 -8
- package/dist/Radios/index.js +7 -7
- package/dist/Select/index.cjs +8 -8
- package/dist/Select/index.js +7 -7
- 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 +6 -6
- package/dist/SubmitButton/index.js +6 -6
- package/dist/Switch/index.cjs +8 -8
- package/dist/Switch/index.d.cts +2 -2
- package/dist/Switch/index.d.ts +2 -2
- package/dist/Switch/index.js +7 -7
- 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 +8 -8
- package/dist/TextArea/index.js +7 -7
- package/dist/{chunk-EFZXZNJO.js → chunk-246OISWB.js} +2 -2
- package/dist/chunk-2OXNDD5W.cjs +162 -0
- package/dist/chunk-2OXNDD5W.cjs.map +1 -0
- package/dist/{chunk-BIC7IWER.js → chunk-7FOSZV75.js} +4 -4
- package/dist/{chunk-6AQ5R4U4.cjs → chunk-7O6LAGV2.cjs} +6 -6
- package/dist/{chunk-6AQ5R4U4.cjs.map → chunk-7O6LAGV2.cjs.map} +1 -1
- package/dist/{chunk-DUYZ7WW3.cjs → chunk-7WKVH43M.cjs} +78 -46
- package/dist/chunk-7WKVH43M.cjs.map +1 -0
- package/dist/{chunk-7WHL6K5T.js → chunk-CEVS6WSG.js} +2 -2
- package/dist/{chunk-R5AOS4DQ.js → chunk-CG7GDQAP.js} +2 -2
- package/dist/{chunk-QE4J4AMH.js → chunk-DQAZSXD6.js} +2 -2
- package/dist/chunk-FUMQULCR.cjs +215 -0
- package/dist/chunk-FUMQULCR.cjs.map +1 -0
- package/dist/{chunk-NG2KM4CA.cjs → chunk-IU4RL2D7.cjs} +3 -3
- package/dist/{chunk-NG2KM4CA.cjs.map → chunk-IU4RL2D7.cjs.map} +1 -1
- package/dist/{chunk-OTFX4BWZ.js → chunk-IZZTVGEW.js} +78 -46
- package/dist/chunk-IZZTVGEW.js.map +1 -0
- package/dist/{chunk-GRQVGEYI.js → chunk-JICFOKDO.js} +2 -2
- package/dist/{chunk-MEIT57H2.cjs → chunk-LTE7PW7F.cjs} +3 -3
- package/dist/{chunk-MEIT57H2.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-OYDNTOOU.cjs → chunk-MEYGGRBQ.cjs} +3 -3
- package/dist/{chunk-OYDNTOOU.cjs.map → chunk-MEYGGRBQ.cjs.map} +1 -1
- package/dist/{chunk-2UHJBGKV.js → chunk-MHQ2V7UW.js} +2 -2
- package/dist/{chunk-WWSJQUTT.cjs → chunk-SR76XJW4.cjs} +3 -3
- package/dist/{chunk-WWSJQUTT.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-UUGSI3FD.js +215 -0
- package/dist/chunk-UUGSI3FD.js.map +1 -0
- package/dist/{chunk-PFFTE4NW.cjs → chunk-V65AMUKK.cjs} +3 -3
- package/dist/{chunk-PFFTE4NW.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-XBVXMQBW.js +217 -0
- package/dist/chunk-XBVXMQBW.js.map +1 -0
- package/dist/{chunk-37RM7TVP.cjs → chunk-XC3C2W4M.cjs} +3 -3
- package/dist/{chunk-37RM7TVP.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-TN7OSO3T.js → chunk-XXLYUZY4.js} +3 -3
- package/dist/{chunk-ZNX2PT6C.cjs → chunk-YCCBMAN2.cjs} +4 -4
- package/dist/{chunk-ZNX2PT6C.cjs.map → chunk-YCCBMAN2.cjs.map} +1 -1
- package/dist/hooks/index.cjs +13 -13
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +16 -16
- package/dist/hooks/useUniformField/index.cjs +4 -4
- package/dist/hooks/useUniformField/index.js +3 -3
- package/dist/hooks/useUniformFieldArray/index.cjs +5 -5
- package/dist/hooks/useUniformFieldArray/index.js +4 -4
- package/dist/index.cjs +34 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +38 -26
- package/package.json +13 -2
- package/dist/chunk-44STFB2F.cjs +0 -170
- package/dist/chunk-44STFB2F.cjs.map +0 -1
- package/dist/chunk-5ZMXUK6O.js +0 -170
- package/dist/chunk-5ZMXUK6O.js.map +0 -1
- package/dist/chunk-DUYZ7WW3.cjs.map +0 -1
- package/dist/chunk-HBPVEZJN.js +0 -105
- package/dist/chunk-HBPVEZJN.js.map +0 -1
- package/dist/chunk-OTFX4BWZ.js.map +0 -1
- package/dist/chunk-PEADXODY.cjs +0 -105
- package/dist/chunk-PEADXODY.cjs.map +0 -1
- /package/dist/{chunk-EFZXZNJO.js.map → chunk-246OISWB.js.map} +0 -0
- /package/dist/{chunk-BIC7IWER.js.map → chunk-7FOSZV75.js.map} +0 -0
- /package/dist/{chunk-7WHL6K5T.js.map → chunk-CEVS6WSG.js.map} +0 -0
- /package/dist/{chunk-R5AOS4DQ.js.map → chunk-CG7GDQAP.js.map} +0 -0
- /package/dist/{chunk-QE4J4AMH.js.map → chunk-DQAZSXD6.js.map} +0 -0
- /package/dist/{chunk-GRQVGEYI.js.map → chunk-JICFOKDO.js.map} +0 -0
- /package/dist/{chunk-2UHJBGKV.js.map → chunk-MHQ2V7UW.js.map} +0 -0
- /package/dist/{chunk-TN7OSO3T.js.map → chunk-XXLYUZY4.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,CAA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AEC,WAAW,GAAG,gBAAgB,EAAE,WAAW,WAAW,OAAO;AAAA,cAE7D,8BAAC,UAAK,WAAW,GAAG,MAAM,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,6 +1,6 @@
|
|
|
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
6
|
var _chunkUUGUQGMXcjs = require('./chunk-UUGUQGMX.cjs');
|
|
@@ -109,7 +109,7 @@ 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
115
|
const { getFieldState } = _chunkUUGUQGMXcjs.useFormContext.call(void 0, );
|
|
@@ -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-PFFTE4NW.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,UAA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BAAA;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-PFFTE4NW.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,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,g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A;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,+CAAA;AAhFG,IAAM,eAAA,EAAiB,4BAAA;AAAG,EAC/B,KAAA,EAAO;AAAA,IACL,IAAA,EAAM,EAAA;AAAA,IACN,UAAA,EAAY,EAAA;AAAA,IACZ,YAAA,EAAc,WAAA;AAAA;AAAA;AAAA,IAGd,KAAA,EACE,yNAAA;AAAA,IACF,YAAA,EAAc,sBAAA;AAAA,IACd,YAAA,EAAc,EAAA;AAAA,IACd,KAAA,EAAO,EAAA;AAAA,IACP,SAAA,EAAW,EAAA;AAAA,IACX,OAAA,EAAS;AAAA,EACX;AACF,CAAC,CAAA;AA6BD,IAAM,OAAA,EAAS,CAAC,EAAA,EAAA,GAQG;AARH,EAAA,IAAA,GAAA,EAAA,EAAA,EACd;AAAA,IAAA,UAAA,EAAY,KAAA,CAAA;AAAA,IACZ,WAAA,EAAa,KAAA,CAAA;AAAA,IACb,IAAA;AAAA,IACA,KAAA,EAAO,KAAA,CAAA;AAAA,IACP,aAAA,EAAe,KAAA,CAAA;AAAA,IACf,UAAA,EAAY,KAAA;AAAA,EA/Dd,EAAA,EAyDgB,EAAA,EAOX,kBAAA,EAAA,yCAAA,EAPW,EAOX;AAAA,IANH,WAAA;AAAA,IACA,YAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,EAAA,CAAA,CAAA;AA/DF,EAAA,IAAAA,GAAAA;AAkEE,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,QAAA;AAAA,I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AAAA,MAAC,cAAA;AAAA,MAAA;AAAA,QACC,GAAA,EAAK,eAAA;AAAA,QACL,UAAA;AAAA,QACA,cAAA,EAAc,OAAA;AAAA,QACd,eAAA,EAAe,QAAA;AAAA,QACf,aAAA,EAAa,MAAA;AAAA,QACb,eAAA,EAAiB,CAAC,CAAC,YAAA;AAAA,QACnB,UAAA;AAAA,QACA,UAAA,EAAY,QAAA;AAAA,QACZ,UAAA,EAAY,CAAC,CAAC,KAAA,CAAM,KAAA;AAAA,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"]}
|