@yahoo/uds 3.160.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/BottomSheet/BottomSheet.cjs +2 -2
- package/dist/components/client/BottomSheet/BottomSheet.js +2 -2
- package/dist/components/client/Button/Button.cjs +2 -1
- package/dist/components/client/Button/Button.js +3 -2
- 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/Chip/ChipBase.cjs +2 -2
- package/dist/components/client/Chip/ChipBase.js +2 -2
- package/dist/components/client/IconButton/IconButton.cjs +2 -1
- package/dist/components/client/IconButton/IconButton.js +3 -2
- package/dist/components/client/Input/Input.cjs +2 -2
- package/dist/components/client/Input/Input.js +2 -2
- 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/Modal/ManagedModal.cjs +2 -2
- package/dist/components/client/Modal/ManagedModal.js +2 -2
- package/dist/components/client/Modal/Modal.cjs +2 -2
- package/dist/components/client/Modal/Modal.js +2 -2
- package/dist/components/client/Popover/Popover.cjs +2 -2
- package/dist/components/client/Popover/Popover.js +2 -2
- 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 +69 -165
- 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 +69 -165
- 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/Switch/Switch.cjs +1 -1
- package/dist/components/client/Switch/Switch.js +1 -1
- package/dist/components/client/Tabs/TabList.cjs +2 -2
- package/dist/components/client/Tabs/TabList.js +2 -2
- package/dist/components/client/Toast/Toast.cjs +2 -2
- package/dist/components/client/Toast/Toast.js +2 -2
- 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/hooks/usePrefersReducedMotion.cjs +27 -15
- package/dist/hooks/usePrefersReducedMotion.js +28 -16
- 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 +45 -45
- package/dist/styles/styler.d.ts +45 -45
- package/dist/uds/generated/componentData.cjs +2540 -2490
- package/dist/uds/generated/componentData.js +2540 -2490
- package/dist/uds/generated/tailwindPurge.cjs +12 -12
- package/dist/uds/generated/tailwindPurge.js +12 -12
- package/generated/componentData.json +3258 -3169
- package/generated/tailwindPurge.ts +2 -2
- package/package.json +1 -1
- package/dist/components/client/Checkbox.cjs +0 -223
- package/dist/components/client/Checkbox.js +0 -218
|
@@ -30,7 +30,7 @@ declare function usePopoverConfig(sizeProp?: PopoverSize | undefined, variantPro
|
|
|
30
30
|
gap: SpacingAlias;
|
|
31
31
|
dismissButtonSpacing: SpacingAlias;
|
|
32
32
|
dismissIconSize: number;
|
|
33
|
-
ariaKitPlacement: ("
|
|
33
|
+
ariaKitPlacement: ("top-start" | "top-end" | "bottom-start" | "bottom-end" | ("top" | "bottom" | "left" | "right") | "left-start" | "right-start" | "left-end" | "right-end") | undefined;
|
|
34
34
|
animationDuration: number;
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
@@ -4,21 +4,17 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
5
5
|
const require_styles_styler = require("../../../styles/styler.cjs");
|
|
6
6
|
const require_components_Box = require("../../Box.cjs");
|
|
7
|
-
const
|
|
7
|
+
const require_hooks_usePrefersReducedMotion = require("../../../hooks/usePrefersReducedMotion.cjs");
|
|
8
8
|
const require_components_client_SpringMotionConfig = require("../SpringMotionConfig.cjs");
|
|
9
|
-
const
|
|
9
|
+
const require_components_client_Radio_radioConstants = require("./radioConstants.cjs");
|
|
10
|
+
const require_components_client_Radio_RadioBase = require("./RadioBase.cjs");
|
|
10
11
|
let react = require("react");
|
|
11
12
|
react = require_runtime.__toESM(react);
|
|
12
13
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
14
|
let motion_react = require("motion/react");
|
|
14
15
|
//#region src/components/client/Radio/Radio.tsx
|
|
15
|
-
const RADIO_VARIANTS = ["primary", "secondary"];
|
|
16
|
-
const RADIO_SIZES = ["sm", "md"];
|
|
17
|
-
const VARIANT_ERROR_MAP = {
|
|
18
|
-
primary: "alert",
|
|
19
|
-
secondary: "alert-secondary"
|
|
20
|
-
};
|
|
21
16
|
const MotionBox = motion_react.m.create(require_components_Box.Box);
|
|
17
|
+
MotionBox.displayName = "RadioMotionBox";
|
|
22
18
|
const hoverTransition = {
|
|
23
19
|
layoutVariant: "smooth",
|
|
24
20
|
layoutSpeed: "3"
|
|
@@ -51,179 +47,87 @@ const pressTransition = {
|
|
|
51
47
|
*
|
|
52
48
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
53
49
|
**/
|
|
54
|
-
const Radio = (0, react.forwardRef)(function Radio({
|
|
55
|
-
const
|
|
56
|
-
const uid = id ?? `uds-radio-${generatedId}`;
|
|
57
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
58
|
-
const radioSlotProps = slotProps?.radio ?? {};
|
|
59
|
-
const radioIconSlotProps = slotProps?.radioIcon ?? {};
|
|
60
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
61
|
-
const innerRef = (0, react.useRef)(null);
|
|
62
|
-
/**
|
|
63
|
-
* State
|
|
64
|
-
*/
|
|
65
|
-
const { name, isControlled, checked, setGroupValue } = require_components_client_Radio_useRadioGroup.useRadioGroup({
|
|
66
|
-
name: nameProp,
|
|
67
|
-
value: valueProp,
|
|
68
|
-
checked: checkedProp,
|
|
69
|
-
defaultChecked
|
|
70
|
-
});
|
|
71
|
-
const [isHovered, setIsHovered] = (0, react.useState)(false);
|
|
72
|
-
const [isPressed, setIsPressed] = (0, react.useState)(false);
|
|
73
|
-
/**
|
|
74
|
-
* Derived values
|
|
75
|
-
*/
|
|
76
|
-
const variant = (0, react.useMemo)(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
77
|
-
const showHoverEffect = (0, react.useMemo)(() => !disabled && isHovered, [disabled, isHovered]);
|
|
78
|
-
const showPressedEffect = (0, react.useMemo)(() => !disabled && !checked && isPressed, [
|
|
79
|
-
checked,
|
|
80
|
-
disabled,
|
|
81
|
-
isPressed
|
|
82
|
-
]);
|
|
83
|
-
const scale = (0, react.useMemo)(() => showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1, [showHoverEffect, showPressedEffect]);
|
|
84
|
-
const checkOpacity = (0, react.useMemo)(() => checked ? showPressedEffect ? "opacity-55" : "opacity-100" : "opacity-0", [checked, showPressedEffect]);
|
|
85
|
-
const showShadow = (0, react.useMemo)(() => {
|
|
86
|
-
return !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
87
|
-
}, [
|
|
88
|
-
checked,
|
|
89
|
-
disabled,
|
|
90
|
-
showHoverEffect,
|
|
91
|
-
showPressedEffect
|
|
92
|
-
]);
|
|
93
|
-
const motionAnimate = (0, react.useMemo)(() => ({ scale }), [scale]);
|
|
94
|
-
const motionTransition = (0, react.useMemo)(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
95
|
-
/**
|
|
96
|
-
* Handlers
|
|
97
|
-
*/
|
|
98
|
-
const handleOnChange = (0, react.useCallback)((e) => {
|
|
99
|
-
setGroupValue(e.target.value);
|
|
100
|
-
onChange?.(e);
|
|
101
|
-
}, [onChange, setGroupValue]);
|
|
102
|
-
const handleFocus = (0, react.useCallback)((e) => {
|
|
103
|
-
onFocus?.(e);
|
|
104
|
-
}, [onFocus]);
|
|
105
|
-
const handleBlur = (0, react.useCallback)((e) => {
|
|
106
|
-
onBlur?.(e);
|
|
107
|
-
}, [onBlur]);
|
|
108
|
-
const handleHoverStart = (0, react.useCallback)(() => {
|
|
109
|
-
setIsHovered(true);
|
|
110
|
-
}, []);
|
|
111
|
-
const handleHoverEnd = (0, react.useCallback)(() => {
|
|
112
|
-
setIsHovered(false);
|
|
113
|
-
}, []);
|
|
114
|
-
const handleTapStart = (0, react.useCallback)(() => {
|
|
115
|
-
setIsPressed(true);
|
|
116
|
-
}, []);
|
|
117
|
-
const handleTapEnd = (0, react.useCallback)(() => {
|
|
118
|
-
setIsPressed(false);
|
|
119
|
-
}, []);
|
|
120
|
-
const prefersReducedMotion = (0, motion_react.useReducedMotion)();
|
|
50
|
+
const Radio = (0, react.forwardRef)(function Radio({ reduceMotion: forceReduceMotion, ...props }, parentRef) {
|
|
51
|
+
const prefersReducedMotion = require_hooks_usePrefersReducedMotion.usePrefersReducedMotion();
|
|
121
52
|
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
122
53
|
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-120";
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(MotionBox, {
|
|
54
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Radio_RadioBase.RadioBase, {
|
|
55
|
+
...props,
|
|
56
|
+
ref: parentRef,
|
|
57
|
+
cssAnimationDuration,
|
|
58
|
+
enableInteractionTracking: true,
|
|
59
|
+
renderRoot: ({ className, style, rootSlotProps, hasLabel, isPressed, onHoverStart, onHoverEnd, onTapStart, onTapEnd, children }) => {
|
|
60
|
+
const RootElement = hasLabel ? motion_react.m.label : motion_react.m.div;
|
|
61
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
|
|
62
|
+
reducedMotion: reduceMotion,
|
|
63
|
+
...isPressed ? pressTransition : hoverTransition,
|
|
64
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RootElement, {
|
|
65
|
+
className,
|
|
66
|
+
"data-testid": "container",
|
|
67
|
+
style,
|
|
68
|
+
onHoverStart,
|
|
69
|
+
onHoverEnd,
|
|
70
|
+
onTapStart,
|
|
71
|
+
onTap: onTapEnd,
|
|
72
|
+
onTapCancel: onTapEnd,
|
|
73
|
+
tabIndex: -1,
|
|
74
|
+
...rootSlotProps,
|
|
75
|
+
children
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
renderIndicator: ({ size, variant, checked, disabled, showHoverEffect, showPressedEffect, cssAnimationDuration, radioSlotProps, radioIconSlotProps, children }) => {
|
|
80
|
+
const scale = showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1;
|
|
81
|
+
const checkOpacity = checked ? showPressedEffect ? require_styles_styler.cx("opacity-55") : require_styles_styler.cx("opacity-100") : require_styles_styler.cx("opacity-0");
|
|
82
|
+
const showShadow = !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
83
|
+
const classNames = {
|
|
84
|
+
radio: require_styles_styler.getStyles({
|
|
85
|
+
radioSizeRadio: size,
|
|
86
|
+
radioVariantRadio: variant,
|
|
87
|
+
radioVariantValueRadio: checked ? "checked" : "unchecked",
|
|
88
|
+
className: require_styles_styler.cx([
|
|
89
|
+
"border",
|
|
90
|
+
"uds-ring",
|
|
91
|
+
"uds-ring-within",
|
|
92
|
+
cssAnimationDuration,
|
|
93
|
+
"transition-[background-color,border-color]",
|
|
94
|
+
"transition-shadow"
|
|
95
|
+
])
|
|
96
|
+
}),
|
|
97
|
+
radioCircle: require_styles_styler.getStyles({
|
|
98
|
+
radioVariantRadioCircle: variant,
|
|
99
|
+
radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
|
|
100
|
+
className: require_styles_styler.cx([
|
|
101
|
+
"pointer-events-none",
|
|
102
|
+
"w-[8px]",
|
|
103
|
+
"h-[8px]",
|
|
104
|
+
checkOpacity,
|
|
105
|
+
cssAnimationDuration,
|
|
106
|
+
"transition-opacity"
|
|
107
|
+
])
|
|
108
|
+
})
|
|
109
|
+
};
|
|
110
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(MotionBox, {
|
|
181
111
|
position: "relative",
|
|
182
112
|
borderRadius: "full",
|
|
183
113
|
alignItems: "center",
|
|
184
114
|
justifyContent: "center",
|
|
185
115
|
flex: "none",
|
|
186
116
|
className: classNames.radio,
|
|
187
|
-
animate:
|
|
117
|
+
animate: { scale },
|
|
188
118
|
insetShadow: showShadow ? "lg-invert" : "none",
|
|
189
119
|
...radioSlotProps,
|
|
190
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
191
|
-
type: "radio",
|
|
192
|
-
tabIndex: 0,
|
|
193
|
-
...radioProps,
|
|
194
|
-
ref: (ref) => {
|
|
195
|
-
innerRef.current = ref;
|
|
196
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
197
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
198
|
-
},
|
|
199
|
-
onFocus: handleFocus,
|
|
200
|
-
onBlur: handleBlur,
|
|
201
|
-
id: uid,
|
|
202
|
-
name,
|
|
203
|
-
value: valueProp,
|
|
204
|
-
disabled,
|
|
205
|
-
"aria-invalid": hasError,
|
|
206
|
-
onChange: handleOnChange,
|
|
207
|
-
...isControlled ? { checked } : { defaultChecked },
|
|
208
|
-
className: classNames.htmlRadio
|
|
209
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
|
|
120
|
+
children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
|
|
210
121
|
borderRadius: "full",
|
|
211
122
|
className: classNames.radioCircle,
|
|
212
123
|
...radioIconSlotProps
|
|
213
124
|
})]
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
variant: "inherit",
|
|
217
|
-
color: "inherit",
|
|
218
|
-
label,
|
|
219
|
-
className: classNames.label,
|
|
220
|
-
...labelSlotProps
|
|
221
|
-
})]
|
|
222
|
-
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
223
127
|
});
|
|
224
128
|
});
|
|
225
129
|
Radio.displayName = "Radio";
|
|
226
130
|
//#endregion
|
|
227
|
-
exports.RADIO_SIZES = RADIO_SIZES;
|
|
228
|
-
exports.RADIO_VARIANTS = RADIO_VARIANTS;
|
|
131
|
+
exports.RADIO_SIZES = require_components_client_Radio_radioConstants.RADIO_SIZES;
|
|
132
|
+
exports.RADIO_VARIANTS = require_components_client_Radio_radioConstants.RADIO_VARIANTS;
|
|
229
133
|
exports.Radio = Radio;
|
|
@@ -1,23 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { RADIO_SIZES, RADIO_VARIANTS } from "./radioConstants.cjs";
|
|
3
|
+
import { RadioProps as RadioProps$1 } from "./types.cjs";
|
|
3
4
|
import React from "react";
|
|
4
5
|
|
|
5
6
|
//#region src/components/client/Radio/Radio.d.ts
|
|
6
|
-
type
|
|
7
|
-
type DataAttributes = {
|
|
8
|
-
[name: `data-${string}`]: string;
|
|
9
|
-
};
|
|
10
|
-
interface RadioProps extends NativeInputProps, UniversalRadioProps {
|
|
11
|
-
/** Props to be passed into various slots within the component. */
|
|
12
|
-
slotProps?: {
|
|
13
|
-
root?: DataAttributes;
|
|
14
|
-
radio?: DataAttributes;
|
|
15
|
-
radioIcon?: DataAttributes;
|
|
16
|
-
label?: DataAttributes;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
declare const RADIO_VARIANTS: RadioVariant[];
|
|
20
|
-
declare const RADIO_SIZES: RadioSize[];
|
|
7
|
+
type RadioProps = RadioProps$1;
|
|
21
8
|
/**
|
|
22
9
|
* **⚙️️ A Radio.
|
|
23
10
|
*
|
|
@@ -42,6 +29,6 @@ declare const RADIO_SIZES: RadioSize[];
|
|
|
42
29
|
*
|
|
43
30
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
44
31
|
**/
|
|
45
|
-
declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLInputElement>>;
|
|
32
|
+
declare const Radio: React.ForwardRefExoticComponent<RadioProps$1 & React.RefAttributes<HTMLInputElement>>;
|
|
46
33
|
//#endregion
|
|
47
34
|
export { RADIO_SIZES, RADIO_VARIANTS, Radio, type RadioProps };
|
|
@@ -1,24 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
"use client";
|
|
3
|
-
import {
|
|
3
|
+
import { RADIO_SIZES, RADIO_VARIANTS } from "./radioConstants.js";
|
|
4
|
+
import { RadioProps as RadioProps$1 } from "./types.js";
|
|
4
5
|
import React from "react";
|
|
5
6
|
|
|
6
7
|
//#region src/components/client/Radio/Radio.d.ts
|
|
7
|
-
type
|
|
8
|
-
type DataAttributes = {
|
|
9
|
-
[name: `data-${string}`]: string;
|
|
10
|
-
};
|
|
11
|
-
interface RadioProps extends NativeInputProps, UniversalRadioProps {
|
|
12
|
-
/** Props to be passed into various slots within the component. */
|
|
13
|
-
slotProps?: {
|
|
14
|
-
root?: DataAttributes;
|
|
15
|
-
radio?: DataAttributes;
|
|
16
|
-
radioIcon?: DataAttributes;
|
|
17
|
-
label?: DataAttributes;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
declare const RADIO_VARIANTS: RadioVariant[];
|
|
21
|
-
declare const RADIO_SIZES: RadioSize[];
|
|
8
|
+
type RadioProps = RadioProps$1;
|
|
22
9
|
/**
|
|
23
10
|
* **⚙️️ A Radio.
|
|
24
11
|
*
|
|
@@ -43,6 +30,6 @@ declare const RADIO_SIZES: RadioSize[];
|
|
|
43
30
|
*
|
|
44
31
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
45
32
|
**/
|
|
46
|
-
declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLInputElement>>;
|
|
33
|
+
declare const Radio: React.ForwardRefExoticComponent<RadioProps$1 & React.RefAttributes<HTMLInputElement>>;
|
|
47
34
|
//#endregion
|
|
48
35
|
export { RADIO_SIZES, RADIO_VARIANTS, Radio, type RadioProps };
|
|
@@ -2,20 +2,16 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { cx, getStyles } from "../../../styles/styler.js";
|
|
4
4
|
import { Box } from "../../Box.js";
|
|
5
|
-
import {
|
|
5
|
+
import { usePrefersReducedMotion } from "../../../hooks/usePrefersReducedMotion.js";
|
|
6
6
|
import { SpringMotionConfig } from "../SpringMotionConfig.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { RADIO_SIZES, RADIO_VARIANTS } from "./radioConstants.js";
|
|
8
|
+
import { RadioBase } from "./RadioBase.js";
|
|
9
|
+
import { forwardRef } from "react";
|
|
9
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
import { m
|
|
11
|
+
import { m } from "motion/react";
|
|
11
12
|
//#region src/components/client/Radio/Radio.tsx
|
|
12
|
-
const RADIO_VARIANTS = ["primary", "secondary"];
|
|
13
|
-
const RADIO_SIZES = ["sm", "md"];
|
|
14
|
-
const VARIANT_ERROR_MAP = {
|
|
15
|
-
primary: "alert",
|
|
16
|
-
secondary: "alert-secondary"
|
|
17
|
-
};
|
|
18
13
|
const MotionBox = m.create(Box);
|
|
14
|
+
MotionBox.displayName = "RadioMotionBox";
|
|
19
15
|
const hoverTransition = {
|
|
20
16
|
layoutVariant: "smooth",
|
|
21
17
|
layoutSpeed: "3"
|
|
@@ -48,175 +44,83 @@ const pressTransition = {
|
|
|
48
44
|
*
|
|
49
45
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
50
46
|
**/
|
|
51
|
-
const Radio = forwardRef(function Radio({
|
|
52
|
-
const
|
|
53
|
-
const uid = id ?? `uds-radio-${generatedId}`;
|
|
54
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
55
|
-
const radioSlotProps = slotProps?.radio ?? {};
|
|
56
|
-
const radioIconSlotProps = slotProps?.radioIcon ?? {};
|
|
57
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
58
|
-
const innerRef = useRef(null);
|
|
59
|
-
/**
|
|
60
|
-
* State
|
|
61
|
-
*/
|
|
62
|
-
const { name, isControlled, checked, setGroupValue } = useRadioGroup({
|
|
63
|
-
name: nameProp,
|
|
64
|
-
value: valueProp,
|
|
65
|
-
checked: checkedProp,
|
|
66
|
-
defaultChecked
|
|
67
|
-
});
|
|
68
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
69
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
70
|
-
/**
|
|
71
|
-
* Derived values
|
|
72
|
-
*/
|
|
73
|
-
const variant = useMemo(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
74
|
-
const showHoverEffect = useMemo(() => !disabled && isHovered, [disabled, isHovered]);
|
|
75
|
-
const showPressedEffect = useMemo(() => !disabled && !checked && isPressed, [
|
|
76
|
-
checked,
|
|
77
|
-
disabled,
|
|
78
|
-
isPressed
|
|
79
|
-
]);
|
|
80
|
-
const scale = useMemo(() => showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1, [showHoverEffect, showPressedEffect]);
|
|
81
|
-
const checkOpacity = useMemo(() => checked ? showPressedEffect ? "opacity-55" : "opacity-100" : "opacity-0", [checked, showPressedEffect]);
|
|
82
|
-
const showShadow = useMemo(() => {
|
|
83
|
-
return !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
84
|
-
}, [
|
|
85
|
-
checked,
|
|
86
|
-
disabled,
|
|
87
|
-
showHoverEffect,
|
|
88
|
-
showPressedEffect
|
|
89
|
-
]);
|
|
90
|
-
const motionAnimate = useMemo(() => ({ scale }), [scale]);
|
|
91
|
-
const motionTransition = useMemo(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
92
|
-
/**
|
|
93
|
-
* Handlers
|
|
94
|
-
*/
|
|
95
|
-
const handleOnChange = useCallback((e) => {
|
|
96
|
-
setGroupValue(e.target.value);
|
|
97
|
-
onChange?.(e);
|
|
98
|
-
}, [onChange, setGroupValue]);
|
|
99
|
-
const handleFocus = useCallback((e) => {
|
|
100
|
-
onFocus?.(e);
|
|
101
|
-
}, [onFocus]);
|
|
102
|
-
const handleBlur = useCallback((e) => {
|
|
103
|
-
onBlur?.(e);
|
|
104
|
-
}, [onBlur]);
|
|
105
|
-
const handleHoverStart = useCallback(() => {
|
|
106
|
-
setIsHovered(true);
|
|
107
|
-
}, []);
|
|
108
|
-
const handleHoverEnd = useCallback(() => {
|
|
109
|
-
setIsHovered(false);
|
|
110
|
-
}, []);
|
|
111
|
-
const handleTapStart = useCallback(() => {
|
|
112
|
-
setIsPressed(true);
|
|
113
|
-
}, []);
|
|
114
|
-
const handleTapEnd = useCallback(() => {
|
|
115
|
-
setIsPressed(false);
|
|
116
|
-
}, []);
|
|
117
|
-
const prefersReducedMotion = useReducedMotion();
|
|
47
|
+
const Radio = forwardRef(function Radio({ reduceMotion: forceReduceMotion, ...props }, parentRef) {
|
|
48
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
118
49
|
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
119
50
|
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-120";
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
children: [/* @__PURE__ */ jsxs(MotionBox, {
|
|
51
|
+
return /* @__PURE__ */ jsx(RadioBase, {
|
|
52
|
+
...props,
|
|
53
|
+
ref: parentRef,
|
|
54
|
+
cssAnimationDuration,
|
|
55
|
+
enableInteractionTracking: true,
|
|
56
|
+
renderRoot: ({ className, style, rootSlotProps, hasLabel, isPressed, onHoverStart, onHoverEnd, onTapStart, onTapEnd, children }) => {
|
|
57
|
+
const RootElement = hasLabel ? m.label : m.div;
|
|
58
|
+
return /* @__PURE__ */ jsx(SpringMotionConfig, {
|
|
59
|
+
reducedMotion: reduceMotion,
|
|
60
|
+
...isPressed ? pressTransition : hoverTransition,
|
|
61
|
+
children: /* @__PURE__ */ jsx(RootElement, {
|
|
62
|
+
className,
|
|
63
|
+
"data-testid": "container",
|
|
64
|
+
style,
|
|
65
|
+
onHoverStart,
|
|
66
|
+
onHoverEnd,
|
|
67
|
+
onTapStart,
|
|
68
|
+
onTap: onTapEnd,
|
|
69
|
+
onTapCancel: onTapEnd,
|
|
70
|
+
tabIndex: -1,
|
|
71
|
+
...rootSlotProps,
|
|
72
|
+
children
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
renderIndicator: ({ size, variant, checked, disabled, showHoverEffect, showPressedEffect, cssAnimationDuration, radioSlotProps, radioIconSlotProps, children }) => {
|
|
77
|
+
const scale = showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1;
|
|
78
|
+
const checkOpacity = checked ? showPressedEffect ? cx("opacity-55") : cx("opacity-100") : cx("opacity-0");
|
|
79
|
+
const showShadow = !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
80
|
+
const classNames = {
|
|
81
|
+
radio: getStyles({
|
|
82
|
+
radioSizeRadio: size,
|
|
83
|
+
radioVariantRadio: variant,
|
|
84
|
+
radioVariantValueRadio: checked ? "checked" : "unchecked",
|
|
85
|
+
className: cx([
|
|
86
|
+
"border",
|
|
87
|
+
"uds-ring",
|
|
88
|
+
"uds-ring-within",
|
|
89
|
+
cssAnimationDuration,
|
|
90
|
+
"transition-[background-color,border-color]",
|
|
91
|
+
"transition-shadow"
|
|
92
|
+
])
|
|
93
|
+
}),
|
|
94
|
+
radioCircle: getStyles({
|
|
95
|
+
radioVariantRadioCircle: variant,
|
|
96
|
+
radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
|
|
97
|
+
className: cx([
|
|
98
|
+
"pointer-events-none",
|
|
99
|
+
"w-[8px]",
|
|
100
|
+
"h-[8px]",
|
|
101
|
+
checkOpacity,
|
|
102
|
+
cssAnimationDuration,
|
|
103
|
+
"transition-opacity"
|
|
104
|
+
])
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
return /* @__PURE__ */ jsxs(MotionBox, {
|
|
178
108
|
position: "relative",
|
|
179
109
|
borderRadius: "full",
|
|
180
110
|
alignItems: "center",
|
|
181
111
|
justifyContent: "center",
|
|
182
112
|
flex: "none",
|
|
183
113
|
className: classNames.radio,
|
|
184
|
-
animate:
|
|
114
|
+
animate: { scale },
|
|
185
115
|
insetShadow: showShadow ? "lg-invert" : "none",
|
|
186
116
|
...radioSlotProps,
|
|
187
|
-
children: [/* @__PURE__ */ jsx(
|
|
188
|
-
type: "radio",
|
|
189
|
-
tabIndex: 0,
|
|
190
|
-
...radioProps,
|
|
191
|
-
ref: (ref) => {
|
|
192
|
-
innerRef.current = ref;
|
|
193
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
194
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
195
|
-
},
|
|
196
|
-
onFocus: handleFocus,
|
|
197
|
-
onBlur: handleBlur,
|
|
198
|
-
id: uid,
|
|
199
|
-
name,
|
|
200
|
-
value: valueProp,
|
|
201
|
-
disabled,
|
|
202
|
-
"aria-invalid": hasError,
|
|
203
|
-
onChange: handleOnChange,
|
|
204
|
-
...isControlled ? { checked } : { defaultChecked },
|
|
205
|
-
className: classNames.htmlRadio
|
|
206
|
-
}), /* @__PURE__ */ jsx(Box, {
|
|
117
|
+
children: [children, /* @__PURE__ */ jsx(Box, {
|
|
207
118
|
borderRadius: "full",
|
|
208
119
|
className: classNames.radioCircle,
|
|
209
120
|
...radioIconSlotProps
|
|
210
121
|
})]
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
variant: "inherit",
|
|
214
|
-
color: "inherit",
|
|
215
|
-
label,
|
|
216
|
-
className: classNames.label,
|
|
217
|
-
...labelSlotProps
|
|
218
|
-
})]
|
|
219
|
-
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
220
124
|
});
|
|
221
125
|
});
|
|
222
126
|
Radio.displayName = "Radio";
|