@yahoo/uds 3.161.0 → 3.162.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/commands/purge.cjs +8 -1
- package/dist/cli/commands/purge.helpers.cjs +7 -0
- package/dist/cli/commands/purge.helpers.d.cts +3 -0
- package/dist/cli/commands/purge.helpers.d.ts +3 -0
- package/dist/cli/commands/purge.helpers.js +7 -0
- package/dist/cli/commands/purge.js +8 -1
- 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/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/dist/commands/css.cjs +2 -0
- package/dist/css/dist/commands/css.helpers.cjs +2 -0
- package/dist/css/dist/commands/css.helpers.js +2 -0
- package/dist/css/dist/commands/css.js +2 -0
- package/dist/css/dist/css/nodeUtils.cjs +28 -11
- package/dist/css/dist/css/nodeUtils.js +29 -12
- package/dist/css/dist/css/runner.cjs +8 -3
- package/dist/css/dist/css/runner.js +8 -3
- package/dist/css/dist/css/theme.d.cts +16 -0
- package/dist/css/dist/css/theme.d.ts +16 -0
- package/dist/css/dist/css/workerPool.cjs +2 -1
- package/dist/css/dist/css/workerPool.js +2 -1
- package/dist/css/dist/purger/optimized/ast/expressions.cjs +104 -11
- package/dist/css/dist/purger/optimized/ast/expressions.js +104 -11
- package/dist/css/dist/purger/optimized/ast/jsx.cjs +74 -0
- package/dist/css/dist/purger/optimized/ast/jsx.js +73 -0
- package/dist/css/dist/purger/optimized/ast/props.cjs +47 -0
- package/dist/css/dist/purger/optimized/ast/props.js +46 -0
- package/dist/css/dist/purger/optimized/ast/spread.cjs +87 -0
- package/dist/css/dist/purger/optimized/ast/spread.js +86 -0
- package/dist/css/dist/purger/optimized/purge.cjs +14 -8
- package/dist/css/dist/purger/optimized/purge.js +15 -9
- package/dist/css/dist/purger/optimized/purgeFromCode.cjs +176 -18
- package/dist/css/dist/purger/optimized/purgeFromCode.js +176 -19
- package/dist/css/dist/purger/optimized/utils/files.cjs +22 -2
- package/dist/css/dist/purger/optimized/utils/files.js +21 -3
- 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 +26 -26
- package/dist/styles/styler.d.ts +26 -26
- package/dist/uds/generated/componentData.cjs +343 -293
- package/dist/uds/generated/componentData.js +343 -293
- package/dist/uds/generated/tailwindPurge.cjs +12 -12
- package/dist/uds/generated/tailwindPurge.js +12 -12
- package/generated/componentData.json +471 -382
- 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
|
@@ -4,22 +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 require_components_FormLabel = require("../../FormLabel.cjs");
|
|
8
7
|
const require_hooks_usePrefersReducedMotion = require("../../../hooks/usePrefersReducedMotion.cjs");
|
|
9
8
|
const require_components_client_SpringMotionConfig = require("../SpringMotionConfig.cjs");
|
|
10
|
-
const
|
|
9
|
+
const require_components_client_Radio_radioConstants = require("./radioConstants.cjs");
|
|
10
|
+
const require_components_client_Radio_RadioBase = require("./RadioBase.cjs");
|
|
11
11
|
let react = require("react");
|
|
12
12
|
react = require_runtime.__toESM(react);
|
|
13
13
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
14
14
|
let motion_react = require("motion/react");
|
|
15
15
|
//#region src/components/client/Radio/Radio.tsx
|
|
16
|
-
const RADIO_VARIANTS = ["primary", "secondary"];
|
|
17
|
-
const RADIO_SIZES = ["sm", "md"];
|
|
18
|
-
const VARIANT_ERROR_MAP = {
|
|
19
|
-
primary: "alert",
|
|
20
|
-
secondary: "alert-secondary"
|
|
21
|
-
};
|
|
22
16
|
const MotionBox = motion_react.m.create(require_components_Box.Box);
|
|
17
|
+
MotionBox.displayName = "RadioMotionBox";
|
|
23
18
|
const hoverTransition = {
|
|
24
19
|
layoutVariant: "smooth",
|
|
25
20
|
layoutSpeed: "3"
|
|
@@ -52,179 +47,87 @@ const pressTransition = {
|
|
|
52
47
|
*
|
|
53
48
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
54
49
|
**/
|
|
55
|
-
const Radio = (0, react.forwardRef)(function Radio({
|
|
56
|
-
const generatedId = (0, react.useId)();
|
|
57
|
-
const uid = id ?? `uds-radio-${generatedId}`;
|
|
58
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
59
|
-
const radioSlotProps = slotProps?.radio ?? {};
|
|
60
|
-
const radioIconSlotProps = slotProps?.radioIcon ?? {};
|
|
61
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
62
|
-
const innerRef = (0, react.useRef)(null);
|
|
63
|
-
/**
|
|
64
|
-
* State
|
|
65
|
-
*/
|
|
66
|
-
const { name, isControlled, checked, setGroupValue } = require_components_client_Radio_useRadioGroup.useRadioGroup({
|
|
67
|
-
name: nameProp,
|
|
68
|
-
value: valueProp,
|
|
69
|
-
checked: checkedProp,
|
|
70
|
-
defaultChecked
|
|
71
|
-
});
|
|
72
|
-
const [isHovered, setIsHovered] = (0, react.useState)(false);
|
|
73
|
-
const [isPressed, setIsPressed] = (0, react.useState)(false);
|
|
74
|
-
/**
|
|
75
|
-
* Derived values
|
|
76
|
-
*/
|
|
77
|
-
const variant = (0, react.useMemo)(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
78
|
-
const showHoverEffect = (0, react.useMemo)(() => !disabled && isHovered, [disabled, isHovered]);
|
|
79
|
-
const showPressedEffect = (0, react.useMemo)(() => !disabled && !checked && isPressed, [
|
|
80
|
-
checked,
|
|
81
|
-
disabled,
|
|
82
|
-
isPressed
|
|
83
|
-
]);
|
|
84
|
-
const scale = (0, react.useMemo)(() => showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1, [showHoverEffect, showPressedEffect]);
|
|
85
|
-
const checkOpacity = (0, react.useMemo)(() => checked ? showPressedEffect ? "opacity-55" : "opacity-100" : "opacity-0", [checked, showPressedEffect]);
|
|
86
|
-
const showShadow = (0, react.useMemo)(() => {
|
|
87
|
-
return !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
88
|
-
}, [
|
|
89
|
-
checked,
|
|
90
|
-
disabled,
|
|
91
|
-
showHoverEffect,
|
|
92
|
-
showPressedEffect
|
|
93
|
-
]);
|
|
94
|
-
const motionAnimate = (0, react.useMemo)(() => ({ scale }), [scale]);
|
|
95
|
-
const motionTransition = (0, react.useMemo)(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
96
|
-
/**
|
|
97
|
-
* Handlers
|
|
98
|
-
*/
|
|
99
|
-
const handleOnChange = (0, react.useCallback)((e) => {
|
|
100
|
-
setGroupValue(e.target.value);
|
|
101
|
-
onChange?.(e);
|
|
102
|
-
}, [onChange, setGroupValue]);
|
|
103
|
-
const handleFocus = (0, react.useCallback)((e) => {
|
|
104
|
-
onFocus?.(e);
|
|
105
|
-
}, [onFocus]);
|
|
106
|
-
const handleBlur = (0, react.useCallback)((e) => {
|
|
107
|
-
onBlur?.(e);
|
|
108
|
-
}, [onBlur]);
|
|
109
|
-
const handleHoverStart = (0, react.useCallback)(() => {
|
|
110
|
-
setIsHovered(true);
|
|
111
|
-
}, []);
|
|
112
|
-
const handleHoverEnd = (0, react.useCallback)(() => {
|
|
113
|
-
setIsHovered(false);
|
|
114
|
-
}, []);
|
|
115
|
-
const handleTapStart = (0, react.useCallback)(() => {
|
|
116
|
-
setIsPressed(true);
|
|
117
|
-
}, []);
|
|
118
|
-
const handleTapEnd = (0, react.useCallback)(() => {
|
|
119
|
-
setIsPressed(false);
|
|
120
|
-
}, []);
|
|
50
|
+
const Radio = (0, react.forwardRef)(function Radio({ reduceMotion: forceReduceMotion, ...props }, parentRef) {
|
|
121
51
|
const prefersReducedMotion = require_hooks_usePrefersReducedMotion.usePrefersReducedMotion();
|
|
122
52
|
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
123
53
|
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-120";
|
|
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
|
-
|
|
181
|
-
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, {
|
|
182
111
|
position: "relative",
|
|
183
112
|
borderRadius: "full",
|
|
184
113
|
alignItems: "center",
|
|
185
114
|
justifyContent: "center",
|
|
186
115
|
flex: "none",
|
|
187
116
|
className: classNames.radio,
|
|
188
|
-
animate:
|
|
117
|
+
animate: { scale },
|
|
189
118
|
insetShadow: showShadow ? "lg-invert" : "none",
|
|
190
119
|
...radioSlotProps,
|
|
191
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
192
|
-
type: "radio",
|
|
193
|
-
tabIndex: 0,
|
|
194
|
-
...radioProps,
|
|
195
|
-
ref: (ref) => {
|
|
196
|
-
innerRef.current = ref;
|
|
197
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
198
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
199
|
-
},
|
|
200
|
-
onFocus: handleFocus,
|
|
201
|
-
onBlur: handleBlur,
|
|
202
|
-
id: uid,
|
|
203
|
-
name,
|
|
204
|
-
value: valueProp,
|
|
205
|
-
disabled,
|
|
206
|
-
"aria-invalid": hasError,
|
|
207
|
-
onChange: handleOnChange,
|
|
208
|
-
...isControlled ? { checked } : { defaultChecked },
|
|
209
|
-
className: classNames.htmlRadio
|
|
210
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
|
|
120
|
+
children: [children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
|
|
211
121
|
borderRadius: "full",
|
|
212
122
|
className: classNames.radioCircle,
|
|
213
123
|
...radioIconSlotProps
|
|
214
124
|
})]
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
variant: "inherit",
|
|
218
|
-
color: "inherit",
|
|
219
|
-
label,
|
|
220
|
-
className: classNames.label,
|
|
221
|
-
...labelSlotProps
|
|
222
|
-
})]
|
|
223
|
-
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
224
127
|
});
|
|
225
128
|
});
|
|
226
129
|
Radio.displayName = "Radio";
|
|
227
130
|
//#endregion
|
|
228
|
-
exports.RADIO_SIZES = RADIO_SIZES;
|
|
229
|
-
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;
|
|
230
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,21 +2,16 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { cx, getStyles } from "../../../styles/styler.js";
|
|
4
4
|
import { Box } from "../../Box.js";
|
|
5
|
-
import { FormLabel } from "../../FormLabel.js";
|
|
6
5
|
import { usePrefersReducedMotion } from "../../../hooks/usePrefersReducedMotion.js";
|
|
7
6
|
import { SpringMotionConfig } from "../SpringMotionConfig.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { RADIO_SIZES, RADIO_VARIANTS } from "./radioConstants.js";
|
|
8
|
+
import { RadioBase } from "./RadioBase.js";
|
|
9
|
+
import { forwardRef } from "react";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { m } from "motion/react";
|
|
12
12
|
//#region src/components/client/Radio/Radio.tsx
|
|
13
|
-
const RADIO_VARIANTS = ["primary", "secondary"];
|
|
14
|
-
const RADIO_SIZES = ["sm", "md"];
|
|
15
|
-
const VARIANT_ERROR_MAP = {
|
|
16
|
-
primary: "alert",
|
|
17
|
-
secondary: "alert-secondary"
|
|
18
|
-
};
|
|
19
13
|
const MotionBox = m.create(Box);
|
|
14
|
+
MotionBox.displayName = "RadioMotionBox";
|
|
20
15
|
const hoverTransition = {
|
|
21
16
|
layoutVariant: "smooth",
|
|
22
17
|
layoutSpeed: "3"
|
|
@@ -49,175 +44,83 @@ const pressTransition = {
|
|
|
49
44
|
*
|
|
50
45
|
* @related [Radio](https://uds.build/docs/components/Radio).
|
|
51
46
|
**/
|
|
52
|
-
const Radio = forwardRef(function Radio({
|
|
53
|
-
const generatedId = useId();
|
|
54
|
-
const uid = id ?? `uds-radio-${generatedId}`;
|
|
55
|
-
const rootSlotProps = slotProps?.root ?? {};
|
|
56
|
-
const radioSlotProps = slotProps?.radio ?? {};
|
|
57
|
-
const radioIconSlotProps = slotProps?.radioIcon ?? {};
|
|
58
|
-
const labelSlotProps = slotProps?.label ?? {};
|
|
59
|
-
const innerRef = useRef(null);
|
|
60
|
-
/**
|
|
61
|
-
* State
|
|
62
|
-
*/
|
|
63
|
-
const { name, isControlled, checked, setGroupValue } = useRadioGroup({
|
|
64
|
-
name: nameProp,
|
|
65
|
-
value: valueProp,
|
|
66
|
-
checked: checkedProp,
|
|
67
|
-
defaultChecked
|
|
68
|
-
});
|
|
69
|
-
const [isHovered, setIsHovered] = useState(false);
|
|
70
|
-
const [isPressed, setIsPressed] = useState(false);
|
|
71
|
-
/**
|
|
72
|
-
* Derived values
|
|
73
|
-
*/
|
|
74
|
-
const variant = useMemo(() => hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
|
|
75
|
-
const showHoverEffect = useMemo(() => !disabled && isHovered, [disabled, isHovered]);
|
|
76
|
-
const showPressedEffect = useMemo(() => !disabled && !checked && isPressed, [
|
|
77
|
-
checked,
|
|
78
|
-
disabled,
|
|
79
|
-
isPressed
|
|
80
|
-
]);
|
|
81
|
-
const scale = useMemo(() => showPressedEffect ? .9 : showHoverEffect ? 1.1 : 1, [showHoverEffect, showPressedEffect]);
|
|
82
|
-
const checkOpacity = useMemo(() => checked ? showPressedEffect ? "opacity-55" : "opacity-100" : "opacity-0", [checked, showPressedEffect]);
|
|
83
|
-
const showShadow = useMemo(() => {
|
|
84
|
-
return !disabled && (showPressedEffect && !checked || showHoverEffect && checked);
|
|
85
|
-
}, [
|
|
86
|
-
checked,
|
|
87
|
-
disabled,
|
|
88
|
-
showHoverEffect,
|
|
89
|
-
showPressedEffect
|
|
90
|
-
]);
|
|
91
|
-
const motionAnimate = useMemo(() => ({ scale }), [scale]);
|
|
92
|
-
const motionTransition = useMemo(() => isPressed ? pressTransition : hoverTransition, [isPressed]);
|
|
93
|
-
/**
|
|
94
|
-
* Handlers
|
|
95
|
-
*/
|
|
96
|
-
const handleOnChange = useCallback((e) => {
|
|
97
|
-
setGroupValue(e.target.value);
|
|
98
|
-
onChange?.(e);
|
|
99
|
-
}, [onChange, setGroupValue]);
|
|
100
|
-
const handleFocus = useCallback((e) => {
|
|
101
|
-
onFocus?.(e);
|
|
102
|
-
}, [onFocus]);
|
|
103
|
-
const handleBlur = useCallback((e) => {
|
|
104
|
-
onBlur?.(e);
|
|
105
|
-
}, [onBlur]);
|
|
106
|
-
const handleHoverStart = useCallback(() => {
|
|
107
|
-
setIsHovered(true);
|
|
108
|
-
}, []);
|
|
109
|
-
const handleHoverEnd = useCallback(() => {
|
|
110
|
-
setIsHovered(false);
|
|
111
|
-
}, []);
|
|
112
|
-
const handleTapStart = useCallback(() => {
|
|
113
|
-
setIsPressed(true);
|
|
114
|
-
}, []);
|
|
115
|
-
const handleTapEnd = useCallback(() => {
|
|
116
|
-
setIsPressed(false);
|
|
117
|
-
}, []);
|
|
47
|
+
const Radio = forwardRef(function Radio({ reduceMotion: forceReduceMotion, ...props }, parentRef) {
|
|
118
48
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
119
49
|
const reduceMotion = forceReduceMotion ? "always" : "user";
|
|
120
50
|
const cssAnimationDuration = prefersReducedMotion || forceReduceMotion ? "duration-0" : "duration-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
|
-
|
|
178
|
-
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, {
|
|
179
108
|
position: "relative",
|
|
180
109
|
borderRadius: "full",
|
|
181
110
|
alignItems: "center",
|
|
182
111
|
justifyContent: "center",
|
|
183
112
|
flex: "none",
|
|
184
113
|
className: classNames.radio,
|
|
185
|
-
animate:
|
|
114
|
+
animate: { scale },
|
|
186
115
|
insetShadow: showShadow ? "lg-invert" : "none",
|
|
187
116
|
...radioSlotProps,
|
|
188
|
-
children: [/* @__PURE__ */ jsx(
|
|
189
|
-
type: "radio",
|
|
190
|
-
tabIndex: 0,
|
|
191
|
-
...radioProps,
|
|
192
|
-
ref: (ref) => {
|
|
193
|
-
innerRef.current = ref;
|
|
194
|
-
if (typeof parentRef === "function") parentRef(ref);
|
|
195
|
-
else if (parentRef !== null) parentRef.current = ref;
|
|
196
|
-
},
|
|
197
|
-
onFocus: handleFocus,
|
|
198
|
-
onBlur: handleBlur,
|
|
199
|
-
id: uid,
|
|
200
|
-
name,
|
|
201
|
-
value: valueProp,
|
|
202
|
-
disabled,
|
|
203
|
-
"aria-invalid": hasError,
|
|
204
|
-
onChange: handleOnChange,
|
|
205
|
-
...isControlled ? { checked } : { defaultChecked },
|
|
206
|
-
className: classNames.htmlRadio
|
|
207
|
-
}), /* @__PURE__ */ jsx(Box, {
|
|
117
|
+
children: [children, /* @__PURE__ */ jsx(Box, {
|
|
208
118
|
borderRadius: "full",
|
|
209
119
|
className: classNames.radioCircle,
|
|
210
120
|
...radioIconSlotProps
|
|
211
121
|
})]
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
variant: "inherit",
|
|
215
|
-
color: "inherit",
|
|
216
|
-
label,
|
|
217
|
-
className: classNames.label,
|
|
218
|
-
...labelSlotProps
|
|
219
|
-
})]
|
|
220
|
-
})
|
|
122
|
+
});
|
|
123
|
+
}
|
|
221
124
|
});
|
|
222
125
|
});
|
|
223
126
|
Radio.displayName = "Radio";
|