@yahoo/uds 3.161.0 → 3.162.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/components/client/Checkbox/Checkbox.cjs +118 -0
- package/dist/components/client/{Checkbox.d.cts → Checkbox/Checkbox.d.cts} +5 -18
- package/dist/components/client/{Checkbox.d.ts → Checkbox/Checkbox.d.ts} +5 -18
- package/dist/components/client/Checkbox/Checkbox.js +113 -0
- package/dist/components/client/Checkbox/CheckboxBase.cjs +141 -0
- package/dist/components/client/Checkbox/CheckboxBase.d.cts +48 -0
- package/dist/components/client/Checkbox/CheckboxBase.d.ts +49 -0
- package/dist/components/client/Checkbox/CheckboxBase.js +138 -0
- package/dist/components/client/Checkbox/checkboxConstants.cjs +23 -0
- package/dist/components/client/Checkbox/checkboxConstants.d.cts +25 -0
- package/dist/components/client/Checkbox/checkboxConstants.d.ts +26 -0
- package/dist/components/client/Checkbox/checkboxConstants.js +17 -0
- package/dist/components/client/Checkbox/index.cjs +10 -0
- package/dist/components/client/Checkbox/index.d.cts +6 -0
- package/dist/components/client/Checkbox/index.d.ts +7 -0
- package/dist/components/client/Checkbox/index.js +6 -0
- package/dist/components/client/Checkbox/types.cjs +2 -0
- package/dist/components/client/Checkbox/types.d.cts +22 -0
- package/dist/components/client/Checkbox/types.d.ts +23 -0
- package/dist/components/client/Checkbox/types.js +2 -0
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +1 -1
- package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +1 -1
- package/dist/components/client/Popover/UDSPopoverConfigProvider.d.cts +1 -1
- package/dist/components/client/Popover/UDSPopoverConfigProvider.d.ts +1 -1
- package/dist/components/client/Radio/Radio.cjs +67 -164
- package/dist/components/client/Radio/Radio.d.cts +4 -17
- package/dist/components/client/Radio/Radio.d.ts +4 -17
- package/dist/components/client/Radio/Radio.js +66 -163
- package/dist/components/client/Radio/RadioBase.cjs +133 -0
- package/dist/components/client/Radio/RadioBase.d.cts +45 -0
- package/dist/components/client/Radio/RadioBase.d.ts +46 -0
- package/dist/components/client/Radio/RadioBase.js +130 -0
- package/dist/components/client/Radio/radioConstants.cjs +14 -0
- package/dist/components/client/Radio/radioConstants.d.cts +8 -0
- package/dist/components/client/Radio/radioConstants.d.ts +9 -0
- package/dist/components/client/Radio/radioConstants.js +11 -0
- package/dist/components/client/Radio/types.cjs +2 -0
- package/dist/components/client/Radio/types.d.cts +20 -0
- package/dist/components/client/Radio/types.d.ts +21 -0
- package/dist/components/client/Radio/types.js +2 -0
- package/dist/components/client/Toast/UDSToastConfigProvider.d.cts +1 -1
- package/dist/components/client/Toast/UDSToastConfigProvider.d.ts +1 -1
- package/dist/components/client/index.cjs +2 -2
- package/dist/components/client/index.d.cts +1 -1
- package/dist/components/client/index.d.ts +1 -1
- package/dist/components/client/index.js +1 -1
- package/dist/components/index.cjs +2 -2
- package/dist/components/index.d.cts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/css-animation/Checkbox/Checkbox.cjs +75 -0
- package/dist/css-animation/Checkbox/Checkbox.d.cts +22 -0
- package/dist/css-animation/Checkbox/Checkbox.d.ts +23 -0
- package/dist/css-animation/Checkbox/Checkbox.js +72 -0
- package/dist/css-animation/Checkbox/index.cjs +5 -0
- package/dist/css-animation/Checkbox/index.d.cts +3 -0
- package/dist/css-animation/Checkbox/index.d.ts +4 -0
- package/dist/css-animation/Checkbox/index.js +4 -0
- package/dist/css-animation/Radio/Radio.cjs +92 -0
- package/dist/css-animation/Radio/Radio.d.cts +22 -0
- package/dist/css-animation/Radio/Radio.d.ts +23 -0
- package/dist/css-animation/Radio/Radio.js +89 -0
- package/dist/css-animation/Radio/index.cjs +5 -0
- package/dist/css-animation/Radio/index.d.cts +3 -0
- package/dist/css-animation/Radio/index.d.ts +4 -0
- package/dist/css-animation/Radio/index.js +4 -0
- package/dist/css-animation/index.cjs +4 -0
- package/dist/css-animation/index.d.cts +3 -1
- package/dist/css-animation/index.d.ts +3 -1
- package/dist/css-animation/index.js +3 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/styles/styler.d.cts +43 -43
- package/dist/styles/styler.d.ts +43 -43
- package/dist/uds/generated/componentData.cjs +2501 -2451
- package/dist/uds/generated/componentData.js +2501 -2451
- package/dist/uds/generated/tailwindPurge.cjs +12 -12
- package/dist/uds/generated/tailwindPurge.js +12 -12
- package/generated/componentData.json +3275 -3186
- package/generated/tailwindPurge.ts +2 -2
- package/package.json +1 -1
- package/dist/components/client/Checkbox.cjs +0 -224
- package/dist/components/client/Checkbox.js +0 -219
package/package.json
CHANGED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
2
|
-
"use client";
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
5
|
-
const require_styles_styler = require("../../styles/styler.cjs");
|
|
6
|
-
const require_components_Icon = require("../Icon.cjs");
|
|
7
|
-
const require_components_Box = require("../Box.cjs");
|
|
8
|
-
const require_components_FormLabel = require("../FormLabel.cjs");
|
|
9
|
-
const require_hooks_usePrefersReducedMotion = require("../../hooks/usePrefersReducedMotion.cjs");
|
|
10
|
-
const require_components_client_SpringMotionConfig = require("./SpringMotionConfig.cjs");
|
|
11
|
-
let _yahoo_uds_icons = require("@yahoo/uds-icons");
|
|
12
|
-
let react = require("react");
|
|
13
|
-
react = require_runtime.__toESM(react);
|
|
14
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
15
|
-
let motion_react = require("motion/react");
|
|
16
|
-
//#region src/components/client/Checkbox.tsx
|
|
17
|
-
const VARIANTS = ["primary", "secondary"];
|
|
18
|
-
const SIZES = ["sm", "md"];
|
|
19
|
-
const VARIANT_ERROR_MAP = {
|
|
20
|
-
primary: "alert",
|
|
21
|
-
secondary: "alert-secondary"
|
|
22
|
-
};
|
|
23
|
-
const isIndeterminate = (checked) => checked === "indeterminate";
|
|
24
|
-
const getIcon = (checked) => {
|
|
25
|
-
if (isIndeterminate(checked)) return _yahoo_uds_icons.Minus;
|
|
26
|
-
return _yahoo_uds_icons.Check;
|
|
27
|
-
};
|
|
28
|
-
const MotionBox = motion_react.m.create(require_components_Box.Box);
|
|
29
|
-
const hoverTransition = {
|
|
30
|
-
layoutVariant: "smooth",
|
|
31
|
-
layoutSpeed: "3"
|
|
32
|
-
};
|
|
33
|
-
const pressTransition = {
|
|
34
|
-
layoutVariant: "veryBouncy",
|
|
35
|
-
layoutSpeed: "4"
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* **⚙️️ An checkbox.
|
|
39
|
-
*
|
|
40
|
-
* @componentType Client component
|
|
41
|
-
*
|
|
42
|
-
* @description
|
|
43
|
-
* A checkbox component allows users to select one or multiple options from a set. It represents a binary state, typically as checked or unchecked, and optionally includes a third "indeterminate" state to indicate partial selection.
|
|
44
|
-
*
|
|
45
|
-
* @see
|
|
46
|
-
* Check out the {@link https://uds.build/docs/components/checkbox Checkbox Docs} for more info
|
|
47
|
-
*
|
|
48
|
-
* @usage
|
|
49
|
-
* - Forms: checkbox
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```tsx
|
|
53
|
-
* 'use client';
|
|
54
|
-
* import { Checkbox } from "@yahoo/uds";
|
|
55
|
-
*
|
|
56
|
-
* <Checkbox label="Name" required />
|
|
57
|
-
*```
|
|
58
|
-
*
|
|
59
|
-
* @related [Radio](https://uds.build/docs/components/radio), [Switch](https://uds.build/docs/components/switch), [Input](https://uds.build/docs/components/input).
|
|
60
|
-
**/
|
|
61
|
-
const Checkbox = (0, react.forwardRef)(function Checkbox({ id, checked: checkedProp, defaultChecked, onChange, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: forceReduceMotion, disabled, required, hasError, className, style, slotProps, ...checkboxProps }, parentRef) {
|
|
62
|
-
const generatedId = (0, react.useId)();
|
|
63
|
-
const uid = id ?? `uds-input-${generatedId}`;
|
|
64
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
65
|
-
const checkboxSlotProps = slotProps?.checkbox ?? {};
|
|
66
|
-
const iconSlotProps = slotProps?.icon ?? {};
|
|
67
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
68
|
-
const innerRef = (0, react.useRef)(null);
|
|
69
|
-
/**
|
|
70
|
-
* State
|
|
71
|
-
*/
|
|
72
|
-
const isControlled = checkedProp !== void 0;
|
|
73
|
-
const [checked, setChecked] = (0, react.useState)(isControlled ? checkedProp : defaultChecked);
|
|
74
|
-
const [isHovered, setIsHovered] = (0, react.useState)(false);
|
|
75
|
-
const [isPressed, setIsPressed] = (0, react.useState)(false);
|
|
76
|
-
/**
|
|
77
|
-
* Derived values
|
|
78
|
-
*/
|
|
79
|
-
const variant = (0, react.useMemo)(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
80
|
-
const showHoverEffect = !disabled && isHovered;
|
|
81
|
-
const showPressedEffect = !disabled && isPressed;
|
|
82
|
-
const scale = (0, react.useMemo)(() => {
|
|
83
|
-
if (showPressedEffect) return .9;
|
|
84
|
-
if (showHoverEffect) return 1.1;
|
|
85
|
-
return 1;
|
|
86
|
-
}, [showPressedEffect, showHoverEffect]);
|
|
87
|
-
const checkOpacity = (0, react.useMemo)(() => {
|
|
88
|
-
if (!checked) return "opacity-0";
|
|
89
|
-
if (showPressedEffect) return "opacity-55";
|
|
90
|
-
return "opacity-100";
|
|
91
|
-
}, [checked, showPressedEffect]);
|
|
92
|
-
const motionAnimate = (0, react.useMemo)(() => ({ scale }), [scale]);
|
|
93
|
-
const motionTransition = (0, react.useMemo)(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
94
|
-
/**
|
|
95
|
-
* Handlers
|
|
96
|
-
*/
|
|
97
|
-
const handleChange = (0, react.useCallback)((e) => {
|
|
98
|
-
onChange?.(e);
|
|
99
|
-
if (!isControlled) setChecked(e.target.checked);
|
|
100
|
-
}, [isControlled, onChange]);
|
|
101
|
-
const handleHoverStart = (0, react.useCallback)(() => {
|
|
102
|
-
setIsHovered(true);
|
|
103
|
-
}, []);
|
|
104
|
-
const handleHoverEnd = (0, react.useCallback)(() => {
|
|
105
|
-
setIsHovered(false);
|
|
106
|
-
}, []);
|
|
107
|
-
const handleTapStart = (0, react.useCallback)(() => {
|
|
108
|
-
setIsPressed(true);
|
|
109
|
-
}, []);
|
|
110
|
-
const handleTapEnd = (0, react.useCallback)(() => {
|
|
111
|
-
setIsPressed(false);
|
|
112
|
-
}, []);
|
|
113
|
-
/**
|
|
114
|
-
* Helpers
|
|
115
|
-
*/
|
|
116
|
-
const setDOMIndeterminate = (checked_) => {
|
|
117
|
-
if (!innerRef.current) return;
|
|
118
|
-
innerRef.current.indeterminate = isIndeterminate(checked_);
|
|
119
|
-
};
|
|
120
|
-
const prefersReducedMotion = require_hooks_usePrefersReducedMotion.usePrefersReducedMotion();
|
|
121
|
-
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
122
|
-
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-120";
|
|
123
|
-
/**
|
|
124
|
-
* Effects
|
|
125
|
-
*/
|
|
126
|
-
(0, react.useEffect)(() => {
|
|
127
|
-
if (isControlled) setChecked(checkedProp);
|
|
128
|
-
}, [checkedProp, isControlled]);
|
|
129
|
-
(0, react.useEffect)(() => {
|
|
130
|
-
setDOMIndeterminate(checked);
|
|
131
|
-
}, [checked]);
|
|
132
|
-
const valueState = isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
133
|
-
const classNames = {
|
|
134
|
-
root: require_styles_styler.getStyles({
|
|
135
|
-
checkboxSizeRoot: size,
|
|
136
|
-
checkboxVariantRoot: variant,
|
|
137
|
-
checkboxVariantValueRoot: valueState,
|
|
138
|
-
display: "flex",
|
|
139
|
-
flexDirection: labelPosition === "start" ? "row" : "row-reverse",
|
|
140
|
-
alignItems: "center",
|
|
141
|
-
className: require_styles_styler.cx({
|
|
142
|
-
"cursor-pointer": !disabled,
|
|
143
|
-
"cursor-default": disabled,
|
|
144
|
-
"opacity-50": disabled
|
|
145
|
-
}, className)
|
|
146
|
-
}),
|
|
147
|
-
checkbox: require_styles_styler.getStyles({
|
|
148
|
-
checkboxSizeCheckbox: size,
|
|
149
|
-
checkboxVariantCheckbox: variant,
|
|
150
|
-
checkboxVariantValueCheckbox: valueState,
|
|
151
|
-
className: require_styles_styler.cx("uds-ring", "uds-ring-within", cssAnimationDuration, "transition-[background-color,border-color,box-shadow]")
|
|
152
|
-
}),
|
|
153
|
-
check: require_styles_styler.getStyles({
|
|
154
|
-
checkboxVariantCheckboxIcon: variant,
|
|
155
|
-
checkboxVariantValueCheckboxIcon: valueState,
|
|
156
|
-
className: require_styles_styler.cx("pointer-events-none", checkOpacity, cssAnimationDuration, "transition-opacity")
|
|
157
|
-
}),
|
|
158
|
-
htmlCheckbox: require_styles_styler.cx("cursor-[inherit]", "absolute", "opacity-0", "top-1/2", "left-1/2", "w-[calc(100%+2px)]", "h-[calc(100%+2px)]", "transform", "translate-x-[-50%]", "translate-y-[-50%]"),
|
|
159
|
-
label: require_styles_styler.cx(labelPosition === "start" ? "text-start" : "text-end")
|
|
160
|
-
};
|
|
161
|
-
const RootElement = label ? motion_react.m.label : motion_react.m.div;
|
|
162
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
|
|
163
|
-
reducedMotion: reduceMotion,
|
|
164
|
-
...motionTransition,
|
|
165
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RootElement, {
|
|
166
|
-
className: classNames.root,
|
|
167
|
-
"data-testid": "container",
|
|
168
|
-
style,
|
|
169
|
-
onHoverStart: handleHoverStart,
|
|
170
|
-
onHoverEnd: handleHoverEnd,
|
|
171
|
-
onTapStart: handleTapStart,
|
|
172
|
-
onTap: handleTapEnd,
|
|
173
|
-
onTapCancel: handleTapEnd,
|
|
174
|
-
tabIndex: -1,
|
|
175
|
-
...rootSlotProps,
|
|
176
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(MotionBox, {
|
|
177
|
-
position: "relative",
|
|
178
|
-
className: classNames.checkbox,
|
|
179
|
-
alignItems: "center",
|
|
180
|
-
justifyContent: "center",
|
|
181
|
-
flex: "none",
|
|
182
|
-
animate: motionAnimate,
|
|
183
|
-
...checkboxSlotProps,
|
|
184
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
185
|
-
type: "checkbox",
|
|
186
|
-
tabIndex: 0,
|
|
187
|
-
...checkboxProps,
|
|
188
|
-
ref: (ref) => {
|
|
189
|
-
innerRef.current = ref;
|
|
190
|
-
setDOMIndeterminate(checked);
|
|
191
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
192
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
193
|
-
},
|
|
194
|
-
id: uid,
|
|
195
|
-
disabled,
|
|
196
|
-
required,
|
|
197
|
-
"aria-invalid": hasError,
|
|
198
|
-
checked: isControlled ? isIndeterminate(checked) ? false : checked : void 0,
|
|
199
|
-
defaultChecked: isControlled ? void 0 : defaultChecked,
|
|
200
|
-
onChange: handleChange,
|
|
201
|
-
className: classNames.htmlCheckbox
|
|
202
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Icon.Icon, {
|
|
203
|
-
name: getIcon(checked),
|
|
204
|
-
size: "sm",
|
|
205
|
-
className: classNames.check,
|
|
206
|
-
...iconSlotProps
|
|
207
|
-
})]
|
|
208
|
-
}), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
|
|
209
|
-
as: "div",
|
|
210
|
-
variant: "inherit",
|
|
211
|
-
color: "inherit",
|
|
212
|
-
required,
|
|
213
|
-
label,
|
|
214
|
-
className: classNames.label,
|
|
215
|
-
...labelSlotProps
|
|
216
|
-
})]
|
|
217
|
-
})
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
Checkbox.displayName = "Checkbox";
|
|
221
|
-
//#endregion
|
|
222
|
-
exports.Checkbox = Checkbox;
|
|
223
|
-
exports.SIZES = SIZES;
|
|
224
|
-
exports.VARIANTS = VARIANTS;
|
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
|
|
2
|
-
"use client";
|
|
3
|
-
import { cx, getStyles } from "../../styles/styler.js";
|
|
4
|
-
import { Icon } from "../Icon.js";
|
|
5
|
-
import { Box } from "../Box.js";
|
|
6
|
-
import { FormLabel } from "../FormLabel.js";
|
|
7
|
-
import { usePrefersReducedMotion } from "../../hooks/usePrefersReducedMotion.js";
|
|
8
|
-
import { SpringMotionConfig } from "./SpringMotionConfig.js";
|
|
9
|
-
import { Check, Minus } from "@yahoo/uds-icons";
|
|
10
|
-
import { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
11
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { m } from "motion/react";
|
|
13
|
-
//#region src/components/client/Checkbox.tsx
|
|
14
|
-
const VARIANTS = ["primary", "secondary"];
|
|
15
|
-
const SIZES = ["sm", "md"];
|
|
16
|
-
const VARIANT_ERROR_MAP = {
|
|
17
|
-
primary: "alert",
|
|
18
|
-
secondary: "alert-secondary"
|
|
19
|
-
};
|
|
20
|
-
const isIndeterminate = (checked) => checked === "indeterminate";
|
|
21
|
-
const getIcon = (checked) => {
|
|
22
|
-
if (isIndeterminate(checked)) return Minus;
|
|
23
|
-
return Check;
|
|
24
|
-
};
|
|
25
|
-
const MotionBox = m.create(Box);
|
|
26
|
-
const hoverTransition = {
|
|
27
|
-
layoutVariant: "smooth",
|
|
28
|
-
layoutSpeed: "3"
|
|
29
|
-
};
|
|
30
|
-
const pressTransition = {
|
|
31
|
-
layoutVariant: "veryBouncy",
|
|
32
|
-
layoutSpeed: "4"
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* **⚙️️ An checkbox.
|
|
36
|
-
*
|
|
37
|
-
* @componentType Client component
|
|
38
|
-
*
|
|
39
|
-
* @description
|
|
40
|
-
* A checkbox component allows users to select one or multiple options from a set. It represents a binary state, typically as checked or unchecked, and optionally includes a third "indeterminate" state to indicate partial selection.
|
|
41
|
-
*
|
|
42
|
-
* @see
|
|
43
|
-
* Check out the {@link https://uds.build/docs/components/checkbox Checkbox Docs} for more info
|
|
44
|
-
*
|
|
45
|
-
* @usage
|
|
46
|
-
* - Forms: checkbox
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```tsx
|
|
50
|
-
* 'use client';
|
|
51
|
-
* import { Checkbox } from "@yahoo/uds";
|
|
52
|
-
*
|
|
53
|
-
* <Checkbox label="Name" required />
|
|
54
|
-
*```
|
|
55
|
-
*
|
|
56
|
-
* @related [Radio](https://uds.build/docs/components/radio), [Switch](https://uds.build/docs/components/switch), [Input](https://uds.build/docs/components/input).
|
|
57
|
-
**/
|
|
58
|
-
const Checkbox = forwardRef(function Checkbox({ id, checked: checkedProp, defaultChecked, onChange, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: forceReduceMotion, disabled, required, hasError, className, style, slotProps, ...checkboxProps }, parentRef) {
|
|
59
|
-
const generatedId = useId();
|
|
60
|
-
const uid = id ?? `uds-input-${generatedId}`;
|
|
61
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
62
|
-
const checkboxSlotProps = slotProps?.checkbox ?? {};
|
|
63
|
-
const iconSlotProps = slotProps?.icon ?? {};
|
|
64
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
65
|
-
const innerRef = useRef(null);
|
|
66
|
-
/**
|
|
67
|
-
* State
|
|
68
|
-
*/
|
|
69
|
-
const isControlled = checkedProp !== void 0;
|
|
70
|
-
const [checked, setChecked] = useState(isControlled ? checkedProp : defaultChecked);
|
|
71
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
72
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
73
|
-
/**
|
|
74
|
-
* Derived values
|
|
75
|
-
*/
|
|
76
|
-
const variant = useMemo(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
77
|
-
const showHoverEffect = !disabled && isHovered;
|
|
78
|
-
const showPressedEffect = !disabled && isPressed;
|
|
79
|
-
const scale = useMemo(() => {
|
|
80
|
-
if (showPressedEffect) return .9;
|
|
81
|
-
if (showHoverEffect) return 1.1;
|
|
82
|
-
return 1;
|
|
83
|
-
}, [showPressedEffect, showHoverEffect]);
|
|
84
|
-
const checkOpacity = useMemo(() => {
|
|
85
|
-
if (!checked) return "opacity-0";
|
|
86
|
-
if (showPressedEffect) return "opacity-55";
|
|
87
|
-
return "opacity-100";
|
|
88
|
-
}, [checked, showPressedEffect]);
|
|
89
|
-
const motionAnimate = useMemo(() => ({ scale }), [scale]);
|
|
90
|
-
const motionTransition = useMemo(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
91
|
-
/**
|
|
92
|
-
* Handlers
|
|
93
|
-
*/
|
|
94
|
-
const handleChange = useCallback((e) => {
|
|
95
|
-
onChange?.(e);
|
|
96
|
-
if (!isControlled) setChecked(e.target.checked);
|
|
97
|
-
}, [isControlled, onChange]);
|
|
98
|
-
const handleHoverStart = useCallback(() => {
|
|
99
|
-
setIsHovered(true);
|
|
100
|
-
}, []);
|
|
101
|
-
const handleHoverEnd = useCallback(() => {
|
|
102
|
-
setIsHovered(false);
|
|
103
|
-
}, []);
|
|
104
|
-
const handleTapStart = useCallback(() => {
|
|
105
|
-
setIsPressed(true);
|
|
106
|
-
}, []);
|
|
107
|
-
const handleTapEnd = useCallback(() => {
|
|
108
|
-
setIsPressed(false);
|
|
109
|
-
}, []);
|
|
110
|
-
/**
|
|
111
|
-
* Helpers
|
|
112
|
-
*/
|
|
113
|
-
const setDOMIndeterminate = (checked_) => {
|
|
114
|
-
if (!innerRef.current) return;
|
|
115
|
-
innerRef.current.indeterminate = isIndeterminate(checked_);
|
|
116
|
-
};
|
|
117
|
-
const prefersReducedMotion = usePrefersReducedMotion();
|
|
118
|
-
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
119
|
-
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-120";
|
|
120
|
-
/**
|
|
121
|
-
* Effects
|
|
122
|
-
*/
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (isControlled) setChecked(checkedProp);
|
|
125
|
-
}, [checkedProp, isControlled]);
|
|
126
|
-
useEffect(() => {
|
|
127
|
-
setDOMIndeterminate(checked);
|
|
128
|
-
}, [checked]);
|
|
129
|
-
const valueState = isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
130
|
-
const classNames = {
|
|
131
|
-
root: getStyles({
|
|
132
|
-
checkboxSizeRoot: size,
|
|
133
|
-
checkboxVariantRoot: variant,
|
|
134
|
-
checkboxVariantValueRoot: valueState,
|
|
135
|
-
display: "flex",
|
|
136
|
-
flexDirection: labelPosition === "start" ? "row" : "row-reverse",
|
|
137
|
-
alignItems: "center",
|
|
138
|
-
className: cx({
|
|
139
|
-
"cursor-pointer": !disabled,
|
|
140
|
-
"cursor-default": disabled,
|
|
141
|
-
"opacity-50": disabled
|
|
142
|
-
}, className)
|
|
143
|
-
}),
|
|
144
|
-
checkbox: getStyles({
|
|
145
|
-
checkboxSizeCheckbox: size,
|
|
146
|
-
checkboxVariantCheckbox: variant,
|
|
147
|
-
checkboxVariantValueCheckbox: valueState,
|
|
148
|
-
className: cx("uds-ring", "uds-ring-within", cssAnimationDuration, "transition-[background-color,border-color,box-shadow]")
|
|
149
|
-
}),
|
|
150
|
-
check: getStyles({
|
|
151
|
-
checkboxVariantCheckboxIcon: variant,
|
|
152
|
-
checkboxVariantValueCheckboxIcon: valueState,
|
|
153
|
-
className: cx("pointer-events-none", checkOpacity, cssAnimationDuration, "transition-opacity")
|
|
154
|
-
}),
|
|
155
|
-
htmlCheckbox: cx("cursor-[inherit]", "absolute", "opacity-0", "top-1/2", "left-1/2", "w-[calc(100%+2px)]", "h-[calc(100%+2px)]", "transform", "translate-x-[-50%]", "translate-y-[-50%]"),
|
|
156
|
-
label: cx(labelPosition === "start" ? "text-start" : "text-end")
|
|
157
|
-
};
|
|
158
|
-
const RootElement = label ? m.label : m.div;
|
|
159
|
-
return /* @__PURE__ */ jsx(SpringMotionConfig, {
|
|
160
|
-
reducedMotion: reduceMotion,
|
|
161
|
-
...motionTransition,
|
|
162
|
-
children: /* @__PURE__ */ jsxs(RootElement, {
|
|
163
|
-
className: classNames.root,
|
|
164
|
-
"data-testid": "container",
|
|
165
|
-
style,
|
|
166
|
-
onHoverStart: handleHoverStart,
|
|
167
|
-
onHoverEnd: handleHoverEnd,
|
|
168
|
-
onTapStart: handleTapStart,
|
|
169
|
-
onTap: handleTapEnd,
|
|
170
|
-
onTapCancel: handleTapEnd,
|
|
171
|
-
tabIndex: -1,
|
|
172
|
-
...rootSlotProps,
|
|
173
|
-
children: [/* @__PURE__ */ jsxs(MotionBox, {
|
|
174
|
-
position: "relative",
|
|
175
|
-
className: classNames.checkbox,
|
|
176
|
-
alignItems: "center",
|
|
177
|
-
justifyContent: "center",
|
|
178
|
-
flex: "none",
|
|
179
|
-
animate: motionAnimate,
|
|
180
|
-
...checkboxSlotProps,
|
|
181
|
-
children: [/* @__PURE__ */ jsx("input", {
|
|
182
|
-
type: "checkbox",
|
|
183
|
-
tabIndex: 0,
|
|
184
|
-
...checkboxProps,
|
|
185
|
-
ref: (ref) => {
|
|
186
|
-
innerRef.current = ref;
|
|
187
|
-
setDOMIndeterminate(checked);
|
|
188
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
189
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
190
|
-
},
|
|
191
|
-
id: uid,
|
|
192
|
-
disabled,
|
|
193
|
-
required,
|
|
194
|
-
"aria-invalid": hasError,
|
|
195
|
-
checked: isControlled ? isIndeterminate(checked) ? false : checked : void 0,
|
|
196
|
-
defaultChecked: isControlled ? void 0 : defaultChecked,
|
|
197
|
-
onChange: handleChange,
|
|
198
|
-
className: classNames.htmlCheckbox
|
|
199
|
-
}), /* @__PURE__ */ jsx(Icon, {
|
|
200
|
-
name: getIcon(checked),
|
|
201
|
-
size: "sm",
|
|
202
|
-
className: classNames.check,
|
|
203
|
-
...iconSlotProps
|
|
204
|
-
})]
|
|
205
|
-
}), label && /* @__PURE__ */ jsx(FormLabel, {
|
|
206
|
-
as: "div",
|
|
207
|
-
variant: "inherit",
|
|
208
|
-
color: "inherit",
|
|
209
|
-
required,
|
|
210
|
-
label,
|
|
211
|
-
className: classNames.label,
|
|
212
|
-
...labelSlotProps
|
|
213
|
-
})]
|
|
214
|
-
})
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
Checkbox.displayName = "Checkbox";
|
|
218
|
-
//#endregion
|
|
219
|
-
export { Checkbox, SIZES, VARIANTS };
|