@yahoo/uds 3.159.1 → 3.160.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 (149) hide show
  1. package/dist/automated-config/dist/properties.cjs +1 -1
  2. package/dist/automated-config/dist/properties.js +1 -1
  3. package/dist/components/Text.cjs +4 -2
  4. package/dist/components/Text.js +4 -2
  5. package/dist/components/client/Button/Button.cjs +213 -0
  6. package/dist/components/client/Button/Button.d.cts +50 -0
  7. package/dist/components/client/Button/Button.d.ts +51 -0
  8. package/dist/components/client/Button/Button.js +208 -0
  9. package/dist/components/client/Button/ButtonBase.cjs +120 -0
  10. package/dist/components/client/Button/ButtonBase.d.cts +52 -0
  11. package/dist/components/client/Button/ButtonBase.d.ts +53 -0
  12. package/dist/components/client/Button/ButtonBase.js +116 -0
  13. package/dist/components/client/{buttonConstants.cjs → Button/buttonConstants.cjs} +1 -1
  14. package/dist/components/client/Button/buttonConstants.d.cts +7 -0
  15. package/dist/components/client/Button/buttonConstants.d.ts +8 -0
  16. package/dist/components/client/{buttonConstants.js → Button/buttonConstants.js} +1 -1
  17. package/dist/components/client/Button/index.cjs +10 -0
  18. package/dist/components/client/Button/index.d.cts +4 -0
  19. package/dist/components/client/Button/index.d.ts +5 -0
  20. package/dist/components/client/Button/index.js +5 -0
  21. package/dist/components/client/IconButton/IconButton.cjs +104 -0
  22. package/dist/components/client/IconButton/IconButton.d.cts +17 -0
  23. package/dist/components/client/IconButton/IconButton.d.ts +18 -0
  24. package/dist/components/client/IconButton/IconButton.js +102 -0
  25. package/dist/components/client/IconButton/IconButtonBase.cjs +68 -0
  26. package/dist/components/client/IconButton/IconButtonBase.d.cts +45 -0
  27. package/dist/components/client/IconButton/IconButtonBase.d.ts +46 -0
  28. package/dist/components/client/IconButton/IconButtonBase.js +65 -0
  29. package/dist/components/client/IconButton/index.cjs +8 -0
  30. package/dist/components/client/IconButton/index.d.cts +4 -0
  31. package/dist/components/client/IconButton/index.d.ts +5 -0
  32. package/dist/components/client/IconButton/index.js +5 -0
  33. package/dist/components/client/Pressable.cjs +3 -1
  34. package/dist/components/client/Pressable.js +3 -1
  35. package/dist/components/client/SpringMotionConfig.cjs +10 -13
  36. package/dist/components/client/SpringMotionConfig.js +10 -13
  37. package/dist/components/client/Switch/Switch.cjs +119 -0
  38. package/dist/components/client/{Switch.d.cts → Switch/Switch.d.cts} +4 -16
  39. package/dist/components/client/{Switch.d.ts → Switch/Switch.d.ts} +4 -16
  40. package/dist/components/client/Switch/Switch.js +115 -0
  41. package/dist/components/client/Switch/SwitchBase.cjs +129 -0
  42. package/dist/components/client/Switch/SwitchBase.d.cts +29 -0
  43. package/dist/components/client/Switch/SwitchBase.d.ts +30 -0
  44. package/dist/components/client/Switch/SwitchBase.js +126 -0
  45. package/dist/components/client/Switch/index.cjs +5 -0
  46. package/dist/components/client/Switch/index.d.cts +3 -0
  47. package/dist/components/client/Switch/index.d.ts +4 -0
  48. package/dist/components/client/Switch/index.js +4 -0
  49. package/dist/components/client/Switch/switchStyles.cjs +17 -0
  50. package/dist/components/client/Switch/switchStyles.d.cts +9 -0
  51. package/dist/components/client/Switch/switchStyles.d.ts +10 -0
  52. package/dist/components/client/Switch/switchStyles.js +16 -0
  53. package/dist/components/client/Switch/types.cjs +2 -0
  54. package/dist/components/client/Switch/types.d.cts +33 -0
  55. package/dist/components/client/Switch/types.d.ts +34 -0
  56. package/dist/components/client/Switch/types.js +2 -0
  57. package/dist/components/client/Toast/Toast.cjs +2 -2
  58. package/dist/components/client/Toast/Toast.d.cts +1 -1
  59. package/dist/components/client/Toast/Toast.d.ts +1 -1
  60. package/dist/components/client/Toast/Toast.js +1 -1
  61. package/dist/components/client/index.cjs +6 -6
  62. package/dist/components/client/index.d.cts +3 -3
  63. package/dist/components/client/index.d.ts +3 -3
  64. package/dist/components/client/index.js +3 -3
  65. package/dist/components/experimental/client/index.cjs +0 -6
  66. package/dist/components/experimental/client/index.d.cts +1 -3
  67. package/dist/components/experimental/client/index.d.ts +1 -3
  68. package/dist/components/experimental/client/index.js +1 -3
  69. package/dist/components/experimental/index.cjs +0 -5
  70. package/dist/components/experimental/index.d.cts +1 -3
  71. package/dist/components/experimental/index.d.ts +1 -3
  72. package/dist/components/experimental/index.js +1 -3
  73. package/dist/components/index.cjs +6 -6
  74. package/dist/components/index.d.cts +3 -3
  75. package/dist/components/index.d.ts +3 -3
  76. package/dist/components/index.js +3 -3
  77. package/dist/css-animation/Button/Button.cjs +85 -0
  78. package/dist/css-animation/Button/Button.d.cts +13 -0
  79. package/dist/css-animation/Button/Button.d.ts +14 -0
  80. package/dist/css-animation/Button/Button.js +82 -0
  81. package/dist/css-animation/Button/index.cjs +5 -0
  82. package/dist/css-animation/Button/index.d.cts +4 -0
  83. package/dist/css-animation/Button/index.d.ts +5 -0
  84. package/dist/css-animation/Button/index.js +4 -0
  85. package/dist/css-animation/IconButton/IconButton.cjs +55 -0
  86. package/dist/css-animation/IconButton/IconButton.d.cts +13 -0
  87. package/dist/css-animation/IconButton/IconButton.d.ts +14 -0
  88. package/dist/css-animation/IconButton/IconButton.js +53 -0
  89. package/dist/css-animation/IconButton/index.cjs +5 -0
  90. package/dist/css-animation/IconButton/index.d.cts +4 -0
  91. package/dist/css-animation/IconButton/index.d.ts +5 -0
  92. package/dist/css-animation/IconButton/index.js +4 -0
  93. package/dist/css-animation/Switch/Switch.cjs +44 -0
  94. package/dist/css-animation/Switch/Switch.d.cts +22 -0
  95. package/dist/css-animation/Switch/Switch.d.ts +23 -0
  96. package/dist/css-animation/Switch/Switch.js +41 -0
  97. package/dist/css-animation/Switch/SwitchStaticHandle.cjs +56 -0
  98. package/dist/css-animation/Switch/SwitchStaticHandle.d.cts +31 -0
  99. package/dist/css-animation/Switch/SwitchStaticHandle.d.ts +32 -0
  100. package/dist/css-animation/Switch/SwitchStaticHandle.js +54 -0
  101. package/dist/css-animation/Switch/index.cjs +5 -0
  102. package/dist/css-animation/Switch/index.d.cts +3 -0
  103. package/dist/css-animation/Switch/index.d.ts +4 -0
  104. package/dist/css-animation/Switch/index.js +4 -0
  105. package/dist/css-animation/index.cjs +9 -0
  106. package/dist/css-animation/index.d.cts +7 -0
  107. package/dist/css-animation/index.d.ts +8 -0
  108. package/dist/css-animation/index.js +6 -0
  109. package/dist/hooks/usePrefersReducedMotion.cjs +24 -0
  110. package/dist/hooks/usePrefersReducedMotion.d.cts +5 -0
  111. package/dist/hooks/usePrefersReducedMotion.d.ts +5 -0
  112. package/dist/hooks/usePrefersReducedMotion.js +22 -0
  113. package/dist/index.cjs +7 -7
  114. package/dist/index.d.cts +3 -3
  115. package/dist/index.d.ts +3 -3
  116. package/dist/index.js +4 -4
  117. package/dist/styles/styler.d.cts +4 -4
  118. package/dist/styles/styler.d.ts +4 -4
  119. package/dist/tailwind-internal/dist/utils/getShadowStyles.d.cts +2 -2
  120. package/dist/tailwind-internal/dist/utils/getShadowStyles.d.ts +2 -2
  121. package/dist/uds/generated/componentData.cjs +372 -381
  122. package/dist/uds/generated/componentData.js +372 -381
  123. package/dist/uds/generated/tailwindPurge.cjs +8 -21
  124. package/dist/uds/generated/tailwindPurge.js +8 -21
  125. package/dist/uds/package.cjs +12 -2
  126. package/dist/uds/package.js +12 -2
  127. package/generated/componentData.json +572 -603
  128. package/generated/tailwindPurge.ts +3 -3
  129. package/package.json +13 -3
  130. package/dist/components/client/Button.cjs +0 -326
  131. package/dist/components/client/Button.d.cts +0 -86
  132. package/dist/components/client/Button.d.ts +0 -87
  133. package/dist/components/client/Button.js +0 -321
  134. package/dist/components/client/IconButton.cjs +0 -161
  135. package/dist/components/client/IconButton.d.cts +0 -46
  136. package/dist/components/client/IconButton.d.ts +0 -47
  137. package/dist/components/client/IconButton.js +0 -159
  138. package/dist/components/client/Switch.cjs +0 -225
  139. package/dist/components/client/Switch.js +0 -222
  140. package/dist/components/client/buttonConstants.d.cts +0 -7
  141. package/dist/components/client/buttonConstants.d.ts +0 -8
  142. package/dist/components/experimental/client/AvoidMotionLibraryProvider.cjs +0 -14
  143. package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.cts +0 -8
  144. package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.ts +0 -9
  145. package/dist/components/experimental/client/AvoidMotionLibraryProvider.js +0 -11
  146. package/dist/components/experimental/client/SwitchV2.cjs +0 -190
  147. package/dist/components/experimental/client/SwitchV2.d.cts +0 -46
  148. package/dist/components/experimental/client/SwitchV2.d.ts +0 -47
  149. package/dist/components/experimental/client/SwitchV2.js +0 -185
@@ -1,190 +0,0 @@
1
- /*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
2
- "use client";
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
5
- const require_styles_styler = require("../../../styles/styler.cjs");
6
- const require_components_IconSlot = require("../../IconSlot.cjs");
7
- const require_components_Box = require("../../Box.cjs");
8
- const require_components_FormLabel = require("../../FormLabel.cjs");
9
- const require_components_experimental_client_AvoidMotionLibraryProvider = require("./AvoidMotionLibraryProvider.cjs");
10
- const require_components_client_SpringMotionConfig = require("../../client/SpringMotionConfig.cjs");
11
- let react = require("react");
12
- react = require_runtime.__toESM(react);
13
- let react_jsx_runtime = require("react/jsx-runtime");
14
- let motion_react_m = require("motion/react-m");
15
- motion_react_m = require_runtime.__toESM(motion_react_m);
16
- //#region src/components/experimental/client/SwitchV2.tsx
17
- const loadFeatures = () => import("@yahoo/uds/__private/motionFeatures/domMax").then(({ domMax }) => domMax);
18
- const MotionBox = motion_react_m.create(require_components_Box.Box);
19
- /**
20
- * **⚙️️ An switch.
21
- *
22
- * @componentType Client component
23
- *
24
- * @description
25
- * A switch (also called a toggle) is a binary on/off input control. It is clickable or touchable on mobile devices allowing users to pick between two clearly opposite choices.
26
- *
27
- * @see
28
- * Check out the {@link https://uds.build/docs/components/switch Switch Docs} for more info
29
- *
30
- * @usage
31
- * - Forms: switch
32
- *
33
- * @example
34
- * ```tsx
35
- * 'use client';
36
- * import { Switch } from "@yahoo/uds";
37
- *
38
- * <Switch label="Name" required />
39
- *```
40
- *
41
- * @related [Checkbox](https://uds.build/docs/components/checkbox).
42
- **/
43
- const SwitchV2 = (0, react.forwardRef)(function Switch({ id, isOn: isOnProp, defaultIsOn, onChange, label, labelPosition = "start", size = "md", onIcon, offIcon, reduceMotion: forceReduceMotion, disabled, required, onFocus, onBlur, className, slotProps, ...switchProps }, parentRef) {
44
- const generatedId = (0, react.useId)();
45
- const uid = id ?? `uds-input-${generatedId}`;
46
- const rootSlotProps = slotProps?.root ?? {};
47
- const switchSlotProps = slotProps?.switch ?? {};
48
- const handleSlotProps = slotProps?.handle ?? {};
49
- const labelSlotProps = slotProps?.label ?? {};
50
- const innerRef = (0, react.useRef)(null);
51
- /**
52
- * State
53
- */
54
- const isControlled = isOnProp !== void 0;
55
- const [isOn, setIsOn] = (0, react.useState)(isControlled ? isOnProp : defaultIsOn);
56
- /**
57
- * Handlers
58
- */
59
- const handleChange = (0, react.useCallback)((e) => {
60
- onChange?.(e);
61
- if (!isControlled) setIsOn(e.target.checked);
62
- }, [isControlled, onChange]);
63
- const handleFocus = (0, react.useCallback)((e) => {
64
- onFocus?.(e);
65
- }, [onFocus]);
66
- const handleBlur = (0, react.useCallback)((e) => {
67
- onBlur?.(e);
68
- }, [onBlur]);
69
- const reduceMotion = forceReduceMotion ? "always" : "user";
70
- const cssAnimationDuration = forceReduceMotion ? "duration-0" : "duration-120 motion-reduce:duration-0";
71
- /**
72
- * Effects
73
- */
74
- (0, react.useEffect)(() => {
75
- if (isControlled) setIsOn(isOnProp);
76
- }, [isOnProp, isControlled]);
77
- const classNames = {
78
- root: require_styles_styler.getStyles({
79
- switchSizeRoot: size,
80
- switchVariantRoot: "default",
81
- switchVariantActiveRoot: isOn ? "on" : "off",
82
- className: require_styles_styler.cx("group", "flex", "items-center", labelPosition === "start" ? "flex-row" : "flex-row-reverse", ...disabled ? ["cursor-default", "opacity-50"] : ["cursor-pointer"], className)
83
- }),
84
- switch: require_styles_styler.getStyles({
85
- switchVariantSwitch: "default",
86
- switchSizeSwitch: size,
87
- switchVariantActiveSwitch: isOn ? "on" : "off",
88
- className: require_styles_styler.cx("uds-ring", "uds-ring-within", "relative", "uds-border-radius-full", "items-center", cssAnimationDuration, "transition-[background-color,box-shadow]")
89
- }),
90
- handleContainer: require_styles_styler.cx("pointer-events-none", "relative", "w-full", "h-full"),
91
- handle: require_styles_styler.getStyles({
92
- switchSizeHandle: size,
93
- className: require_styles_styler.cx("absolute", "top-0", "bottom-0", isOn ? "right-0" : "left-0")
94
- }),
95
- handleContents: require_styles_styler.cx("relative", "w-full", "h-full", "uds-border-radius-full", "overflow-hidden", !disabled && "group-hover:scale-105", "opacity-95", !disabled && "group-hover:opacity-100", cssAnimationDuration, "transition-[transform,opacity]"),
96
- handleCircle: require_styles_styler.getStyles({
97
- switchVariantActiveHandle: isOn ? "on" : "off",
98
- switchVariantHandle: "default",
99
- className: require_styles_styler.cx("absolute", "top-0", "left-0", "right-0", "bottom-0")
100
- }),
101
- handleIcon: require_styles_styler.getStyles({
102
- switchSizeHandleIcon: size,
103
- switchVariantHandleIcon: "default",
104
- switchVariantActiveHandleIcon: isOn ? "on" : "off",
105
- className: require_styles_styler.cx("absolute", "opacity-0", "top-1/2", "left-1/2", "transform", "translate-x-[-50%]", "translate-y-[-50%]", cssAnimationDuration, "transition-opacity")
106
- }),
107
- htmlCheckbox: require_styles_styler.cx("cursor-[inherit]", "absolute", "opacity-0", "top-1/2", "left-1/2", "w-[calc(100%+2px)]", "h-[calc(100%+2px)]", "transform", "translate-x-[-50%]", "translate-y-[-50%]"),
108
- label: require_styles_styler.cx(labelPosition === "start" ? "text-start" : "text-end")
109
- };
110
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
111
- reducedMotion: reduceMotion,
112
- loadFeatures,
113
- layoutVariant: "bouncy",
114
- layoutSpeed: "4",
115
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(label ? "label" : "div", {
116
- className: classNames.root,
117
- "data-testid": "switch-root",
118
- tabIndex: -1,
119
- ...rootSlotProps,
120
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Box.Box, {
121
- className: classNames.switch,
122
- ...switchSlotProps,
123
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
124
- type: "checkbox",
125
- ...switchProps,
126
- ref: (ref) => {
127
- innerRef.current = ref;
128
- if (typeof parentRef === "function") parentRef(ref);
129
- else if (parentRef !== null) parentRef.current = ref;
130
- },
131
- onFocus: handleFocus,
132
- onBlur: handleBlur,
133
- id: uid,
134
- disabled,
135
- required,
136
- checked: isControlled ? isOn : void 0,
137
- defaultChecked: isControlled ? void 0 : defaultIsOn,
138
- onChange: handleChange,
139
- className: classNames.htmlCheckbox,
140
- style: {}
141
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, {
142
- className: classNames.handleContainer,
143
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MotionBox, {
144
- className: classNames.handle,
145
- layout: "position",
146
- layoutDependency: isOn,
147
- ...handleSlotProps,
148
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_components_Box.Box, {
149
- className: classNames.handleContents,
150
- children: [
151
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Box.Box, { className: classNames.handleCircle }),
152
- onIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
153
- icon: onIcon,
154
- iconProps: {
155
- variant: "fill",
156
- size: "sm"
157
- },
158
- "data-testid": "on-icon",
159
- className: require_styles_styler.cx(classNames.handleIcon, isOn ? "opacity-100" : "opacity-0")
160
- }),
161
- offIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
162
- icon: offIcon,
163
- iconProps: {
164
- variant: "fill",
165
- size: "sm"
166
- },
167
- "data-testid": "off-icon",
168
- className: require_styles_styler.cx(classNames.handleIcon, !isOn ? "opacity-100" : "opacity-0")
169
- })
170
- ]
171
- })
172
- })
173
- })]
174
- }), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
175
- as: "div",
176
- variant: "inherit",
177
- color: "inherit",
178
- required,
179
- label,
180
- className: classNames.label,
181
- ...labelSlotProps
182
- })]
183
- })
184
- });
185
- });
186
- SwitchV2.displayName = "SwitchV2";
187
- const SwitchV2AvoidMotionLibraryProvider = require_components_experimental_client_AvoidMotionLibraryProvider.AvoidMotionLibraryProvider;
188
- //#endregion
189
- exports.SwitchV2 = SwitchV2;
190
- exports.SwitchV2AvoidMotionLibraryProvider = SwitchV2AvoidMotionLibraryProvider;
@@ -1,46 +0,0 @@
1
-
2
- import { UniversalSwitchProps } from "../../../types/dist/index.cjs";
3
- import React from "react";
4
-
5
- //#region src/components/experimental/client/SwitchV2.d.ts
6
- type NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'checked' | 'size' | 'height' | 'width' | 'color' | 'defaultChecked' | 'children'>;
7
- type DataAttributes = {
8
- [name: `data-${string}`]: string;
9
- };
10
- interface SwitchV2Props extends NativeInputProps, UniversalSwitchProps {
11
- /** Props to be passed into various slots within the component. */
12
- slotProps?: {
13
- root?: DataAttributes;
14
- switch?: DataAttributes;
15
- handle?: DataAttributes;
16
- label?: DataAttributes;
17
- };
18
- }
19
- /**
20
- * **⚙️️ An switch.
21
- *
22
- * @componentType Client component
23
- *
24
- * @description
25
- * A switch (also called a toggle) is a binary on/off input control. It is clickable or touchable on mobile devices allowing users to pick between two clearly opposite choices.
26
- *
27
- * @see
28
- * Check out the {@link https://uds.build/docs/components/switch Switch Docs} for more info
29
- *
30
- * @usage
31
- * - Forms: switch
32
- *
33
- * @example
34
- * ```tsx
35
- * 'use client';
36
- * import { Switch } from "@yahoo/uds";
37
- *
38
- * <Switch label="Name" required />
39
- *```
40
- *
41
- * @related [Checkbox](https://uds.build/docs/components/checkbox).
42
- **/
43
- declare const SwitchV2: React.ForwardRefExoticComponent<SwitchV2Props & React.RefAttributes<HTMLInputElement>>;
44
- declare const SwitchV2AvoidMotionLibraryProvider: React.Provider<boolean>;
45
- //#endregion
46
- export { SwitchV2, SwitchV2AvoidMotionLibraryProvider, type SwitchV2Props };
@@ -1,47 +0,0 @@
1
-
2
- "use client";
3
- import { UniversalSwitchProps } from "../../../types/dist/index.js";
4
- import React from "react";
5
-
6
- //#region src/components/experimental/client/SwitchV2.d.ts
7
- type NativeInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type' | 'checked' | 'size' | 'height' | 'width' | 'color' | 'defaultChecked' | 'children'>;
8
- type DataAttributes = {
9
- [name: `data-${string}`]: string;
10
- };
11
- interface SwitchV2Props extends NativeInputProps, UniversalSwitchProps {
12
- /** Props to be passed into various slots within the component. */
13
- slotProps?: {
14
- root?: DataAttributes;
15
- switch?: DataAttributes;
16
- handle?: DataAttributes;
17
- label?: DataAttributes;
18
- };
19
- }
20
- /**
21
- * **⚙️️ An switch.
22
- *
23
- * @componentType Client component
24
- *
25
- * @description
26
- * A switch (also called a toggle) is a binary on/off input control. It is clickable or touchable on mobile devices allowing users to pick between two clearly opposite choices.
27
- *
28
- * @see
29
- * Check out the {@link https://uds.build/docs/components/switch Switch Docs} for more info
30
- *
31
- * @usage
32
- * - Forms: switch
33
- *
34
- * @example
35
- * ```tsx
36
- * 'use client';
37
- * import { Switch } from "@yahoo/uds";
38
- *
39
- * <Switch label="Name" required />
40
- *```
41
- *
42
- * @related [Checkbox](https://uds.build/docs/components/checkbox).
43
- **/
44
- declare const SwitchV2: React.ForwardRefExoticComponent<SwitchV2Props & React.RefAttributes<HTMLInputElement>>;
45
- declare const SwitchV2AvoidMotionLibraryProvider: React.Provider<boolean>;
46
- //#endregion
47
- export { SwitchV2, SwitchV2AvoidMotionLibraryProvider, type SwitchV2Props };
@@ -1,185 +0,0 @@
1
- /*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
2
- "use client";
3
- import { cx, getStyles } from "../../../styles/styler.js";
4
- import { IconSlot } from "../../IconSlot.js";
5
- import { Box } from "../../Box.js";
6
- import { FormLabel } from "../../FormLabel.js";
7
- import { AvoidMotionLibraryProvider } from "./AvoidMotionLibraryProvider.js";
8
- import { SpringMotionConfig } from "../../client/SpringMotionConfig.js";
9
- import { forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
10
- import { jsx, jsxs } from "react/jsx-runtime";
11
- import * as m from "motion/react-m";
12
- //#region src/components/experimental/client/SwitchV2.tsx
13
- const loadFeatures = () => import("@yahoo/uds/__private/motionFeatures/domMax").then(({ domMax }) => domMax);
14
- const MotionBox = m.create(Box);
15
- /**
16
- * **⚙️️ An switch.
17
- *
18
- * @componentType Client component
19
- *
20
- * @description
21
- * A switch (also called a toggle) is a binary on/off input control. It is clickable or touchable on mobile devices allowing users to pick between two clearly opposite choices.
22
- *
23
- * @see
24
- * Check out the {@link https://uds.build/docs/components/switch Switch Docs} for more info
25
- *
26
- * @usage
27
- * - Forms: switch
28
- *
29
- * @example
30
- * ```tsx
31
- * 'use client';
32
- * import { Switch } from "@yahoo/uds";
33
- *
34
- * <Switch label="Name" required />
35
- *```
36
- *
37
- * @related [Checkbox](https://uds.build/docs/components/checkbox).
38
- **/
39
- const SwitchV2 = forwardRef(function Switch({ id, isOn: isOnProp, defaultIsOn, onChange, label, labelPosition = "start", size = "md", onIcon, offIcon, reduceMotion: forceReduceMotion, disabled, required, onFocus, onBlur, className, slotProps, ...switchProps }, parentRef) {
40
- const generatedId = useId();
41
- const uid = id ?? `uds-input-${generatedId}`;
42
- const rootSlotProps = slotProps?.root ?? {};
43
- const switchSlotProps = slotProps?.switch ?? {};
44
- const handleSlotProps = slotProps?.handle ?? {};
45
- const labelSlotProps = slotProps?.label ?? {};
46
- const innerRef = useRef(null);
47
- /**
48
- * State
49
- */
50
- const isControlled = isOnProp !== void 0;
51
- const [isOn, setIsOn] = useState(isControlled ? isOnProp : defaultIsOn);
52
- /**
53
- * Handlers
54
- */
55
- const handleChange = useCallback((e) => {
56
- onChange?.(e);
57
- if (!isControlled) setIsOn(e.target.checked);
58
- }, [isControlled, onChange]);
59
- const handleFocus = useCallback((e) => {
60
- onFocus?.(e);
61
- }, [onFocus]);
62
- const handleBlur = useCallback((e) => {
63
- onBlur?.(e);
64
- }, [onBlur]);
65
- const reduceMotion = forceReduceMotion ? "always" : "user";
66
- const cssAnimationDuration = forceReduceMotion ? "duration-0" : "duration-120 motion-reduce:duration-0";
67
- /**
68
- * Effects
69
- */
70
- useEffect(() => {
71
- if (isControlled) setIsOn(isOnProp);
72
- }, [isOnProp, isControlled]);
73
- const classNames = {
74
- root: getStyles({
75
- switchSizeRoot: size,
76
- switchVariantRoot: "default",
77
- switchVariantActiveRoot: isOn ? "on" : "off",
78
- className: cx("group", "flex", "items-center", labelPosition === "start" ? "flex-row" : "flex-row-reverse", ...disabled ? ["cursor-default", "opacity-50"] : ["cursor-pointer"], className)
79
- }),
80
- switch: getStyles({
81
- switchVariantSwitch: "default",
82
- switchSizeSwitch: size,
83
- switchVariantActiveSwitch: isOn ? "on" : "off",
84
- className: cx("uds-ring", "uds-ring-within", "relative", "uds-border-radius-full", "items-center", cssAnimationDuration, "transition-[background-color,box-shadow]")
85
- }),
86
- handleContainer: cx("pointer-events-none", "relative", "w-full", "h-full"),
87
- handle: getStyles({
88
- switchSizeHandle: size,
89
- className: cx("absolute", "top-0", "bottom-0", isOn ? "right-0" : "left-0")
90
- }),
91
- handleContents: cx("relative", "w-full", "h-full", "uds-border-radius-full", "overflow-hidden", !disabled && "group-hover:scale-105", "opacity-95", !disabled && "group-hover:opacity-100", cssAnimationDuration, "transition-[transform,opacity]"),
92
- handleCircle: getStyles({
93
- switchVariantActiveHandle: isOn ? "on" : "off",
94
- switchVariantHandle: "default",
95
- className: cx("absolute", "top-0", "left-0", "right-0", "bottom-0")
96
- }),
97
- handleIcon: getStyles({
98
- switchSizeHandleIcon: size,
99
- switchVariantHandleIcon: "default",
100
- switchVariantActiveHandleIcon: isOn ? "on" : "off",
101
- className: cx("absolute", "opacity-0", "top-1/2", "left-1/2", "transform", "translate-x-[-50%]", "translate-y-[-50%]", cssAnimationDuration, "transition-opacity")
102
- }),
103
- htmlCheckbox: cx("cursor-[inherit]", "absolute", "opacity-0", "top-1/2", "left-1/2", "w-[calc(100%+2px)]", "h-[calc(100%+2px)]", "transform", "translate-x-[-50%]", "translate-y-[-50%]"),
104
- label: cx(labelPosition === "start" ? "text-start" : "text-end")
105
- };
106
- return /* @__PURE__ */ jsx(SpringMotionConfig, {
107
- reducedMotion: reduceMotion,
108
- loadFeatures,
109
- layoutVariant: "bouncy",
110
- layoutSpeed: "4",
111
- children: /* @__PURE__ */ jsxs(label ? "label" : "div", {
112
- className: classNames.root,
113
- "data-testid": "switch-root",
114
- tabIndex: -1,
115
- ...rootSlotProps,
116
- children: [/* @__PURE__ */ jsxs(Box, {
117
- className: classNames.switch,
118
- ...switchSlotProps,
119
- children: [/* @__PURE__ */ jsx("input", {
120
- type: "checkbox",
121
- ...switchProps,
122
- ref: (ref) => {
123
- innerRef.current = ref;
124
- if (typeof parentRef === "function") parentRef(ref);
125
- else if (parentRef !== null) parentRef.current = ref;
126
- },
127
- onFocus: handleFocus,
128
- onBlur: handleBlur,
129
- id: uid,
130
- disabled,
131
- required,
132
- checked: isControlled ? isOn : void 0,
133
- defaultChecked: isControlled ? void 0 : defaultIsOn,
134
- onChange: handleChange,
135
- className: classNames.htmlCheckbox,
136
- style: {}
137
- }), /* @__PURE__ */ jsx(Box, {
138
- className: classNames.handleContainer,
139
- children: /* @__PURE__ */ jsx(MotionBox, {
140
- className: classNames.handle,
141
- layout: "position",
142
- layoutDependency: isOn,
143
- ...handleSlotProps,
144
- children: /* @__PURE__ */ jsxs(Box, {
145
- className: classNames.handleContents,
146
- children: [
147
- /* @__PURE__ */ jsx(Box, { className: classNames.handleCircle }),
148
- onIcon && /* @__PURE__ */ jsx(IconSlot, {
149
- icon: onIcon,
150
- iconProps: {
151
- variant: "fill",
152
- size: "sm"
153
- },
154
- "data-testid": "on-icon",
155
- className: cx(classNames.handleIcon, isOn ? "opacity-100" : "opacity-0")
156
- }),
157
- offIcon && /* @__PURE__ */ jsx(IconSlot, {
158
- icon: offIcon,
159
- iconProps: {
160
- variant: "fill",
161
- size: "sm"
162
- },
163
- "data-testid": "off-icon",
164
- className: cx(classNames.handleIcon, !isOn ? "opacity-100" : "opacity-0")
165
- })
166
- ]
167
- })
168
- })
169
- })]
170
- }), label && /* @__PURE__ */ jsx(FormLabel, {
171
- as: "div",
172
- variant: "inherit",
173
- color: "inherit",
174
- required,
175
- label,
176
- className: classNames.label,
177
- ...labelSlotProps
178
- })]
179
- })
180
- });
181
- });
182
- SwitchV2.displayName = "SwitchV2";
183
- const SwitchV2AvoidMotionLibraryProvider = AvoidMotionLibraryProvider;
184
- //#endregion
185
- export { SwitchV2, SwitchV2AvoidMotionLibraryProvider };