@atlaskit/top-layer 0.1.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 (300) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +151 -0
  3. package/animations/package.json +17 -0
  4. package/arrow/package.json +17 -0
  5. package/create-close-event/package.json +17 -0
  6. package/dialog/package.json +17 -0
  7. package/dialog-scroll-lock/package.json +17 -0
  8. package/dist/cjs/animations/presets.js +199 -0
  9. package/dist/cjs/animations/types.js +5 -0
  10. package/dist/cjs/arrow/index.js +130 -0
  11. package/dist/cjs/arrow/types.js +5 -0
  12. package/dist/cjs/dialog/create-close-event.js +39 -0
  13. package/dist/cjs/dialog/dialog-content.compiled.css +14 -0
  14. package/dist/cjs/dialog/dialog-content.js +144 -0
  15. package/dist/cjs/dialog/index.js +19 -0
  16. package/dist/cjs/dialog/types.js +5 -0
  17. package/dist/cjs/dialog-scroll-lock/index.js +46 -0
  18. package/dist/cjs/entry-points/animations.js +36 -0
  19. package/dist/cjs/entry-points/arrow.js +12 -0
  20. package/dist/cjs/entry-points/create-close-event.js +19 -0
  21. package/dist/cjs/entry-points/dialog-scroll-lock.js +12 -0
  22. package/dist/cjs/entry-points/dialog.js +12 -0
  23. package/dist/cjs/entry-points/focus.js +24 -0
  24. package/dist/cjs/entry-points/placement-map.js +18 -0
  25. package/dist/cjs/entry-points/popover.js +12 -0
  26. package/dist/cjs/entry-points/popup-surface.js +12 -0
  27. package/dist/cjs/entry-points/popup.js +12 -0
  28. package/dist/cjs/entry-points/use-anchor-position.js +12 -0
  29. package/dist/cjs/entry-points/use-arrow-navigation.js +18 -0
  30. package/dist/cjs/entry-points/use-simple-light-dismiss.js +12 -0
  31. package/dist/cjs/focus/focus.js +115 -0
  32. package/dist/cjs/focus/index.js +24 -0
  33. package/dist/cjs/index.js +8 -0
  34. package/dist/cjs/internal/anchor-positioning-fallback.js +154 -0
  35. package/dist/cjs/internal/combine.js +29 -0
  36. package/dist/cjs/internal/ensure-preset-styles.js +34 -0
  37. package/dist/cjs/internal/reduced-motion.js +27 -0
  38. package/dist/cjs/internal/resolve-placement.js +24 -0
  39. package/dist/cjs/internal/role-types.js +66 -0
  40. package/dist/cjs/internal/set-style.js +42 -0
  41. package/dist/cjs/internal/slot.js +65 -0
  42. package/dist/cjs/internal/use-anchor-positioning.js +336 -0
  43. package/dist/cjs/internal/use-animated-visibility.js +169 -0
  44. package/dist/cjs/internal/use-animation-preset.js +24 -0
  45. package/dist/cjs/internal/use-focus-wrap.js +94 -0
  46. package/dist/cjs/internal/use-initial-focus.js +112 -0
  47. package/dist/cjs/internal/use-preset-styles.js +27 -0
  48. package/dist/cjs/placement-map/index.js +147 -0
  49. package/dist/cjs/popover/create-close-event.js +44 -0
  50. package/dist/cjs/popover/index.js +19 -0
  51. package/dist/cjs/popover/popover.compiled.css +13 -0
  52. package/dist/cjs/popover/popover.js +251 -0
  53. package/dist/cjs/popover/types.js +5 -0
  54. package/dist/cjs/popup/index.js +37 -0
  55. package/dist/cjs/popup/popup-content.js +201 -0
  56. package/dist/cjs/popup/popup-context.js +42 -0
  57. package/dist/cjs/popup/popup-surface.compiled.css +5 -0
  58. package/dist/cjs/popup/popup-surface.js +30 -0
  59. package/dist/cjs/popup/popup-trigger-function.js +74 -0
  60. package/dist/cjs/popup/popup-trigger.js +82 -0
  61. package/dist/cjs/popup/popup.js +70 -0
  62. package/dist/cjs/popup/types.js +5 -0
  63. package/dist/cjs/use-arrow-navigation/index.js +18 -0
  64. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +245 -0
  65. package/dist/cjs/use-simple-light-dismiss/index.js +84 -0
  66. package/dist/es2019/animations/presets.js +375 -0
  67. package/dist/es2019/animations/types.js +1 -0
  68. package/dist/es2019/arrow/index.js +249 -0
  69. package/dist/es2019/arrow/types.js +1 -0
  70. package/dist/es2019/dialog/create-close-event.js +34 -0
  71. package/dist/es2019/dialog/dialog-content.compiled.css +14 -0
  72. package/dist/es2019/dialog/dialog-content.js +138 -0
  73. package/dist/es2019/dialog/index.js +2 -0
  74. package/dist/es2019/dialog/types.js +1 -0
  75. package/dist/es2019/dialog-scroll-lock/index.js +41 -0
  76. package/dist/es2019/entry-points/animations.js +1 -0
  77. package/dist/es2019/entry-points/arrow.js +1 -0
  78. package/dist/es2019/entry-points/create-close-event.js +2 -0
  79. package/dist/es2019/entry-points/dialog-scroll-lock.js +1 -0
  80. package/dist/es2019/entry-points/dialog.js +1 -0
  81. package/dist/es2019/entry-points/focus.js +1 -0
  82. package/dist/es2019/entry-points/placement-map.js +1 -0
  83. package/dist/es2019/entry-points/popover.js +1 -0
  84. package/dist/es2019/entry-points/popup-surface.js +1 -0
  85. package/dist/es2019/entry-points/popup.js +1 -0
  86. package/dist/es2019/entry-points/use-anchor-position.js +1 -0
  87. package/dist/es2019/entry-points/use-arrow-navigation.js +1 -0
  88. package/dist/es2019/entry-points/use-simple-light-dismiss.js +1 -0
  89. package/dist/es2019/focus/focus.js +107 -0
  90. package/dist/es2019/focus/index.js +1 -0
  91. package/dist/es2019/index.js +7 -0
  92. package/dist/es2019/internal/anchor-positioning-fallback.js +153 -0
  93. package/dist/es2019/internal/combine.js +18 -0
  94. package/dist/es2019/internal/ensure-preset-styles.js +29 -0
  95. package/dist/es2019/internal/reduced-motion.js +21 -0
  96. package/dist/es2019/internal/resolve-placement.js +19 -0
  97. package/dist/es2019/internal/role-types.js +61 -0
  98. package/dist/es2019/internal/set-style.js +39 -0
  99. package/dist/es2019/internal/slot.js +57 -0
  100. package/dist/es2019/internal/use-anchor-positioning.js +330 -0
  101. package/dist/es2019/internal/use-animated-visibility.js +159 -0
  102. package/dist/es2019/internal/use-animation-preset.js +18 -0
  103. package/dist/es2019/internal/use-focus-wrap.js +90 -0
  104. package/dist/es2019/internal/use-initial-focus.js +109 -0
  105. package/dist/es2019/internal/use-preset-styles.js +22 -0
  106. package/dist/es2019/placement-map/index.js +142 -0
  107. package/dist/es2019/popover/create-close-event.js +39 -0
  108. package/dist/es2019/popover/index.js +2 -0
  109. package/dist/es2019/popover/popover.compiled.css +13 -0
  110. package/dist/es2019/popover/popover.js +240 -0
  111. package/dist/es2019/popover/types.js +1 -0
  112. package/dist/es2019/popup/index.js +33 -0
  113. package/dist/es2019/popup/popup-content.js +192 -0
  114. package/dist/es2019/popup/popup-context.js +34 -0
  115. package/dist/es2019/popup/popup-surface.compiled.css +5 -0
  116. package/dist/es2019/popup/popup-surface.js +24 -0
  117. package/dist/es2019/popup/popup-trigger-function.js +69 -0
  118. package/dist/es2019/popup/popup-trigger.js +76 -0
  119. package/dist/es2019/popup/popup.js +56 -0
  120. package/dist/es2019/popup/types.js +1 -0
  121. package/dist/es2019/use-arrow-navigation/index.js +1 -0
  122. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +238 -0
  123. package/dist/es2019/use-simple-light-dismiss/index.js +79 -0
  124. package/dist/esm/animations/presets.js +190 -0
  125. package/dist/esm/animations/types.js +1 -0
  126. package/dist/esm/arrow/index.js +123 -0
  127. package/dist/esm/arrow/types.js +1 -0
  128. package/dist/esm/dialog/create-close-event.js +33 -0
  129. package/dist/esm/dialog/dialog-content.compiled.css +14 -0
  130. package/dist/esm/dialog/dialog-content.js +135 -0
  131. package/dist/esm/dialog/index.js +2 -0
  132. package/dist/esm/dialog/types.js +1 -0
  133. package/dist/esm/dialog-scroll-lock/index.js +41 -0
  134. package/dist/esm/entry-points/animations.js +1 -0
  135. package/dist/esm/entry-points/arrow.js +1 -0
  136. package/dist/esm/entry-points/create-close-event.js +2 -0
  137. package/dist/esm/entry-points/dialog-scroll-lock.js +1 -0
  138. package/dist/esm/entry-points/dialog.js +1 -0
  139. package/dist/esm/entry-points/focus.js +1 -0
  140. package/dist/esm/entry-points/placement-map.js +1 -0
  141. package/dist/esm/entry-points/popover.js +1 -0
  142. package/dist/esm/entry-points/popup-surface.js +1 -0
  143. package/dist/esm/entry-points/popup.js +1 -0
  144. package/dist/esm/entry-points/use-anchor-position.js +1 -0
  145. package/dist/esm/entry-points/use-arrow-navigation.js +1 -0
  146. package/dist/esm/entry-points/use-simple-light-dismiss.js +1 -0
  147. package/dist/esm/focus/focus.js +107 -0
  148. package/dist/esm/focus/index.js +1 -0
  149. package/dist/esm/index.js +7 -0
  150. package/dist/esm/internal/anchor-positioning-fallback.js +147 -0
  151. package/dist/esm/internal/combine.js +23 -0
  152. package/dist/esm/internal/ensure-preset-styles.js +28 -0
  153. package/dist/esm/internal/reduced-motion.js +21 -0
  154. package/dist/esm/internal/resolve-placement.js +18 -0
  155. package/dist/esm/internal/role-types.js +60 -0
  156. package/dist/esm/internal/set-style.js +36 -0
  157. package/dist/esm/internal/slot.js +59 -0
  158. package/dist/esm/internal/use-anchor-positioning.js +323 -0
  159. package/dist/esm/internal/use-animated-visibility.js +162 -0
  160. package/dist/esm/internal/use-animation-preset.js +18 -0
  161. package/dist/esm/internal/use-focus-wrap.js +89 -0
  162. package/dist/esm/internal/use-initial-focus.js +107 -0
  163. package/dist/esm/internal/use-preset-styles.js +21 -0
  164. package/dist/esm/placement-map/index.js +141 -0
  165. package/dist/esm/popover/create-close-event.js +38 -0
  166. package/dist/esm/popover/index.js +2 -0
  167. package/dist/esm/popover/popover.compiled.css +13 -0
  168. package/dist/esm/popover/popover.js +242 -0
  169. package/dist/esm/popover/types.js +1 -0
  170. package/dist/esm/popup/index.js +33 -0
  171. package/dist/esm/popup/popup-content.js +192 -0
  172. package/dist/esm/popup/popup-context.js +34 -0
  173. package/dist/esm/popup/popup-surface.compiled.css +5 -0
  174. package/dist/esm/popup/popup-surface.js +23 -0
  175. package/dist/esm/popup/popup-trigger-function.js +69 -0
  176. package/dist/esm/popup/popup-trigger.js +74 -0
  177. package/dist/esm/popup/popup.js +61 -0
  178. package/dist/esm/popup/types.js +1 -0
  179. package/dist/esm/use-arrow-navigation/index.js +1 -0
  180. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +238 -0
  181. package/dist/esm/use-simple-light-dismiss/index.js +78 -0
  182. package/dist/types/animations/presets.d.ts +94 -0
  183. package/dist/types/animations/types.d.ts +42 -0
  184. package/dist/types/arrow/index.d.ts +24 -0
  185. package/dist/types/arrow/types.d.ts +29 -0
  186. package/dist/types/dialog/create-close-event.d.ts +24 -0
  187. package/dist/types/dialog/dialog-content.d.ts +20 -0
  188. package/dist/types/dialog/index.d.ts +3 -0
  189. package/dist/types/dialog/types.d.ts +92 -0
  190. package/dist/types/dialog-scroll-lock/index.d.ts +24 -0
  191. package/dist/types/entry-points/animations.d.ts +2 -0
  192. package/dist/types/entry-points/arrow.d.ts +2 -0
  193. package/dist/types/entry-points/create-close-event.d.ts +4 -0
  194. package/dist/types/entry-points/dialog-scroll-lock.d.ts +1 -0
  195. package/dist/types/entry-points/dialog.d.ts +2 -0
  196. package/dist/types/entry-points/focus.d.ts +2 -0
  197. package/dist/types/entry-points/placement-map.d.ts +2 -0
  198. package/dist/types/entry-points/popover.d.ts +2 -0
  199. package/dist/types/entry-points/popup-surface.d.ts +2 -0
  200. package/dist/types/entry-points/popup.d.ts +2 -0
  201. package/dist/types/entry-points/use-anchor-position.d.ts +1 -0
  202. package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -0
  203. package/dist/types/entry-points/use-simple-light-dismiss.d.ts +2 -0
  204. package/dist/types/focus/focus.d.ts +42 -0
  205. package/dist/types/focus/index.d.ts +2 -0
  206. package/dist/types/index.d.ts +0 -0
  207. package/dist/types/internal/anchor-positioning-fallback.d.ts +24 -0
  208. package/dist/types/internal/combine.d.ts +14 -0
  209. package/dist/types/internal/ensure-preset-styles.d.ts +6 -0
  210. package/dist/types/internal/reduced-motion.d.ts +14 -0
  211. package/dist/types/internal/resolve-placement.d.ts +16 -0
  212. package/dist/types/internal/role-types.d.ts +62 -0
  213. package/dist/types/internal/set-style.d.ts +28 -0
  214. package/dist/types/internal/slot.d.ts +29 -0
  215. package/dist/types/internal/use-anchor-positioning.d.ts +95 -0
  216. package/dist/types/internal/use-animated-visibility.d.ts +74 -0
  217. package/dist/types/internal/use-animation-preset.d.ts +11 -0
  218. package/dist/types/internal/use-focus-wrap.d.ts +20 -0
  219. package/dist/types/internal/use-initial-focus.d.ts +21 -0
  220. package/dist/types/internal/use-preset-styles.d.ts +15 -0
  221. package/dist/types/placement-map/index.d.ts +55 -0
  222. package/dist/types/popover/create-close-event.d.ts +26 -0
  223. package/dist/types/popover/index.d.ts +3 -0
  224. package/dist/types/popover/popover.d.ts +22 -0
  225. package/dist/types/popover/types.d.ts +153 -0
  226. package/dist/types/popup/index.d.ts +34 -0
  227. package/dist/types/popup/popup-content.d.ts +14 -0
  228. package/dist/types/popup/popup-context.d.ts +96 -0
  229. package/dist/types/popup/popup-surface.d.ts +16 -0
  230. package/dist/types/popup/popup-trigger-function.d.ts +108 -0
  231. package/dist/types/popup/popup-trigger.d.ts +23 -0
  232. package/dist/types/popup/popup.d.ts +14 -0
  233. package/dist/types/popup/types.d.ts +289 -0
  234. package/dist/types/use-arrow-navigation/index.d.ts +2 -0
  235. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +136 -0
  236. package/dist/types/use-simple-light-dismiss/index.d.ts +45 -0
  237. package/dist/types-ts4.5/animations/presets.d.ts +94 -0
  238. package/dist/types-ts4.5/animations/types.d.ts +42 -0
  239. package/dist/types-ts4.5/arrow/index.d.ts +24 -0
  240. package/dist/types-ts4.5/arrow/types.d.ts +29 -0
  241. package/dist/types-ts4.5/dialog/create-close-event.d.ts +24 -0
  242. package/dist/types-ts4.5/dialog/dialog-content.d.ts +20 -0
  243. package/dist/types-ts4.5/dialog/index.d.ts +3 -0
  244. package/dist/types-ts4.5/dialog/types.d.ts +92 -0
  245. package/dist/types-ts4.5/dialog-scroll-lock/index.d.ts +24 -0
  246. package/dist/types-ts4.5/entry-points/animations.d.ts +2 -0
  247. package/dist/types-ts4.5/entry-points/arrow.d.ts +2 -0
  248. package/dist/types-ts4.5/entry-points/create-close-event.d.ts +4 -0
  249. package/dist/types-ts4.5/entry-points/dialog-scroll-lock.d.ts +1 -0
  250. package/dist/types-ts4.5/entry-points/dialog.d.ts +2 -0
  251. package/dist/types-ts4.5/entry-points/focus.d.ts +2 -0
  252. package/dist/types-ts4.5/entry-points/placement-map.d.ts +2 -0
  253. package/dist/types-ts4.5/entry-points/popover.d.ts +2 -0
  254. package/dist/types-ts4.5/entry-points/popup-surface.d.ts +2 -0
  255. package/dist/types-ts4.5/entry-points/popup.d.ts +2 -0
  256. package/dist/types-ts4.5/entry-points/use-anchor-position.d.ts +1 -0
  257. package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -0
  258. package/dist/types-ts4.5/entry-points/use-simple-light-dismiss.d.ts +2 -0
  259. package/dist/types-ts4.5/focus/focus.d.ts +42 -0
  260. package/dist/types-ts4.5/focus/index.d.ts +2 -0
  261. package/dist/types-ts4.5/index.d.ts +0 -0
  262. package/dist/types-ts4.5/internal/anchor-positioning-fallback.d.ts +24 -0
  263. package/dist/types-ts4.5/internal/combine.d.ts +14 -0
  264. package/dist/types-ts4.5/internal/ensure-preset-styles.d.ts +6 -0
  265. package/dist/types-ts4.5/internal/reduced-motion.d.ts +14 -0
  266. package/dist/types-ts4.5/internal/resolve-placement.d.ts +16 -0
  267. package/dist/types-ts4.5/internal/role-types.d.ts +62 -0
  268. package/dist/types-ts4.5/internal/set-style.d.ts +28 -0
  269. package/dist/types-ts4.5/internal/slot.d.ts +29 -0
  270. package/dist/types-ts4.5/internal/use-anchor-positioning.d.ts +95 -0
  271. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +74 -0
  272. package/dist/types-ts4.5/internal/use-animation-preset.d.ts +11 -0
  273. package/dist/types-ts4.5/internal/use-focus-wrap.d.ts +20 -0
  274. package/dist/types-ts4.5/internal/use-initial-focus.d.ts +21 -0
  275. package/dist/types-ts4.5/internal/use-preset-styles.d.ts +15 -0
  276. package/dist/types-ts4.5/placement-map/index.d.ts +55 -0
  277. package/dist/types-ts4.5/popover/create-close-event.d.ts +26 -0
  278. package/dist/types-ts4.5/popover/index.d.ts +3 -0
  279. package/dist/types-ts4.5/popover/popover.d.ts +22 -0
  280. package/dist/types-ts4.5/popover/types.d.ts +153 -0
  281. package/dist/types-ts4.5/popup/index.d.ts +34 -0
  282. package/dist/types-ts4.5/popup/popup-content.d.ts +14 -0
  283. package/dist/types-ts4.5/popup/popup-context.d.ts +96 -0
  284. package/dist/types-ts4.5/popup/popup-surface.d.ts +16 -0
  285. package/dist/types-ts4.5/popup/popup-trigger-function.d.ts +108 -0
  286. package/dist/types-ts4.5/popup/popup-trigger.d.ts +23 -0
  287. package/dist/types-ts4.5/popup/popup.d.ts +14 -0
  288. package/dist/types-ts4.5/popup/types.d.ts +289 -0
  289. package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -0
  290. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +136 -0
  291. package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +45 -0
  292. package/focus/package.json +17 -0
  293. package/package.json +95 -0
  294. package/placement-map/package.json +17 -0
  295. package/popover/package.json +17 -0
  296. package/popup/package.json +17 -0
  297. package/popup-surface/package.json +17 -0
  298. package/use-anchor-position/package.json +17 -0
  299. package/use-arrow-navigation/package.json +17 -0
  300. package/use-simple-light-dismiss/package.json +17 -0
@@ -0,0 +1,192 @@
1
+ /* popup-content.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { forwardRef, useCallback, useLayoutEffect, useRef } from 'react';
5
+ import mergeRefs from '@atlaskit/ds-lib/merge-refs';
6
+ import { roleToAriaHasPopup } from '../internal/role-types';
7
+ import { useAnchorPosition } from '../internal/use-anchor-positioning';
8
+ import { usePresetStyles } from '../internal/use-preset-styles';
9
+ import { Popover } from '../popover/popover';
10
+ import { useMaybePopupContext } from './popup-context';
11
+ /**
12
+ * Thin context wrapper that composes `Popover` + `useAnchorPosition`.
13
+ *
14
+ * Used inside the `<Popup>` compound — reads triggerRef, placement, isOpen,
15
+ * and onClose from context. For standalone usage (tooltip, spotlight, flag),
16
+ * use `Popover` + `useAnchorPosition` directly.
17
+ */
18
+ export const PopupContent = /*#__PURE__*/forwardRef(function PopupContent({
19
+ children,
20
+ role,
21
+ label,
22
+ labelledBy,
23
+ animate,
24
+ arrow,
25
+ mode,
26
+ width = 'content',
27
+ isOpen: isOpenProp,
28
+ triggerRef: triggerRefProp,
29
+ placement: placementProp,
30
+ onClose: onCloseProp,
31
+ testId: testIdProp,
32
+ offset: offsetProp,
33
+ forceFallbackPositioning: forceFallbackPositioningProp
34
+ }, ref) {
35
+ var _ref, _ref2, _ctx$popoverRef;
36
+ // When inside <Popup>, context provides defaults. Props always win.
37
+ const ctx = useMaybePopupContext();
38
+ const triggerRef = triggerRefProp !== null && triggerRefProp !== void 0 ? triggerRefProp : ctx === null || ctx === void 0 ? void 0 : ctx.triggerRef;
39
+ const placement = (_ref = placementProp !== null && placementProp !== void 0 ? placementProp : ctx === null || ctx === void 0 ? void 0 : ctx.placement) !== null && _ref !== void 0 ? _ref : {};
40
+ const onClose = onCloseProp !== null && onCloseProp !== void 0 ? onCloseProp : ctx === null || ctx === void 0 ? void 0 : ctx.onClose;
41
+ const testId = testIdProp !== null && testIdProp !== void 0 ? testIdProp : ctx === null || ctx === void 0 ? void 0 : ctx.testId;
42
+ const forceFallbackPositioning = forceFallbackPositioningProp !== null && forceFallbackPositioningProp !== void 0 ? forceFallbackPositioningProp : ctx === null || ctx === void 0 ? void 0 : ctx.forceFallbackPositioning;
43
+
44
+ // Resolve isOpen: prop wins, then context.
45
+ // Inside the <Popup> compound, ctx.isOpen tracks the browser's toggle state.
46
+ const isOpen = (_ref2 = isOpenProp !== null && isOpenProp !== void 0 ? isOpenProp : ctx === null || ctx === void 0 ? void 0 : ctx.isOpen) !== null && _ref2 !== void 0 ? _ref2 : false;
47
+
48
+ // Combine internal state sync with consumer's onOpenChange callback.
49
+ // The Popup compound needs setIsOpen to keep aria-expanded on the trigger
50
+ // in sync, and the consumer may also want to respond to open/close events
51
+ // (e.g. for focus management).
52
+ const setIsOpen = ctx === null || ctx === void 0 ? void 0 : ctx.setIsOpen;
53
+ const consumerOnOpenChange = ctx === null || ctx === void 0 ? void 0 : ctx.onOpenChange;
54
+ // Note: onOpenChange composition is handled by handleOpenChange below,
55
+ // which also adds nested-popover focus restoration.
56
+
57
+ // ── Sync aria-haspopup on the trigger with the content's role ──
58
+ const setAriaHasPopup = ctx === null || ctx === void 0 ? void 0 : ctx.setAriaHasPopup;
59
+ useLayoutEffect(() => {
60
+ setAriaHasPopup === null || setAriaHasPopup === void 0 ? void 0 : setAriaHasPopup(roleToAriaHasPopup({
61
+ role
62
+ }));
63
+ }, [role, setAriaHasPopup]);
64
+
65
+ // ── Focus restoration ──
66
+ // The native Popover API handles focus restoration automatically for
67
+ // popover="auto" and popover="hint":
68
+ // - Escape → restores focus to the previously focused element (the trigger)
69
+ // - Click-outside → does NOT restore (correct: the user clicked deliberately)
70
+ // - hidePopover() → restores focus to the previously focused element
71
+ //
72
+ // However, for **nested** popover="auto" popovers, the browser only captures
73
+ // `previouslyFocusedElement` for the outermost popover in the auto stack.
74
+ // Inner popovers have `shouldRestoreFocus=false` per the spec, so the browser
75
+ // does not restore focus when they close.
76
+ //
77
+ // To handle this, we listen for the close transition via `onOpenChange` and
78
+ // restore focus to the trigger if the browser didn't. This runs after the
79
+ // browser's native restoration (which happens synchronously during hidePopover),
80
+ // so it only takes effect when the browser skipped restoration (nested case).
81
+ //
82
+ // See: notes/architecture/focus-restoration.md
83
+ const handleOpenChange = useCallback(args => {
84
+ // Sync compound state
85
+ setIsOpen === null || setIsOpen === void 0 ? void 0 : setIsOpen(args.isOpen);
86
+ consumerOnOpenChange === null || consumerOnOpenChange === void 0 ? void 0 : consumerOnOpenChange(args);
87
+
88
+ // ── Nested popover focus restoration fallback ──
89
+ // The browser only captures `previouslyFocusedElement` for the
90
+ // outermost popover="auto" in the stack. Inner (nested) popovers
91
+ // have shouldRestoreFocus=false, so the browser won't restore
92
+ // focus when they close.
93
+ //
94
+ // We detect this case by checking if focus is still inside the
95
+ // closing popover element. If it is, the browser didn't restore,
96
+ // and we need to move focus to the trigger ourselves.
97
+ //
98
+ // This does NOT fire for:
99
+ // - Outermost popovers (browser already restored to trigger)
100
+ // - Click-outside (focus is on the clicked element, not in popover)
101
+ if (!args.isOpen) {
102
+ const trigger = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current;
103
+ const focusStillInPopover = trigger && args.element.contains(document.activeElement);
104
+ if (focusStillInPopover) {
105
+ const shouldRestore = role === 'dialog' || role === 'alertdialog' || role === 'menu' || role === 'listbox';
106
+ if (shouldRestore) {
107
+ trigger.focus({
108
+ preventScroll: true
109
+ });
110
+ }
111
+ }
112
+ }
113
+ }, [setIsOpen, consumerOnOpenChange, triggerRef, role]);
114
+
115
+ // ── Anchor positioning ──
116
+ // Compose useAnchorPosition with Popover. The hook positions the popover
117
+ // relative to the trigger element via CSS Anchor Positioning (with JS fallback).
118
+ // Use ctx.popoverRef when inside the compound (so the trigger can also
119
+ // reach the same DOM element for togglePopover). Otherwise use a local ref.
120
+ const localRef = useRef(null);
121
+ const popoverRef = (_ctx$popoverRef = ctx === null || ctx === void 0 ? void 0 : ctx.popoverRef) !== null && _ctx$popoverRef !== void 0 ? _ctx$popoverRef : localRef;
122
+ const arrowPreset = usePresetStyles({
123
+ preset: arrow
124
+ });
125
+ useAnchorPosition({
126
+ anchorRef: triggerRef !== null && triggerRef !== void 0 ? triggerRef : {
127
+ current: null
128
+ },
129
+ popoverRef,
130
+ placement,
131
+ offset: offsetProp,
132
+ forceFallbackPositioning,
133
+ arrow: arrowPreset !== null && arrowPreset !== void 0 ? arrowPreset : undefined
134
+ });
135
+
136
+ // ── Width: match trigger ──
137
+ // When width="trigger" or width="min-trigger", size the popover relative
138
+ // to the trigger element. Uses CSS `anchor-size(width)` when supported,
139
+ // falling back to a one-off measurement of the trigger's offsetWidth.
140
+ useLayoutEffect(() => {
141
+ if (width === 'content') {
142
+ return;
143
+ }
144
+ const node = popoverRef.current;
145
+ if (!node) {
146
+ return;
147
+ }
148
+ const cssProperty = width === 'trigger' ? 'width' : 'min-width';
149
+ const anchorValue = 'anchor-size(width)';
150
+
151
+ // Feature-detect `anchor-size()` specifically (not just `anchor-name`)
152
+ // so the JS fallback fires correctly in browsers that support anchor
153
+ // positioning but not anchor sizing.
154
+ const supportsAnchorSize = typeof CSS !== 'undefined' && typeof CSS.supports === 'function' && CSS.supports('width', 'anchor-size(width)');
155
+ if (supportsAnchorSize) {
156
+ node.style.setProperty(cssProperty, anchorValue);
157
+ } else {
158
+ // JS fallback: one-off read of the trigger's width.
159
+ const trigger = triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.current;
160
+ if (trigger) {
161
+ node.style.setProperty(cssProperty, `${trigger.offsetWidth}px`);
162
+ }
163
+ }
164
+ return () => {
165
+ node.style.removeProperty(cssProperty);
166
+ };
167
+ }, [width, popoverRef, triggerRef]);
168
+
169
+ // Merge: the popoverRef (shared with trigger + positioning) and the forwarded ref.
170
+ const combinedRef = mergeRefs([popoverRef, ref]);
171
+
172
+ // TPopupContentProps already validates the discriminated union (role + label,
173
+ // mode + onClose) at its API boundary. Popover accepts TPopoverInternalProps
174
+ // internally so individual prop forwarding doesn't need to re-prove the union.
175
+ const popoverProps = {
176
+ isOpen,
177
+ animate,
178
+ placement,
179
+ mode,
180
+ role,
181
+ label,
182
+ labelledBy,
183
+ onClose: onClose !== null && onClose !== void 0 ? onClose : undefined,
184
+ onOpenChange: handleOpenChange,
185
+ testId,
186
+ children,
187
+ id: ctx === null || ctx === void 0 ? void 0 : ctx.popoverId
188
+ };
189
+ return /*#__PURE__*/React.createElement(Popover, _extends({
190
+ ref: combinedRef
191
+ }, popoverProps));
192
+ });
@@ -0,0 +1,34 @@
1
+ import { createContext, useContext } from 'react';
2
+ const PopupContext = /*#__PURE__*/createContext(null);
3
+
4
+ /**
5
+ * __Popup provider__
6
+ *
7
+ * Provides shared popup state (placement, popoverId, triggerRef,
8
+ * isOpen, onClose) to compound child components such as `Popup.Trigger` and
9
+ * `Popup.Content`.
10
+ */
11
+ export const PopupProvider = PopupContext.Provider;
12
+
13
+ /**
14
+ * Returns the nearest `Popup` context value.
15
+ *
16
+ * Throws if called outside of a `<Popup>` compound component.
17
+ */
18
+ export function usePopupContext() {
19
+ const ctx = useContext(PopupContext);
20
+ if (ctx === null) {
21
+ throw new Error('@atlaskit/top-layer: Popup compound components must be used within <Popup>.');
22
+ }
23
+ return ctx;
24
+ }
25
+
26
+ /**
27
+ * Returns the popup context if available, or `null` when used outside `<Popup>`.
28
+ *
29
+ * Used by `PopupContent` to support standalone usage (e.g. tooltip)
30
+ * where values are passed as props instead of coming from a compound component.
31
+ */
32
+ export function useMaybePopupContext() {
33
+ return useContext(PopupContext);
34
+ }
@@ -0,0 +1,5 @@
1
+
2
+ ._2rkofajl{border-radius:var(--ds-radius-small,3px)}._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
3
+ ._18m91wug{overflow-y:auto}
4
+ ._1reo1wug{overflow-x:auto}
5
+ ._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
@@ -0,0 +1,24 @@
1
+ /* popup-surface.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./popup-surface.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React from 'react';
5
+ const styles = {
6
+ root: "_2rkofajl _1reo1wug _18m91wug _bfhk1bhr _16qs130s"
7
+ };
8
+
9
+ /**
10
+ * Optional styled wrapper for popup content.
11
+ *
12
+ * Adds default visual styling (background, border-radius, box-shadow)
13
+ * using design tokens. Consumers who want fully custom styling
14
+ * should use `Popup.Content` without wrapping in `PopupSurface`.
15
+ *
16
+ * Exposed as `Popup.Surface` on the compound component.
17
+ */
18
+ export function PopupSurface({
19
+ children
20
+ }) {
21
+ return /*#__PURE__*/React.createElement("div", {
22
+ className: ax([styles.root])
23
+ }, children);
24
+ }
@@ -0,0 +1,69 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { usePopupContext } from './popup-context';
3
+
4
+ /**
5
+ * Props passed to the `TriggerFunction` render-prop child.
6
+ */
7
+
8
+ /**
9
+ * Render-prop alternative to `Popup.Trigger`.
10
+ *
11
+ * Use when you need full control over the trigger element — for example,
12
+ * to compose your own trigger with custom event handlers, wrap a third-party
13
+ * component, or build a trigger from multiple elements.
14
+ *
15
+ * `Popup.Trigger` uses `cloneElement` internally, which limits composability.
16
+ * `Popup.TriggerFunction` hands you the raw props and lets you wire them up.
17
+ *
18
+ * **Note:** This sub-component uses a render-prop pattern and is not
19
+ * compatible with React Server Components (RSC). It must be used inside
20
+ * a client component boundary (`'use client'`).
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * <Popup placement={{ edge: 'end' }} onClose={handleClose}>
25
+ * <Popup.TriggerFunction>
26
+ * {({ ref, toggle, ariaAttributes }) => (
27
+ * <button ref={ref} onClick={toggle} {...ariaAttributes}>
28
+ * Open
29
+ * </button>
30
+ * )}
31
+ * </Popup.TriggerFunction>
32
+ * <Popup.Content role="dialog" label="My popup">
33
+ * Content
34
+ * </Popup.Content>
35
+ * </Popup>
36
+ * ```
37
+ */
38
+ export function PopupTriggerFunction({
39
+ children
40
+ }) {
41
+ const {
42
+ triggerRef,
43
+ popoverRef,
44
+ popoverId,
45
+ isOpen,
46
+ ariaHasPopup
47
+ } = usePopupContext();
48
+ const ref = useCallback(node => {
49
+ triggerRef.current = node;
50
+ }, [triggerRef]);
51
+ const toggle = useCallback(() => {
52
+ const popoverEl = popoverRef.current;
53
+ if (popoverEl) {
54
+ popoverEl.togglePopover();
55
+ }
56
+ }, [popoverRef]);
57
+ const ariaAttributes = useMemo(() => ({
58
+ 'aria-expanded': isOpen,
59
+ 'aria-controls': popoverId,
60
+ 'aria-haspopup': ariaHasPopup
61
+ }), [isOpen, popoverId, ariaHasPopup]);
62
+ return children({
63
+ ref,
64
+ isOpen,
65
+ popoverId,
66
+ toggle,
67
+ ariaAttributes
68
+ });
69
+ }
@@ -0,0 +1,76 @@
1
+ import React, { isValidElement, useCallback } from 'react';
2
+ import { Slot } from '../internal/slot';
3
+ import { usePopupContext } from './popup-context';
4
+ /**
5
+ * Wraps the trigger element. Attaches aria attributes and handles
6
+ * click to toggle the popover. Sets the anchor-name on the trigger
7
+ * for CSS Anchor Positioning.
8
+ *
9
+ * `aria-haspopup` is derived from the content's role via context
10
+ * (set by `Popup.Content`). This ensures the trigger always matches
11
+ * the content's semantic role without the consumer specifying it
12
+ * in two places.
13
+ *
14
+ * **Limitation:** Uses `cloneElement` internally (via `Slot`), which is
15
+ * incompatible with Compiled's `css` prop on the direct child element.
16
+ * The `@jsx jsx` pragma transforms the child before `cloneElement` can
17
+ * inject `onClick` and `ref` onto the DOM node, preventing the popover
18
+ * from opening.
19
+ *
20
+ * If you need Compiled `css` on the trigger, use `Popup.TriggerFunction`
21
+ * instead — it hands you raw props via a render-prop and avoids
22
+ * `cloneElement` entirely.
23
+ */
24
+ export function PopupTrigger({
25
+ children
26
+ }) {
27
+ const {
28
+ triggerRef,
29
+ popoverRef,
30
+ popoverId,
31
+ isOpen,
32
+ ariaHasPopup
33
+ } = usePopupContext();
34
+ const childOnClick = /*#__PURE__*/isValidElement(children) ? children.props.onClick : undefined;
35
+
36
+ // Use a ref to track the latest isOpen value so the click handler
37
+ // doesn't need isOpen in its dependency array (which would recreate
38
+ // the handler on every open/close, breaking cloneElement identity).
39
+ const isOpenRef = React.useRef(isOpen);
40
+ isOpenRef.current = isOpen;
41
+ const handleClick = useCallback(event => {
42
+ const popoverEl = popoverRef.current;
43
+ if (popoverEl) {
44
+ // For popover="auto", clicking the trigger (which is outside
45
+ // the popover) can cause the browser's built-in light-dismiss
46
+ // to fire before our click handler runs. This means by the time
47
+ // we get here, the DOM may have already closed the popover.
48
+ //
49
+ // We use React's `isOpen` state (via ref) rather than the DOM
50
+ // state to determine intent:
51
+ // - If React thinks it was open → the user wants to close.
52
+ // The browser already did this via light-dismiss, so do nothing.
53
+ // - If React thinks it was closed → the user wants to open.
54
+ // Call showPopover().
55
+ if (!isOpenRef.current) {
56
+ try {
57
+ popoverEl.showPopover();
58
+ } catch {
59
+ // Already showing — safe to ignore.
60
+ }
61
+ }
62
+ // When isOpenRef.current is true, the browser's light-dismiss
63
+ // already closed the popover and fired the toggle event, which
64
+ // will update React state via handleToggle → setIsOpen(false).
65
+ // No action needed here.
66
+ }
67
+ childOnClick === null || childOnClick === void 0 ? void 0 : childOnClick(event);
68
+ }, [popoverRef, childOnClick]);
69
+ return /*#__PURE__*/React.createElement(Slot, {
70
+ ref: triggerRef,
71
+ onClick: handleClick,
72
+ "aria-expanded": isOpen,
73
+ "aria-controls": popoverId,
74
+ "aria-haspopup": ariaHasPopup
75
+ }, children);
76
+ }
@@ -0,0 +1,56 @@
1
+ import React, { useCallback, useId, useRef, useState } from 'react';
2
+ import { PopupProvider } from './popup-context';
3
+ /**
4
+ * Popup compound — trigger + popover content.
5
+ *
6
+ * Use when a button opens anchored content (dropdown, menu, dialog).
7
+ * The browser manages visibility via `togglePopover()` — the consumer
8
+ * never manages `isOpen`. For custom trigger lifecycles (hover, timers,
9
+ * external state), use `Popover` directly instead.
10
+ *
11
+ * Provides context (triggerRef, placement, isOpen, onClose, mode) that
12
+ * `Popup.Content` reads and forwards to the underlying `Popover`.
13
+ */
14
+ export function PopupRoot(props) {
15
+ var _props$mode;
16
+ const {
17
+ placement,
18
+ children,
19
+ testId,
20
+ forceFallbackPositioning,
21
+ onOpenChange
22
+ } = props;
23
+ const mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : 'auto';
24
+ const onClose = mode === 'manual' ? null : props.onClose;
25
+ const id = useId();
26
+ // Regex is intentional — `replaceAll` is not available in our supported
27
+ // browser matrix. `useId()` returns IDs containing colons (e.g. `:r1:`)
28
+ // which are invalid in CSS selectors and `popover` target attributes.
29
+ const sanitizedId = id.replace(/:/g, '');
30
+ const popoverId = `popover-${sanitizedId}`;
31
+ const triggerRef = useRef(null);
32
+ const popoverRef = useRef(null);
33
+ const [isOpen, setIsOpen] = useState(false);
34
+ const [ariaHasPopup, setAriaHasPopup] = useState('dialog');
35
+ const handleClose = useCallback(args => {
36
+ onClose === null || onClose === void 0 ? void 0 : onClose(args);
37
+ }, [onClose]);
38
+ const contextValue = {
39
+ popoverId,
40
+ placement,
41
+ onClose: mode === 'manual' ? null : handleClose,
42
+ triggerRef,
43
+ popoverRef,
44
+ isOpen,
45
+ setIsOpen,
46
+ onOpenChange,
47
+ mode,
48
+ ariaHasPopup,
49
+ setAriaHasPopup,
50
+ testId,
51
+ forceFallbackPositioning
52
+ };
53
+ return /*#__PURE__*/React.createElement(PopupProvider, {
54
+ value: contextValue
55
+ }, children);
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { useArrowNavigation, isAtCurrentMenuLevel } from './use-arrow-navigation';