@yahoo/uds 3.59.0-beta.1 → 3.59.0-beta.2

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 (304) hide show
  1. package/cli/bin/uds-darwin-arm64-baseline +0 -0
  2. package/cli/bin/uds-darwin-x64 +0 -0
  3. package/cli/bin/uds-linux-arm64 +0 -0
  4. package/cli/bin/uds-linux-x64-baseline +0 -0
  5. package/dist/components/Box.d.ts +2 -2
  6. package/dist/components/Box.d.ts.map +1 -1
  7. package/dist/components/Divider/Divider.d.cts +2 -2
  8. package/dist/components/Divider/Divider.d.ts +2 -2
  9. package/dist/components/Divider/DividerCore.d.cts +2 -2
  10. package/dist/components/Divider/DividerCore.d.ts +2 -2
  11. package/dist/components/Divider/DividerInternal.d.cts +2 -2
  12. package/dist/components/Divider/DividerInternal.d.ts +2 -2
  13. package/dist/components/FormLabel.d.ts +2 -2
  14. package/dist/components/HStack.d.ts +2 -2
  15. package/dist/components/Icon.d.ts +2 -2
  16. package/dist/components/Link.d.ts +2 -2
  17. package/dist/components/Text.d.cts +5 -5
  18. package/dist/components/Text.d.cts.map +1 -1
  19. package/dist/components/Text.d.ts +8 -8
  20. package/dist/components/Text.d.ts.map +1 -1
  21. package/dist/components/VStack.d.ts +2 -2
  22. package/dist/components/VStack.d.ts.map +1 -1
  23. package/dist/components/client/AnimateHeightChange.d.cts +2 -2
  24. package/dist/components/client/AnimateHeightChange.d.ts +2 -2
  25. package/dist/components/client/Avatar/Avatar.d.cts +2 -2
  26. package/dist/components/client/Avatar/Avatar.d.cts.map +1 -1
  27. package/dist/components/client/Avatar/Avatar.d.ts +2 -2
  28. package/dist/components/client/Avatar/AvatarIcon.d.cts +2 -2
  29. package/dist/components/client/Avatar/AvatarIcon.d.cts.map +1 -1
  30. package/dist/components/client/Avatar/AvatarIcon.d.ts +2 -2
  31. package/dist/components/client/Avatar/AvatarImage.d.cts +2 -2
  32. package/dist/components/client/Avatar/AvatarImage.d.ts +2 -2
  33. package/dist/components/client/Avatar/AvatarText.d.cts +2 -2
  34. package/dist/components/client/Avatar/AvatarText.d.ts +2 -2
  35. package/dist/components/client/IconButton.d.cts +2 -2
  36. package/dist/components/client/IconButton.d.ts +2 -2
  37. package/dist/components/client/IconButton.d.ts.map +1 -1
  38. package/dist/components/client/Input/Input.d.cts +2 -2
  39. package/dist/components/client/Input/Input.d.ts +2 -2
  40. package/dist/components/client/Input/InputHelpText.d.cts +2 -2
  41. package/dist/components/client/Input/InputHelpText.d.cts.map +1 -1
  42. package/dist/components/client/Input/InputHelpText.d.ts +2 -2
  43. package/dist/components/client/Input/InputHelpTextInternal.d.cts +4 -4
  44. package/dist/components/client/Input/InputHelpTextInternal.d.cts.map +1 -1
  45. package/dist/components/client/Input/InputHelpTextInternal.d.ts +4 -4
  46. package/dist/components/client/Menu/Menu.Content.d.cts +2 -2
  47. package/dist/components/client/Menu/Menu.Content.d.ts +2 -2
  48. package/dist/components/client/Menu/Menu.Divider.d.cts +2 -2
  49. package/dist/components/client/Menu/Menu.Divider.d.ts +2 -2
  50. package/dist/components/client/Menu/Menu.Item.d.cts +2 -2
  51. package/dist/components/client/Menu/Menu.ItemBase.d.cts +2 -2
  52. package/dist/components/client/Menu/Menu.ItemBase.d.ts +2 -2
  53. package/dist/components/client/Menu/Menu.ItemCheckbox.d.cts +2 -2
  54. package/dist/components/client/Menu/Menu.ItemCheckbox.d.ts +2 -2
  55. package/dist/components/client/Menu/Menu.Provider.d.cts +2 -2
  56. package/dist/components/client/Menu/Menu.Provider.d.ts +2 -2
  57. package/dist/components/client/Menu/Menu.Trigger.d.cts +2 -2
  58. package/dist/components/client/Menu/Menu.Trigger.d.ts +2 -2
  59. package/dist/components/client/Pressable.d.cts +2 -2
  60. package/dist/components/client/Pressable.d.ts +2 -2
  61. package/dist/components/client/Pressable.d.ts.map +1 -1
  62. package/dist/components/client/Radio/RadioGroupStore.d.ts +2 -2
  63. package/dist/components/client/SpringMotionConfig.d.cts +3 -3
  64. package/dist/components/client/SpringMotionConfig.d.ts +3 -3
  65. package/dist/components/client/SpringMotionConfig.d.ts.map +1 -1
  66. package/dist/components/experimental/Spinner.d.cts +2 -2
  67. package/dist/components/experimental/Spinner.d.cts.map +1 -1
  68. package/dist/components/experimental/Spinner.d.ts +2 -2
  69. package/dist/components/experimental/Table.d.cts +2 -2
  70. package/dist/components/experimental/Table.d.ts +2 -2
  71. package/dist/components/experimental/client/Accordion.d.cts +2 -2
  72. package/dist/components/experimental/client/Accordion.d.cts.map +1 -1
  73. package/dist/components/experimental/client/Accordion.d.ts +2 -2
  74. package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.cts +2 -2
  75. package/dist/components/experimental/client/AvoidMotionLibraryProvider.d.ts +2 -2
  76. package/dist/components/experimental/client/Modal.d.cts +3 -3
  77. package/dist/components/experimental/client/Modal.d.cts.map +1 -1
  78. package/dist/components/experimental/client/Modal.d.ts +3 -3
  79. package/dist/components/experimental/client/Popover.d.cts +3 -3
  80. package/dist/components/experimental/client/Popover.d.cts.map +1 -1
  81. package/dist/components/experimental/client/Popover.d.ts +3 -3
  82. package/dist/components/experimental/client/Tabs.d.cts +3 -3
  83. package/dist/components/experimental/client/Tabs.d.ts +6 -6
  84. package/dist/components/experimental/client/Toast.d.cts +2 -2
  85. package/dist/components/experimental/client/Toast.d.ts +2 -2
  86. package/dist/providers/ColorModeProvider.d.cts +4 -4
  87. package/dist/providers/ColorModeProvider.d.cts.map +1 -1
  88. package/dist/providers/ColorModeProvider.d.ts +4 -4
  89. package/dist/providers/ColorModeProvider.d.ts.map +1 -1
  90. package/dist/providers/ScaleModeProvider.d.cts +4 -4
  91. package/dist/providers/ScaleModeProvider.d.cts.map +1 -1
  92. package/dist/providers/ScaleModeProvider.d.ts +4 -4
  93. package/dist/providers/ScaleModeProvider.d.ts.map +1 -1
  94. package/dist/providers/ThemeProvider.d.cts +2 -2
  95. package/dist/providers/ThemeProvider.d.cts.map +1 -1
  96. package/dist/providers/ThemeProvider.d.ts +2 -2
  97. package/dist/styles/styler.d.cts +33 -33
  98. package/dist/styles/styler.d.ts +33 -33
  99. package/dist/styles/stylerTypes.d.ts.map +1 -1
  100. package/dist/tailwind/tailwind.config.d.ts +3 -3
  101. package/dist/tailwind/tailwindPlugin.d.ts +3 -3
  102. package/dist/tailwind/utils/getMotionStyles.d.cts +1 -1
  103. package/dist/tailwind/utils/getMotionStyles.d.ts +1 -1
  104. package/dist/tokens/automation/utils/getConfigVariantProperties.d.cts +2 -2
  105. package/dist/tokens/automation/utils/getConfigVariantProperties.d.cts.map +1 -1
  106. package/dist/tokens/automation/utils/getConfigVariantProperties.d.ts +2 -2
  107. package/dist/tokens/automation/utils/getConfigVariantProperties.d.ts.map +1 -1
  108. package/dist/tokens/types.d.cts.map +1 -1
  109. package/dist/tokens/types.d.ts.map +1 -1
  110. package/dist/utils/intersperse.d.cts +2 -2
  111. package/dist/utils/intersperse.d.ts +2 -2
  112. package/package.json +1 -3
  113. package/cli/FlattenButtonVariant.mock.tsx +0 -17
  114. package/src/components/Box.tsx +0 -181
  115. package/src/components/Divider/Divider.tsx +0 -44
  116. package/src/components/Divider/DividerCore.tsx +0 -101
  117. package/src/components/Divider/DividerInternal.tsx +0 -56
  118. package/src/components/Divider/index.ts +0 -1
  119. package/src/components/FormLabel.tsx +0 -66
  120. package/src/components/HStack.tsx +0 -53
  121. package/src/components/Icon.tsx +0 -82
  122. package/src/components/IconSlot.tsx +0 -82
  123. package/src/components/Image.tsx +0 -162
  124. package/src/components/Link.tsx +0 -134
  125. package/src/components/Text.tsx +0 -272
  126. package/src/components/VStack.tsx +0 -53
  127. package/src/components/client/AnimateHeightChange.tsx +0 -50
  128. package/src/components/client/Avatar/Avatar.tsx +0 -31
  129. package/src/components/client/Avatar/AvatarIcon.tsx +0 -103
  130. package/src/components/client/Avatar/AvatarImage.tsx +0 -147
  131. package/src/components/client/Avatar/AvatarText.tsx +0 -88
  132. package/src/components/client/Avatar/index.ts +0 -4
  133. package/src/components/client/Avatar/utils.ts +0 -105
  134. package/src/components/client/Badge.tsx +0 -133
  135. package/src/components/client/Button.tsx +0 -312
  136. package/src/components/client/Checkbox.tsx +0 -377
  137. package/src/components/client/Chip/Chip.tsx +0 -81
  138. package/src/components/client/Chip/ChipBase.tsx +0 -151
  139. package/src/components/client/Chip/ChipButton.tsx +0 -54
  140. package/src/components/client/Chip/ChipDismissible.tsx +0 -90
  141. package/src/components/client/Chip/ChipLink.tsx +0 -60
  142. package/src/components/client/Chip/ChipToggle.tsx +0 -79
  143. package/src/components/client/Chip/index.ts +0 -5
  144. package/src/components/client/IconButton.tsx +0 -198
  145. package/src/components/client/Input/Input.tsx +0 -323
  146. package/src/components/client/Input/InputHelpText.tsx +0 -52
  147. package/src/components/client/Input/InputHelpTextInternal.tsx +0 -81
  148. package/src/components/client/Input/index.ts +0 -2
  149. package/src/components/client/Menu/Menu.Content.tsx +0 -391
  150. package/src/components/client/Menu/Menu.Divider.tsx +0 -102
  151. package/src/components/client/Menu/Menu.Item.tsx +0 -114
  152. package/src/components/client/Menu/Menu.ItemBase.tsx +0 -265
  153. package/src/components/client/Menu/Menu.ItemCheckbox.tsx +0 -197
  154. package/src/components/client/Menu/Menu.Provider.tsx +0 -154
  155. package/src/components/client/Menu/Menu.Trigger.tsx +0 -119
  156. package/src/components/client/Menu/Menu.index.tsx +0 -9
  157. package/src/components/client/Menu/Menu.tsx +0 -2
  158. package/src/components/client/Menu/index.ts +0 -7
  159. package/src/components/client/Menu/utils/transformAriakitPlacement.ts +0 -66
  160. package/src/components/client/Pressable.tsx +0 -194
  161. package/src/components/client/Radio/Radio.tsx +0 -351
  162. package/src/components/client/Radio/RadioGroupProvider.tsx +0 -122
  163. package/src/components/client/Radio/RadioGroupStore.tsx +0 -56
  164. package/src/components/client/Radio/index.ts +0 -2
  165. package/src/components/client/Radio/useRadioGroup.ts +0 -149
  166. package/src/components/client/SpringMotionConfig.tsx +0 -151
  167. package/src/components/client/Switch.tsx +0 -377
  168. package/src/components/client/index.ts +0 -30
  169. package/src/components/client/motionFeatures/domAnimation.ts +0 -2
  170. package/src/components/client/motionFeatures/domMax.ts +0 -2
  171. package/src/components/experimental/Spinner.tsx +0 -30
  172. package/src/components/experimental/Table.mocks.tsx +0 -38
  173. package/src/components/experimental/Table.tsx +0 -239
  174. package/src/components/experimental/client/Accordion.tsx +0 -77
  175. package/src/components/experimental/client/AvoidMotionLibraryProvider.tsx +0 -10
  176. package/src/components/experimental/client/Modal.tsx +0 -68
  177. package/src/components/experimental/client/Popover.tsx +0 -63
  178. package/src/components/experimental/client/SwitchV2.tsx +0 -343
  179. package/src/components/experimental/client/Tabs.tsx +0 -106
  180. package/src/components/experimental/client/Toast.tsx +0 -186
  181. package/src/components/experimental/client/index.ts +0 -15
  182. package/src/components/experimental/index.ts +0 -48
  183. package/src/components/index.ts +0 -41
  184. package/src/defaultTokensConfig.ts +0 -31
  185. package/src/fixtures/index.ts +0 -638
  186. package/src/fixtures/macros/typesToConstants.ts +0 -42
  187. package/src/fixtures/utils/getScaleModeRamp.ts +0 -48
  188. package/src/fixtures/utils/getTailwindAsUdsColors.ts +0 -115
  189. package/src/flags.ts +0 -45
  190. package/src/hooks/useForkRef.ts +0 -34
  191. package/src/hooks/useNestedBorderRadius.ts +0 -138
  192. package/src/hooks/useRtl.ts +0 -64
  193. package/src/index.ts +0 -4
  194. package/src/providers/ColorModeProvider.tsx +0 -21
  195. package/src/providers/ScaleModeProvider.tsx +0 -29
  196. package/src/providers/ThemeProvider.tsx +0 -26
  197. package/src/styles/styler.ts +0 -194
  198. package/src/styles/stylerTypes.ts +0 -81
  199. package/src/styles/toast.css +0 -0
  200. package/src/styles/variants.ts +0 -1351
  201. package/src/tailwind/base/addColorModeVars.ts +0 -23
  202. package/src/tailwind/base/addColorModeVarsV2.ts +0 -57
  203. package/src/tailwind/base/addFontFaceDeclarations.ts +0 -13
  204. package/src/tailwind/base/addFontVars.ts +0 -9
  205. package/src/tailwind/base/addMotionVars.ts +0 -9
  206. package/src/tailwind/base/addScaleModeVars.ts +0 -33
  207. package/src/tailwind/base/types.ts +0 -8
  208. package/src/tailwind/components/getButtonStyles.ts +0 -240
  209. package/src/tailwind/components/getFocusRingStyles.ts +0 -32
  210. package/src/tailwind/components/getGroupedTextStyles.ts +0 -29
  211. package/src/tailwind/components/getHitTargetStyles.ts +0 -23
  212. package/src/tailwind/components/getIconButtonStyles.ts +0 -49
  213. package/src/tailwind/components/getIconStyles.ts +0 -13
  214. package/src/tailwind/components/getInputStyles.ts +0 -20
  215. package/src/tailwind/components/getResponsiveTextStyles.ts +0 -161
  216. package/src/tailwind/components/types.ts +0 -14
  217. package/src/tailwind/components/utils.ts +0 -73
  218. package/src/tailwind/defaultTailwindThemeAsUdsConfig.ts +0 -78
  219. package/src/tailwind/postcss.config.ts +0 -6
  220. package/src/tailwind/purger/index.ts +0 -1
  221. package/src/tailwind/tailwind.config.ts +0 -50
  222. package/src/tailwind/tailwind.d.ts +0 -5
  223. package/src/tailwind/tailwindPlugin.ts +0 -724
  224. package/src/tailwind/theme/getFontFamilyTheme.ts +0 -28
  225. package/src/tailwind/tsMorph.ts +0 -1
  226. package/src/tailwind/uds.css +0 -3
  227. package/src/tailwind/utils/addFontsPlugin.ts +0 -17
  228. package/src/tailwind/utils/getColorModeStyles.ts +0 -21
  229. package/src/tailwind/utils/getFontFaceDeclarations.ts +0 -12
  230. package/src/tailwind/utils/getFontStyles.ts +0 -38
  231. package/src/tailwind/utils/getMotionStyles.ts +0 -35
  232. package/src/tailwind/utils/getScaleModeStyles.ts +0 -23
  233. package/src/tailwind/utils/getShadowPresetValues.ts +0 -133
  234. package/src/tailwind/utils/getShadowStyles.ts +0 -26
  235. package/src/tailwind/utils/getShadowVars.ts +0 -40
  236. package/src/tailwind/utils/index.ts +0 -9
  237. package/src/tokens/automation/configs/avatar.ts +0 -297
  238. package/src/tokens/automation/configs/badge.ts +0 -306
  239. package/src/tokens/automation/configs/checkbox.ts +0 -226
  240. package/src/tokens/automation/configs/chip.ts +0 -521
  241. package/src/tokens/automation/configs/divider.ts +0 -112
  242. package/src/tokens/automation/configs/index.ts +0 -10
  243. package/src/tokens/automation/configs/input.ts +0 -496
  244. package/src/tokens/automation/configs/link.ts +0 -183
  245. package/src/tokens/automation/configs/menu.ts +0 -344
  246. package/src/tokens/automation/configs/radio.ts +0 -225
  247. package/src/tokens/automation/configs/switch.ts +0 -323
  248. package/src/tokens/automation/index.ts +0 -5
  249. package/src/tokens/automation/mapTextVariantFixtureToValue.ts +0 -8
  250. package/src/tokens/automation/properties.ts +0 -433
  251. package/src/tokens/automation/types/ComponentConfig.ts +0 -116
  252. package/src/tokens/automation/types/ComponentDB.ts +0 -1
  253. package/src/tokens/automation/types/ComponentStyles.ts +0 -47
  254. package/src/tokens/automation/types/index.ts +0 -2
  255. package/src/tokens/automation/utils/cartesianProduct.ts +0 -13
  256. package/src/tokens/automation/utils/coalesceConfigVariant.ts +0 -49
  257. package/src/tokens/automation/utils/defaults.ts +0 -29
  258. package/src/tokens/automation/utils/generateKeyFromFlatConfigPath.ts +0 -15
  259. package/src/tokens/automation/utils/generateSchemaKey.ts +0 -29
  260. package/src/tokens/automation/utils/getConfigComponentVariant.ts +0 -28
  261. package/src/tokens/automation/utils/getConfigVariantComponentStatesMatrix.ts +0 -40
  262. package/src/tokens/automation/utils/getConfigVariantProperties.ts +0 -32
  263. package/src/tokens/automation/utils/getConfigVariantPseudoStates.ts +0 -70
  264. package/src/tokens/automation/utils/getConfigVariants.ts +0 -73
  265. package/src/tokens/automation/utils/index.ts +0 -939
  266. package/src/tokens/automation/utils/mapColorFixtureToValue.ts +0 -34
  267. package/src/tokens/automation/utils/subcomponents.ts +0 -13
  268. package/src/tokens/automation/utils/variableData.ts +0 -79
  269. package/src/tokens/automation/utils/variantConfigGuards.ts +0 -17
  270. package/src/tokens/configs/borderRadius.ts +0 -23
  271. package/src/tokens/configs/borderWidth.ts +0 -17
  272. package/src/tokens/configs/button.ts +0 -888
  273. package/src/tokens/configs/colorMode.ts +0 -14
  274. package/src/tokens/configs/font.ts +0 -9
  275. package/src/tokens/configs/iconButton.ts +0 -28
  276. package/src/tokens/configs/motion.ts +0 -135
  277. package/src/tokens/configs/palette.ts +0 -124
  278. package/src/tokens/configs/scaleMode.ts +0 -28
  279. package/src/tokens/configs/shadow.ts +0 -286
  280. package/src/tokens/configs/sizes.ts +0 -23
  281. package/src/tokens/configs/spectrum.ts +0 -729
  282. package/src/tokens/configs/typography.ts +0 -417
  283. package/src/tokens/configs/yosConfig.ts +0 -7651
  284. package/src/tokens/consts/buttonMotionTokens.ts +0 -99
  285. package/src/tokens/consts/cssTokens.ts +0 -110
  286. package/src/tokens/consts/defaultModes.ts +0 -15
  287. package/src/tokens/consts/fontDeclarationsMap.ts +0 -509
  288. package/src/tokens/index.ts +0 -15
  289. package/src/tokens/parseButtonVariants.ts +0 -59
  290. package/src/tokens/parseTokens.ts +0 -122
  291. package/src/tokens/types.ts +0 -1882
  292. package/src/tokens/utils/entries.ts +0 -14
  293. package/src/tokens/utils/fromEntries.ts +0 -11
  294. package/src/tokens/utils/mapValues.ts +0 -15
  295. package/src/types.ts +0 -2
  296. package/src/utils/assertUnreachable.ts +0 -6
  297. package/src/utils/composeRefs.ts +0 -23
  298. package/src/utils/createSlot.tsx +0 -131
  299. package/src/utils/entries.ts +0 -6
  300. package/src/utils/falsyToString.ts +0 -3
  301. package/src/utils/getMotionVar.ts +0 -18
  302. package/src/utils/intersperse.ts +0 -45
  303. package/src/utils/mapValues.ts +0 -15
  304. package/src/utils/mergeSlotProps.ts +0 -70
@@ -1,312 +0,0 @@
1
- import { buttonIconSvgSize } from '@yahoo/uds/fixtures';
2
- import type { MotionVariant, UniversalButtonProps } from '@yahoo/uds/tokens';
3
- import { parseDeprecatedButtonPaletteVariant } from '@yahoo/uds/tokens';
4
- import { Progress } from '@yahoo/uds-icons';
5
- import type { HTMLMotionProps } from 'motion/react';
6
- import { AnimatePresence, m, useReducedMotion } from 'motion/react';
7
- import type { ForwardRefExoticComponent } from 'react';
8
- import React, {
9
- cloneElement,
10
- forwardRef,
11
- isValidElement,
12
- useImperativeHandle,
13
- useMemo,
14
- useRef,
15
- } from 'react';
16
-
17
- import { cx, getStyles } from '../../styles/styler';
18
- import {
19
- buttonMotionVariants,
20
- getGapVariant,
21
- getStartVariant,
22
- iconContainerMotionVariants,
23
- iconMotionVariants,
24
- loadingMotionVariants,
25
- } from '../../tokens/consts/buttonMotionTokens';
26
- import { createSlot } from '../../utils/createSlot';
27
- import { Icon } from '../Icon';
28
- import { IconSlot } from '../IconSlot';
29
- import { SpringMotionConfig } from './SpringMotionConfig';
30
-
31
- type HtmlButtonProps = Omit<HTMLMotionProps<'button'>, 'color' | 'name'> &
32
- Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'color'>;
33
-
34
- interface ButtonProps extends HtmlButtonProps, UniversalButtonProps {}
35
-
36
- /**
37
- * **🖲️ A button element that can be used to trigger an action**
38
- *
39
- * @componentType Client component
40
- *
41
- * @description A button is a fundamental component used to trigger an action or event. Buttons are interactive elements that users can click, tap, or otherwise engage with to submit forms, open dialogues, or perform any other interaction within an application or website. Consider an IconButton for buttons that only contain an icon.
42
- *
43
- * @see The {@link https://uds.build/docs/components/button Button Docs} for more info
44
- *
45
- * @example
46
- * ```tsx
47
- * 'use client';
48
- * import { Button, HStack } from "@yahoo/uds";
49
- *
50
- * export function Demo() {
51
- * return (
52
- * <HStack gap="2">
53
- * <Button onClick={console.log}>Save</Button>
54
- * <Button variant="secondary" onClick={console.log}>Cancel</Button>
55
- * </HStack>
56
- * )
57
- * }
58
- * ```
59
- *
60
- * @usage
61
- * Buttons should be used to clearly indicate and initiate actions that users can take.
62
- *
63
- * @related [Icon](https://uds.build/docs/components/icon), [IconButton](https://uds.build/docs/components/icon-button), [Pressable](https://uds.build/docs/components/pressable)
64
- **/
65
- const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
66
- {
67
- // Button config props
68
- variant,
69
- size: buttonSize,
70
- // Icon props
71
- startIcon,
72
- endIcon,
73
- iconVariant,
74
- // State props
75
- loading,
76
- disableEffects,
77
- // Misc props
78
- children,
79
- asChild,
80
- // HTML props (className, disabled, aria-*, data-*, onClick, etc.)
81
- type = 'button',
82
- className,
83
- // Size props
84
- width,
85
- ...rest
86
- },
87
- forwardedRef,
88
- ) {
89
- /* ------------------------------- Setup refs ------------------------------- */
90
- const ref = useRef<HTMLButtonElement>(null);
91
- useImperativeHandle(forwardedRef, () => ref.current as HTMLButtonElement);
92
-
93
- /* --------------------------- Create motion slot --------------------------- */
94
- const Slot = useMemo(() => createSlot<ForwardRefExoticComponent<HtmlButtonProps>>(), []);
95
- const MotionSlot = useMemo(() => m.create(Slot), [Slot]);
96
-
97
- /* -------------------------------- Variants -------------------------------- */
98
- const endVariant = endIcon ? 'icon' : 'hide';
99
- const gapVariant = getGapVariant({ startIcon, endIcon, loading });
100
- const startVariant = getStartVariant({ loading, startIcon });
101
-
102
- const { palette: buttonPalette_DEPRECATED, variant: buttonVariant_DEPRECATED } = useMemo(
103
- () => parseDeprecatedButtonPaletteVariant({ flatVariant: variant }),
104
- [variant],
105
- );
106
-
107
- /* ---------------------------- Setup classNames ---------------------------- */
108
- const classNames = useMemo(
109
- () => ({
110
- button: getStyles({
111
- width,
112
- buttonSize,
113
- buttonVariant: buttonVariant_DEPRECATED,
114
- buttonPalette: buttonPalette_DEPRECATED,
115
- className: cx(
116
- // Base class name
117
- 'uds-button',
118
- // Focus ring
119
- 'uds-ring',
120
- // Minimum hit target of 44px
121
- 'uds-hit-target',
122
- // State
123
- loading && 'uds-button-loading',
124
- disableEffects && 'uds-button-without-effects',
125
- gapVariant === 'withIcon' && 'uds-button-with-gap',
126
-
127
- // Consumer class names
128
- className,
129
- ),
130
- }),
131
- content: 'uds-button-content truncate',
132
- iconContainer: 'uds-button-icon-container flex overflow-clip',
133
- loading: 'uds-button-icon start-content animate-spin',
134
- start: 'uds-button-icon start-content',
135
- end: 'uds-button-icon end-content',
136
- }),
137
- [
138
- width,
139
- buttonSize,
140
- buttonVariant_DEPRECATED,
141
- buttonPalette_DEPRECATED,
142
- className,
143
- loading,
144
- disableEffects,
145
- gapVariant,
146
- ],
147
- );
148
-
149
- /* --------------------- Motion config setup for button --------------------- */
150
- const prefersReducedMotion = useReducedMotion();
151
- const layoutVariant: MotionVariant = prefersReducedMotion ? 'smooth' : 'subtle';
152
-
153
- /* -------------------------- Start and end content ------------------------- */
154
-
155
- /**
156
- * TODO see if we can get these to work as ReactElements like (ie <StartContent />)
157
- * Animations aren't currently propagating if I do that
158
- **/
159
-
160
- const startContent = useMemo(
161
- () => (
162
- <m.span
163
- className={classNames.iconContainer}
164
- initial={false}
165
- variants={iconContainerMotionVariants}
166
- animate={startVariant}
167
- >
168
- <AnimatePresence initial={false} mode="popLayout">
169
- {loading && (
170
- <m.span
171
- key="loading"
172
- variants={loadingMotionVariants}
173
- initial="hide"
174
- animate="loading"
175
- exit="hide"
176
- >
177
- <Icon
178
- size={buttonIconSvgSize}
179
- name={Progress}
180
- variant={iconVariant}
181
- color="current"
182
- className={classNames.loading}
183
- />
184
- </m.span>
185
- )}
186
- {startIcon && !loading && (
187
- <m.span variants={iconMotionVariants} initial="hide" animate="icon" exit="hide">
188
- <IconSlot
189
- className={classNames.start}
190
- icon={startIcon}
191
- iconProps={{
192
- size: buttonIconSvgSize,
193
- variant: iconVariant,
194
- color: 'current',
195
- }}
196
- />
197
- </m.span>
198
- )}
199
- </AnimatePresence>
200
- </m.span>
201
- ),
202
- [
203
- classNames.iconContainer,
204
- classNames.loading,
205
- classNames.start,
206
- startVariant,
207
- loading,
208
- iconVariant,
209
- startIcon,
210
- ],
211
- );
212
-
213
- const endContent = useMemo(
214
- () => (
215
- <m.span
216
- className={classNames.iconContainer}
217
- initial={false}
218
- variants={iconContainerMotionVariants}
219
- animate={endVariant}
220
- >
221
- <AnimatePresence initial={false} mode="popLayout">
222
- {endIcon && (
223
- <m.span variants={iconMotionVariants} initial="hide" animate="icon" exit="hide">
224
- <IconSlot
225
- className={classNames.end}
226
- icon={endIcon}
227
- iconProps={{
228
- size: buttonIconSvgSize,
229
- variant: iconVariant,
230
- color: 'current',
231
- }}
232
- />
233
- </m.span>
234
- )}
235
- </AnimatePresence>
236
- </m.span>
237
- ),
238
- [classNames.iconContainer, classNames.end, endIcon, endVariant, iconVariant],
239
- );
240
-
241
- const buttonVariants = useMemo(() => {
242
- if (!disableEffects) {
243
- return buttonMotionVariants;
244
- }
245
- return {
246
- ...buttonMotionVariants,
247
- rest: {},
248
- hover: {},
249
- pressed: {},
250
- };
251
- }, [disableEffects]);
252
-
253
- /* -------------------------------------------------------------------------- */
254
- /* The button */
255
- /* -------------------------------------------------------------------------- */
256
-
257
- /* ---------------------------------- TODO ---------------------------------- */
258
- /* ----------------------------- Button asChild ----------------------------- */
259
- /* ------------ Remove this cloneElement stuff when UD-734 lands ------------ */
260
- if (asChild && isValidElement(children)) {
261
- return (
262
- <SpringMotionConfig layoutSpeed="3" layoutVariant={layoutVariant}>
263
- <MotionSlot
264
- type={type}
265
- className={classNames.button}
266
- initial={['hide', gapVariant]}
267
- animate={gapVariant}
268
- variants={buttonVariants}
269
- whileHover="hover"
270
- whileTap="pressed"
271
- {...rest}
272
- >
273
- {cloneElement(
274
- children,
275
- children.props,
276
- <>
277
- {startContent}
278
- <span className={classNames.content}>{children.props.children}</span>
279
- {endContent}
280
- </>,
281
- )}
282
- </MotionSlot>
283
- </SpringMotionConfig>
284
- );
285
- }
286
- /* -------------------------------- End TODO -------------------------------- */
287
-
288
- /* ----------------------------- Standard button ---------------------------- */
289
- return (
290
- <SpringMotionConfig layoutSpeed="3" layoutVariant={layoutVariant}>
291
- <m.button
292
- ref={ref}
293
- type={type}
294
- className={classNames.button}
295
- initial={['hide', gapVariant]}
296
- animate={gapVariant}
297
- variants={buttonVariants}
298
- whileHover="hover"
299
- whileTap="pressed"
300
- {...rest}
301
- >
302
- {startContent}
303
- <span className={classNames.content}>{children}</span>
304
- {endContent}
305
- </m.button>
306
- </SpringMotionConfig>
307
- );
308
- });
309
-
310
- Button.displayName = 'Button';
311
-
312
- export { Button, type ButtonProps };
@@ -1,377 +0,0 @@
1
- import type {
2
- CheckboxSize,
3
- CheckboxValue,
4
- CheckboxVariant,
5
- UniversalCheckboxProps,
6
- } from '@yahoo/uds/tokens';
7
- import { Check, Minus } from '@yahoo/uds-icons';
8
- import { m, useReducedMotion } from 'motion/react';
9
- import type { ChangeEvent } from 'react';
10
- import React, { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
11
-
12
- import { cx, getStyles } from '../../styles/styler';
13
- import { Box } from '../Box';
14
- import { FormLabel } from '../FormLabel';
15
- import { Icon } from '../Icon';
16
- import { SpringMotionConfig } from './SpringMotionConfig';
17
-
18
- type NativeInputProps = Omit<
19
- React.InputHTMLAttributes<HTMLInputElement>,
20
- 'type' | 'checked' | 'size' | 'height' | 'width' | 'color'
21
- >;
22
-
23
- type CheckboxChangeEvent = ChangeEvent<HTMLInputElement>;
24
-
25
- interface CheckboxProps extends NativeInputProps, UniversalCheckboxProps {
26
- layerClassNames?: {
27
- root?: string;
28
- checkbox?: string;
29
- label?: string;
30
- };
31
- }
32
-
33
- const VARIANTS = ['primary', 'secondary'] satisfies CheckboxVariant[];
34
- const SIZES = ['sm', 'md'] satisfies CheckboxSize[];
35
-
36
- const VARIANT_ERROR_MAP: Record<CheckboxVariant, 'alert' | 'alert-secondary'> = {
37
- primary: 'alert',
38
- secondary: 'alert-secondary',
39
- };
40
-
41
- const isIndeterminate = (checked?: CheckboxValue) => checked === 'indeterminate';
42
-
43
- const getIcon = (checked: CheckboxProps['checked']) => {
44
- if (isIndeterminate(checked)) {
45
- return Minus;
46
- }
47
-
48
- return Check;
49
- };
50
-
51
- const MotionBox = m.create(Box);
52
-
53
- const hoverTransition = { layoutVariant: 'smooth', layoutSpeed: '3' } as const;
54
- const pressTransition = { layoutVariant: 'veryBouncy', layoutSpeed: '4' } as const;
55
-
56
- /**
57
- * **⚙️️ An checkbox.
58
- *
59
- * @componentType Client component
60
- *
61
- * @description
62
- * A checkbox component allows users to select one or multiple options from a set. It represents a binary state, typically as checked or unchecked, and optionally includes a third "indeterminate" state to indicate partial selection.
63
- *
64
- * @see
65
- * Check out the {@link https://uds.build/docs/components/checkbox Checkbox Docs} for more info
66
- *
67
- * @usage
68
- * - Forms: checkbox
69
- *
70
- * @example
71
- * ```tsx
72
- * 'use client';
73
- * import { Checkbox } from "@yahoo/uds";
74
- *
75
- * <Checkbox label="Name" required />
76
- *```
77
- *
78
- * @related [Radio](https://uds.build/docs/components/radio), [Switch](https://uds.build/docs/components/switch), [Input](https://uds.build/docs/components/input).
79
- **/
80
- const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Checkbox(
81
- {
82
- id,
83
- checked: checkedProp,
84
- defaultChecked,
85
- onChange,
86
- label,
87
- labelPosition = 'start',
88
- variant: variantProp = 'primary',
89
- size = 'md',
90
- reduceMotion: forceReduceMotion,
91
- disabled,
92
- required,
93
- hasError,
94
- className,
95
- layerClassNames,
96
- ...checkboxProps
97
- },
98
- parentRef,
99
- ) {
100
- const generatedId = useId();
101
- const uid = id ?? `uds-input-${generatedId}`;
102
-
103
- const innerRef = useRef<HTMLInputElement | null>(null);
104
-
105
- /**
106
- * State
107
- */
108
- const isControlled = checkedProp !== undefined;
109
- const [checked, setChecked] = useState(isControlled ? checkedProp : defaultChecked);
110
- const [isHovered, setIsHovered] = useState(false);
111
- const [isPressed, setIsPressed] = useState(false);
112
-
113
- /**
114
- * Derived values
115
- */
116
- const variant = useMemo(
117
- () => (hasError ? VARIANT_ERROR_MAP[variantProp] : variantProp),
118
- [hasError, variantProp],
119
- );
120
-
121
- const showHoverEffect = !disabled && isHovered;
122
- const showPressedEffect = !disabled && isPressed;
123
-
124
- const scale = useMemo(() => {
125
- if (showPressedEffect) {
126
- return 0.9;
127
- }
128
-
129
- if (showHoverEffect) {
130
- return 1.1;
131
- }
132
-
133
- return 1;
134
- }, [showPressedEffect, showHoverEffect]);
135
-
136
- const checkOpacity = useMemo(() => {
137
- if (!checked) {
138
- return 'opacity-0';
139
- }
140
-
141
- if (showPressedEffect) {
142
- return 'opacity-55';
143
- }
144
-
145
- return 'opacity-100';
146
- }, [checked, showPressedEffect]);
147
-
148
- const motionAnimate = useMemo(
149
- () => ({
150
- scale,
151
- }),
152
- [scale],
153
- );
154
-
155
- const motionTransition = useMemo(
156
- () => (isPressed ? pressTransition : hoverTransition),
157
- [isPressed],
158
- );
159
-
160
- /**
161
- * Handlers
162
- */
163
- const handleChange = useCallback(
164
- (e: CheckboxChangeEvent) => {
165
- onChange?.(e);
166
-
167
- // If uncontrolled, immediate change internal state.
168
- if (!isControlled) {
169
- setChecked(e.target.checked);
170
- }
171
- },
172
- [isControlled, onChange],
173
- );
174
-
175
- const handleHoverStart = useCallback(() => {
176
- setIsHovered(true);
177
- }, []);
178
-
179
- const handleHoverEnd = useCallback(() => {
180
- setIsHovered(false);
181
- }, []);
182
-
183
- const handleTapStart = useCallback(() => {
184
- setIsPressed(true);
185
- }, []);
186
-
187
- const handleTapEnd = useCallback(() => {
188
- setIsPressed(false);
189
- }, []);
190
-
191
- /**
192
- * Helpers
193
- */
194
- const setDOMIndeterminate = (checked_: CheckboxProps['checked']) => {
195
- if (!innerRef.current) {
196
- return;
197
- }
198
-
199
- innerRef.current.indeterminate = isIndeterminate(checked_);
200
- };
201
-
202
- // Motion
203
- const prefersReducedMotion = useReducedMotion();
204
- const reduceMotion = forceReduceMotion ? 'always' : 'user';
205
-
206
- const cssAnimationDuration =
207
- prefersReducedMotion || forceReduceMotion ? 'duration-0' : 'duration-120';
208
-
209
- /**
210
- * Effects
211
- */
212
- // Reset state if prop changes.
213
- useEffect(() => {
214
- if (isControlled) {
215
- setChecked(checkedProp);
216
- }
217
- }, [checkedProp, isControlled]);
218
-
219
- // When the checked prop changes, also set DOM indeterminate state.
220
- useEffect(() => {
221
- setDOMIndeterminate(checked);
222
- }, [checked]);
223
-
224
- const valueState = isIndeterminate(checked) ? 'indeterminate' : checked ? 'checked' : 'unchecked';
225
-
226
- const classNames = {
227
- root: getStyles({
228
- checkboxSizeRoot: size,
229
- checkboxVariantRoot: variant,
230
- checkboxVariantValueRoot: valueState,
231
- display: 'flex',
232
- flexDirection: labelPosition === 'start' ? 'row' : 'row-reverse',
233
- alignItems: 'center',
234
- className: cx(
235
- {
236
- 'cursor-pointer': !disabled,
237
- 'cursor-default': disabled,
238
- 'opacity-50': disabled,
239
- },
240
-
241
- className,
242
- layerClassNames?.root,
243
- ),
244
- }),
245
-
246
- checkbox: getStyles({
247
- checkboxSizeCheckbox: size,
248
- checkboxVariantCheckbox: variant,
249
- checkboxVariantValueCheckbox: valueState,
250
- className: cx(
251
- 'border',
252
- 'rounded-[4px]',
253
- 'uds-ring',
254
- 'uds-ring-within',
255
-
256
- cssAnimationDuration,
257
- 'transition-[background-color,border-color,box-shadow]',
258
-
259
- layerClassNames?.checkbox,
260
- ),
261
- }),
262
-
263
- check: getStyles({
264
- checkboxVariantCheckboxIcon: variant,
265
- checkboxVariantValueCheckboxIcon: valueState,
266
- className: cx(
267
- 'pointer-events-none',
268
-
269
- checkOpacity,
270
-
271
- cssAnimationDuration,
272
- 'transition-opacity',
273
- ),
274
- }),
275
-
276
- htmlCheckbox: cx(
277
- // Control the cursor at the top of the component
278
- // and don't let the input override it back to the
279
- // default value.
280
- 'cursor-[inherit]',
281
-
282
- // Overlay the invisible checkbox over the designed
283
- // checkbox so that it can be clicked directly.
284
- 'absolute',
285
- 'opacity-0',
286
- 'top-1/2',
287
- 'left-1/2',
288
- 'w-[calc(100%+2px)]',
289
- 'h-[calc(100%+2px)]',
290
- 'transform',
291
- 'translate-x-[-50%]',
292
- 'translate-y-[-50%]',
293
- ),
294
-
295
- label: cx(labelPosition === 'start' ? 'text-start' : 'text-end', layerClassNames?.label),
296
- };
297
-
298
- const RootElement = label ? m.label : m.div;
299
-
300
- return (
301
- <SpringMotionConfig reducedMotion={reduceMotion} {...motionTransition}>
302
- <RootElement
303
- className={classNames.root}
304
- data-testid="container"
305
- onHoverStart={handleHoverStart}
306
- onHoverEnd={handleHoverEnd}
307
- onTapStart={handleTapStart}
308
- onTap={handleTapEnd}
309
- onTapCancel={handleTapEnd}
310
- tabIndex={-1}
311
- >
312
- <MotionBox
313
- position="relative"
314
- className={classNames.checkbox}
315
- alignItems="center"
316
- justifyContent="center"
317
- flex="none"
318
- animate={motionAnimate}
319
- >
320
- <input
321
- type="checkbox"
322
- // Required for Safari to render a focus ring
323
- tabIndex={0}
324
- // These are standard HTML input props for customization.
325
- {...checkboxProps}
326
- //
327
- // Provide a ref to the underlying input element for customization.
328
- ref={(ref) => {
329
- // Set internal ref.
330
- innerRef.current = ref;
331
-
332
- // Now that we have the ref, apply the current state.
333
- setDOMIndeterminate(checked);
334
-
335
- // Forward the ref to parent.
336
- if (typeof parentRef === 'function') {
337
- parentRef(ref);
338
- } else if (parentRef !== null) {
339
- parentRef.current = ref;
340
- }
341
- }}
342
- //
343
- // Core props for the checkbox.
344
- id={uid}
345
- disabled={disabled}
346
- required={required}
347
- aria-invalid={hasError}
348
- checked={isControlled ? (isIndeterminate(checked) ? false : checked) : undefined}
349
- defaultChecked={isControlled ? undefined : defaultChecked}
350
- onChange={handleChange}
351
- //
352
- // styles
353
- className={classNames.htmlCheckbox}
354
- />
355
-
356
- <Icon name={getIcon(checked)} size="sm" className={classNames.check} />
357
- </MotionBox>
358
-
359
- {label && (
360
- <FormLabel
361
- as="div"
362
- variant="inherit"
363
- color="inherit"
364
- required={required}
365
- label={label}
366
- className={classNames.label}
367
- />
368
- )}
369
- </RootElement>
370
- </SpringMotionConfig>
371
- );
372
- });
373
-
374
- // Need to re-set this because of the forwardRef wrapper
375
- Checkbox.displayName = 'Checkbox';
376
-
377
- export { Checkbox, type CheckboxProps, SIZES, VARIANTS };