@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,21 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Moves focus into a popover element when it opens, based on its ARIA role.
|
|
4
|
+
*
|
|
5
|
+
* This implements WCAG 2.4.3 (Focus Order) initial focus placement:
|
|
6
|
+
* - `dialog` / `alertdialog` → focus first focusable (or `[autofocus]`)
|
|
7
|
+
* - `menu` → focus first menu item
|
|
8
|
+
* - `listbox` → focus selected or first option
|
|
9
|
+
* - `tooltip` / no role → no focus movement
|
|
10
|
+
*
|
|
11
|
+
* The role is read from the element's `role` attribute (not passed as a prop),
|
|
12
|
+
* following the same pattern as `useFocusWrap`.
|
|
13
|
+
*
|
|
14
|
+
* Always call this hook unconditionally. Focus is only moved when `isOpen`
|
|
15
|
+
* transitions to `true` and the role requires it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useInitialFocus({ elementRef, isOpen, role, }: {
|
|
18
|
+
elementRef: RefObject<HTMLElement | null>;
|
|
19
|
+
isOpen: boolean;
|
|
20
|
+
role: string | undefined;
|
|
21
|
+
}): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type TPresetWithCssAndName = {
|
|
2
|
+
css: string;
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes a preset prop to a value (or null) and ensures its CSS
|
|
7
|
+
* is injected once into `document.head`.
|
|
8
|
+
*
|
|
9
|
+
* Works with any preset that has `{ css, name }` — animation presets
|
|
10
|
+
* (TAnimationPreset) and arrow presets (TArrowPreset) both satisfy this shape.
|
|
11
|
+
*/
|
|
12
|
+
export declare function usePresetStyles<T extends TPresetWithCssAndName>({ preset, }: {
|
|
13
|
+
preset: T | false | null | undefined;
|
|
14
|
+
}): T | null;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type TPlacement } from '../internal/resolve-placement';
|
|
2
|
+
import { type TPlacementOptions } from '../popup/types';
|
|
3
|
+
/**
|
|
4
|
+
* Legacy Popper.js placement values (used by `@atlaskit/popper`, `@atlaskit/popup`,
|
|
5
|
+
* `@atlaskit/tooltip`, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export type TLegacyPlacement = 'auto' | 'auto-start' | 'auto-end' | 'top' | 'top-start' | 'top-center' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-center' | 'bottom-end' | 'right' | 'right-start' | 'right-end' | 'left' | 'left-start' | 'left-end';
|
|
8
|
+
/**
|
|
9
|
+
* Maps legacy Popper.js placement values to the new object-based
|
|
10
|
+
* `Placement` values used by `@atlaskit/top-layer/popover`.
|
|
11
|
+
*
|
|
12
|
+
* **Mapping logic:**
|
|
13
|
+
*
|
|
14
|
+
* | Legacy (Popper.js) | New (Placement object) |
|
|
15
|
+
* | ------------------- | --------------------------------------------------- |
|
|
16
|
+
* | `top` | `{ axis: 'block', edge: 'start', align: 'center' }` |
|
|
17
|
+
* | `top-start` | `{ axis: 'block', edge: 'start', align: 'start' }` |
|
|
18
|
+
* | `top-end` | `{ axis: 'block', edge: 'start', align: 'end' }` |
|
|
19
|
+
* | `bottom` | `{ axis: 'block', edge: 'end', align: 'center' }` |
|
|
20
|
+
* | `bottom-start` | `{ axis: 'block', edge: 'end', align: 'start' }` |
|
|
21
|
+
* | `bottom-end` | `{ axis: 'block', edge: 'end', align: 'end' }` |
|
|
22
|
+
* | `right` | `{ axis: 'inline', edge: 'end', align: 'center' }` |
|
|
23
|
+
* | `right-start` | `{ axis: 'inline', edge: 'end', align: 'start' }` |
|
|
24
|
+
* | `right-end` | `{ axis: 'inline', edge: 'end', align: 'end' }` |
|
|
25
|
+
* | `left` | `{ axis: 'inline', edge: 'start', align: 'center' }` |
|
|
26
|
+
* | `left-start` | `{ axis: 'inline', edge: 'start', align: 'start' }` |
|
|
27
|
+
* | `left-end` | `{ axis: 'inline', edge: 'start', align: 'end' }` |
|
|
28
|
+
* | `auto` | `{ axis: 'block', edge: 'end', align: 'center' }` |
|
|
29
|
+
* | `auto-start` | `{ axis: 'block', edge: 'end', align: 'start' }` |
|
|
30
|
+
* | `auto-end` | `{ axis: 'block', edge: 'end', align: 'end' }` |
|
|
31
|
+
*
|
|
32
|
+
* The `position-try-fallbacks` CSS property handles flipping automatically.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { fromLegacyPlacement } from '@atlaskit/top-layer/placement-map';
|
|
37
|
+
*
|
|
38
|
+
* // In a migration from @atlaskit/popup:
|
|
39
|
+
* const oldPlacement: TLegacyPlacement = 'bottom-start';
|
|
40
|
+
* const newPlacement: TPlacementOptions = fromLegacyPlacement({ legacy: oldPlacement });
|
|
41
|
+
* // newPlacement === { axis: 'block', edge: 'end', align: 'start' }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare const placementMapping: Record<TLegacyPlacement, TPlacement>;
|
|
45
|
+
/**
|
|
46
|
+
* Convert a legacy Popper.js placement to the new CSS `position-area`-based Placement.
|
|
47
|
+
*/
|
|
48
|
+
export declare function fromLegacyPlacement({ legacy }: {
|
|
49
|
+
legacy: TLegacyPlacement;
|
|
50
|
+
}): TPlacementOptions;
|
|
51
|
+
/**
|
|
52
|
+
* The full mapping record, exposed for consumers that need to iterate or introspect.
|
|
53
|
+
*/
|
|
54
|
+
export { placementMapping };
|
|
55
|
+
export type { TPlacementOptions };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type TPopoverCloseReason } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a synthetic DOM event from a `TPopoverCloseReason`.
|
|
4
|
+
*
|
|
5
|
+
* Useful when bridging the Popover primitive's `onClose({ reason })` callback
|
|
6
|
+
* to a legacy API that expects a native DOM event — for example,
|
|
7
|
+
* `@atlaskit/inline-dialog`'s `onClose(event)` contract.
|
|
8
|
+
*
|
|
9
|
+
* - `'escape'` → `KeyboardEvent('keydown', { key: 'Escape' })`
|
|
10
|
+
* - `'light-dismiss'` → `MouseEvent('click')`
|
|
11
|
+
*
|
|
12
|
+
* For any other reason, a generic `Event('close')` is returned as a fallback.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { createPopoverCloseEvent } from '@atlaskit/top-layer/create-close-event';
|
|
17
|
+
* import { type TPopoverCloseReason } from '@atlaskit/top-layer/popover';
|
|
18
|
+
*
|
|
19
|
+
* function onPopoverClose({ reason }: { reason: TPopoverCloseReason }) {
|
|
20
|
+
* legacyOnClose(createPopoverCloseEvent({ reason }));
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createPopoverCloseEvent({ reason, }: {
|
|
25
|
+
reason: TPopoverCloseReason;
|
|
26
|
+
}): KeyboardEvent | MouseEvent | Event;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { type TPopoverForwardedProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Unopinionated top-layer primitive.
|
|
9
|
+
*
|
|
10
|
+
* Manages only visibility (isOpen) and animation (animate). Has no knowledge
|
|
11
|
+
* of positioning — compose with `useAnchorPosition` for anchor positioning.
|
|
12
|
+
*
|
|
13
|
+
* Visibility is driven by the `isOpen` prop:
|
|
14
|
+
* - `isOpen={true}` → `showPopover()`, entry animation via `@starting-style`
|
|
15
|
+
* - `isOpen={false}` → `hidePopover()`, exit animation via `allow-discrete`
|
|
16
|
+
*
|
|
17
|
+
* For `mode="auto"`, the browser can dismiss the popover via light dismiss
|
|
18
|
+
* (Escape, click outside). When that happens, `onClose` is called and the
|
|
19
|
+
* consumer must set `isOpen` to `false`. The DOM owns the dismiss — React
|
|
20
|
+
* must follow.
|
|
21
|
+
*/
|
|
22
|
+
export declare const Popover: React.ForwardRefExoticComponent<TPopoverForwardedProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type TAnimationPreset } from '../animations/types';
|
|
3
|
+
import { type TAriaRoleOptional, type TRoleRequiringAccessibleName, type TRoleWithImplicitName } from '../internal/role-types';
|
|
4
|
+
import { type TPlacementOptions } from '../popup/types';
|
|
5
|
+
/**
|
|
6
|
+
* The reason a popover was dismissed via light dismiss.
|
|
7
|
+
*
|
|
8
|
+
* - `'escape'`: The user pressed the Escape key.
|
|
9
|
+
* - `'light-dismiss'`: The user clicked outside the popover (or the browser
|
|
10
|
+
* dismissed it for another auto-mode reason).
|
|
11
|
+
*/
|
|
12
|
+
export type TPopoverCloseReason = 'escape' | 'light-dismiss';
|
|
13
|
+
/**
|
|
14
|
+
* Flat (non-discriminated) props accepted by the Popover component internally.
|
|
15
|
+
*
|
|
16
|
+
* TypeScript limitation: when PopupContent destructures props from a
|
|
17
|
+
* discriminated union (role, label, labelledBy) and re-passes them individually
|
|
18
|
+
* to Popover, TypeScript cannot prove the individual fields still satisfy the
|
|
19
|
+
* union constraint. This flat type accepts all role/label combinations without
|
|
20
|
+
* the union, since ARIA correctness is enforced at the TPopupContentProps
|
|
21
|
+
* boundary where consumers interact.
|
|
22
|
+
*/
|
|
23
|
+
export type TPopoverForwardedProps = TPopoverBaseProps & {
|
|
24
|
+
mode?: 'auto' | 'hint' | 'manual';
|
|
25
|
+
onClose?: (args: {
|
|
26
|
+
reason: TPopoverCloseReason;
|
|
27
|
+
}) => void;
|
|
28
|
+
role?: TRoleRequiringAccessibleName | TRoleWithImplicitName;
|
|
29
|
+
label?: string;
|
|
30
|
+
labelledBy?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Alias for TPopoverForwardedProps.
|
|
34
|
+
*
|
|
35
|
+
* Used internally by PopupContent to forward props to Popover without
|
|
36
|
+
* re-proving the discriminated union at each call site.
|
|
37
|
+
*/
|
|
38
|
+
export type TPopoverInternalProps = TPopoverForwardedProps;
|
|
39
|
+
type TPopoverBaseProps = {
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
/**
|
|
42
|
+
* Animation preset for entry/exit transitions.
|
|
43
|
+
*
|
|
44
|
+
* Animations use `@starting-style` and `allow-discrete` for progressive
|
|
45
|
+
* enhancement: browsers without support show/hide instantly.
|
|
46
|
+
*/
|
|
47
|
+
animate?: false | TAnimationPreset;
|
|
48
|
+
/**
|
|
49
|
+
* Test ID applied to the popover element.
|
|
50
|
+
*/
|
|
51
|
+
testId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* HTML `id` attribute for the popover element. When omitted, a unique ID
|
|
54
|
+
* is generated automatically. The `<Popup>` compound passes its context ID
|
|
55
|
+
* so that `Popup.Trigger` can reference it via `aria-controls` / `popovertarget`.
|
|
56
|
+
*/
|
|
57
|
+
id?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether the popover is open.
|
|
60
|
+
*
|
|
61
|
+
* - **`true`:** show the popover (calls `showPopover()`, entry animation plays via `@starting-style`).
|
|
62
|
+
* - **`false`:** hide the popover. When an `animate` preset is provided, the exit
|
|
63
|
+
* animation plays (via `allow-discrete`) before the popover becomes logically closed.
|
|
64
|
+
* Otherwise hides instantly.
|
|
65
|
+
*
|
|
66
|
+
* The element stays mounted in the DOM at all times — the consumer does not
|
|
67
|
+
* conditionally render it. Visibility is driven by this prop.
|
|
68
|
+
*
|
|
69
|
+
* **Important:** For `mode="auto"` popovers, the browser can dismiss the popover
|
|
70
|
+
* via light dismiss (Escape, click outside) independently of this prop. When that
|
|
71
|
+
* happens, `onClose` is called — the consumer should respond by setting `isOpen`
|
|
72
|
+
* to `false`. If `isOpen` remains `true` after a browser dismiss, the DOM and
|
|
73
|
+
* React state will be out of sync (the popover will be hidden despite `isOpen={true}`).
|
|
74
|
+
*/
|
|
75
|
+
isOpen: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Called when the popover's open state changes via browser toggle events.
|
|
78
|
+
*
|
|
79
|
+
* Receives the new open state and a reference to the popover element,
|
|
80
|
+
* which is useful for focus management (e.g. focusing the first interactive
|
|
81
|
+
* child on open via `getFirstFocusable` from `@atlaskit/top-layer/focus`).
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* <Popover
|
|
86
|
+
* onOpenChange={({ isOpen, element }) => {
|
|
87
|
+
* if (isOpen) {
|
|
88
|
+
* getFirstFocusable({ container: element })?.focus();
|
|
89
|
+
* }
|
|
90
|
+
* }}
|
|
91
|
+
* />
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
onOpenChange?: (args: {
|
|
95
|
+
isOpen: boolean;
|
|
96
|
+
element: HTMLDivElement;
|
|
97
|
+
}) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Placement hint for directional animations (e.g. `slideAndFade`).
|
|
100
|
+
*
|
|
101
|
+
* When `animate` is provided, the preset's `getProperties(placement)` is
|
|
102
|
+
* called to set CSS custom properties (like `--ds-popover-tx`, `--ds-popover-ty`)
|
|
103
|
+
* that control the slide direction. Has no effect without `animate`.
|
|
104
|
+
*
|
|
105
|
+
* This does NOT control positioning — use `useAnchorPosition` for that.
|
|
106
|
+
*/
|
|
107
|
+
placement?: TPlacementOptions;
|
|
108
|
+
/**
|
|
109
|
+
* Called after the exit animation completes (or immediately on close when
|
|
110
|
+
* there is no animation or reduced motion is active).
|
|
111
|
+
*
|
|
112
|
+
* Use this for external lifecycle coordination — e.g. notifying a manager
|
|
113
|
+
* that the hide sequence is finished, or firing an `onCloseComplete` callback.
|
|
114
|
+
*/
|
|
115
|
+
onExitFinish?: () => void;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Unopinionated top-layer primitive.
|
|
119
|
+
*
|
|
120
|
+
* `Popover` manages only top-layer visibility and animation — it has no
|
|
121
|
+
* knowledge of positioning. For anchor positioning, compose with the
|
|
122
|
+
* `useAnchorPosition` hook separately.
|
|
123
|
+
*
|
|
124
|
+
* Use `Popover` directly for custom trigger lifecycles (hover, timers,
|
|
125
|
+
* external state) or trigger-less UI (flags, toasts). For the common
|
|
126
|
+
* button-opens-content pattern, use the `Popup` compound instead.
|
|
127
|
+
*
|
|
128
|
+
* Dismiss behavior:
|
|
129
|
+
* - `'auto'` (default): Escape to close, click-outside to close, focus restoration,
|
|
130
|
+
* automatic nesting, mutual exclusivity.
|
|
131
|
+
* - `'hint'`: ephemeral UI (e.g. tooltips) that doesn't close other `auto` popovers.
|
|
132
|
+
* Falls back to `'auto'` in browsers without `popover="hint"` support.
|
|
133
|
+
* - `'manual'`: no light dismiss. Consumer controls show/hide entirely. Only
|
|
134
|
+
* appropriate for persistent UI (e.g. flags, banners).
|
|
135
|
+
*/
|
|
136
|
+
export type TPopoverProps = TPopoverBaseProps & TAriaRoleOptional & ({
|
|
137
|
+
mode?: 'auto' | 'hint';
|
|
138
|
+
/**
|
|
139
|
+
* Called when the popover is dismissed via light dismiss
|
|
140
|
+
* (Escape, click outside).
|
|
141
|
+
*
|
|
142
|
+
* The `reason` field indicates how the dismiss occurred:
|
|
143
|
+
* - `'escape'`: the user pressed the Escape key.
|
|
144
|
+
* - `'light-dismiss'`: the user clicked outside (or another auto-dismiss).
|
|
145
|
+
*/
|
|
146
|
+
onClose?: (args: {
|
|
147
|
+
reason: TPopoverCloseReason;
|
|
148
|
+
}) => void;
|
|
149
|
+
} | {
|
|
150
|
+
mode: 'manual';
|
|
151
|
+
onClose?: never;
|
|
152
|
+
});
|
|
153
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PopupRoot } from './popup';
|
|
2
|
+
import { PopupContent } from './popup-content';
|
|
3
|
+
import { PopupSurface } from './popup-surface';
|
|
4
|
+
import { PopupTrigger } from './popup-trigger';
|
|
5
|
+
import { PopupTriggerFunction } from './popup-trigger-function';
|
|
6
|
+
/**
|
|
7
|
+
* Compound component for rendering content in the browser's top layer
|
|
8
|
+
* using the native Popover API (`popover="auto"`).
|
|
9
|
+
* Placement is owned by this compound: root provides it via context, Content applies it
|
|
10
|
+
* (CSS Anchor Positioning or JS fallback).
|
|
11
|
+
*
|
|
12
|
+
* For default overlay styling (background, shadow, border-radius), see `PopupSurface` in the package examples.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Popup placement={{ edge: 'end' }} onClose={handleClose}>
|
|
17
|
+
* <Popup.Trigger>
|
|
18
|
+
* <button>Open</button>
|
|
19
|
+
* </Popup.Trigger>
|
|
20
|
+
* <Popup.Content role="dialog" label="My popup">
|
|
21
|
+
* Content goes here
|
|
22
|
+
* </Popup.Content>
|
|
23
|
+
* </Popup>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const Popup: typeof PopupRoot & {
|
|
27
|
+
Trigger: typeof PopupTrigger;
|
|
28
|
+
TriggerFunction: typeof PopupTriggerFunction;
|
|
29
|
+
Content: typeof PopupContent;
|
|
30
|
+
Surface: typeof PopupSurface;
|
|
31
|
+
};
|
|
32
|
+
export { Popup };
|
|
33
|
+
export type { TPlacementOptions, TPopupProps, TPopupContentProps, TPopupRole, TPopupSurfaceProps, TPopupTriggerProps, } from './types';
|
|
34
|
+
export type { TTriggerFunctionRenderProps } from './popup-trigger-function';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { type TPopupContentProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Thin context wrapper that composes `Popover` + `useAnchorPosition`.
|
|
9
|
+
*
|
|
10
|
+
* Used inside the `<Popup>` compound — reads triggerRef, placement, isOpen,
|
|
11
|
+
* and onClose from context. For standalone usage (tooltip, spotlight, flag),
|
|
12
|
+
* use `Popover` + `useAnchorPosition` directly.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PopupContent: React.ForwardRefExoticComponent<TPopupContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React, { type MutableRefObject, type RefObject } from 'react';
|
|
2
|
+
import { type TAriaHasPopupValue } from '../internal/role-types';
|
|
3
|
+
import { type TPopoverCloseReason } from '../popover/types';
|
|
4
|
+
import { type TPlacementOptions } from './types';
|
|
5
|
+
export type TPopupContextValue = {
|
|
6
|
+
/**
|
|
7
|
+
* Auto-generated ID for the popover content element (used for aria-controls).
|
|
8
|
+
*/
|
|
9
|
+
popoverId: string;
|
|
10
|
+
/**
|
|
11
|
+
* Requested placement.
|
|
12
|
+
*/
|
|
13
|
+
placement: TPlacementOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Called when the popover is dismissed via light dismiss.
|
|
16
|
+
* `null` when mode is 'manual' (no light dismiss).
|
|
17
|
+
*/
|
|
18
|
+
onClose: ((args: {
|
|
19
|
+
reason: TPopoverCloseReason;
|
|
20
|
+
}) => void) | null;
|
|
21
|
+
/**
|
|
22
|
+
* Mutable ref to the trigger element (set by Popup.Trigger / Popup.TriggerFunction).
|
|
23
|
+
*/
|
|
24
|
+
triggerRef: MutableRefObject<HTMLElement | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Ref to the popover content element (set by Popup.Content).
|
|
27
|
+
*/
|
|
28
|
+
popoverRef: RefObject<HTMLDivElement | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the popover is currently open.
|
|
31
|
+
*/
|
|
32
|
+
isOpen: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Set the open state (internal context sync).
|
|
35
|
+
*/
|
|
36
|
+
setIsOpen: (open: boolean) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Consumer's onOpenChange callback, forwarded to the Popover.
|
|
39
|
+
*/
|
|
40
|
+
onOpenChange?: (args: {
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
element: HTMLDivElement;
|
|
43
|
+
}) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Native popover mode. Flows from the Popup root to Content via context.
|
|
46
|
+
*/
|
|
47
|
+
mode: 'auto' | 'hint' | 'manual';
|
|
48
|
+
/**
|
|
49
|
+
* The `aria-haspopup` value derived from the content's role.
|
|
50
|
+
*
|
|
51
|
+
* Set by `Popup.Content` via `setAriaHasPopup` when it renders.
|
|
52
|
+
* Read by `Popup.Trigger` / `Popup.TriggerFunction` to set
|
|
53
|
+
* the correct `aria-haspopup` on the trigger element.
|
|
54
|
+
*
|
|
55
|
+
* This flows the content's role to the trigger without requiring
|
|
56
|
+
* the consumer to specify the role in two places. The trigger
|
|
57
|
+
* renders with the default ('dialog') on first paint; Content's
|
|
58
|
+
* layout effect updates it before the browser paints.
|
|
59
|
+
*/
|
|
60
|
+
ariaHasPopup: TAriaHasPopupValue;
|
|
61
|
+
/**
|
|
62
|
+
* Updates `ariaHasPopup` — called by Content on mount/role change.
|
|
63
|
+
*/
|
|
64
|
+
setAriaHasPopup: (value: TAriaHasPopupValue) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Test ID prefix.
|
|
67
|
+
*/
|
|
68
|
+
testId?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Forces the JavaScript positioning fallback even when the browser
|
|
71
|
+
* supports CSS Anchor Positioning. Useful for testing fallback
|
|
72
|
+
* behavior in any environment, including production.
|
|
73
|
+
*/
|
|
74
|
+
forceFallbackPositioning?: boolean;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* __Popup provider__
|
|
78
|
+
*
|
|
79
|
+
* Provides shared popup state (placement, popoverId, triggerRef,
|
|
80
|
+
* isOpen, onClose) to compound child components such as `Popup.Trigger` and
|
|
81
|
+
* `Popup.Content`.
|
|
82
|
+
*/
|
|
83
|
+
export declare const PopupProvider: React.Provider<TPopupContextValue | null>;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the nearest `Popup` context value.
|
|
86
|
+
*
|
|
87
|
+
* Throws if called outside of a `<Popup>` compound component.
|
|
88
|
+
*/
|
|
89
|
+
export declare function usePopupContext(): TPopupContextValue;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the popup context if available, or `null` when used outside `<Popup>`.
|
|
92
|
+
*
|
|
93
|
+
* Used by `PopupContent` to support standalone usage (e.g. tooltip)
|
|
94
|
+
* where values are passed as props instead of coming from a compound component.
|
|
95
|
+
*/
|
|
96
|
+
export declare function useMaybePopupContext(): TPopupContextValue | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { type TPopupSurfaceProps } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Optional styled wrapper for popup content.
|
|
9
|
+
*
|
|
10
|
+
* Adds default visual styling (background, border-radius, box-shadow)
|
|
11
|
+
* using design tokens. Consumers who want fully custom styling
|
|
12
|
+
* should use `Popup.Content` without wrapping in `PopupSurface`.
|
|
13
|
+
*
|
|
14
|
+
* Exposed as `Popup.Surface` on the compound component.
|
|
15
|
+
*/
|
|
16
|
+
export declare function PopupSurface({ children }: TPopupSurfaceProps): React.ReactElement;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React, { type ReactNode, type RefCallback } from 'react';
|
|
2
|
+
import { type TAriaHasPopupValue } from '../internal/role-types';
|
|
3
|
+
/**
|
|
4
|
+
* Props passed to the `TriggerFunction` render-prop child.
|
|
5
|
+
*/
|
|
6
|
+
export type TTriggerFunctionRenderProps = {
|
|
7
|
+
/**
|
|
8
|
+
* Ref callback to attach to the trigger element. Sets `triggerRef` in
|
|
9
|
+
* popup context for anchor positioning and `togglePopover`.
|
|
10
|
+
*/
|
|
11
|
+
ref: RefCallback<HTMLElement>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the popover content is currently visible.
|
|
14
|
+
* Use for `aria-expanded` and conditional styling.
|
|
15
|
+
*/
|
|
16
|
+
isOpen: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* ID of the popover content element. Use for `aria-controls`.
|
|
19
|
+
*/
|
|
20
|
+
popoverId: string;
|
|
21
|
+
/**
|
|
22
|
+
* Toggle the popover open/closed via the native Popover API.
|
|
23
|
+
*
|
|
24
|
+
* Calling `toggle()` invokes `popoverEl.togglePopover()` on the
|
|
25
|
+
* underlying content element. This hides the imperative DOM API
|
|
26
|
+
* behind a stable function reference.
|
|
27
|
+
*/
|
|
28
|
+
toggle: () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Pre-composed ARIA attributes for the trigger element.
|
|
31
|
+
*
|
|
32
|
+
* Spread these onto your trigger: `{...ariaAttributes}`.
|
|
33
|
+
*
|
|
34
|
+
* Contains:
|
|
35
|
+
* - `aria-expanded`: whether the popover is open
|
|
36
|
+
* - `aria-controls`: ID of the popover content
|
|
37
|
+
* - `aria-haspopup`: derived from the content's ARIA role via context
|
|
38
|
+
*
|
|
39
|
+
* **Note on `aria-haspopup`:** When the content's role maps to a specific
|
|
40
|
+
* popup type (`'menu'`, `'dialog'`, `'listbox'`, etc.), the corresponding
|
|
41
|
+
* string value is used. For unmapped roles, the value is `true` (boolean).
|
|
42
|
+
* React serialises `aria-haspopup={true}` as `aria-haspopup="true"` in the
|
|
43
|
+
* DOM, which is the correct default per the HTML spec. The values can be
|
|
44
|
+
* spread directly onto trigger elements without conversion.
|
|
45
|
+
*/
|
|
46
|
+
ariaAttributes: {
|
|
47
|
+
'aria-expanded': boolean;
|
|
48
|
+
'aria-controls': string;
|
|
49
|
+
'aria-haspopup': TAriaHasPopupValue;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
type TPopupTriggerFunctionProps = {
|
|
53
|
+
/**
|
|
54
|
+
* Render-prop function that receives trigger props.
|
|
55
|
+
*
|
|
56
|
+
* Unlike `Popup.Trigger`, this does not use `cloneElement` — the consumer
|
|
57
|
+
* is responsible for spreading ref, ARIA attributes, and attaching `toggle`
|
|
58
|
+
* to the appropriate event(s).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* <Popup.TriggerFunction>
|
|
63
|
+
* {({ ref, toggle, ariaAttributes }) => (
|
|
64
|
+
* <button ref={ref} onClick={toggle} {...ariaAttributes}>
|
|
65
|
+
* Open menu
|
|
66
|
+
* </button>
|
|
67
|
+
* )}
|
|
68
|
+
* </Popup.TriggerFunction>
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* **Note:** This sub-component uses a render-prop pattern and is not
|
|
72
|
+
* compatible with React Server Components (RSC). It must be used
|
|
73
|
+
* inside a client component boundary (`'use client'`).
|
|
74
|
+
*/
|
|
75
|
+
children: (props: TTriggerFunctionRenderProps) => ReactNode;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Render-prop alternative to `Popup.Trigger`.
|
|
79
|
+
*
|
|
80
|
+
* Use when you need full control over the trigger element — for example,
|
|
81
|
+
* to compose your own trigger with custom event handlers, wrap a third-party
|
|
82
|
+
* component, or build a trigger from multiple elements.
|
|
83
|
+
*
|
|
84
|
+
* `Popup.Trigger` uses `cloneElement` internally, which limits composability.
|
|
85
|
+
* `Popup.TriggerFunction` hands you the raw props and lets you wire them up.
|
|
86
|
+
*
|
|
87
|
+
* **Note:** This sub-component uses a render-prop pattern and is not
|
|
88
|
+
* compatible with React Server Components (RSC). It must be used inside
|
|
89
|
+
* a client component boundary (`'use client'`).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```tsx
|
|
93
|
+
* <Popup placement={{ edge: 'end' }} onClose={handleClose}>
|
|
94
|
+
* <Popup.TriggerFunction>
|
|
95
|
+
* {({ ref, toggle, ariaAttributes }) => (
|
|
96
|
+
* <button ref={ref} onClick={toggle} {...ariaAttributes}>
|
|
97
|
+
* Open
|
|
98
|
+
* </button>
|
|
99
|
+
* )}
|
|
100
|
+
* </Popup.TriggerFunction>
|
|
101
|
+
* <Popup.Content role="dialog" label="My popup">
|
|
102
|
+
* Content
|
|
103
|
+
* </Popup.Content>
|
|
104
|
+
* </Popup>
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function PopupTriggerFunction({ children }: TPopupTriggerFunctionProps): React.ReactNode;
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type TPopupTriggerProps } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps the trigger element. Attaches aria attributes and handles
|
|
5
|
+
* click to toggle the popover. Sets the anchor-name on the trigger
|
|
6
|
+
* for CSS Anchor Positioning.
|
|
7
|
+
*
|
|
8
|
+
* `aria-haspopup` is derived from the content's role via context
|
|
9
|
+
* (set by `Popup.Content`). This ensures the trigger always matches
|
|
10
|
+
* the content's semantic role without the consumer specifying it
|
|
11
|
+
* in two places.
|
|
12
|
+
*
|
|
13
|
+
* **Limitation:** Uses `cloneElement` internally (via `Slot`), which is
|
|
14
|
+
* incompatible with Compiled's `css` prop on the direct child element.
|
|
15
|
+
* The `@jsx jsx` pragma transforms the child before `cloneElement` can
|
|
16
|
+
* inject `onClick` and `ref` onto the DOM node, preventing the popover
|
|
17
|
+
* from opening.
|
|
18
|
+
*
|
|
19
|
+
* If you need Compiled `css` on the trigger, use `Popup.TriggerFunction`
|
|
20
|
+
* instead — it hands you raw props via a render-prop and avoids
|
|
21
|
+
* `cloneElement` entirely.
|
|
22
|
+
*/
|
|
23
|
+
export declare function PopupTrigger({ children }: TPopupTriggerProps): ReactNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type TPopupProps } from './types';
|
|
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 declare function PopupRoot(props: TPopupProps): React.ReactElement;
|