@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.
Files changed (107) hide show
  1. package/dist/components/client/BottomSheet/BottomSheet.cjs +2 -2
  2. package/dist/components/client/BottomSheet/BottomSheet.js +2 -2
  3. package/dist/components/client/Button/Button.cjs +2 -1
  4. package/dist/components/client/Button/Button.js +3 -2
  5. package/dist/components/client/Checkbox/Checkbox.cjs +118 -0
  6. package/dist/components/client/{Checkbox.d.cts → Checkbox/Checkbox.d.cts} +5 -18
  7. package/dist/components/client/{Checkbox.d.ts → Checkbox/Checkbox.d.ts} +5 -18
  8. package/dist/components/client/Checkbox/Checkbox.js +113 -0
  9. package/dist/components/client/Checkbox/CheckboxBase.cjs +141 -0
  10. package/dist/components/client/Checkbox/CheckboxBase.d.cts +48 -0
  11. package/dist/components/client/Checkbox/CheckboxBase.d.ts +49 -0
  12. package/dist/components/client/Checkbox/CheckboxBase.js +138 -0
  13. package/dist/components/client/Checkbox/checkboxConstants.cjs +23 -0
  14. package/dist/components/client/Checkbox/checkboxConstants.d.cts +25 -0
  15. package/dist/components/client/Checkbox/checkboxConstants.d.ts +26 -0
  16. package/dist/components/client/Checkbox/checkboxConstants.js +17 -0
  17. package/dist/components/client/Checkbox/index.cjs +10 -0
  18. package/dist/components/client/Checkbox/index.d.cts +6 -0
  19. package/dist/components/client/Checkbox/index.d.ts +7 -0
  20. package/dist/components/client/Checkbox/index.js +6 -0
  21. package/dist/components/client/Checkbox/types.cjs +2 -0
  22. package/dist/components/client/Checkbox/types.d.cts +22 -0
  23. package/dist/components/client/Checkbox/types.d.ts +23 -0
  24. package/dist/components/client/Checkbox/types.js +2 -0
  25. package/dist/components/client/Chip/ChipBase.cjs +2 -2
  26. package/dist/components/client/Chip/ChipBase.js +2 -2
  27. package/dist/components/client/IconButton/IconButton.cjs +2 -1
  28. package/dist/components/client/IconButton/IconButton.js +3 -2
  29. package/dist/components/client/Input/Input.cjs +2 -2
  30. package/dist/components/client/Input/Input.js +2 -2
  31. package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +1 -1
  32. package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +1 -1
  33. package/dist/components/client/Modal/ManagedModal.cjs +2 -2
  34. package/dist/components/client/Modal/ManagedModal.js +2 -2
  35. package/dist/components/client/Modal/Modal.cjs +2 -2
  36. package/dist/components/client/Modal/Modal.js +2 -2
  37. package/dist/components/client/Popover/Popover.cjs +2 -2
  38. package/dist/components/client/Popover/Popover.js +2 -2
  39. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.cts +1 -1
  40. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.ts +1 -1
  41. package/dist/components/client/Radio/Radio.cjs +69 -165
  42. package/dist/components/client/Radio/Radio.d.cts +4 -17
  43. package/dist/components/client/Radio/Radio.d.ts +4 -17
  44. package/dist/components/client/Radio/Radio.js +69 -165
  45. package/dist/components/client/Radio/RadioBase.cjs +133 -0
  46. package/dist/components/client/Radio/RadioBase.d.cts +45 -0
  47. package/dist/components/client/Radio/RadioBase.d.ts +46 -0
  48. package/dist/components/client/Radio/RadioBase.js +130 -0
  49. package/dist/components/client/Radio/radioConstants.cjs +14 -0
  50. package/dist/components/client/Radio/radioConstants.d.cts +8 -0
  51. package/dist/components/client/Radio/radioConstants.d.ts +9 -0
  52. package/dist/components/client/Radio/radioConstants.js +11 -0
  53. package/dist/components/client/Radio/types.cjs +2 -0
  54. package/dist/components/client/Radio/types.d.cts +20 -0
  55. package/dist/components/client/Radio/types.d.ts +21 -0
  56. package/dist/components/client/Radio/types.js +2 -0
  57. package/dist/components/client/Switch/Switch.cjs +1 -1
  58. package/dist/components/client/Switch/Switch.js +1 -1
  59. package/dist/components/client/Tabs/TabList.cjs +2 -2
  60. package/dist/components/client/Tabs/TabList.js +2 -2
  61. package/dist/components/client/Toast/Toast.cjs +2 -2
  62. package/dist/components/client/Toast/Toast.js +2 -2
  63. package/dist/components/client/index.cjs +2 -2
  64. package/dist/components/client/index.d.cts +1 -1
  65. package/dist/components/client/index.d.ts +1 -1
  66. package/dist/components/client/index.js +1 -1
  67. package/dist/components/index.cjs +2 -2
  68. package/dist/components/index.d.cts +1 -1
  69. package/dist/components/index.d.ts +1 -1
  70. package/dist/components/index.js +1 -1
  71. package/dist/css-animation/Checkbox/Checkbox.cjs +75 -0
  72. package/dist/css-animation/Checkbox/Checkbox.d.cts +22 -0
  73. package/dist/css-animation/Checkbox/Checkbox.d.ts +23 -0
  74. package/dist/css-animation/Checkbox/Checkbox.js +72 -0
  75. package/dist/css-animation/Checkbox/index.cjs +5 -0
  76. package/dist/css-animation/Checkbox/index.d.cts +3 -0
  77. package/dist/css-animation/Checkbox/index.d.ts +4 -0
  78. package/dist/css-animation/Checkbox/index.js +4 -0
  79. package/dist/css-animation/Radio/Radio.cjs +92 -0
  80. package/dist/css-animation/Radio/Radio.d.cts +22 -0
  81. package/dist/css-animation/Radio/Radio.d.ts +23 -0
  82. package/dist/css-animation/Radio/Radio.js +89 -0
  83. package/dist/css-animation/Radio/index.cjs +5 -0
  84. package/dist/css-animation/Radio/index.d.cts +3 -0
  85. package/dist/css-animation/Radio/index.d.ts +4 -0
  86. package/dist/css-animation/Radio/index.js +4 -0
  87. package/dist/css-animation/index.cjs +4 -0
  88. package/dist/css-animation/index.d.cts +3 -1
  89. package/dist/css-animation/index.d.ts +3 -1
  90. package/dist/css-animation/index.js +3 -1
  91. package/dist/hooks/usePrefersReducedMotion.cjs +27 -15
  92. package/dist/hooks/usePrefersReducedMotion.js +28 -16
  93. package/dist/index.cjs +2 -2
  94. package/dist/index.d.cts +1 -1
  95. package/dist/index.d.ts +1 -1
  96. package/dist/index.js +1 -1
  97. package/dist/styles/styler.d.cts +45 -45
  98. package/dist/styles/styler.d.ts +45 -45
  99. package/dist/uds/generated/componentData.cjs +2540 -2490
  100. package/dist/uds/generated/componentData.js +2540 -2490
  101. package/dist/uds/generated/tailwindPurge.cjs +12 -12
  102. package/dist/uds/generated/tailwindPurge.js +12 -12
  103. package/generated/componentData.json +3258 -3169
  104. package/generated/tailwindPurge.ts +2 -2
  105. package/package.json +1 -1
  106. package/dist/components/client/Checkbox.cjs +0 -223
  107. 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: ("bottom-start" | "bottom-end" | "top-start" | "top-end" | ("bottom" | "left" | "right" | "top") | "left-start" | "right-start" | "left-end" | "right-end") | undefined;
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 require_components_FormLabel = require("../../FormLabel.cjs");
7
+ const require_hooks_usePrefersReducedMotion = require("../../../hooks/usePrefersReducedMotion.cjs");
8
8
  const require_components_client_SpringMotionConfig = require("../SpringMotionConfig.cjs");
9
- const require_components_client_Radio_useRadioGroup = require("./useRadioGroup.cjs");
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({ id, name: nameProp, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: forceReduceMotion, value: valueProp = "", checked: checkedProp, defaultChecked, disabled, hasError, onChange, onFocus, onBlur, className, style, slotProps, ...radioProps }, parentRef) {
55
- const generatedId = (0, react.useId)();
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
- const classNames = {
124
- root: require_styles_styler.getStyles({
125
- radioSizeRoot: size,
126
- radioVariantValueRoot: checked ? "checked" : "unchecked",
127
- radioVariantRoot: variant,
128
- display: "flex",
129
- flexDirection: labelPosition === "start" ? "row" : "row-reverse",
130
- alignItems: "center",
131
- className: require_styles_styler.cx([{
132
- "cursor-pointer": !disabled,
133
- "cursor-default": disabled,
134
- "opacity-50": disabled
135
- }, className])
136
- }),
137
- radio: require_styles_styler.getStyles({
138
- radioSizeRadio: size,
139
- radioVariantRadio: variant,
140
- radioVariantValueRadio: checked ? "checked" : "unchecked",
141
- className: require_styles_styler.cx([
142
- "border",
143
- "uds-ring",
144
- "uds-ring-within",
145
- cssAnimationDuration,
146
- "transition-[background-color,border-color]",
147
- "transition-shadow"
148
- ])
149
- }),
150
- radioCircle: require_styles_styler.getStyles({
151
- radioVariantRadioCircle: variant,
152
- radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
153
- className: require_styles_styler.cx([
154
- "pointer-events-none",
155
- "w-[8px]",
156
- "h-[8px]",
157
- checkOpacity,
158
- cssAnimationDuration,
159
- "transition-opacity"
160
- ])
161
- }),
162
- htmlRadio: 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%]"),
163
- label: require_styles_styler.cx(labelPosition === "start" ? "text-start" : "text-end")
164
- };
165
- const RootElement = label ? motion_react.m.label : motion_react.m.div;
166
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
167
- reducedMotion: reduceMotion,
168
- ...motionTransition,
169
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RootElement, {
170
- className: classNames.root,
171
- "data-testid": "container",
172
- style,
173
- onHoverStart: handleHoverStart,
174
- onHoverEnd: handleHoverEnd,
175
- onTapStart: handleTapStart,
176
- onTap: handleTapEnd,
177
- onTapCancel: handleTapEnd,
178
- tabIndex: -1,
179
- ...rootSlotProps,
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: motionAnimate,
117
+ animate: { scale },
188
118
  insetShadow: showShadow ? "lg-invert" : "none",
189
119
  ...radioSlotProps,
190
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
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
- }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
215
- as: "div",
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 { RadioSize, RadioVariant, UniversalRadioProps } from "../../../types/dist/index.cjs";
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 NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'checked' | 'value' | 'size' | 'height' | 'width' | 'color' | 'required'>;
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 { RadioSize, RadioVariant, UniversalRadioProps } from "../../../types/dist/index.js";
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 NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'checked' | 'value' | 'size' | 'height' | 'width' | 'color' | 'required'>;
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 { FormLabel } from "../../FormLabel.js";
5
+ import { usePrefersReducedMotion } from "../../../hooks/usePrefersReducedMotion.js";
6
6
  import { SpringMotionConfig } from "../SpringMotionConfig.js";
7
- import { useRadioGroup } from "./useRadioGroup.js";
8
- import { forwardRef, useCallback, useId, useMemo, useRef, useState } from "react";
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, useReducedMotion } from "motion/react";
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({ id, name: nameProp, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: forceReduceMotion, value: valueProp = "", checked: checkedProp, defaultChecked, disabled, hasError, onChange, onFocus, onBlur, className, style, slotProps, ...radioProps }, parentRef) {
52
- const generatedId = useId();
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
- const classNames = {
121
- root: getStyles({
122
- radioSizeRoot: size,
123
- radioVariantValueRoot: checked ? "checked" : "unchecked",
124
- radioVariantRoot: variant,
125
- display: "flex",
126
- flexDirection: labelPosition === "start" ? "row" : "row-reverse",
127
- alignItems: "center",
128
- className: cx([{
129
- "cursor-pointer": !disabled,
130
- "cursor-default": disabled,
131
- "opacity-50": disabled
132
- }, className])
133
- }),
134
- radio: getStyles({
135
- radioSizeRadio: size,
136
- radioVariantRadio: variant,
137
- radioVariantValueRadio: checked ? "checked" : "unchecked",
138
- className: cx([
139
- "border",
140
- "uds-ring",
141
- "uds-ring-within",
142
- cssAnimationDuration,
143
- "transition-[background-color,border-color]",
144
- "transition-shadow"
145
- ])
146
- }),
147
- radioCircle: getStyles({
148
- radioVariantRadioCircle: variant,
149
- radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
150
- className: cx([
151
- "pointer-events-none",
152
- "w-[8px]",
153
- "h-[8px]",
154
- checkOpacity,
155
- cssAnimationDuration,
156
- "transition-opacity"
157
- ])
158
- }),
159
- htmlRadio: 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%]"),
160
- label: cx(labelPosition === "start" ? "text-start" : "text-end")
161
- };
162
- const RootElement = label ? m.label : m.div;
163
- return /* @__PURE__ */ jsx(SpringMotionConfig, {
164
- reducedMotion: reduceMotion,
165
- ...motionTransition,
166
- children: /* @__PURE__ */ jsxs(RootElement, {
167
- className: classNames.root,
168
- "data-testid": "container",
169
- style,
170
- onHoverStart: handleHoverStart,
171
- onHoverEnd: handleHoverEnd,
172
- onTapStart: handleTapStart,
173
- onTap: handleTapEnd,
174
- onTapCancel: handleTapEnd,
175
- tabIndex: -1,
176
- ...rootSlotProps,
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: motionAnimate,
114
+ animate: { scale },
185
115
  insetShadow: showShadow ? "lg-invert" : "none",
186
116
  ...radioSlotProps,
187
- children: [/* @__PURE__ */ jsx("input", {
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
- }), label && /* @__PURE__ */ jsx(FormLabel, {
212
- as: "div",
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";