@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.
Files changed (115) hide show
  1. package/dist/cli/commands/purge.cjs +8 -1
  2. package/dist/cli/commands/purge.helpers.cjs +7 -0
  3. package/dist/cli/commands/purge.helpers.d.cts +3 -0
  4. package/dist/cli/commands/purge.helpers.d.ts +3 -0
  5. package/dist/cli/commands/purge.helpers.js +7 -0
  6. package/dist/cli/commands/purge.js +8 -1
  7. package/dist/components/client/Checkbox/Checkbox.cjs +118 -0
  8. package/dist/components/client/{Checkbox.d.cts → Checkbox/Checkbox.d.cts} +5 -18
  9. package/dist/components/client/{Checkbox.d.ts → Checkbox/Checkbox.d.ts} +5 -18
  10. package/dist/components/client/Checkbox/Checkbox.js +113 -0
  11. package/dist/components/client/Checkbox/CheckboxBase.cjs +141 -0
  12. package/dist/components/client/Checkbox/CheckboxBase.d.cts +48 -0
  13. package/dist/components/client/Checkbox/CheckboxBase.d.ts +49 -0
  14. package/dist/components/client/Checkbox/CheckboxBase.js +138 -0
  15. package/dist/components/client/Checkbox/checkboxConstants.cjs +23 -0
  16. package/dist/components/client/Checkbox/checkboxConstants.d.cts +25 -0
  17. package/dist/components/client/Checkbox/checkboxConstants.d.ts +26 -0
  18. package/dist/components/client/Checkbox/checkboxConstants.js +17 -0
  19. package/dist/components/client/Checkbox/index.cjs +10 -0
  20. package/dist/components/client/Checkbox/index.d.cts +6 -0
  21. package/dist/components/client/Checkbox/index.d.ts +7 -0
  22. package/dist/components/client/Checkbox/index.js +6 -0
  23. package/dist/components/client/Checkbox/types.cjs +2 -0
  24. package/dist/components/client/Checkbox/types.d.cts +22 -0
  25. package/dist/components/client/Checkbox/types.d.ts +23 -0
  26. package/dist/components/client/Checkbox/types.js +2 -0
  27. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.cts +1 -1
  28. package/dist/components/client/Popover/UDSPopoverConfigProvider.d.ts +1 -1
  29. package/dist/components/client/Radio/Radio.cjs +67 -164
  30. package/dist/components/client/Radio/Radio.d.cts +4 -17
  31. package/dist/components/client/Radio/Radio.d.ts +4 -17
  32. package/dist/components/client/Radio/Radio.js +66 -163
  33. package/dist/components/client/Radio/RadioBase.cjs +133 -0
  34. package/dist/components/client/Radio/RadioBase.d.cts +45 -0
  35. package/dist/components/client/Radio/RadioBase.d.ts +46 -0
  36. package/dist/components/client/Radio/RadioBase.js +130 -0
  37. package/dist/components/client/Radio/radioConstants.cjs +14 -0
  38. package/dist/components/client/Radio/radioConstants.d.cts +8 -0
  39. package/dist/components/client/Radio/radioConstants.d.ts +9 -0
  40. package/dist/components/client/Radio/radioConstants.js +11 -0
  41. package/dist/components/client/Radio/types.cjs +2 -0
  42. package/dist/components/client/Radio/types.d.cts +20 -0
  43. package/dist/components/client/Radio/types.d.ts +21 -0
  44. package/dist/components/client/Radio/types.js +2 -0
  45. package/dist/components/client/Toast/UDSToastConfigProvider.d.cts +1 -1
  46. package/dist/components/client/Toast/UDSToastConfigProvider.d.ts +1 -1
  47. package/dist/components/client/index.cjs +2 -2
  48. package/dist/components/client/index.d.cts +1 -1
  49. package/dist/components/client/index.d.ts +1 -1
  50. package/dist/components/client/index.js +1 -1
  51. package/dist/components/index.cjs +2 -2
  52. package/dist/components/index.d.cts +1 -1
  53. package/dist/components/index.d.ts +1 -1
  54. package/dist/components/index.js +1 -1
  55. package/dist/css/dist/commands/css.cjs +2 -0
  56. package/dist/css/dist/commands/css.helpers.cjs +2 -0
  57. package/dist/css/dist/commands/css.helpers.js +2 -0
  58. package/dist/css/dist/commands/css.js +2 -0
  59. package/dist/css/dist/css/nodeUtils.cjs +28 -11
  60. package/dist/css/dist/css/nodeUtils.js +29 -12
  61. package/dist/css/dist/css/runner.cjs +8 -3
  62. package/dist/css/dist/css/runner.js +8 -3
  63. package/dist/css/dist/css/theme.d.cts +16 -0
  64. package/dist/css/dist/css/theme.d.ts +16 -0
  65. package/dist/css/dist/css/workerPool.cjs +2 -1
  66. package/dist/css/dist/css/workerPool.js +2 -1
  67. package/dist/css/dist/purger/optimized/ast/expressions.cjs +104 -11
  68. package/dist/css/dist/purger/optimized/ast/expressions.js +104 -11
  69. package/dist/css/dist/purger/optimized/ast/jsx.cjs +74 -0
  70. package/dist/css/dist/purger/optimized/ast/jsx.js +73 -0
  71. package/dist/css/dist/purger/optimized/ast/props.cjs +47 -0
  72. package/dist/css/dist/purger/optimized/ast/props.js +46 -0
  73. package/dist/css/dist/purger/optimized/ast/spread.cjs +87 -0
  74. package/dist/css/dist/purger/optimized/ast/spread.js +86 -0
  75. package/dist/css/dist/purger/optimized/purge.cjs +14 -8
  76. package/dist/css/dist/purger/optimized/purge.js +15 -9
  77. package/dist/css/dist/purger/optimized/purgeFromCode.cjs +176 -18
  78. package/dist/css/dist/purger/optimized/purgeFromCode.js +176 -19
  79. package/dist/css/dist/purger/optimized/utils/files.cjs +22 -2
  80. package/dist/css/dist/purger/optimized/utils/files.js +21 -3
  81. package/dist/css-animation/Checkbox/Checkbox.cjs +75 -0
  82. package/dist/css-animation/Checkbox/Checkbox.d.cts +22 -0
  83. package/dist/css-animation/Checkbox/Checkbox.d.ts +23 -0
  84. package/dist/css-animation/Checkbox/Checkbox.js +72 -0
  85. package/dist/css-animation/Checkbox/index.cjs +5 -0
  86. package/dist/css-animation/Checkbox/index.d.cts +3 -0
  87. package/dist/css-animation/Checkbox/index.d.ts +4 -0
  88. package/dist/css-animation/Checkbox/index.js +4 -0
  89. package/dist/css-animation/Radio/Radio.cjs +92 -0
  90. package/dist/css-animation/Radio/Radio.d.cts +22 -0
  91. package/dist/css-animation/Radio/Radio.d.ts +23 -0
  92. package/dist/css-animation/Radio/Radio.js +89 -0
  93. package/dist/css-animation/Radio/index.cjs +5 -0
  94. package/dist/css-animation/Radio/index.d.cts +3 -0
  95. package/dist/css-animation/Radio/index.d.ts +4 -0
  96. package/dist/css-animation/Radio/index.js +4 -0
  97. package/dist/css-animation/index.cjs +4 -0
  98. package/dist/css-animation/index.d.cts +3 -1
  99. package/dist/css-animation/index.d.ts +3 -1
  100. package/dist/css-animation/index.js +3 -1
  101. package/dist/index.cjs +2 -2
  102. package/dist/index.d.cts +1 -1
  103. package/dist/index.d.ts +1 -1
  104. package/dist/index.js +1 -1
  105. package/dist/styles/styler.d.cts +26 -26
  106. package/dist/styles/styler.d.ts +26 -26
  107. package/dist/uds/generated/componentData.cjs +343 -293
  108. package/dist/uds/generated/componentData.js +343 -293
  109. package/dist/uds/generated/tailwindPurge.cjs +12 -12
  110. package/dist/uds/generated/tailwindPurge.js +12 -12
  111. package/generated/componentData.json +471 -382
  112. package/generated/tailwindPurge.ts +2 -2
  113. package/package.json +1 -1
  114. package/dist/components/client/Checkbox.cjs +0 -224
  115. 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 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");
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({ 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) {
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
- const classNames = {
125
- root: require_styles_styler.getStyles({
126
- radioSizeRoot: size,
127
- radioVariantValueRoot: checked ? "checked" : "unchecked",
128
- radioVariantRoot: variant,
129
- display: "flex",
130
- flexDirection: labelPosition === "start" ? "row" : "row-reverse",
131
- alignItems: "center",
132
- className: require_styles_styler.cx([{
133
- "cursor-pointer": !disabled,
134
- "cursor-default": disabled,
135
- "opacity-50": disabled
136
- }, className])
137
- }),
138
- radio: require_styles_styler.getStyles({
139
- radioSizeRadio: size,
140
- radioVariantRadio: variant,
141
- radioVariantValueRadio: checked ? "checked" : "unchecked",
142
- className: require_styles_styler.cx([
143
- "border",
144
- "uds-ring",
145
- "uds-ring-within",
146
- cssAnimationDuration,
147
- "transition-[background-color,border-color]",
148
- "transition-shadow"
149
- ])
150
- }),
151
- radioCircle: require_styles_styler.getStyles({
152
- radioVariantRadioCircle: variant,
153
- radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
154
- className: require_styles_styler.cx([
155
- "pointer-events-none",
156
- "w-[8px]",
157
- "h-[8px]",
158
- checkOpacity,
159
- cssAnimationDuration,
160
- "transition-opacity"
161
- ])
162
- }),
163
- 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%]"),
164
- label: require_styles_styler.cx(labelPosition === "start" ? "text-start" : "text-end")
165
- };
166
- const RootElement = label ? motion_react.m.label : motion_react.m.div;
167
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
168
- reducedMotion: reduceMotion,
169
- ...motionTransition,
170
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RootElement, {
171
- className: classNames.root,
172
- "data-testid": "container",
173
- style,
174
- onHoverStart: handleHoverStart,
175
- onHoverEnd: handleHoverEnd,
176
- onTapStart: handleTapStart,
177
- onTap: handleTapEnd,
178
- onTapCancel: handleTapEnd,
179
- tabIndex: -1,
180
- ...rootSlotProps,
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: motionAnimate,
117
+ animate: { scale },
189
118
  insetShadow: showShadow ? "lg-invert" : "none",
190
119
  ...radioSlotProps,
191
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
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
- }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
216
- as: "div",
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 { 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,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 { useRadioGroup } from "./useRadioGroup.js";
9
- 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";
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({ 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) {
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
- const classNames = {
122
- root: getStyles({
123
- radioSizeRoot: size,
124
- radioVariantValueRoot: checked ? "checked" : "unchecked",
125
- radioVariantRoot: variant,
126
- display: "flex",
127
- flexDirection: labelPosition === "start" ? "row" : "row-reverse",
128
- alignItems: "center",
129
- className: cx([{
130
- "cursor-pointer": !disabled,
131
- "cursor-default": disabled,
132
- "opacity-50": disabled
133
- }, className])
134
- }),
135
- radio: getStyles({
136
- radioSizeRadio: size,
137
- radioVariantRadio: variant,
138
- radioVariantValueRadio: checked ? "checked" : "unchecked",
139
- className: cx([
140
- "border",
141
- "uds-ring",
142
- "uds-ring-within",
143
- cssAnimationDuration,
144
- "transition-[background-color,border-color]",
145
- "transition-shadow"
146
- ])
147
- }),
148
- radioCircle: getStyles({
149
- radioVariantRadioCircle: variant,
150
- radioVariantValueRadioCircle: checked ? "checked" : "unchecked",
151
- className: cx([
152
- "pointer-events-none",
153
- "w-[8px]",
154
- "h-[8px]",
155
- checkOpacity,
156
- cssAnimationDuration,
157
- "transition-opacity"
158
- ])
159
- }),
160
- 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%]"),
161
- label: cx(labelPosition === "start" ? "text-start" : "text-end")
162
- };
163
- const RootElement = label ? m.label : m.div;
164
- return /* @__PURE__ */ jsx(SpringMotionConfig, {
165
- reducedMotion: reduceMotion,
166
- ...motionTransition,
167
- children: /* @__PURE__ */ jsxs(RootElement, {
168
- className: classNames.root,
169
- "data-testid": "container",
170
- style,
171
- onHoverStart: handleHoverStart,
172
- onHoverEnd: handleHoverEnd,
173
- onTapStart: handleTapStart,
174
- onTap: handleTapEnd,
175
- onTapCancel: handleTapEnd,
176
- tabIndex: -1,
177
- ...rootSlotProps,
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: motionAnimate,
114
+ animate: { scale },
186
115
  insetShadow: showShadow ? "lg-invert" : "none",
187
116
  ...radioSlotProps,
188
- children: [/* @__PURE__ */ jsx("input", {
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
- }), label && /* @__PURE__ */ jsx(FormLabel, {
213
- as: "div",
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";