@astryxdesign/core 0.7.7-canary.550ff21 → 0.7.7-canary.559b005

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 (264) hide show
  1. package/dist/Avatar/Avatar.d.ts.map +1 -1
  2. package/dist/Avatar/Avatar.js +1 -1
  3. package/dist/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
  4. package/dist/Breadcrumbs/BreadcrumbItem.js +2 -1
  5. package/dist/Button/Button.d.ts.map +1 -1
  6. package/dist/Button/Button.js +3 -2
  7. package/dist/DateInput/Wheel.d.ts +17 -1
  8. package/dist/DateInput/Wheel.d.ts.map +1 -1
  9. package/dist/DateInput/Wheel.js +179 -19
  10. package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
  11. package/dist/DateRangeInput/DateRangeInput.js +63 -49
  12. package/dist/Dialog/Dialog.d.ts.map +1 -1
  13. package/dist/Dialog/Dialog.js +49 -12
  14. package/dist/Drawer/Drawer.d.ts.map +1 -1
  15. package/dist/Drawer/Drawer.js +15 -10
  16. package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -1
  17. package/dist/Drawer/useDrawerDialogPresence.js +4 -0
  18. package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  19. package/dist/DropdownMenu/DropdownMenu.js +20 -4
  20. package/dist/InfoTip/InfoTip.d.ts +63 -0
  21. package/dist/InfoTip/InfoTip.d.ts.map +1 -0
  22. package/dist/InfoTip/InfoTip.js +126 -0
  23. package/dist/InfoTip/index.d.ts +10 -0
  24. package/dist/InfoTip/index.d.ts.map +1 -0
  25. package/dist/InfoTip/index.js +12 -0
  26. package/dist/Layer/layerClickBoundary.d.ts +7 -1
  27. package/dist/Layer/layerClickBoundary.d.ts.map +1 -1
  28. package/dist/Layer/layerClickBoundary.js +2 -2
  29. package/dist/Layer/useBackdropPress.d.ts +27 -0
  30. package/dist/Layer/useBackdropPress.d.ts.map +1 -0
  31. package/dist/Layer/useBackdropPress.js +53 -0
  32. package/dist/Layer/usePressPin.d.ts +95 -0
  33. package/dist/Layer/usePressPin.d.ts.map +1 -0
  34. package/dist/Layer/usePressPin.js +365 -0
  35. package/dist/Layer/useTouchTrigger.d.ts +23 -1
  36. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  37. package/dist/Layer/useTouchTrigger.js +45 -7
  38. package/dist/Lightbox/Lightbox.d.ts.map +1 -1
  39. package/dist/Lightbox/Lightbox.js +2 -1
  40. package/dist/Popover/usePopover.d.ts.map +1 -1
  41. package/dist/Popover/usePopover.js +56 -7
  42. package/dist/PowerSearch/PowerSearch.d.ts.map +1 -1
  43. package/dist/PowerSearch/PowerSearch.js +38 -30
  44. package/dist/ProgressBar/ProgressBar.d.ts +1 -1
  45. package/dist/ProgressBar/ProgressBar.d.ts.map +1 -1
  46. package/dist/ProgressBar/ProgressBar.js +33 -6
  47. package/dist/SegmentedControl/SegmentedControl.d.ts +3 -1
  48. package/dist/SegmentedControl/SegmentedControl.d.ts.map +1 -1
  49. package/dist/SegmentedControl/SegmentedControl.js +115 -8
  50. package/dist/SegmentedControl/SegmentedControlContext.d.ts +6 -0
  51. package/dist/SegmentedControl/SegmentedControlContext.d.ts.map +1 -1
  52. package/dist/SegmentedControl/SegmentedControlItem.d.ts +1 -0
  53. package/dist/SegmentedControl/SegmentedControlItem.d.ts.map +1 -1
  54. package/dist/SegmentedControl/SegmentedControlItem.js +10 -2
  55. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts +357 -0
  56. package/dist/SegmentedControl/useSegmentedSelectionMotion.d.ts.map +1 -0
  57. package/dist/SegmentedControl/useSegmentedSelectionMotion.js +1349 -0
  58. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts +70 -0
  59. package/dist/SegmentedControl/useSegmentedTouchTracking.d.ts.map +1 -0
  60. package/dist/SegmentedControl/useSegmentedTouchTracking.js +264 -0
  61. package/dist/Selector/Selector.d.ts.map +1 -1
  62. package/dist/Selector/Selector.js +96 -67
  63. package/dist/Selector/optionShape.d.ts +24 -0
  64. package/dist/Selector/optionShape.d.ts.map +1 -0
  65. package/dist/Selector/optionShape.js +48 -0
  66. package/dist/Selector/selectableOptionEntries.d.ts +20 -0
  67. package/dist/Selector/selectableOptionEntries.d.ts.map +1 -0
  68. package/dist/Selector/selectableOptionEntries.js +38 -0
  69. package/dist/Selector/utils.d.ts +2 -17
  70. package/dist/Selector/utils.d.ts.map +1 -1
  71. package/dist/Selector/utils.js +3 -51
  72. package/dist/Switch/Switch.d.ts +1 -1
  73. package/dist/Switch/Switch.d.ts.map +1 -1
  74. package/dist/Switch/Switch.js +200 -46
  75. package/dist/Switch/switchFill.d.ts +31 -0
  76. package/dist/Switch/switchFill.d.ts.map +1 -0
  77. package/dist/Switch/switchFill.js +88 -0
  78. package/dist/Switch/switchTouch.d.ts +74 -0
  79. package/dist/Switch/switchTouch.d.ts.map +1 -0
  80. package/dist/Switch/switchTouch.js +125 -0
  81. package/dist/Switch/useSwitchTouch.d.ts +276 -0
  82. package/dist/Switch/useSwitchTouch.d.ts.map +1 -0
  83. package/dist/Switch/useSwitchTouch.js +939 -0
  84. package/dist/TabList/Tab.d.ts.map +1 -1
  85. package/dist/TabList/Tab.js +4 -3
  86. package/dist/Toast/Toast.d.ts.map +1 -1
  87. package/dist/Toast/Toast.js +5 -0
  88. package/dist/Token/Token.d.ts.map +1 -1
  89. package/dist/Token/Token.js +1 -0
  90. package/dist/Tokenizer/Tokenizer.d.ts.map +1 -1
  91. package/dist/Tokenizer/Tokenizer.js +12 -5
  92. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts +3 -0
  93. package/dist/Tokenizer/TokenizerItemRemovableContext.d.ts.map +1 -0
  94. package/dist/Tokenizer/TokenizerItemRemovableContext.js +17 -0
  95. package/dist/Tooltip/Tooltip.d.ts +30 -6
  96. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  97. package/dist/Tooltip/Tooltip.js +5 -0
  98. package/dist/Tooltip/index.d.ts +1 -1
  99. package/dist/Tooltip/index.d.ts.map +1 -1
  100. package/dist/Tooltip/useTooltip.d.ts +31 -5
  101. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  102. package/dist/Tooltip/useTooltip.js +59 -18
  103. package/dist/Typeahead/Typeahead.d.ts.map +1 -1
  104. package/dist/Typeahead/Typeahead.js +26 -15
  105. package/dist/astryx.css +125 -2
  106. package/dist/gestures/GestureHost.d.ts.map +1 -1
  107. package/dist/gestures/GestureHost.js +71 -14
  108. package/dist/gestures/PressTracker.d.ts +6 -0
  109. package/dist/gestures/PressTracker.d.ts.map +1 -1
  110. package/dist/gestures/PressTracker.js +3 -0
  111. package/dist/gestures/types.d.ts +6 -0
  112. package/dist/gestures/types.d.ts.map +1 -1
  113. package/dist/gestures/usePressTracker.d.ts.map +1 -1
  114. package/dist/gestures/usePressTracker.js +1 -0
  115. package/dist/gestures/wheelSegmenter.d.ts +14 -3
  116. package/dist/gestures/wheelSegmenter.d.ts.map +1 -1
  117. package/dist/gestures/wheelSegmenter.js +32 -8
  118. package/dist/hooks/actionGroupTracker.d.ts +3 -3
  119. package/dist/hooks/actionGroupTracker.d.ts.map +1 -1
  120. package/dist/hooks/actionGroupTracker.js +6 -53
  121. package/dist/hooks/useAttachment.d.ts +16 -8
  122. package/dist/hooks/useAttachment.d.ts.map +1 -1
  123. package/dist/hooks/useAttachment.js +35 -15
  124. package/dist/hooks/useFocusTrap.d.ts +15 -0
  125. package/dist/hooks/useFocusTrap.d.ts.map +1 -1
  126. package/dist/hooks/useFocusTrap.js +13 -2
  127. package/dist/hooks/useHighlightedOptionScroll.d.ts.map +1 -1
  128. package/dist/hooks/useHighlightedOptionScroll.js +14 -11
  129. package/dist/hooks/useMediaQuery.d.ts +2 -1
  130. package/dist/hooks/useMediaQuery.d.ts.map +1 -1
  131. package/dist/hooks/useMediaQuery.js +7 -4
  132. package/dist/hooks/usePager.d.ts +261 -0
  133. package/dist/hooks/usePager.d.ts.map +1 -0
  134. package/dist/hooks/usePager.js +1169 -0
  135. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts +8 -0
  136. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.d.ts.map +1 -0
  137. package/dist/i18n/generated-english/InfoTip/InfoTip.generated.js +12 -0
  138. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  139. package/dist/i18n/generated-locales/en.generated.js +2 -1
  140. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  141. package/dist/i18n/generated-locales/pseudo.generated.js +2 -1
  142. package/dist/index.d.ts +1 -0
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +1 -0
  145. package/dist/motion/paging.d.ts +16 -5
  146. package/dist/motion/paging.d.ts.map +1 -1
  147. package/dist/motion/paging.js +34 -14
  148. package/dist/motion/roles.d.ts +7 -1
  149. package/dist/motion/roles.d.ts.map +1 -1
  150. package/dist/motion/roles.js +20 -1
  151. package/dist/motion/uikit/index.d.ts +7 -4
  152. package/dist/motion/uikit/index.d.ts.map +1 -1
  153. package/dist/motion/uikit/index.js +7 -4
  154. package/dist/motion/uikit/paging.d.ts +31 -20
  155. package/dist/motion/uikit/paging.d.ts.map +1 -1
  156. package/dist/motion/uikit/paging.js +41 -11
  157. package/dist/motion/uikit/progressBar.d.ts +27 -7
  158. package/dist/motion/uikit/progressBar.d.ts.map +1 -1
  159. package/dist/motion/uikit/progressBar.js +31 -11
  160. package/dist/motion/uikit/segmented.d.ts +55 -0
  161. package/dist/motion/uikit/segmented.d.ts.map +1 -0
  162. package/dist/motion/uikit/segmented.js +77 -0
  163. package/dist/motion/uikit/springs.d.ts +8 -42
  164. package/dist/motion/uikit/springs.d.ts.map +1 -1
  165. package/dist/motion/uikit/springs.js +12 -42
  166. package/dist/motion/uikit/switch.d.ts +166 -0
  167. package/dist/motion/uikit/switch.d.ts.map +1 -0
  168. package/dist/motion/uikit/switch.js +186 -0
  169. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts +18 -0
  170. package/dist/privateAttributes/pressHoldsDrag.stylex.d.ts.map +1 -0
  171. package/dist/privateAttributes/pressHoldsDrag.stylex.js +28 -0
  172. package/dist/privateAttributes/segmentTitle.stylex.d.ts +5 -0
  173. package/dist/privateAttributes/segmentTitle.stylex.d.ts.map +1 -0
  174. package/dist/privateAttributes/segmentTitle.stylex.js +22 -0
  175. package/dist/utils/browserClickWait.d.ts +35 -0
  176. package/dist/utils/browserClickWait.d.ts.map +1 -0
  177. package/dist/utils/browserClickWait.js +123 -0
  178. package/dist/utils/clickGuard.d.ts +7 -1
  179. package/dist/utils/clickGuard.d.ts.map +1 -1
  180. package/dist/utils/clickGuard.js +23 -1
  181. package/dist/utils/pressFeedback.d.ts.map +1 -1
  182. package/dist/utils/pressFeedback.js +5 -0
  183. package/locales/en.json +4 -0
  184. package/locales/pseudo.json +3 -0
  185. package/package.json +9 -4
  186. package/src/Avatar/Avatar.tsx +3 -1
  187. package/src/Breadcrumbs/BreadcrumbItem.tsx +4 -1
  188. package/src/Button/Button.tsx +3 -2
  189. package/src/DateInput/Wheel.tsx +174 -14
  190. package/src/DateRangeInput/DateRangeInput.doc.mjs +3 -2
  191. package/src/DateRangeInput/DateRangeInput.tsx +117 -71
  192. package/src/Dialog/Dialog.tsx +62 -11
  193. package/src/Drawer/Drawer.tsx +27 -10
  194. package/src/Drawer/useDrawerDialogPresence.ts +4 -0
  195. package/src/DropdownMenu/DropdownMenu.tsx +28 -6
  196. package/src/InfoTip/InfoTip.doc.mjs +192 -0
  197. package/src/InfoTip/InfoTip.tsx +186 -0
  198. package/src/InfoTip/index.ts +14 -0
  199. package/src/Layer/layerClickBoundary.ts +2 -2
  200. package/src/Layer/useBackdropPress.ts +81 -0
  201. package/src/Layer/usePressPin.ts +516 -0
  202. package/src/Layer/useTouchTrigger.ts +56 -6
  203. package/src/Lightbox/Lightbox.tsx +2 -1
  204. package/src/Popover/usePopover.tsx +71 -9
  205. package/src/PowerSearch/PowerSearch.tsx +38 -31
  206. package/src/ProgressBar/ProgressBar.doc.mjs +4 -2
  207. package/src/ProgressBar/ProgressBar.tsx +67 -7
  208. package/src/SegmentedControl/SegmentedControl.doc.mjs +3 -3
  209. package/src/SegmentedControl/SegmentedControl.tsx +179 -5
  210. package/src/SegmentedControl/SegmentedControlContext.ts +6 -0
  211. package/src/SegmentedControl/SegmentedControlItem.tsx +14 -2
  212. package/src/SegmentedControl/useSegmentedSelectionMotion.ts +1637 -0
  213. package/src/SegmentedControl/useSegmentedTouchTracking.ts +308 -0
  214. package/src/Selector/Selector.tsx +136 -89
  215. package/src/Selector/optionShape.ts +64 -0
  216. package/src/Selector/selectableOptionEntries.ts +39 -0
  217. package/src/Selector/utils.ts +9 -68
  218. package/src/Switch/Switch.doc.mjs +3 -3
  219. package/src/Switch/Switch.tsx +412 -86
  220. package/src/Switch/switchFill.ts +106 -0
  221. package/src/Switch/switchTouch.ts +186 -0
  222. package/src/Switch/useSwitchTouch.ts +1051 -0
  223. package/src/TabList/Tab.tsx +5 -3
  224. package/src/Toast/Toast.tsx +5 -0
  225. package/src/Token/Token.tsx +2 -0
  226. package/src/Tokenizer/Tokenizer.tsx +15 -5
  227. package/src/Tokenizer/TokenizerItemRemovableContext.ts +22 -0
  228. package/src/Tooltip/Tooltip.doc.mjs +21 -6
  229. package/src/Tooltip/Tooltip.tsx +42 -5
  230. package/src/Tooltip/index.ts +1 -0
  231. package/src/Tooltip/useTooltip.doc.mjs +4 -2
  232. package/src/Tooltip/useTooltip.tsx +84 -21
  233. package/src/Typeahead/Typeahead.tsx +29 -15
  234. package/src/gestures/GestureHost.ts +100 -11
  235. package/src/gestures/PressTracker.ts +10 -0
  236. package/src/gestures/types.ts +6 -0
  237. package/src/gestures/usePressTracker.ts +2 -0
  238. package/src/gestures/wheelSegmenter.ts +36 -7
  239. package/src/hooks/actionGroupTracker.ts +12 -56
  240. package/src/hooks/useAttachment.ts +56 -14
  241. package/src/hooks/useFocusTrap.ts +26 -2
  242. package/src/hooks/useHighlightedOptionScroll.ts +15 -11
  243. package/src/hooks/useMediaQuery.doc.mjs +2 -2
  244. package/src/hooks/useMediaQuery.ts +13 -4
  245. package/src/hooks/usePager.ts +1446 -0
  246. package/src/i18n/generated-english/InfoTip/InfoTip.generated.ts +13 -0
  247. package/src/i18n/generated-locales/en.generated.ts +1 -0
  248. package/src/i18n/generated-locales/pseudo.generated.ts +1 -0
  249. package/src/index.ts +1 -0
  250. package/src/motion/MEASUREMENTS.md +36 -27
  251. package/src/motion/README.md +3 -1
  252. package/src/motion/paging.ts +37 -14
  253. package/src/motion/roles.ts +20 -1
  254. package/src/motion/uikit/index.ts +6 -5
  255. package/src/motion/uikit/paging.ts +41 -10
  256. package/src/motion/uikit/progressBar.ts +31 -11
  257. package/src/motion/uikit/segmented.ts +74 -0
  258. package/src/motion/uikit/springs.ts +12 -42
  259. package/src/motion/uikit/switch.ts +174 -0
  260. package/src/privateAttributes/pressHoldsDrag.stylex.ts +28 -0
  261. package/src/privateAttributes/segmentTitle.stylex.ts +22 -0
  262. package/src/utils/browserClickWait.ts +133 -0
  263. package/src/utils/clickGuard.ts +28 -1
  264. package/src/utils/pressFeedback.ts +5 -0
@@ -78,9 +78,11 @@ import {layerTextReset} from '../Layer/layerTextReset.stylex';
78
78
  import {layerStructureReset} from '../Layer/layerStructureReset.stylex';
79
79
  import {LayerContentBoundary} from '../Layer/layerScopedContext';
80
80
  import {useModalOutlet} from '../Layer/modalOutlet';
81
+ import {useBackdropPress} from '../Layer/useBackdropPress';
81
82
  import {layerClickBoundary} from '../Layer/layerClickBoundary';
82
83
  import {ModalAnnounceProvider} from '../hooks/ModalAnnounceProvider';
83
84
  import {composeEventHandlers, mergeProps, themeProps} from '../utils';
85
+ import {chainEventHandlers} from '../utils/chainEventHandlers';
84
86
  import {container, overlayPaddingReset} from '../Layout';
85
87
  import {
86
88
  containerPaddingBlockEndVarStyles,
@@ -92,6 +94,8 @@ import {
92
94
  import type {SpacingStep, SpacingToken} from '../Layout';
93
95
  import {useDrawerDialogPresence} from './useDrawerDialogPresence';
94
96
 
97
+ type PointerHandler = (event: React.PointerEvent<HTMLDialogElement>) => void;
98
+
95
99
  // =============================================================================
96
100
  // Styles
97
101
  // =============================================================================
@@ -543,15 +547,14 @@ export function Drawer({
543
547
  [allowEscape, handleDismiss, shouldDismissOnCloseRequest],
544
548
  );
545
549
 
546
- // Clicks on the ::backdrop target the <dialog> element itself; clicks on
547
- // drawer content always target a child (the content area fills the panel).
548
- const handleClick = useCallback(
549
- (event: React.MouseEvent<HTMLDialogElement>) => {
550
- if (event.target === event.currentTarget && hasScrim && allowScrimClick) {
551
- onOpenChange(false);
552
- }
553
- },
554
- [allowScrimClick, hasScrim, onOpenChange],
550
+ // A press on the ::backdrop targets the <dialog> itself (the content area
551
+ // fills the panel). The press must start and end there.
552
+ const handleScrimPress = useCallback(() => {
553
+ onOpenChange(false);
554
+ }, [onOpenChange]);
555
+ const scrimPress = useBackdropPress(
556
+ handleScrimPress,
557
+ hasScrim && allowScrimClick,
555
558
  );
556
559
 
557
560
  const widthValue = typeof width === 'number' ? `${width}px` : width;
@@ -612,8 +615,22 @@ export function Drawer({
612
615
  // written.
613
616
  {...layerClickBoundary({
614
617
  ...safeProps,
615
- onClick: composeEventHandlers(onClickProp, handleClick),
618
+ onClick: composeEventHandlers(onClickProp, scrimPress.onClick),
616
619
  })}
620
+ // The hook records where the press started first. The caller's capture
621
+ // handler then runs, also when a child prevented default.
622
+ onPointerDownCapture={chainEventHandlers(
623
+ scrimPress.onPointerDownCapture,
624
+ safeProps.onPointerDownCapture as PointerHandler | undefined,
625
+ )}
626
+ onPointerUpCapture={chainEventHandlers(
627
+ scrimPress.onPointerUpCapture,
628
+ safeProps.onPointerUpCapture as PointerHandler | undefined,
629
+ )}
630
+ onPointerCancelCapture={chainEventHandlers(
631
+ scrimPress.onPointerCancelCapture,
632
+ safeProps.onPointerCancelCapture as PointerHandler | undefined,
633
+ )}
617
634
  onKeyDown={onKeyDownProp}
618
635
  onCancel={handleCancel}>
619
636
  <ModalAnnounceProvider dialogRef={dialogRef} isOpen={isOpen && hasScrim}>
@@ -32,6 +32,7 @@ import {
32
32
  type SetStateAction,
33
33
  } from 'react';
34
34
  import {flushSync} from 'react-dom';
35
+ import {notifyTopLayerEntry} from '../Layer/modalOutlet';
35
36
 
36
37
  /** Slack past the computed transition before the backstop gives up waiting. */
37
38
  const EXIT_BACKSTOP_BUFFER_MS = 50;
@@ -71,6 +72,9 @@ function showDrawerHost(dialog: HTMLDialogElement, isModal: boolean): void {
71
72
  dialog.showModal();
72
73
  } else if (typeof dialog.showPopover === 'function') {
73
74
  dialog.showPopover();
75
+ // The drawer is now the newest top-layer entry: global hosts shown before
76
+ // it (the toast viewport) re-enter above it, as they do above a modal.
77
+ notifyTopLayerEntry();
74
78
  } else {
75
79
  // Reduced fallback for browsers below the Popover API support floor.
76
80
  dialog.show();
@@ -533,6 +533,20 @@ function holdInvokerThroughPress(
533
533
  doc.addEventListener('pointercancel', onPressEnd, true);
534
534
  }
535
535
 
536
+ /**
537
+ * The name of a menu opened from a custom trigger: the caller's `aria-label`
538
+ * when it is a non-empty string, else the trigger's own accessible name. The
539
+ * popover and the bottom sheet both name the menu through this.
540
+ */
541
+ function resolveCustomTriggerMenuName(
542
+ callerLabel: unknown,
543
+ triggerName: string | undefined,
544
+ ): string | undefined {
545
+ return typeof callerLabel === 'string' && callerLabel.trim() !== ''
546
+ ? callerLabel
547
+ : triggerName;
548
+ }
549
+
536
550
  function DropdownMenuBottomSheet({
537
551
  button: buttonFromProps,
538
552
  renderTrigger,
@@ -596,11 +610,22 @@ function DropdownMenuBottomSheet({
596
610
  useEffect(() => {
597
611
  void preloadMenuBottomSheetActionList();
598
612
  }, []);
613
+ // The control's name is only readable from the DOM once it is rendered.
614
+ const [triggerName, setTriggerName] = useState<string | undefined>(undefined);
615
+ useIsomorphicLayoutEffect(() => {
616
+ if (renderTrigger != null && isOpen) {
617
+ setTriggerName(readAccessibleName(buttonRef.current));
618
+ }
619
+ }, [renderTrigger, isOpen]);
620
+ const rootTitle =
621
+ (renderTrigger != null
622
+ ? resolveCustomTriggerMenuName(rest['aria-label'], triggerName)
623
+ : undefined) ?? button.label;
599
624
  const currentSubmenu = submenuPath.at(-1);
600
625
  const currentItems = currentSubmenu?.items ?? items;
601
- const currentTitle = currentSubmenu?.label ?? button.label;
626
+ const currentTitle = currentSubmenu?.label ?? rootTitle;
602
627
  const sheetLabel =
603
- typeof currentTitle === 'string' ? currentTitle : button.label;
628
+ typeof currentTitle === 'string' ? currentTitle : rootTitle;
604
629
 
605
630
  const setOpen = useCallback(
606
631
  (nextIsOpen: boolean) => {
@@ -1040,12 +1065,9 @@ function DropdownMenuPopover({
1040
1065
  // The design system's button names the menu by its label. A custom trigger
1041
1066
  // names it by reference (or the caller's `aria-label` does), so that name
1042
1067
  // is read off the control as the menu opens.
1043
- const callerMenuLabel = rest['aria-label'];
1044
1068
  const menuLabel =
1045
1069
  renderTrigger != null
1046
- ? typeof callerMenuLabel === 'string' && callerMenuLabel.trim() !== ''
1047
- ? callerMenuLabel
1048
- : triggerName
1070
+ ? resolveCustomTriggerMenuName(rest['aria-label'], triggerName)
1049
1071
  : typeof button.label === 'string'
1050
1072
  ? button.label
1051
1073
  : undefined;
@@ -0,0 +1,192 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
4
+
5
+ export const docs = {
6
+ name: 'InfoTip',
7
+ displayName: 'Info Tip',
8
+ // Keeps the registry route InfoTip had as a canary-only Lab component.
9
+ registry: {aliases: ['lab/info-tip']},
10
+ category: 'Feedback & Status',
11
+ keywords: [
12
+ 'info',
13
+ 'tooltip',
14
+ 'help',
15
+ 'hint',
16
+ 'affordance',
17
+ 'icon',
18
+ 'label',
19
+ 'field',
20
+ 'metric',
21
+ 'definition',
22
+ ],
23
+ props: [
24
+ {
25
+ name: 'content',
26
+ type: 'ReactNode',
27
+ description:
28
+ "Content to display in the tooltip. Typically short, non-interactive text. Mirrors Tooltip's content prop.",
29
+ required: true,
30
+ },
31
+ {
32
+ name: 'label',
33
+ type: 'string',
34
+ description:
35
+ 'Accessible name for the trigger button. Defaults to the translated "More information".',
36
+ default: "'More information'",
37
+ },
38
+ {
39
+ name: 'size',
40
+ type: "'xsm' | 'sm' | 'md' | 'lg'",
41
+ description:
42
+ 'Size of the info icon (12px, 16px, 20px, 24px). Maps 1:1 to Icon sizes.',
43
+ default: "'sm'",
44
+ },
45
+ {
46
+ name: 'xstyle',
47
+ type: 'StyleXStyles',
48
+ description:
49
+ 'StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value, not an inline style object like style={{}}.',
50
+ },
51
+ ],
52
+ usage: {
53
+ description:
54
+ 'An info icon that reveals help: a small "i" button. Hover and keyboard focus preview the help, and a click, tap, Enter, or Space pins it open until Escape, a second press, a press outside, or focus leaving. Use it next to labels, values, and metrics for permission notes, metric definitions, and field help. Its value over hand-composing Icon inside Tooltip is the pre-wired accessible trigger: a real button with an aria-label, Tab-reachable, tooltip on hover AND focus AND tap, and Escape dismissal.',
55
+ bestPractices: [
56
+ {
57
+ guidance: true,
58
+ description:
59
+ 'Keep tooltip content concise, plain, and non-interactive; use Popover or HoverCard for links and buttons.',
60
+ },
61
+ {
62
+ guidance: true,
63
+ description:
64
+ 'Override label when "More information" is too generic, e.g. "About this metric".',
65
+ },
66
+ {
67
+ guidance: true,
68
+ description:
69
+ 'Rely on InfoTip rather than a hand-rolled info button on touch: it sets Tooltip triggerBehavior to toggle, so a tap, a click, Enter, or Space pins the tooltip even though the trigger is a button, and a tap outside dismisses it.',
70
+ },
71
+ {
72
+ guidance: false,
73
+ description:
74
+ 'Hand-compose Icon inside Tooltip for info affordances; the bare Icon is aria-hidden and unfocusable, so keyboard and screen-reader users never see it.',
75
+ },
76
+ {
77
+ guidance: false,
78
+ description:
79
+ 'Use InfoTip for essential information users must see to complete a task; put that text inline instead.',
80
+ },
81
+ ],
82
+ },
83
+ };
84
+
85
+ /** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */
86
+ export const docsZh = {
87
+ name: 'InfoTip',
88
+ displayName: 'Info Tip',
89
+ props: [
90
+ {
91
+ name: 'content',
92
+ type: 'ReactNode',
93
+ description:
94
+ '工具提示中显示的内容。通常为简短的非交互文本。与 Tooltip 的 content 属性一致。',
95
+ required: true,
96
+ },
97
+ {
98
+ name: 'label',
99
+ type: 'string',
100
+ description: '触发按钮的无障碍名称。默认为翻译后的“More information”。',
101
+ default: "'More information'",
102
+ },
103
+ {
104
+ name: 'size',
105
+ type: "'xsm' | 'sm' | 'md' | 'lg'",
106
+ description:
107
+ '信息图标的尺寸(12px、16px、20px、24px)。与 Icon 尺寸一一对应。',
108
+ default: "'sm'",
109
+ },
110
+ {
111
+ name: 'xstyle',
112
+ type: 'StyleXStyles',
113
+ description:
114
+ '用于布局自定义的 StyleX 样式(边距、定位、尺寸)。必须是 stylex.create() 的值,不能是内联样式对象如 style={{}}。',
115
+ },
116
+ ],
117
+ usage: {
118
+ description:
119
+ 'An info icon that reveals help: a small "i" button. Hover and keyboard focus preview the help, and a click, tap, Enter, or Space pins it open until Escape, a second press, a press outside, or focus leaving. Use it next to labels, values, and metrics for permission notes, metric definitions, and field help.',
120
+ bestPractices: [
121
+ {
122
+ guidance: true,
123
+ description:
124
+ 'Keep tooltip content concise, plain, and non-interactive; use Popover or HoverCard for links and buttons.',
125
+ },
126
+ {
127
+ guidance: true,
128
+ description:
129
+ 'Override label when "More information" is too generic, e.g. "About this metric".',
130
+ },
131
+ {
132
+ guidance: true,
133
+ description:
134
+ 'Rely on InfoTip rather than a hand-rolled info button on touch: it sets Tooltip triggerBehavior to toggle, so a tap, a click, Enter, or Space pins the tooltip even though the trigger is a button, and a tap outside dismisses it.',
135
+ },
136
+ {
137
+ guidance: false,
138
+ description:
139
+ 'Hand-compose Icon inside Tooltip for info affordances; the bare Icon is aria-hidden and unfocusable, so keyboard and screen-reader users never see it.',
140
+ },
141
+ {
142
+ guidance: false,
143
+ description:
144
+ 'Use InfoTip for essential information users must see to complete a task; put that text inline instead.',
145
+ },
146
+ ],
147
+ },
148
+ };
149
+
150
+ /** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
151
+ export const docsDense = {
152
+ description:
153
+ 'Inline info-icon help affordance: accessible "i" button trigger pre-wired into a Tooltip.',
154
+ usage: {
155
+ description:
156
+ 'A small "i" button: hover and keyboard focus preview the help; a click, tap, Enter, or Space pins it open. Use next to labels, values, and metrics for permission notes, metric definitions, and field help. Pre-wired accessible trigger: real button, aria-label, Tab-reachable, tooltip on hover AND focus AND tap, Escape dismissal.',
157
+ bestPractices: [
158
+ {
159
+ guidance: true,
160
+ description:
161
+ 'Keep tooltip content concise, plain, and non-interactive; use Popover or HoverCard for links and buttons.',
162
+ },
163
+ {
164
+ guidance: true,
165
+ description:
166
+ 'Override label when "More information" is too generic, e.g. "About this metric".',
167
+ },
168
+ {
169
+ guidance: true,
170
+ description:
171
+ 'Rely on InfoTip rather than a hand-rolled info button on touch: it sets Tooltip triggerBehavior to toggle, so a tap, a click, Enter, or Space pins the tooltip even though the trigger is a button, and a tap outside dismisses it.',
172
+ },
173
+ {
174
+ guidance: false,
175
+ description:
176
+ 'Hand-compose Icon inside Tooltip for info affordances; the bare Icon is aria-hidden and unfocusable.',
177
+ },
178
+ {
179
+ guidance: false,
180
+ description:
181
+ 'Use InfoTip for essential information users must see to complete a task; put that text inline instead.',
182
+ },
183
+ ],
184
+ },
185
+ propDescriptions: {
186
+ content:
187
+ 'Tooltip content. Short, non-interactive text. Mirrors Tooltip content prop.',
188
+ label:
189
+ "Accessible name for the trigger button. Default: the translated 'More information'.",
190
+ size: 'Info icon size (12/16/20/24px). Maps 1:1 to Icon sizes.',
191
+ },
192
+ };
@@ -0,0 +1,186 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file InfoTip.tsx
7
+ * @input Uses React, StyleX, Tooltip, Icon, useComponentTranslator, the shared
8
+ * touch hit area, color/spacing/radius/duration/ease tokens
9
+ * @output Exports InfoTip component, InfoTipProps, InfoTipSize types
10
+ * @position Core implementation; consumed by index.ts, tested by
11
+ * InfoTip.test.tsx; `@astryxdesign/lab` re-exports it, deprecated
12
+ *
13
+ * SYNC: When modified, update these files to stay in sync:
14
+ * - /packages/core/src/InfoTip/InfoTip.doc.mjs (props table, features)
15
+ * - /docs/specs/components/InfoTip/InfoTip.spec.md (contract)
16
+ * - /packages/core/src/InfoTip/InfoTip.test.tsx (tests for new/changed behavior)
17
+ * - /packages/core/src/InfoTip/index.ts (exports if types change)
18
+ */
19
+
20
+ import {useCallback, type ReactNode, type Ref} from 'react';
21
+ import * as stylex from '@stylexjs/stylex';
22
+
23
+ import type {BaseProps} from '../BaseProps';
24
+ import {useMergedRefs} from '../hooks/useMergedRefs';
25
+ import {Icon, type IconSize} from '../Icon/Icon';
26
+ import {Tooltip} from '../Tooltip/Tooltip';
27
+ import {
28
+ registerEnglishFallback,
29
+ useComponentTranslator,
30
+ } from '../i18n/useComponentTranslator';
31
+ import english from '../i18n/generated-english/InfoTip/InfoTip.generated';
32
+ import {
33
+ colorVars,
34
+ durationVars,
35
+ easeVars,
36
+ radiusVars,
37
+ spacingVars,
38
+ } from '../theme/tokens.stylex';
39
+ import {focusOutlineStyles} from '../utils/focusOutline.stylex';
40
+ import {mergeProps} from '../utils/mergeProps';
41
+ import {watchHitArea, writeHitInsets} from '../utils/hitArea';
42
+
43
+ registerEnglishFallback(english);
44
+
45
+ /**
46
+ * Size of the info icon. Maps 1:1 to Icon sizes
47
+ * (xsm: 12px, sm: 16px, md: 20px, lg: 24px).
48
+ */
49
+ export type InfoTipSize = IconSize;
50
+
51
+ export interface InfoTipProps extends Pick<
52
+ BaseProps,
53
+ 'xstyle' | 'className' | 'style'
54
+ > {
55
+ /** Ref forwarded to the info button. */
56
+ ref?: Ref<HTMLButtonElement>;
57
+ /**
58
+ * The help the button reveals. Short, noninteractive text; for links or
59
+ * buttons, use HoverCard.
60
+ */
61
+ content: ReactNode;
62
+ /**
63
+ * Accessible name of the button.
64
+ * @default A translated "More information"
65
+ */
66
+ label?: string;
67
+ /**
68
+ * Size of the info icon.
69
+ * @default 'sm'
70
+ */
71
+ size?: InfoTipSize;
72
+ }
73
+
74
+ const styles = stylex.create({
75
+ trigger: {
76
+ position: 'relative',
77
+ display: 'inline-flex',
78
+ alignItems: 'center',
79
+ justifyContent: 'center',
80
+ verticalAlign: 'middle',
81
+ padding: spacingVars['--spacing-0-5'],
82
+ margin: 0,
83
+ borderStyle: 'none',
84
+ backgroundColor: 'transparent',
85
+ borderRadius: radiusVars['--radius-full'],
86
+ cursor: {
87
+ default: 'pointer',
88
+ ':is(:disabled,[aria-disabled="true"])': 'default',
89
+ },
90
+ color: {
91
+ default: colorVars['--color-icon-secondary'],
92
+ ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
93
+ default: null,
94
+ '@media (hover: hover)': colorVars['--color-icon-primary'],
95
+ },
96
+ },
97
+ transitionProperty: 'color',
98
+ transitionDuration: durationVars['--duration-fast'],
99
+ transitionTimingFunction: easeVars['--ease-standard'],
100
+ },
101
+ // The invisible hit area. Under a coarse pointer, the shared hit area writes
102
+ // how far the button may grow toward 44 px on each side. It never takes a
103
+ // neighbour's tap, and it writes 0 elsewhere. This layer takes taps out to
104
+ // there.
105
+ // SYNC: /packages/core/src/utils/hitArea.ts (HIT_INSET_PROPERTIES)
106
+ hitArea: {
107
+ '::after': {
108
+ content: '""',
109
+ position: 'absolute',
110
+ // Physical sides on purpose: the shared hit area measures each side
111
+ // from the page's rects, left and right included, in any direction.
112
+ inset:
113
+ 'calc(var(--astryx-hit-inset-top, 0px) * -1) calc(var(--astryx-hit-inset-right, 0px) * -1) calc(var(--astryx-hit-inset-bottom, 0px) * -1) calc(var(--astryx-hit-inset-left, 0px) * -1)',
114
+ },
115
+ },
116
+ });
117
+
118
+ /**
119
+ * An info icon that reveals help: a small "i" button. Hover and keyboard
120
+ * focus preview the help. A click, tap, Enter, or Space pins it open until
121
+ * Escape, a second press, a press outside, or focus leaving. Use it next to
122
+ * labels, values, and metrics for permission notes, metric definitions, and
123
+ * field help.
124
+ *
125
+ * InfoTip is Tooltip with `triggerBehavior="toggle"` on a named button: Tooltip
126
+ * opens, pins, announces, and closes the help. The info icon resolves from
127
+ * the icon registry, so themes can replace it.
128
+ *
129
+ * @example
130
+ * ```
131
+ * <InfoTip content="Editors can change this field; viewers cannot." />
132
+ * <InfoTip content="30-day rolling average." label="About this metric" />
133
+ * ```
134
+ */
135
+ export function InfoTip({
136
+ content,
137
+ label,
138
+ size = 'sm',
139
+ ref,
140
+ xstyle,
141
+ className,
142
+ style,
143
+ }: InfoTipProps): ReactNode {
144
+ const t = useComponentTranslator();
145
+ // Under a coarse pointer the button takes taps out toward 44 px. The watch
146
+ // lives as long as the button is attached: the ref's cleanup stops it, and a
147
+ // replaced button starts its own.
148
+ const watchButtonHitArea = useCallback((button: HTMLButtonElement | null) => {
149
+ if (button == null) {
150
+ return;
151
+ }
152
+ return watchHitArea(button, insets => writeHitInsets(button, insets));
153
+ }, []);
154
+ const mergedRef = useMergedRefs(ref, watchButtonHitArea);
155
+
156
+ // No Escape handler of its own. Tooltip's entry in the shared dismissal
157
+ // stack takes Escape, so one press never closes both the help and an
158
+ // enclosing Dialog.
159
+ return (
160
+ <Tooltip
161
+ content={content}
162
+ // The tooltip is the button's only purpose. A click, a tap, Enter, or
163
+ // Space pins it open, and the press stops at the button. So an InfoTip's
164
+ // content is reachable on a phone and from the keyboard alike.
165
+ triggerBehavior="toggle">
166
+ <button
167
+ ref={mergedRef}
168
+ type="button"
169
+ aria-label={label ?? t('@astryx.infoTip.label')}
170
+ {...mergeProps(
171
+ stylex.props(
172
+ focusOutlineStyles.focusVisible,
173
+ styles.trigger,
174
+ styles.hitArea,
175
+ xstyle,
176
+ ),
177
+ className,
178
+ style,
179
+ )}>
180
+ <Icon icon="info" size={size} />
181
+ </button>
182
+ </Tooltip>
183
+ );
184
+ }
185
+
186
+ InfoTip.displayName = 'InfoTip';
@@ -0,0 +1,14 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file InfoTip component barrel export
7
+ * @input InfoTip.tsx
8
+ * @output Exports InfoTip, InfoTipProps, InfoTipSize
9
+ * @position Barrel; consumed by packages/core/src/index.ts and the
10
+ * `@astryxdesign/core/InfoTip` entry
11
+ */
12
+
13
+ export {InfoTip} from './InfoTip';
14
+ export type {InfoTipProps, InfoTipSize} from './InfoTip';
@@ -6,7 +6,7 @@
6
6
  * @file layerClickBoundary.ts
7
7
  * @input React pointer, mouse, touch and click events on a layer root
8
8
  * @output Exports layerClickBoundary, the props every layer content root
9
- * spreads, including the layer-root mark
9
+ * spreads, including the layer-root mark; also stopInReactTree
10
10
  * @position Internal to Layer; used by useLayer's renderers and the Dialog,
11
11
  * Drawer, Lightbox, MobileNav, BottomSheetPanel and ToastViewport roots.
12
12
  * Not exported from the package.
@@ -61,7 +61,7 @@ const returnTrue = () => true;
61
61
  * React's dispatch asks `isPropagationStopped()` before each further
62
62
  * listener; the native event is left alone.
63
63
  */
64
- function stopInReactTree(event: SyntheticEvent): void {
64
+ export function stopInReactTree(event: SyntheticEvent): void {
65
65
  event.isPropagationStopped = returnTrue;
66
66
  }
67
67
 
@@ -0,0 +1,81 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file useBackdropPress.ts
7
+ * @input A modal layer's backdrop dismissal and whether it is allowed now
8
+ * @output Capture-phase pointer handlers and a click handler for the layer's
9
+ * <dialog> root
10
+ * @position Shared backdrop-press rule for Dialog and Drawer
11
+ */
12
+
13
+ import {useCallback, useRef, type PointerEvent, type MouseEvent} from 'react';
14
+
15
+ export interface BackdropPressHandlers {
16
+ onPointerDownCapture: (event: PointerEvent<HTMLElement>) => void;
17
+ onPointerUpCapture: (event: PointerEvent<HTMLElement>) => void;
18
+ onPointerCancelCapture: (event: PointerEvent<HTMLElement>) => void;
19
+ onClick: (event: MouseEvent<HTMLElement>) => void;
20
+ }
21
+
22
+ /**
23
+ * A press on a modal layer's backdrop targets the <dialog> root itself. A
24
+ * click there is also what the browser sends when a press starts on one side
25
+ * of the layer's edge and ends on the other (it goes to the nearest common
26
+ * ancestor), so a backdrop press dismisses only when its pointer-down and its
27
+ * pointer-up both landed on the backdrop. A cancelled pointer ends the press.
28
+ *
29
+ * The pointer handlers run in the capture phase. A nested layer, such as a
30
+ * popover open in the dialog, stops its presses at its own root, so a
31
+ * bubble-phase handler here does not see them.
32
+ */
33
+ export function useBackdropPress(
34
+ onBackdropPress: () => void,
35
+ isEnabled: boolean,
36
+ ): BackdropPressHandlers {
37
+ const startedOnBackdropRef = useRef(false);
38
+ const endedOnBackdropRef = useRef(false);
39
+
40
+ const onPointerDownCapture = useCallback(
41
+ (event: PointerEvent<HTMLElement>) => {
42
+ startedOnBackdropRef.current = event.target === event.currentTarget;
43
+ endedOnBackdropRef.current = false;
44
+ },
45
+ [],
46
+ );
47
+
48
+ const onPointerUpCapture = useCallback((event: PointerEvent<HTMLElement>) => {
49
+ endedOnBackdropRef.current =
50
+ startedOnBackdropRef.current && event.target === event.currentTarget;
51
+ startedOnBackdropRef.current = false;
52
+ }, []);
53
+
54
+ const onPointerCancelCapture = useCallback(() => {
55
+ startedOnBackdropRef.current = false;
56
+ endedOnBackdropRef.current = false;
57
+ }, []);
58
+
59
+ const onClick = useCallback(
60
+ (event: MouseEvent<HTMLElement>) => {
61
+ const pressWasOnBackdrop = endedOnBackdropRef.current;
62
+ startedOnBackdropRef.current = false;
63
+ endedOnBackdropRef.current = false;
64
+ if (
65
+ isEnabled &&
66
+ pressWasOnBackdrop &&
67
+ event.target === event.currentTarget
68
+ ) {
69
+ onBackdropPress();
70
+ }
71
+ },
72
+ [isEnabled, onBackdropPress],
73
+ );
74
+
75
+ return {
76
+ onPointerDownCapture,
77
+ onPointerUpCapture,
78
+ onPointerCancelCapture,
79
+ onClick,
80
+ };
81
+ }