@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.
- package/CHANGELOG.md +44 -0
- package/README.md +151 -0
- package/animations/package.json +17 -0
- package/arrow/package.json +17 -0
- package/create-close-event/package.json +17 -0
- package/dialog/package.json +17 -0
- package/dialog-scroll-lock/package.json +17 -0
- package/dist/cjs/animations/presets.js +199 -0
- package/dist/cjs/animations/types.js +5 -0
- package/dist/cjs/arrow/index.js +130 -0
- package/dist/cjs/arrow/types.js +5 -0
- package/dist/cjs/dialog/create-close-event.js +39 -0
- package/dist/cjs/dialog/dialog-content.compiled.css +14 -0
- package/dist/cjs/dialog/dialog-content.js +144 -0
- package/dist/cjs/dialog/index.js +19 -0
- package/dist/cjs/dialog/types.js +5 -0
- package/dist/cjs/dialog-scroll-lock/index.js +46 -0
- package/dist/cjs/entry-points/animations.js +36 -0
- package/dist/cjs/entry-points/arrow.js +12 -0
- package/dist/cjs/entry-points/create-close-event.js +19 -0
- package/dist/cjs/entry-points/dialog-scroll-lock.js +12 -0
- package/dist/cjs/entry-points/dialog.js +12 -0
- package/dist/cjs/entry-points/focus.js +24 -0
- package/dist/cjs/entry-points/placement-map.js +18 -0
- package/dist/cjs/entry-points/popover.js +12 -0
- package/dist/cjs/entry-points/popup-surface.js +12 -0
- package/dist/cjs/entry-points/popup.js +12 -0
- package/dist/cjs/entry-points/use-anchor-position.js +12 -0
- package/dist/cjs/entry-points/use-arrow-navigation.js +18 -0
- package/dist/cjs/entry-points/use-simple-light-dismiss.js +12 -0
- package/dist/cjs/focus/focus.js +115 -0
- package/dist/cjs/focus/index.js +24 -0
- package/dist/cjs/index.js +8 -0
- package/dist/cjs/internal/anchor-positioning-fallback.js +154 -0
- package/dist/cjs/internal/combine.js +29 -0
- package/dist/cjs/internal/ensure-preset-styles.js +34 -0
- package/dist/cjs/internal/reduced-motion.js +27 -0
- package/dist/cjs/internal/resolve-placement.js +24 -0
- package/dist/cjs/internal/role-types.js +66 -0
- package/dist/cjs/internal/set-style.js +42 -0
- package/dist/cjs/internal/slot.js +65 -0
- package/dist/cjs/internal/use-anchor-positioning.js +336 -0
- package/dist/cjs/internal/use-animated-visibility.js +169 -0
- package/dist/cjs/internal/use-animation-preset.js +24 -0
- package/dist/cjs/internal/use-focus-wrap.js +94 -0
- package/dist/cjs/internal/use-initial-focus.js +112 -0
- package/dist/cjs/internal/use-preset-styles.js +27 -0
- package/dist/cjs/placement-map/index.js +147 -0
- package/dist/cjs/popover/create-close-event.js +44 -0
- package/dist/cjs/popover/index.js +19 -0
- package/dist/cjs/popover/popover.compiled.css +13 -0
- package/dist/cjs/popover/popover.js +251 -0
- package/dist/cjs/popover/types.js +5 -0
- package/dist/cjs/popup/index.js +37 -0
- package/dist/cjs/popup/popup-content.js +201 -0
- package/dist/cjs/popup/popup-context.js +42 -0
- package/dist/cjs/popup/popup-surface.compiled.css +5 -0
- package/dist/cjs/popup/popup-surface.js +30 -0
- package/dist/cjs/popup/popup-trigger-function.js +74 -0
- package/dist/cjs/popup/popup-trigger.js +82 -0
- package/dist/cjs/popup/popup.js +70 -0
- package/dist/cjs/popup/types.js +5 -0
- package/dist/cjs/use-arrow-navigation/index.js +18 -0
- package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +245 -0
- package/dist/cjs/use-simple-light-dismiss/index.js +84 -0
- package/dist/es2019/animations/presets.js +375 -0
- package/dist/es2019/animations/types.js +1 -0
- package/dist/es2019/arrow/index.js +249 -0
- package/dist/es2019/arrow/types.js +1 -0
- package/dist/es2019/dialog/create-close-event.js +34 -0
- package/dist/es2019/dialog/dialog-content.compiled.css +14 -0
- package/dist/es2019/dialog/dialog-content.js +138 -0
- package/dist/es2019/dialog/index.js +2 -0
- package/dist/es2019/dialog/types.js +1 -0
- package/dist/es2019/dialog-scroll-lock/index.js +41 -0
- package/dist/es2019/entry-points/animations.js +1 -0
- package/dist/es2019/entry-points/arrow.js +1 -0
- package/dist/es2019/entry-points/create-close-event.js +2 -0
- package/dist/es2019/entry-points/dialog-scroll-lock.js +1 -0
- package/dist/es2019/entry-points/dialog.js +1 -0
- package/dist/es2019/entry-points/focus.js +1 -0
- package/dist/es2019/entry-points/placement-map.js +1 -0
- package/dist/es2019/entry-points/popover.js +1 -0
- package/dist/es2019/entry-points/popup-surface.js +1 -0
- package/dist/es2019/entry-points/popup.js +1 -0
- package/dist/es2019/entry-points/use-anchor-position.js +1 -0
- package/dist/es2019/entry-points/use-arrow-navigation.js +1 -0
- package/dist/es2019/entry-points/use-simple-light-dismiss.js +1 -0
- package/dist/es2019/focus/focus.js +107 -0
- package/dist/es2019/focus/index.js +1 -0
- package/dist/es2019/index.js +7 -0
- package/dist/es2019/internal/anchor-positioning-fallback.js +153 -0
- package/dist/es2019/internal/combine.js +18 -0
- package/dist/es2019/internal/ensure-preset-styles.js +29 -0
- package/dist/es2019/internal/reduced-motion.js +21 -0
- package/dist/es2019/internal/resolve-placement.js +19 -0
- package/dist/es2019/internal/role-types.js +61 -0
- package/dist/es2019/internal/set-style.js +39 -0
- package/dist/es2019/internal/slot.js +57 -0
- package/dist/es2019/internal/use-anchor-positioning.js +330 -0
- package/dist/es2019/internal/use-animated-visibility.js +159 -0
- package/dist/es2019/internal/use-animation-preset.js +18 -0
- package/dist/es2019/internal/use-focus-wrap.js +90 -0
- package/dist/es2019/internal/use-initial-focus.js +109 -0
- package/dist/es2019/internal/use-preset-styles.js +22 -0
- package/dist/es2019/placement-map/index.js +142 -0
- package/dist/es2019/popover/create-close-event.js +39 -0
- package/dist/es2019/popover/index.js +2 -0
- package/dist/es2019/popover/popover.compiled.css +13 -0
- package/dist/es2019/popover/popover.js +240 -0
- package/dist/es2019/popover/types.js +1 -0
- package/dist/es2019/popup/index.js +33 -0
- package/dist/es2019/popup/popup-content.js +192 -0
- package/dist/es2019/popup/popup-context.js +34 -0
- package/dist/es2019/popup/popup-surface.compiled.css +5 -0
- package/dist/es2019/popup/popup-surface.js +24 -0
- package/dist/es2019/popup/popup-trigger-function.js +69 -0
- package/dist/es2019/popup/popup-trigger.js +76 -0
- package/dist/es2019/popup/popup.js +56 -0
- package/dist/es2019/popup/types.js +1 -0
- package/dist/es2019/use-arrow-navigation/index.js +1 -0
- package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +238 -0
- package/dist/es2019/use-simple-light-dismiss/index.js +79 -0
- package/dist/esm/animations/presets.js +190 -0
- package/dist/esm/animations/types.js +1 -0
- package/dist/esm/arrow/index.js +123 -0
- package/dist/esm/arrow/types.js +1 -0
- package/dist/esm/dialog/create-close-event.js +33 -0
- package/dist/esm/dialog/dialog-content.compiled.css +14 -0
- package/dist/esm/dialog/dialog-content.js +135 -0
- package/dist/esm/dialog/index.js +2 -0
- package/dist/esm/dialog/types.js +1 -0
- package/dist/esm/dialog-scroll-lock/index.js +41 -0
- package/dist/esm/entry-points/animations.js +1 -0
- package/dist/esm/entry-points/arrow.js +1 -0
- package/dist/esm/entry-points/create-close-event.js +2 -0
- package/dist/esm/entry-points/dialog-scroll-lock.js +1 -0
- package/dist/esm/entry-points/dialog.js +1 -0
- package/dist/esm/entry-points/focus.js +1 -0
- package/dist/esm/entry-points/placement-map.js +1 -0
- package/dist/esm/entry-points/popover.js +1 -0
- package/dist/esm/entry-points/popup-surface.js +1 -0
- package/dist/esm/entry-points/popup.js +1 -0
- package/dist/esm/entry-points/use-anchor-position.js +1 -0
- package/dist/esm/entry-points/use-arrow-navigation.js +1 -0
- package/dist/esm/entry-points/use-simple-light-dismiss.js +1 -0
- package/dist/esm/focus/focus.js +107 -0
- package/dist/esm/focus/index.js +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/internal/anchor-positioning-fallback.js +147 -0
- package/dist/esm/internal/combine.js +23 -0
- package/dist/esm/internal/ensure-preset-styles.js +28 -0
- package/dist/esm/internal/reduced-motion.js +21 -0
- package/dist/esm/internal/resolve-placement.js +18 -0
- package/dist/esm/internal/role-types.js +60 -0
- package/dist/esm/internal/set-style.js +36 -0
- package/dist/esm/internal/slot.js +59 -0
- package/dist/esm/internal/use-anchor-positioning.js +323 -0
- package/dist/esm/internal/use-animated-visibility.js +162 -0
- package/dist/esm/internal/use-animation-preset.js +18 -0
- package/dist/esm/internal/use-focus-wrap.js +89 -0
- package/dist/esm/internal/use-initial-focus.js +107 -0
- package/dist/esm/internal/use-preset-styles.js +21 -0
- package/dist/esm/placement-map/index.js +141 -0
- package/dist/esm/popover/create-close-event.js +38 -0
- package/dist/esm/popover/index.js +2 -0
- package/dist/esm/popover/popover.compiled.css +13 -0
- package/dist/esm/popover/popover.js +242 -0
- package/dist/esm/popover/types.js +1 -0
- package/dist/esm/popup/index.js +33 -0
- package/dist/esm/popup/popup-content.js +192 -0
- package/dist/esm/popup/popup-context.js +34 -0
- package/dist/esm/popup/popup-surface.compiled.css +5 -0
- package/dist/esm/popup/popup-surface.js +23 -0
- package/dist/esm/popup/popup-trigger-function.js +69 -0
- package/dist/esm/popup/popup-trigger.js +74 -0
- package/dist/esm/popup/popup.js +61 -0
- package/dist/esm/popup/types.js +1 -0
- package/dist/esm/use-arrow-navigation/index.js +1 -0
- package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +238 -0
- package/dist/esm/use-simple-light-dismiss/index.js +78 -0
- package/dist/types/animations/presets.d.ts +94 -0
- package/dist/types/animations/types.d.ts +42 -0
- package/dist/types/arrow/index.d.ts +24 -0
- package/dist/types/arrow/types.d.ts +29 -0
- package/dist/types/dialog/create-close-event.d.ts +24 -0
- package/dist/types/dialog/dialog-content.d.ts +20 -0
- package/dist/types/dialog/index.d.ts +3 -0
- package/dist/types/dialog/types.d.ts +92 -0
- package/dist/types/dialog-scroll-lock/index.d.ts +24 -0
- package/dist/types/entry-points/animations.d.ts +2 -0
- package/dist/types/entry-points/arrow.d.ts +2 -0
- package/dist/types/entry-points/create-close-event.d.ts +4 -0
- package/dist/types/entry-points/dialog-scroll-lock.d.ts +1 -0
- package/dist/types/entry-points/dialog.d.ts +2 -0
- package/dist/types/entry-points/focus.d.ts +2 -0
- package/dist/types/entry-points/placement-map.d.ts +2 -0
- package/dist/types/entry-points/popover.d.ts +2 -0
- package/dist/types/entry-points/popup-surface.d.ts +2 -0
- package/dist/types/entry-points/popup.d.ts +2 -0
- package/dist/types/entry-points/use-anchor-position.d.ts +1 -0
- package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -0
- package/dist/types/entry-points/use-simple-light-dismiss.d.ts +2 -0
- package/dist/types/focus/focus.d.ts +42 -0
- package/dist/types/focus/index.d.ts +2 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/internal/anchor-positioning-fallback.d.ts +24 -0
- package/dist/types/internal/combine.d.ts +14 -0
- package/dist/types/internal/ensure-preset-styles.d.ts +6 -0
- package/dist/types/internal/reduced-motion.d.ts +14 -0
- package/dist/types/internal/resolve-placement.d.ts +16 -0
- package/dist/types/internal/role-types.d.ts +62 -0
- package/dist/types/internal/set-style.d.ts +28 -0
- package/dist/types/internal/slot.d.ts +29 -0
- package/dist/types/internal/use-anchor-positioning.d.ts +95 -0
- package/dist/types/internal/use-animated-visibility.d.ts +74 -0
- package/dist/types/internal/use-animation-preset.d.ts +11 -0
- package/dist/types/internal/use-focus-wrap.d.ts +20 -0
- package/dist/types/internal/use-initial-focus.d.ts +21 -0
- package/dist/types/internal/use-preset-styles.d.ts +15 -0
- package/dist/types/placement-map/index.d.ts +55 -0
- package/dist/types/popover/create-close-event.d.ts +26 -0
- package/dist/types/popover/index.d.ts +3 -0
- package/dist/types/popover/popover.d.ts +22 -0
- package/dist/types/popover/types.d.ts +153 -0
- package/dist/types/popup/index.d.ts +34 -0
- package/dist/types/popup/popup-content.d.ts +14 -0
- package/dist/types/popup/popup-context.d.ts +96 -0
- package/dist/types/popup/popup-surface.d.ts +16 -0
- package/dist/types/popup/popup-trigger-function.d.ts +108 -0
- package/dist/types/popup/popup-trigger.d.ts +23 -0
- package/dist/types/popup/popup.d.ts +14 -0
- package/dist/types/popup/types.d.ts +289 -0
- package/dist/types/use-arrow-navigation/index.d.ts +2 -0
- package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +136 -0
- package/dist/types/use-simple-light-dismiss/index.d.ts +45 -0
- package/dist/types-ts4.5/animations/presets.d.ts +94 -0
- package/dist/types-ts4.5/animations/types.d.ts +42 -0
- package/dist/types-ts4.5/arrow/index.d.ts +24 -0
- package/dist/types-ts4.5/arrow/types.d.ts +29 -0
- package/dist/types-ts4.5/dialog/create-close-event.d.ts +24 -0
- package/dist/types-ts4.5/dialog/dialog-content.d.ts +20 -0
- package/dist/types-ts4.5/dialog/index.d.ts +3 -0
- package/dist/types-ts4.5/dialog/types.d.ts +92 -0
- package/dist/types-ts4.5/dialog-scroll-lock/index.d.ts +24 -0
- package/dist/types-ts4.5/entry-points/animations.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/arrow.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/create-close-event.d.ts +4 -0
- package/dist/types-ts4.5/entry-points/dialog-scroll-lock.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/dialog.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/focus.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/placement-map.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/popover.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/popup-surface.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/popup.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/use-anchor-position.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -0
- package/dist/types-ts4.5/entry-points/use-simple-light-dismiss.d.ts +2 -0
- package/dist/types-ts4.5/focus/focus.d.ts +42 -0
- package/dist/types-ts4.5/focus/index.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +0 -0
- package/dist/types-ts4.5/internal/anchor-positioning-fallback.d.ts +24 -0
- package/dist/types-ts4.5/internal/combine.d.ts +14 -0
- package/dist/types-ts4.5/internal/ensure-preset-styles.d.ts +6 -0
- package/dist/types-ts4.5/internal/reduced-motion.d.ts +14 -0
- package/dist/types-ts4.5/internal/resolve-placement.d.ts +16 -0
- package/dist/types-ts4.5/internal/role-types.d.ts +62 -0
- package/dist/types-ts4.5/internal/set-style.d.ts +28 -0
- package/dist/types-ts4.5/internal/slot.d.ts +29 -0
- package/dist/types-ts4.5/internal/use-anchor-positioning.d.ts +95 -0
- package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +74 -0
- package/dist/types-ts4.5/internal/use-animation-preset.d.ts +11 -0
- package/dist/types-ts4.5/internal/use-focus-wrap.d.ts +20 -0
- package/dist/types-ts4.5/internal/use-initial-focus.d.ts +21 -0
- package/dist/types-ts4.5/internal/use-preset-styles.d.ts +15 -0
- package/dist/types-ts4.5/placement-map/index.d.ts +55 -0
- package/dist/types-ts4.5/popover/create-close-event.d.ts +26 -0
- package/dist/types-ts4.5/popover/index.d.ts +3 -0
- package/dist/types-ts4.5/popover/popover.d.ts +22 -0
- package/dist/types-ts4.5/popover/types.d.ts +153 -0
- package/dist/types-ts4.5/popup/index.d.ts +34 -0
- package/dist/types-ts4.5/popup/popup-content.d.ts +14 -0
- package/dist/types-ts4.5/popup/popup-context.d.ts +96 -0
- package/dist/types-ts4.5/popup/popup-surface.d.ts +16 -0
- package/dist/types-ts4.5/popup/popup-trigger-function.d.ts +108 -0
- package/dist/types-ts4.5/popup/popup-trigger.d.ts +23 -0
- package/dist/types-ts4.5/popup/popup.d.ts +14 -0
- package/dist/types-ts4.5/popup/types.d.ts +289 -0
- package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -0
- package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +136 -0
- package/dist/types-ts4.5/use-simple-light-dismiss/index.d.ts +45 -0
- package/focus/package.json +17 -0
- package/package.json +95 -0
- package/placement-map/package.json +17 -0
- package/popover/package.json +17 -0
- package/popup/package.json +17 -0
- package/popup-surface/package.json +17 -0
- package/use-anchor-position/package.json +17 -0
- package/use-arrow-navigation/package.json +17 -0
- package/use-simple-light-dismiss/package.json +17 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
4
|
+
import { KEY_DOWN, KEY_END, KEY_HOME, KEY_TAB, KEY_UP } from '@atlaskit/ds-lib/keycodes';
|
|
5
|
+
import { getFirstFocusable, getLastFocusable, getNextFocusable } from '../focus';
|
|
6
|
+
const menuScope = '[role="menu"]';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the element belongs to the current menu level of the
|
|
10
|
+
* container — i.e. it is NOT inside a nested `role="menu"` sub-container.
|
|
11
|
+
*
|
|
12
|
+
* Uses `element.closest('[role="menu"]')` to determine the nearest menu
|
|
13
|
+
* scope. If the nearest scope is the container's own `role="menu"` element,
|
|
14
|
+
* the element belongs to this level. If it's a different (nested) menu,
|
|
15
|
+
* the element belongs to a child level and should be excluded.
|
|
16
|
+
*
|
|
17
|
+
* Supports two container patterns:
|
|
18
|
+
*
|
|
19
|
+
* **1. Container has `role="menu"` directly** (preferred — used by avatar-group):
|
|
20
|
+
* ```
|
|
21
|
+
* <div ref={containerRef} role="menu">
|
|
22
|
+
* <button role="menuitem" /> ← isAtCurrentMenuLevel → true
|
|
23
|
+
* <div role="menu"> ← nested sub-menu
|
|
24
|
+
* <button role="menuitem" /> ← isAtCurrentMenuLevel → false
|
|
25
|
+
* </div>
|
|
26
|
+
* </div>
|
|
27
|
+
* ```
|
|
28
|
+
* Uses the simple check: `element.closest('[role="menu"]') === container`
|
|
29
|
+
*
|
|
30
|
+
* **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
|
|
31
|
+
* where `MenuGroup` owns `role="menu"` but doesn't accept a ref):
|
|
32
|
+
* ```
|
|
33
|
+
* <div ref={containerRef}> ← wrapper (no role="menu")
|
|
34
|
+
* <MenuGroup role="menu">
|
|
35
|
+
* <button role="menuitem" /> ← isAtCurrentMenuLevel → true
|
|
36
|
+
* <div role="menu"> ← nested sub-menu
|
|
37
|
+
* <button role="menuitem" /> ← isAtCurrentMenuLevel → false
|
|
38
|
+
* </div>
|
|
39
|
+
* </MenuGroup>
|
|
40
|
+
* </div>
|
|
41
|
+
* ```
|
|
42
|
+
* Falls back to walking the DOM to check that the element's closest
|
|
43
|
+
* `role="menu"` is the container's own menu (not doubly nested).
|
|
44
|
+
*
|
|
45
|
+
* Ideally all consumers should use pattern 1 (place the ref directly on the
|
|
46
|
+
* `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
|
|
47
|
+
* `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
|
|
48
|
+
* support in the future, dropdown-menu should switch to pattern 1 and the
|
|
49
|
+
* fallback path can be removed.
|
|
50
|
+
*
|
|
51
|
+
* Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
|
|
52
|
+
* a guard to prevent parent menu handlers from acting on events that
|
|
53
|
+
* belong to a nested menu.
|
|
54
|
+
*/
|
|
55
|
+
export function isAtCurrentMenuLevel(element, container) {
|
|
56
|
+
const closestMenu = element.closest(menuScope);
|
|
57
|
+
|
|
58
|
+
// Container itself has role="menu" — element belongs to this level
|
|
59
|
+
// if its closest menu is the container.
|
|
60
|
+
if (container.getAttribute('role') === 'menu') {
|
|
61
|
+
return closestMenu === container;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Container is a wrapper without role="menu" (e.g. dropdown-menu
|
|
65
|
+
// wraps a MenuGroup). The element belongs to the top level if its
|
|
66
|
+
// closest role="menu" ancestor is a direct child of the container,
|
|
67
|
+
// i.e. there's no nested role="menu" between them.
|
|
68
|
+
if (closestMenu === null) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Walk up from the closest menu to see if it's "owned" by this
|
|
73
|
+
// container without passing through another role="menu" first.
|
|
74
|
+
let parent = closestMenu.parentElement;
|
|
75
|
+
while (parent && parent !== container) {
|
|
76
|
+
if (parent.getAttribute('role') === 'menu') {
|
|
77
|
+
// There's a parent menu between the closest menu and the
|
|
78
|
+
// container — the element is in a nested sub-menu.
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
parent = parent.parentElement;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The closest menu is directly inside the container (no nesting).
|
|
85
|
+
return parent === container;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Provides arrow key navigation for menu containers.
|
|
89
|
+
*
|
|
90
|
+
* Uses the focusable helpers from `@atlaskit/top-layer/focus` to manage
|
|
91
|
+
* DOM-based focus movement within a container.
|
|
92
|
+
*
|
|
93
|
+
* - **ArrowDown / ArrowUp**: Move focus to the next/previous item (wraps).
|
|
94
|
+
* - **Home / End**: Move focus to the first/last item.
|
|
95
|
+
* - **Tab**: Calls `onClose` to exit the menu.
|
|
96
|
+
*
|
|
97
|
+
* When a `filter` is provided, it is used both for scoping focusable
|
|
98
|
+
* elements and as a guard to prevent parent menu handlers from acting
|
|
99
|
+
* on events that belong to a nested menu.
|
|
100
|
+
*
|
|
101
|
+
* @example Basic usage
|
|
102
|
+
* ```tsx
|
|
103
|
+
* useArrowNavigation({
|
|
104
|
+
* containerRef: menuRef,
|
|
105
|
+
* onClose: () => setIsOpen(false),
|
|
106
|
+
* isEnabled: isOpen,
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example With nested menu filter
|
|
111
|
+
* ```tsx
|
|
112
|
+
* import { useArrowNavigation, isAtCurrentMenuLevel } from '@atlaskit/top-layer/use-arrow-navigation';
|
|
113
|
+
*
|
|
114
|
+
* useArrowNavigation({
|
|
115
|
+
* containerRef: menuRef,
|
|
116
|
+
* onClose: () => setIsOpen(false),
|
|
117
|
+
* isEnabled: isOpen,
|
|
118
|
+
* filter: isAtCurrentMenuLevel,
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function useArrowNavigation({
|
|
123
|
+
containerRef,
|
|
124
|
+
onClose,
|
|
125
|
+
onNestedOpen,
|
|
126
|
+
onNestedClose,
|
|
127
|
+
isEnabled = true,
|
|
128
|
+
filter
|
|
129
|
+
}) {
|
|
130
|
+
const handleKeyDown = useCallback(event => {
|
|
131
|
+
var _getDocument;
|
|
132
|
+
const container = containerRef.current;
|
|
133
|
+
if (!container) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Guard: only handle the event if the currently focused element
|
|
138
|
+
// belongs to this menu level. The focused element's closest
|
|
139
|
+
// [role="menu"] must be this container (not a nested sub-menu).
|
|
140
|
+
// When no filter is provided, fall back to the closest-menu check
|
|
141
|
+
// if the container has role="menu".
|
|
142
|
+
const focused = (_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.activeElement;
|
|
143
|
+
if (focused instanceof HTMLElement) {
|
|
144
|
+
if (filter) {
|
|
145
|
+
if (!filter(focused, container)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!filter && container.getAttribute('role') === 'menu' && focused.closest(menuScope) !== container) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (event.key === KEY_DOWN) {
|
|
154
|
+
var _getNextFocusable;
|
|
155
|
+
// Prevent page scroll while navigating menu items.
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
(_getNextFocusable = getNextFocusable({
|
|
158
|
+
container,
|
|
159
|
+
direction: 'forwards',
|
|
160
|
+
filter
|
|
161
|
+
})) === null || _getNextFocusable === void 0 ? void 0 : _getNextFocusable.focus();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (event.key === KEY_UP) {
|
|
165
|
+
var _getNextFocusable2;
|
|
166
|
+
// Prevent page scroll while navigating menu items.
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
(_getNextFocusable2 = getNextFocusable({
|
|
169
|
+
container,
|
|
170
|
+
direction: 'backwards',
|
|
171
|
+
filter
|
|
172
|
+
})) === null || _getNextFocusable2 === void 0 ? void 0 : _getNextFocusable2.focus();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (event.key === KEY_HOME) {
|
|
176
|
+
var _getFirstFocusable;
|
|
177
|
+
// Prevent browser default (e.g. scrolling to top of page).
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
(_getFirstFocusable = getFirstFocusable({
|
|
180
|
+
container,
|
|
181
|
+
filter
|
|
182
|
+
})) === null || _getFirstFocusable === void 0 ? void 0 : _getFirstFocusable.focus();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (event.key === KEY_END) {
|
|
186
|
+
var _getLastFocusable;
|
|
187
|
+
// Prevent browser default (e.g. scrolling to bottom of page).
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
(_getLastFocusable = getLastFocusable({
|
|
190
|
+
container,
|
|
191
|
+
filter
|
|
192
|
+
})) === null || _getLastFocusable === void 0 ? void 0 : _getLastFocusable.focus();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (event.key === KEY_TAB) {
|
|
196
|
+
onClose();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ── Nested menu navigation (WAI-ARIA menu pattern) ──
|
|
201
|
+
// ArrowRight on a menuitem with aria-haspopup opens the submenu.
|
|
202
|
+
if (event.key === 'ArrowRight') {
|
|
203
|
+
if (onNestedOpen && focused instanceof HTMLElement && focused.hasAttribute('aria-haspopup')) {
|
|
204
|
+
event.preventDefault();
|
|
205
|
+
onNestedOpen({
|
|
206
|
+
trigger: focused
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ArrowLeft closes the current menu if it is nested inside a parent menu.
|
|
213
|
+
if (event.key === 'ArrowLeft') {
|
|
214
|
+
if (onNestedClose) {
|
|
215
|
+
var _container$parentElem;
|
|
216
|
+
// Only close if this container is inside another role="menu"
|
|
217
|
+
// (i.e. it's a submenu, not the top-level menu).
|
|
218
|
+
// Walk up from the parent to avoid matching the container itself.
|
|
219
|
+
const isNested = ((_container$parentElem = container.parentElement) === null || _container$parentElem === void 0 ? void 0 : _container$parentElem.closest(menuScope)) !== null;
|
|
220
|
+
if (isNested) {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
onNestedClose();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}, [containerRef, onClose, onNestedOpen, onNestedClose, filter]);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
const container = containerRef.current;
|
|
230
|
+
if (!container || !isEnabled) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
return bind(container, {
|
|
234
|
+
type: 'keydown',
|
|
235
|
+
listener: handleKeyDown
|
|
236
|
+
});
|
|
237
|
+
}, [containerRef, handleKeyDown, isEnabled]);
|
|
238
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
/**
|
|
4
|
+
* Simple light-dismiss hook for `popover="manual"` elements.
|
|
5
|
+
*
|
|
6
|
+
* Provides Escape-to-close and click-outside-to-close behavior without
|
|
7
|
+
* relying on the browser's `popover="auto"` light-dismiss stack.
|
|
8
|
+
*
|
|
9
|
+
* **No stacking awareness:** This hook does not track a popover stack.
|
|
10
|
+
* If multiple manual popovers are open and all use this hook, a single
|
|
11
|
+
* Escape press or outside click will dismiss **all of them simultaneously**.
|
|
12
|
+
* This is by design — the hook is intentionally simple for cases where
|
|
13
|
+
* only one manual popover is open at a time.
|
|
14
|
+
*
|
|
15
|
+
* For stacked/nested popovers that should dismiss one-at-a-time, use
|
|
16
|
+
* `popover="auto"` mode instead, which provides native stack-aware
|
|
17
|
+
* light dismiss via the browser's top-layer stack.
|
|
18
|
+
*/
|
|
19
|
+
export function useSimpleLightDismiss({
|
|
20
|
+
popoverRef,
|
|
21
|
+
isOpen,
|
|
22
|
+
onClose
|
|
23
|
+
}) {
|
|
24
|
+
// Keep a stable ref to onClose so the effect doesn't re-bind on every render.
|
|
25
|
+
const onCloseRef = useRef(onClose);
|
|
26
|
+
onCloseRef.current = onClose;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!isOpen) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line @atlaskit/platform/no-direct-document-usage -- binding to document for light dismiss
|
|
33
|
+
const unbindEscape = bind(document, {
|
|
34
|
+
type: 'keydown',
|
|
35
|
+
listener: event => {
|
|
36
|
+
if (event.key === 'Escape') {
|
|
37
|
+
onCloseRef.current({
|
|
38
|
+
reason: 'escape'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Listen for click-outside in the **capture** phase.
|
|
45
|
+
//
|
|
46
|
+
// The click that opened the popover propagates in bubble phase
|
|
47
|
+
// (trigger onClick → setIsOpen(true) → React render → useEffect).
|
|
48
|
+
// By the time this effect runs, the opening click has finished
|
|
49
|
+
// bubbling. A capture-phase listener added now cannot retroactively
|
|
50
|
+
// fire for that event — it only fires for *future* clicks.
|
|
51
|
+
//
|
|
52
|
+
// This avoids the need for timestamp guards or deferred binding.
|
|
53
|
+
// eslint-disable-next-line @atlaskit/platform/no-direct-document-usage -- binding to document for light dismiss
|
|
54
|
+
const unbindClickOutside = bind(document, {
|
|
55
|
+
type: 'click',
|
|
56
|
+
listener: event => {
|
|
57
|
+
const el = popoverRef.current;
|
|
58
|
+
if (!el) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If the click target is inside the popover, don't dismiss.
|
|
63
|
+
if (event.target instanceof Node && el.contains(event.target)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
onCloseRef.current({
|
|
67
|
+
reason: 'light-dismiss'
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
capture: true
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return () => {
|
|
75
|
+
unbindEscape();
|
|
76
|
+
unbindClickOutside();
|
|
77
|
+
};
|
|
78
|
+
}, [isOpen, popoverRef]);
|
|
79
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { getPlacement } from '../internal/use-anchor-positioning';
|
|
2
|
+
|
|
3
|
+
// ── slideAndFade ──
|
|
4
|
+
|
|
5
|
+
function getSlideAndFadeProperties(_ref) {
|
|
6
|
+
var placement = _ref.placement,
|
|
7
|
+
distance = _ref.distance;
|
|
8
|
+
var pos = "".concat(distance, "px");
|
|
9
|
+
var neg = "-".concat(distance, "px");
|
|
10
|
+
var _getPlacement = getPlacement({
|
|
11
|
+
placement: placement
|
|
12
|
+
}),
|
|
13
|
+
axis = _getPlacement.axis,
|
|
14
|
+
edge = _getPlacement.edge;
|
|
15
|
+
if (axis === 'block' && edge === 'start') {
|
|
16
|
+
return {
|
|
17
|
+
'--ds-popover-tx': '0',
|
|
18
|
+
'--ds-popover-ty': pos
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
if (axis === 'block' && edge === 'end') {
|
|
22
|
+
return {
|
|
23
|
+
'--ds-popover-tx': '0',
|
|
24
|
+
'--ds-popover-ty': neg
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (axis === 'inline' && edge === 'start') {
|
|
28
|
+
return {
|
|
29
|
+
'--ds-popover-tx': pos,
|
|
30
|
+
'--ds-popover-ty': '0'
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (axis === 'inline' && edge === 'end') {
|
|
34
|
+
return {
|
|
35
|
+
'--ds-popover-tx': neg,
|
|
36
|
+
'--ds-popover-ty': '0'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
'--ds-popover-tx': '0',
|
|
41
|
+
'--ds-popover-ty': neg
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var SLIDE_AND_FADE_CSS = "\n[data-ds-popover-slide-and-fade] {\n opacity: 0;\n transform: translate3d(var(--ds-popover-tx, 0), var(--ds-popover-ty, 0), 0);\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-slide-and-fade]:popover-open {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-slide-and-fade]:popover-open {\n opacity: 0;\n transform: translate3d(var(--ds-popover-tx, 0), var(--ds-popover-ty, 0), 0);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-slide-and-fade],\n [data-ds-popover-slide-and-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Directional slide + opacity animation.
|
|
48
|
+
*
|
|
49
|
+
* The popover slides in from the direction opposite its placement edge
|
|
50
|
+
* (e.g. a `block-end` popover slides down from above).
|
|
51
|
+
*
|
|
52
|
+
* @param options.distance - Slide distance in pixels. Defaults to `4`.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* import { slideAndFade } from '@atlaskit/top-layer/animations';
|
|
57
|
+
*
|
|
58
|
+
* // Default 4px slide (tooltip)
|
|
59
|
+
* <Popup.Content animate={slideAndFade()} />
|
|
60
|
+
*
|
|
61
|
+
* // Custom 8px slide (popup / dropdown)
|
|
62
|
+
* <Popup.Content animate={slideAndFade({ distance: 8 })} />
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function slideAndFade(options) {
|
|
66
|
+
var _options$distance;
|
|
67
|
+
var distance = (_options$distance = options === null || options === void 0 ? void 0 : options.distance) !== null && _options$distance !== void 0 ? _options$distance : 4;
|
|
68
|
+
return {
|
|
69
|
+
name: 'slide-and-fade',
|
|
70
|
+
css: SLIDE_AND_FADE_CSS,
|
|
71
|
+
getProperties: function getProperties(_ref2) {
|
|
72
|
+
var placement = _ref2.placement;
|
|
73
|
+
return getSlideAndFadeProperties({
|
|
74
|
+
placement: placement,
|
|
75
|
+
distance: distance
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
exitDurationMs: 175
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ── fade ──
|
|
83
|
+
|
|
84
|
+
var FADE_CSS = "\n[data-ds-popover-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-fade]:popover-open {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-fade]:popover-open {\n opacity: 0;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-fade],\n [data-ds-popover-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Simple opacity transition, no transform.
|
|
88
|
+
*
|
|
89
|
+
* Suitable for popup dialogs or content that does not need directional motion.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* import { fade } from '@atlaskit/top-layer/animations';
|
|
94
|
+
*
|
|
95
|
+
* <Popup.Content animate={fade()} />
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function fade() {
|
|
99
|
+
return {
|
|
100
|
+
name: 'fade',
|
|
101
|
+
css: FADE_CSS,
|
|
102
|
+
exitDurationMs: 175
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── scaleAndFade ──
|
|
107
|
+
|
|
108
|
+
var SCALE_AND_FADE_CSS = "\n[data-ds-popover-scale-and-fade] {\n opacity: 0;\n transform: scale(0.95);\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-popover-scale-and-fade]:popover-open {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-popover-scale-and-fade]:popover-open {\n opacity: 0;\n transform: scale(0.95);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-popover-scale-and-fade],\n [data-ds-popover-scale-and-fade]:popover-open {\n transition-duration: 0s;\n }\n}\n";
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Scale from 0.95 + opacity transition.
|
|
112
|
+
*
|
|
113
|
+
* Suitable for menus, dropdowns, and select options.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```tsx
|
|
117
|
+
* import { scaleAndFade } from '@atlaskit/top-layer/animations';
|
|
118
|
+
*
|
|
119
|
+
* <Popup.Content animate={scaleAndFade()} />
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function scaleAndFade() {
|
|
123
|
+
return {
|
|
124
|
+
name: 'scale-and-fade',
|
|
125
|
+
css: SCALE_AND_FADE_CSS,
|
|
126
|
+
exitDurationMs: 175
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
131
|
+
// Dialog presets
|
|
132
|
+
// ══════════════════════════════════════════════════════════════════════════════
|
|
133
|
+
|
|
134
|
+
// ── dialogSlideUpAndFade ──
|
|
135
|
+
|
|
136
|
+
var DIALOG_SLIDE_UP_AND_FADE_CSS = "\n[data-ds-dialog-slide-up-and-fade] {\n opacity: 0;\n transform: translateY(calc(-1 * var(--ds-dialog-ty, 12px)));\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n transform 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open] {\n opacity: 1;\n transform: none;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open] {\n opacity: 0;\n transform: translateY(var(--ds-dialog-ty, 12px));\n }\n}\n\n[data-ds-dialog-slide-up-and-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-slide-up-and-fade],\n [data-ds-dialog-slide-up-and-fade][open],\n [data-ds-dialog-slide-up-and-fade]::backdrop,\n [data-ds-dialog-slide-up-and-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Slide up + opacity animation for dialogs.
|
|
140
|
+
*
|
|
141
|
+
* Entry slides up from below; exit slides up and out (asymmetric).
|
|
142
|
+
* Includes backdrop fade animation.
|
|
143
|
+
*
|
|
144
|
+
* @param options.distance - Slide distance in pixels. Defaults to `12`.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```tsx
|
|
148
|
+
* import { dialogSlideUpAndFade } from '@atlaskit/top-layer/animations';
|
|
149
|
+
*
|
|
150
|
+
* const animation = dialogSlideUpAndFade();
|
|
151
|
+
* <Dialog animate={animation} isOpen={isOpen} onClose={handleClose} label="...">
|
|
152
|
+
* ...
|
|
153
|
+
* </Dialog>
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export function dialogSlideUpAndFade(options) {
|
|
157
|
+
var _options$distance2;
|
|
158
|
+
var distance = (_options$distance2 = options === null || options === void 0 ? void 0 : options.distance) !== null && _options$distance2 !== void 0 ? _options$distance2 : 12;
|
|
159
|
+
return {
|
|
160
|
+
name: distance === 12 ? 'dialog-slide-up-and-fade' : "dialog-slide-up-and-fade-".concat(distance),
|
|
161
|
+
css: distance === 12 ? DIALOG_SLIDE_UP_AND_FADE_CSS : DIALOG_SLIDE_UP_AND_FADE_CSS.replace(/12px/g, "".concat(distance, "px")),
|
|
162
|
+
exitDurationMs: 175
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ── dialogFade ──
|
|
167
|
+
|
|
168
|
+
var DIALOG_FADE_CSS = "\n[data-ds-dialog-fade] {\n opacity: 0;\n transition:\n opacity 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open] {\n opacity: 1;\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open] {\n opacity: 0;\n }\n}\n\n[data-ds-dialog-fade]::backdrop {\n background-color: transparent;\n transition:\n background-color 175ms cubic-bezier(0.15, 1, 0.3, 1),\n overlay 175ms allow-discrete,\n display 175ms allow-discrete;\n}\n\n[data-ds-dialog-fade][open]::backdrop {\n background-color: var(--ds-blanket, #050C1F75);\n transition-duration: 350ms;\n}\n\n@starting-style {\n [data-ds-dialog-fade][open]::backdrop {\n background-color: transparent;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n [data-ds-dialog-fade],\n [data-ds-dialog-fade][open],\n [data-ds-dialog-fade]::backdrop,\n [data-ds-dialog-fade][open]::backdrop {\n transition-duration: 0s;\n }\n}\n";
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Simple opacity transition for dialogs, no transform.
|
|
172
|
+
*
|
|
173
|
+
* Includes backdrop fade animation.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* import { dialogFade } from '@atlaskit/top-layer/animations';
|
|
178
|
+
*
|
|
179
|
+
* <Dialog animate={dialogFade()} isOpen={isOpen} onClose={handleClose} label="...">
|
|
180
|
+
* ...
|
|
181
|
+
* </Dialog>
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export function dialogFade() {
|
|
185
|
+
return {
|
|
186
|
+
name: 'dialog-fade',
|
|
187
|
+
css: DIALOG_FADE_CSS,
|
|
188
|
+
exitDurationMs: 175
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import once from '@atlaskit/ds-lib/once';
|
|
2
|
+
import { getPlacement, placementToPositionArea } from '../internal/use-anchor-positioning';
|
|
3
|
+
/**
|
|
4
|
+
* CSS for popover arrows using the `clip-path: inset() margin-box` technique.
|
|
5
|
+
*
|
|
6
|
+
* How it works:
|
|
7
|
+
* 1. Four arrow shapes exist simultaneously as `::before` (top/bottom) and
|
|
8
|
+
* `::after` (left/right) hexagonal pseudo-elements.
|
|
9
|
+
* 2. `clip-path: inset(1px) margin-box` clips the popover to its margin-box.
|
|
10
|
+
* 3. Margin on the anchor-facing side pushes the popover away, creating space
|
|
11
|
+
* where one arrow "escapes" the clip boundary and becomes visible.
|
|
12
|
+
* 4. `@position-try` rules change both `position-area` and `margin` when
|
|
13
|
+
* flipping, ensuring the correct arrow is always shown.
|
|
14
|
+
*
|
|
15
|
+
* Constraints:
|
|
16
|
+
* - `box-shadow` must be `none` (interferes with `clip-path: inset() margin-box`)
|
|
17
|
+
* - `::before` and `::after` are consumed — consumers cannot use them
|
|
18
|
+
* - Arrow pseudo-elements use `background: inherit` from the popover element
|
|
19
|
+
*
|
|
20
|
+
* @see https://goulet.dev/posts/tooltip-with-popover-and-anchor-positioning/
|
|
21
|
+
*/
|
|
22
|
+
var ARROW_CSS = "\n[data-ds-popover-arrow] {\n clip-path: inset(var(--ds-arrow-offset, 1px)) margin-box;\n box-shadow: none;\n}\n\n/* Top and Bottom arrows (vertical hexagon) */\n[data-ds-popover-arrow]::before {\n content: \"\";\n position: absolute;\n z-index: -1;\n background: inherit;\n left: 50%;\n transform: translateX(-50%);\n width: calc(var(--ds-arrow-size, 8px) * 2);\n height: calc(100% + var(--ds-arrow-size, 8px) * 2);\n top: calc(var(--ds-arrow-size, 8px) * -1);\n clip-path: polygon(\n 0 var(--ds-arrow-size, 8px),\n 50% 0,\n 100% var(--ds-arrow-size, 8px),\n 100% calc(100% - var(--ds-arrow-size, 8px)),\n 50% 100%,\n 0 calc(100% - var(--ds-arrow-size, 8px))\n );\n}\n\n/* Left and Right arrows (horizontal hexagon) */\n[data-ds-popover-arrow]::after {\n content: \"\";\n position: absolute;\n z-index: -1;\n background: inherit;\n top: 50%;\n transform: translateY(-50%);\n height: calc(var(--ds-arrow-size, 8px) * 2);\n width: calc(100% + var(--ds-arrow-size, 8px) * 2);\n left: calc(var(--ds-arrow-size, 8px) * -1);\n clip-path: polygon(\n var(--ds-arrow-size, 8px) 0,\n calc(100% - var(--ds-arrow-size, 8px)) 0,\n 100% 50%,\n calc(100% - var(--ds-arrow-size, 8px)) 100%,\n var(--ds-arrow-size, 8px) 100%,\n 0 50%\n );\n}\n\n/* \u2500\u2500 @position-try rules \u2500\u2500\n * One rule per possible position-area value.\n * Each sets the position-area and the correct margin direction\n * so the arrow on the anchor-facing side is revealed.\n *\n * Margin direction per edge:\n * block-start (above anchor) \u2192 margin-block-end (bottom, facing anchor)\n * block-end (below anchor) \u2192 margin-block-start (top, facing anchor)\n * inline-start (left of anchor) \u2192 margin-inline-end (right, facing anchor)\n * inline-end (right of anchor) \u2192 margin-inline-start (left, facing anchor)\n */\n\n/* Single-axis centered */\n@position-try --ds-arrow-block-start {\n position-area: block-start;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-block-end {\n position-area: block-end;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-inline-start {\n position-area: inline-start;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-inline-end {\n position-area: inline-end;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n}\n\n/* Block edge + inline span */\n@position-try --ds-arrow-block-start-span-inline-start {\n position-area: block-start span-inline-start;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-block-start-span-inline-end {\n position-area: block-start span-inline-end;\n margin: 0;\n margin-block-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-block-end-span-inline-start {\n position-area: block-end span-inline-start;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-block-end-span-inline-end {\n position-area: block-end span-inline-end;\n margin: 0;\n margin-block-start: var(--ds-arrow-size, 8px);\n}\n\n/* Inline edge + block span */\n@position-try --ds-arrow-inline-start-span-block-start {\n position-area: inline-start span-block-start;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-inline-start-span-block-end {\n position-area: inline-start span-block-end;\n margin: 0;\n margin-inline-end: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-inline-end-span-block-start {\n position-area: inline-end span-block-start;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n}\n@position-try --ds-arrow-inline-end-span-block-end {\n position-area: inline-end span-block-end;\n margin: 0;\n margin-inline-start: var(--ds-arrow-size, 8px);\n}\n";
|
|
23
|
+
|
|
24
|
+
// ── Placement utilities ──
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Converts a `position-area` value to a CSS rule name by replacing spaces with hyphens
|
|
28
|
+
* and prepending `--ds-arrow-`.
|
|
29
|
+
*
|
|
30
|
+
* @example positionAreaToRuleName('block-end span-inline-start') → '--ds-arrow-block-end-span-inline-start'
|
|
31
|
+
*/
|
|
32
|
+
function positionAreaToRuleName(_ref) {
|
|
33
|
+
var positionArea = _ref.positionArea;
|
|
34
|
+
return "--ds-arrow-".concat(positionArea.replace(/ /g, '-'));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns `position-try-fallbacks` using named `@position-try` rules
|
|
39
|
+
* that change both `position-area` and `margin` when flipping.
|
|
40
|
+
*
|
|
41
|
+
* This is required for the arrow technique because built-in keywords
|
|
42
|
+
* (`flip-block`, `flip-inline`) only flip `position-area` — they do
|
|
43
|
+
* not update the margin direction needed to reveal the correct arrow.
|
|
44
|
+
*/
|
|
45
|
+
function getTryFallbacks(_ref2) {
|
|
46
|
+
var placement = _ref2.placement;
|
|
47
|
+
var _getPlacement = getPlacement({
|
|
48
|
+
placement: placement
|
|
49
|
+
}),
|
|
50
|
+
axis = _getPlacement.axis,
|
|
51
|
+
edge = _getPlacement.edge,
|
|
52
|
+
align = _getPlacement.align;
|
|
53
|
+
if (align === 'center') {
|
|
54
|
+
// Single-axis: only flip the edge
|
|
55
|
+
var _flippedEdge = edge === 'start' ? 'end' : 'start';
|
|
56
|
+
return positionAreaToRuleName({
|
|
57
|
+
positionArea: placementToPositionArea({
|
|
58
|
+
placement: {
|
|
59
|
+
axis: axis,
|
|
60
|
+
edge: _flippedEdge
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Compound placement: try flipping edge, alignment, and both
|
|
67
|
+
var flippedEdge = edge === 'start' ? 'end' : 'start';
|
|
68
|
+
var flippedAlign = align === 'start' ? 'end' : 'start';
|
|
69
|
+
return [positionAreaToRuleName({
|
|
70
|
+
positionArea: placementToPositionArea({
|
|
71
|
+
placement: {
|
|
72
|
+
axis: axis,
|
|
73
|
+
edge: flippedEdge,
|
|
74
|
+
align: align
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}), positionAreaToRuleName({
|
|
78
|
+
positionArea: placementToPositionArea({
|
|
79
|
+
placement: {
|
|
80
|
+
axis: axis,
|
|
81
|
+
edge: edge,
|
|
82
|
+
align: flippedAlign
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}), positionAreaToRuleName({
|
|
86
|
+
positionArea: placementToPositionArea({
|
|
87
|
+
placement: {
|
|
88
|
+
axis: axis,
|
|
89
|
+
edge: flippedEdge,
|
|
90
|
+
align: flippedAlign
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
})].join(', ');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates an arrow preset for popover content.
|
|
98
|
+
*
|
|
99
|
+
* The returned object is passed to `PopoverContent`'s `arrow` prop.
|
|
100
|
+
* It carries the CSS string and fallback logic so that consumers who
|
|
101
|
+
* don't use arrows pay no bundle cost.
|
|
102
|
+
*
|
|
103
|
+
* The arrows inherit their background from the popover element.
|
|
104
|
+
* When `arrow` is active, `PopoverContent` does not reset `background`
|
|
105
|
+
* to `transparent`, allowing the UA default (`canvas`) or a consumer-set
|
|
106
|
+
* background to show through.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```tsx
|
|
110
|
+
* import { arrow } from '@atlaskit/top-layer/arrow';
|
|
111
|
+
*
|
|
112
|
+
* const myArrow = arrow();
|
|
113
|
+
*
|
|
114
|
+
* <Popup.Content arrow={myArrow} />
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export var arrow = once(function () {
|
|
118
|
+
return {
|
|
119
|
+
name: 'arrow',
|
|
120
|
+
css: ARROW_CSS,
|
|
121
|
+
getTryFallbacks: getTryFallbacks
|
|
122
|
+
};
|
|
123
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a synthetic DOM event from a `TDialogCloseReason`.
|
|
3
|
+
*
|
|
4
|
+
* Useful when bridging the Dialog primitive's `onClose({ reason })` callback
|
|
5
|
+
* to a legacy API that expects a `KeyboardEvent` or `MouseEvent` — for example,
|
|
6
|
+
* `@atlaskit/modal-dialog`'s `onClose(event, analyticsEvent)` contract.
|
|
7
|
+
*
|
|
8
|
+
* - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
|
|
9
|
+
* - `'overlay-click'` → `MouseEvent('click')`
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { createCloseEvent } from '@atlaskit/top-layer/create-close-event';
|
|
14
|
+
* import { type TDialogCloseReason } from '@atlaskit/top-layer/dialog';
|
|
15
|
+
*
|
|
16
|
+
* function onDialogClose({ reason }: { reason: TDialogCloseReason }) {
|
|
17
|
+
* legacyOnClose(createCloseEvent({ reason }));
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createCloseEvent(_ref) {
|
|
22
|
+
var reason = _ref.reason;
|
|
23
|
+
if (reason === 'escape') {
|
|
24
|
+
return new KeyboardEvent('keydown', {
|
|
25
|
+
key: 'Escape',
|
|
26
|
+
bubbles: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return new MouseEvent('click', {
|
|
30
|
+
bubbles: true,
|
|
31
|
+
cancelable: true
|
|
32
|
+
});
|
|
33
|
+
}
|