@box/blueprint-web 19.5.0 → 20.0.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/THIRD_PARTY_LICENSES +119 -0
- package/dist/lib-esm/accordion/accordion.js +14 -6
- package/dist/lib-esm/accordion/accordion.module.js +1 -1
- package/dist/lib-esm/accordion/types.d.ts +1 -1
- package/dist/lib-esm/blueprint-configuration-context/consts.d.ts +1 -1
- package/dist/lib-esm/blueprint-configuration-context/consts.js +1 -1
- package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
- package/dist/lib-esm/checkbox/types.d.ts +1 -1
- package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
- package/dist/lib-esm/collapsible/types.d.ts +1 -1
- package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
- package/dist/lib-esm/components.css +400 -280
- package/dist/lib-esm/date-picker/date-picker.js +8 -7
- package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
- package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
- package/dist/lib-esm/index.css +400 -280
- package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
- package/dist/lib-esm/modal/modal-close.js +2 -2
- package/dist/lib-esm/modal/modal-content.d.ts +1 -1
- package/dist/lib-esm/modal/modal-content.js +4 -4
- package/dist/lib-esm/modal/modal-description.js +2 -2
- package/dist/lib-esm/modal/modal-title.js +2 -2
- package/dist/lib-esm/modal/modal-trigger.js +2 -2
- package/dist/lib-esm/modal/modal.d.ts +1 -1
- package/dist/lib-esm/modal/modal.js +1 -1
- package/dist/lib-esm/modal/types.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
- package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
- package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
- package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/chip.js +2 -2
- package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
- package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
- package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
- package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
- package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
- package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
- package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
- package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
- package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
- package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
- package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
- package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
- package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
- package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
- package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
- package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
- package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
- package/dist/lib-esm/radio-group/index.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
- package/dist/lib-esm/radio-group/radio-group.js +2 -2
- package/dist/lib-esm/radio-group/radio-item.js +3 -3
- package/dist/lib-esm/radio-group/types.d.ts +1 -1
- package/dist/lib-esm/select/select.js +12 -12
- package/dist/lib-esm/select/types.d.ts +1 -1
- package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
- package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
- package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
- package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
- package/dist/lib-esm/side-panel/side-panel.js +1 -1
- package/dist/lib-esm/side-panel/types.d.ts +1 -1
- package/dist/lib-esm/small-list-item/small-list.js +8 -0
- package/dist/lib-esm/switch/switch-item.js +3 -3
- package/dist/lib-esm/switch/types.d.ts +1 -1
- package/dist/lib-esm/toolbar/index.d.ts +2 -2
- package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
- package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
- package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
- package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
- package/dist/lib-esm/toolbar/types.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
- package/dist/lib-esm/tooltip/tooltip.js +6 -6
- package/dist/lib-esm/tooltip/types.d.ts +1 -1
- package/dist/lib-esm/util-components/base-grid-list-item/base-grid-list-item.module.js +1 -1
- package/dist/lib-esm/utils/TooltipWrapper.d.ts +1 -1
- package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
- package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
- package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
- package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
- package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
- package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
- package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
- package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
- package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
- package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
- package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
- package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
- package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
- package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
- package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
- package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
- package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
- package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
- package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
- package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
- package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
- package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
- package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
- package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
- package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
- package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
- package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
- package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
- package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
- package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
- package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
- package/dist/lib-esm/utils/radix-compat/select.js +901 -0
- package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
- package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
- package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
- package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
- package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
- package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
- package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
- package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
- package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
- package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
- package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
- package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
- package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
- package/package.json +8 -19
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { Dialog, useDialogStore } from '@ariakit/react';
|
|
3
|
+
import { forwardRef, useContext, createContext, useRef, useCallback, useState, cloneElement, isValidElement, useId, useMemo, Children } from 'react';
|
|
4
|
+
import { RemoveScroll } from 'react-remove-scroll';
|
|
5
|
+
import { composeEventHandlers } from '../composeEventHandlers.js';
|
|
6
|
+
import { useControllableState } from '../useControllableState.js';
|
|
7
|
+
import { AllowAutoFocus } from './allow-auto-focus.js';
|
|
8
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
9
|
+
import { DismissMarker } from './dismiss-marker.js';
|
|
10
|
+
import { preventRightClickDismiss, useDismissable } from './dismissable.js';
|
|
11
|
+
import { useFocusScope } from './focus-scope.js';
|
|
12
|
+
import { useHideOthers } from './hide-others.js';
|
|
13
|
+
import { getPersistentElements } from './layers.js';
|
|
14
|
+
import { Portal as Portal$1 } from './portal.js';
|
|
15
|
+
import { Presence } from './presence.js';
|
|
16
|
+
import { Slot } from './slot.js';
|
|
17
|
+
import { overlayStoreOptions } from './store-options.js';
|
|
18
|
+
import { useStripViewportHeight } from './viewport-height.js';
|
|
19
|
+
|
|
20
|
+
const getState = open => open ? 'open' : 'closed';
|
|
21
|
+
const DialogContext = /*#__PURE__*/createContext(null);
|
|
22
|
+
function useDialogContext(consumerName) {
|
|
23
|
+
const context = useContext(DialogContext);
|
|
24
|
+
if (!context) {
|
|
25
|
+
throw new Error(`\`${consumerName}\` must be used within \`Dialog\``);
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Dialog with the Radix API and DOM, rendered by the Ariakit `Dialog`. Focus management and dismiss callbacks
|
|
31
|
+
* follow Radix; modality (inert outside content, scroll lock) is Ariakit's.
|
|
32
|
+
*/
|
|
33
|
+
const Root = props => {
|
|
34
|
+
const {
|
|
35
|
+
children,
|
|
36
|
+
open: openProp,
|
|
37
|
+
defaultOpen,
|
|
38
|
+
onOpenChange,
|
|
39
|
+
modal = true
|
|
40
|
+
} = props;
|
|
41
|
+
const triggerRef = useRef(null);
|
|
42
|
+
const contentRef = useRef(null);
|
|
43
|
+
const contentId = useId();
|
|
44
|
+
const titleId = useId();
|
|
45
|
+
const descriptionId = useId();
|
|
46
|
+
const [open = false, setOpen] = useControllableState({
|
|
47
|
+
prop: openProp,
|
|
48
|
+
defaultProp: defaultOpen,
|
|
49
|
+
onChange: onOpenChange
|
|
50
|
+
});
|
|
51
|
+
const store = useDialogStore({
|
|
52
|
+
...overlayStoreOptions,
|
|
53
|
+
open,
|
|
54
|
+
setOpen: nextOpen => {
|
|
55
|
+
if (!nextOpen) {
|
|
56
|
+
setOpen(false);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const onOpenToggle = useCallback(() => setOpen(prevOpen => !prevOpen), [setOpen]);
|
|
61
|
+
const onOpenChangeCallback = useCallback(nextOpen => setOpen(nextOpen), [setOpen]);
|
|
62
|
+
const value = useMemo(() => ({
|
|
63
|
+
triggerRef,
|
|
64
|
+
contentRef,
|
|
65
|
+
contentId,
|
|
66
|
+
titleId,
|
|
67
|
+
descriptionId,
|
|
68
|
+
open,
|
|
69
|
+
onOpenChange: onOpenChangeCallback,
|
|
70
|
+
onOpenToggle,
|
|
71
|
+
modal,
|
|
72
|
+
store
|
|
73
|
+
}), [contentId, titleId, descriptionId, open, onOpenChangeCallback, onOpenToggle, modal, store]);
|
|
74
|
+
return jsx(DialogContext.Provider, {
|
|
75
|
+
value: value,
|
|
76
|
+
children: children
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
Root.displayName = 'Dialog';
|
|
80
|
+
const Trigger = /*#__PURE__*/forwardRef(({
|
|
81
|
+
asChild,
|
|
82
|
+
...triggerProps
|
|
83
|
+
}, forwardedRef) => {
|
|
84
|
+
const context = useDialogContext('DialogTrigger');
|
|
85
|
+
const composedRefs = useComposedRefs(forwardedRef, context.triggerRef);
|
|
86
|
+
const Comp = asChild ? Slot : 'button';
|
|
87
|
+
return jsx(Comp, {
|
|
88
|
+
"aria-controls": context.contentId,
|
|
89
|
+
"aria-expanded": context.open,
|
|
90
|
+
"aria-haspopup": "dialog",
|
|
91
|
+
"data-state": getState(context.open),
|
|
92
|
+
type: "button",
|
|
93
|
+
...triggerProps,
|
|
94
|
+
ref: composedRefs,
|
|
95
|
+
onClick: composeEventHandlers(triggerProps.onClick, context.onOpenToggle)
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
Trigger.displayName = 'DialogTrigger';
|
|
99
|
+
/* -------------------------------------------------------------------------------------------------
|
|
100
|
+
* Portal
|
|
101
|
+
* -----------------------------------------------------------------------------------------------*/
|
|
102
|
+
const PortalContext = /*#__PURE__*/createContext({
|
|
103
|
+
forceMount: undefined
|
|
104
|
+
});
|
|
105
|
+
/** Portals each child separately, like Radix, so the overlay and the content can be siblings. */
|
|
106
|
+
const Portal = ({
|
|
107
|
+
forceMount,
|
|
108
|
+
children,
|
|
109
|
+
container
|
|
110
|
+
}) => {
|
|
111
|
+
const context = useDialogContext('DialogPortal');
|
|
112
|
+
return jsx(PortalContext.Provider, {
|
|
113
|
+
value: {
|
|
114
|
+
forceMount
|
|
115
|
+
},
|
|
116
|
+
children: Children.map(children, child => jsx(Presence, {
|
|
117
|
+
present: Boolean(forceMount) || context.open,
|
|
118
|
+
children: jsx(Portal$1, {
|
|
119
|
+
container: container,
|
|
120
|
+
children: child
|
|
121
|
+
})
|
|
122
|
+
}))
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
Portal.displayName = 'DialogPortal';
|
|
126
|
+
const Overlay = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
127
|
+
const portalContext = useContext(PortalContext);
|
|
128
|
+
const {
|
|
129
|
+
forceMount = portalContext.forceMount,
|
|
130
|
+
...overlayProps
|
|
131
|
+
} = props;
|
|
132
|
+
const context = useDialogContext('DialogOverlay');
|
|
133
|
+
return context.modal ? jsx(Presence, {
|
|
134
|
+
present: Boolean(forceMount) || context.open,
|
|
135
|
+
children: jsx(OverlayImpl, {
|
|
136
|
+
...overlayProps,
|
|
137
|
+
ref: forwardedRef
|
|
138
|
+
})
|
|
139
|
+
}) : null;
|
|
140
|
+
});
|
|
141
|
+
Overlay.displayName = 'DialogOverlay';
|
|
142
|
+
const OverlayImpl = /*#__PURE__*/forwardRef(({
|
|
143
|
+
asChild,
|
|
144
|
+
style,
|
|
145
|
+
...overlayProps
|
|
146
|
+
}, forwardedRef) => {
|
|
147
|
+
const context = useDialogContext('DialogOverlay');
|
|
148
|
+
const Comp = asChild ? Slot : 'div';
|
|
149
|
+
return (
|
|
150
|
+
// The content stays scrollable even when it isn't inside the overlay.
|
|
151
|
+
jsx(RemoveScroll, {
|
|
152
|
+
allowPinchZoom: true,
|
|
153
|
+
as: Slot,
|
|
154
|
+
shards: [context.contentRef],
|
|
155
|
+
children: jsx(Comp, {
|
|
156
|
+
"data-state": getState(context.open),
|
|
157
|
+
...overlayProps,
|
|
158
|
+
ref: forwardedRef,
|
|
159
|
+
style: {
|
|
160
|
+
pointerEvents: 'auto',
|
|
161
|
+
...style
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
168
|
+
const portalContext = useContext(PortalContext);
|
|
169
|
+
const {
|
|
170
|
+
forceMount = portalContext.forceMount,
|
|
171
|
+
...contentProps
|
|
172
|
+
} = props;
|
|
173
|
+
const context = useDialogContext('DialogContent');
|
|
174
|
+
return jsx(Presence, {
|
|
175
|
+
present: Boolean(forceMount) || context.open,
|
|
176
|
+
children: context.modal ? jsx(ContentModal, {
|
|
177
|
+
...contentProps,
|
|
178
|
+
ref: forwardedRef
|
|
179
|
+
}) : jsx(ContentNonModal, {
|
|
180
|
+
...contentProps,
|
|
181
|
+
ref: forwardedRef
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
Content.displayName = 'DialogContent';
|
|
186
|
+
const ContentModal = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
187
|
+
const context = useDialogContext('DialogContent');
|
|
188
|
+
const composedRefs = useComposedRefs(forwardedRef, context.contentRef);
|
|
189
|
+
return jsx(ContentImpl, {
|
|
190
|
+
...props,
|
|
191
|
+
ref: composedRefs,
|
|
192
|
+
// Focus is only trapped while open, so it can leave during the exit animation.
|
|
193
|
+
trapFocus: context.open,
|
|
194
|
+
onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
context.triggerRef.current?.focus();
|
|
197
|
+
}),
|
|
198
|
+
// A right click acts on the overlay, so it doesn't close the dialog.
|
|
199
|
+
onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, preventRightClickDismiss),
|
|
200
|
+
// A `focusout` event may still happen while focus is trapped.
|
|
201
|
+
onFocusOutside: composeEventHandlers(props.onFocusOutside, event => event.preventDefault())
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
const ContentNonModal = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
205
|
+
const {
|
|
206
|
+
onCloseAutoFocus,
|
|
207
|
+
onInteractOutside
|
|
208
|
+
} = props;
|
|
209
|
+
const {
|
|
210
|
+
triggerRef
|
|
211
|
+
} = useDialogContext('DialogContent');
|
|
212
|
+
const hasInteractedOutsideRef = useRef(false);
|
|
213
|
+
const hasPointerDownOutsideRef = useRef(false);
|
|
214
|
+
const handleCloseAutoFocus = useCallback(event => {
|
|
215
|
+
onCloseAutoFocus?.(event);
|
|
216
|
+
if (!event.defaultPrevented) {
|
|
217
|
+
if (!hasInteractedOutsideRef.current) {
|
|
218
|
+
triggerRef.current?.focus();
|
|
219
|
+
}
|
|
220
|
+
// Always prevent auto focus because we either focus manually or want user agent focus.
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
}
|
|
223
|
+
hasInteractedOutsideRef.current = false;
|
|
224
|
+
hasPointerDownOutsideRef.current = false;
|
|
225
|
+
}, [onCloseAutoFocus, triggerRef]);
|
|
226
|
+
const handleInteractOutside = useCallback(event => {
|
|
227
|
+
onInteractOutside?.(event);
|
|
228
|
+
if (!event.defaultPrevented) {
|
|
229
|
+
hasInteractedOutsideRef.current = true;
|
|
230
|
+
if (event.detail.originalEvent.type === 'pointerdown') {
|
|
231
|
+
hasPointerDownOutsideRef.current = true;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// The trigger toggles the dialog itself, so it must not dismiss it as an outside interaction.
|
|
235
|
+
const target = event.target;
|
|
236
|
+
if (triggerRef.current?.contains(target)) {
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
}
|
|
239
|
+
// Safari reports a focus outside after a pointer down outside on a focusable container.
|
|
240
|
+
if (event.detail.originalEvent.type === 'focusin' && hasPointerDownOutsideRef.current) {
|
|
241
|
+
event.preventDefault();
|
|
242
|
+
}
|
|
243
|
+
}, [onInteractOutside, triggerRef]);
|
|
244
|
+
return jsx(ContentImpl, {
|
|
245
|
+
...props,
|
|
246
|
+
ref: forwardedRef,
|
|
247
|
+
onCloseAutoFocus: handleCloseAutoFocus,
|
|
248
|
+
onInteractOutside: handleInteractOutside,
|
|
249
|
+
trapFocus: false
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
const ContentImpl = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
253
|
+
const {
|
|
254
|
+
trapFocus,
|
|
255
|
+
onOpenAutoFocus,
|
|
256
|
+
onCloseAutoFocus,
|
|
257
|
+
onEscapeKeyDown,
|
|
258
|
+
onPointerDownOutside,
|
|
259
|
+
onFocusOutside,
|
|
260
|
+
onInteractOutside,
|
|
261
|
+
asChild,
|
|
262
|
+
style,
|
|
263
|
+
children,
|
|
264
|
+
...contentProps
|
|
265
|
+
} = props;
|
|
266
|
+
const context = useDialogContext('DialogContent');
|
|
267
|
+
const [content, setContent] = useState(null);
|
|
268
|
+
const composedRefs = useComposedRefs(forwardedRef, setContent);
|
|
269
|
+
useHideOthers(content, context.modal);
|
|
270
|
+
useStripViewportHeight(content);
|
|
271
|
+
const focusScope = useFocusScope({
|
|
272
|
+
container: content,
|
|
273
|
+
loop: true,
|
|
274
|
+
trapped: trapFocus,
|
|
275
|
+
onMountAutoFocus: onOpenAutoFocus,
|
|
276
|
+
onUnmountAutoFocus: onCloseAutoFocus
|
|
277
|
+
});
|
|
278
|
+
const dismissable = useDismissable({
|
|
279
|
+
open: context.open,
|
|
280
|
+
disableOutsidePointerEvents: context.modal,
|
|
281
|
+
onDismiss: () => context.onOpenChange(false),
|
|
282
|
+
onEscapeKeyDown,
|
|
283
|
+
onPointerDownOutside,
|
|
284
|
+
onFocusOutside,
|
|
285
|
+
onInteractOutside
|
|
286
|
+
});
|
|
287
|
+
const marker = context.modal ? jsx(DismissMarker, {}) : null;
|
|
288
|
+
const child = asChild && /*#__PURE__*/isValidElement(children) ? children : null;
|
|
289
|
+
return jsxs(Dialog, {
|
|
290
|
+
alwaysVisible: true,
|
|
291
|
+
"aria-describedby": context.descriptionId,
|
|
292
|
+
"aria-labelledby": context.titleId,
|
|
293
|
+
autoFocusOnHide: false,
|
|
294
|
+
autoFocusOnShow: false,
|
|
295
|
+
backdrop: false,
|
|
296
|
+
"data-state": getState(context.open),
|
|
297
|
+
getPersistentElements: getPersistentElements,
|
|
298
|
+
hideOnEscape: false,
|
|
299
|
+
hideOnInteractOutside: dismissable.hideOnInteractOutside,
|
|
300
|
+
id: context.contentId,
|
|
301
|
+
modal: context.modal,
|
|
302
|
+
portal: false,
|
|
303
|
+
// The overlay locks scrolling, like in Radix.
|
|
304
|
+
preventBodyScroll: false,
|
|
305
|
+
render: child ? /*#__PURE__*/cloneElement(child, {}, jsx(AllowAutoFocus, {
|
|
306
|
+
children: child.props.children
|
|
307
|
+
}), marker) : undefined,
|
|
308
|
+
role: "dialog",
|
|
309
|
+
store: context.store,
|
|
310
|
+
...contentProps,
|
|
311
|
+
ref: composedRefs,
|
|
312
|
+
onKeyDown: composeEventHandlers(contentProps.onKeyDown, focusScope.onKeyDown),
|
|
313
|
+
onBlurCapture: composeEventHandlers(contentProps.onBlurCapture, dismissable.contentProps.onBlurCapture),
|
|
314
|
+
onFocusCapture: composeEventHandlers(contentProps.onFocusCapture, dismissable.contentProps.onFocusCapture),
|
|
315
|
+
onPointerDownCapture: composeEventHandlers(contentProps.onPointerDownCapture, dismissable.contentProps.onPointerDownCapture),
|
|
316
|
+
// Radix re-enabled pointer events on modal content while they were disabled on the body.
|
|
317
|
+
style: {
|
|
318
|
+
pointerEvents: context.modal ? 'auto' : undefined,
|
|
319
|
+
...style
|
|
320
|
+
},
|
|
321
|
+
children: [child ? undefined : jsx(AllowAutoFocus, {
|
|
322
|
+
children: children
|
|
323
|
+
}), child ? undefined : marker]
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
const Title = /*#__PURE__*/forwardRef(({
|
|
327
|
+
asChild,
|
|
328
|
+
...titleProps
|
|
329
|
+
}, forwardedRef) => {
|
|
330
|
+
const context = useDialogContext('DialogTitle');
|
|
331
|
+
const Comp = asChild ? Slot : 'h2';
|
|
332
|
+
return jsx(Comp, {
|
|
333
|
+
id: context.titleId,
|
|
334
|
+
...titleProps,
|
|
335
|
+
ref: forwardedRef
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
Title.displayName = 'DialogTitle';
|
|
339
|
+
const Description = /*#__PURE__*/forwardRef(({
|
|
340
|
+
asChild,
|
|
341
|
+
...descriptionProps
|
|
342
|
+
}, forwardedRef) => {
|
|
343
|
+
const context = useDialogContext('DialogDescription');
|
|
344
|
+
const Comp = asChild ? Slot : 'p';
|
|
345
|
+
return jsx(Comp, {
|
|
346
|
+
id: context.descriptionId,
|
|
347
|
+
...descriptionProps,
|
|
348
|
+
ref: forwardedRef
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
Description.displayName = 'DialogDescription';
|
|
352
|
+
const Close = /*#__PURE__*/forwardRef(({
|
|
353
|
+
asChild,
|
|
354
|
+
...closeProps
|
|
355
|
+
}, forwardedRef) => {
|
|
356
|
+
const context = useDialogContext('DialogClose');
|
|
357
|
+
const Comp = asChild ? Slot : 'button';
|
|
358
|
+
return jsx(Comp, {
|
|
359
|
+
type: "button",
|
|
360
|
+
...closeProps,
|
|
361
|
+
ref: forwardedRef,
|
|
362
|
+
onClick: composeEventHandlers(closeProps.onClick, () => context.onOpenChange(false))
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
Close.displayName = 'DialogClose';
|
|
366
|
+
|
|
367
|
+
export { Close, Content, Description, Overlay, Portal, Root, Title, Trigger };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells an Ariakit modal dialog that it has its own way to be dismissed, so it doesn't render its visually
|
|
3
|
+
* hidden "Dismiss popup" button next to the content, which Radix overlays never had.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DismissMarker: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tells an Ariakit modal dialog that it has its own way to be dismissed, so it doesn't render its visually
|
|
5
|
+
* hidden "Dismiss popup" button next to the content, which Radix overlays never had.
|
|
6
|
+
*/
|
|
7
|
+
const DismissMarker = () => jsx("span", {
|
|
8
|
+
"data-dialog-dismiss": "",
|
|
9
|
+
hidden: true
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export { DismissMarker };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type DismissableLayerProps, type PointerDownOutsideEvent } from './types';
|
|
2
|
+
interface UseDismissableOptions extends DismissableLayerProps {
|
|
3
|
+
/** Whether the layer is open. Outside interactions are only tracked while open. */
|
|
4
|
+
open: boolean;
|
|
5
|
+
/** Whether the layer is modal, so the layers below it don't react to pointer downs outside of them. */
|
|
6
|
+
disableOutsidePointerEvents?: boolean;
|
|
7
|
+
/** Closes the layer for an Escape key press. */
|
|
8
|
+
onDismiss: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Handles the dismissal of an overlay like the Radix dismissable layer, with its callbacks and event shapes.
|
|
12
|
+
*
|
|
13
|
+
* Escape is handled on the document, after the handlers inside the overlay ran, by the most recently opened
|
|
14
|
+
* layer only: `onEscapeKeyDown` can prevent the dismissal, and the key press keeps propagating, so the Ariakit
|
|
15
|
+
* overlays must not hide on Escape themselves. Outside interactions are handled on the document too:
|
|
16
|
+
* `onPointerDownOutside` runs on `pointerdown` (on the click that follows it for touch), `onFocusOutside` on
|
|
17
|
+
* `focusin`, and calling `preventDefault()` keeps the overlay open. Ariakit mustn't hide the overlay on outside
|
|
18
|
+
* interactions itself: once focus was inside, it ignores elements added to the page after the overlay opened.
|
|
19
|
+
*
|
|
20
|
+
* Returns the props for the Ariakit dialog and the capture handlers to spread on the content element,
|
|
21
|
+
* which keep pointer downs in React portals rendered from the content counted as inside.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useDismissable({ open, disableOutsidePointerEvents, onDismiss, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, }: UseDismissableOptions): {
|
|
24
|
+
hideOnInteractOutside: boolean;
|
|
25
|
+
hasInteractedOutsideRef: import("react").MutableRefObject<boolean>;
|
|
26
|
+
contentProps: {
|
|
27
|
+
onPointerDownCapture: () => void;
|
|
28
|
+
onFocusCapture: () => void;
|
|
29
|
+
onBlurCapture: () => void;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** Composes a Radix style outside handler so that right clicks and Ctrl + left clicks never dismiss. */
|
|
33
|
+
export declare function preventRightClickDismiss(event: PointerDownOutsideEvent): void;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { useCallbackRef } from '../useCallbackRef.js';
|
|
4
|
+
import { useLayer, isInsidePersistentElement } from './layers.js';
|
|
5
|
+
|
|
6
|
+
const POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
|
|
7
|
+
const FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
|
|
8
|
+
function dispatchOutsideEvent(name, originalEvent, handler, discrete) {
|
|
9
|
+
const target = originalEvent.target;
|
|
10
|
+
const event = new CustomEvent(name, {
|
|
11
|
+
bubbles: false,
|
|
12
|
+
cancelable: true,
|
|
13
|
+
detail: {
|
|
14
|
+
originalEvent
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
const listener = customEvent => handler(customEvent);
|
|
18
|
+
if (target && 'dispatchEvent' in target) {
|
|
19
|
+
target.addEventListener(name, listener, {
|
|
20
|
+
once: true
|
|
21
|
+
});
|
|
22
|
+
if (discrete) {
|
|
23
|
+
flushSync(() => target.dispatchEvent(event));
|
|
24
|
+
} else {
|
|
25
|
+
target.dispatchEvent(event);
|
|
26
|
+
}
|
|
27
|
+
target.removeEventListener(name, listener);
|
|
28
|
+
} else {
|
|
29
|
+
handler(event);
|
|
30
|
+
}
|
|
31
|
+
return event;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles the dismissal of an overlay like the Radix dismissable layer, with its callbacks and event shapes.
|
|
35
|
+
*
|
|
36
|
+
* Escape is handled on the document, after the handlers inside the overlay ran, by the most recently opened
|
|
37
|
+
* layer only: `onEscapeKeyDown` can prevent the dismissal, and the key press keeps propagating, so the Ariakit
|
|
38
|
+
* overlays must not hide on Escape themselves. Outside interactions are handled on the document too:
|
|
39
|
+
* `onPointerDownOutside` runs on `pointerdown` (on the click that follows it for touch), `onFocusOutside` on
|
|
40
|
+
* `focusin`, and calling `preventDefault()` keeps the overlay open. Ariakit mustn't hide the overlay on outside
|
|
41
|
+
* interactions itself: once focus was inside, it ignores elements added to the page after the overlay opened.
|
|
42
|
+
*
|
|
43
|
+
* Returns the props for the Ariakit dialog and the capture handlers to spread on the content element,
|
|
44
|
+
* which keep pointer downs in React portals rendered from the content counted as inside.
|
|
45
|
+
*/
|
|
46
|
+
function useDismissable({
|
|
47
|
+
open,
|
|
48
|
+
disableOutsidePointerEvents = false,
|
|
49
|
+
onDismiss,
|
|
50
|
+
onEscapeKeyDown,
|
|
51
|
+
onPointerDownOutside,
|
|
52
|
+
onFocusOutside,
|
|
53
|
+
onInteractOutside
|
|
54
|
+
}) {
|
|
55
|
+
const handleDismiss = useCallbackRef(onDismiss);
|
|
56
|
+
const handleEscapeKeyDown = useCallbackRef(onEscapeKeyDown);
|
|
57
|
+
const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
|
|
58
|
+
const handleFocusOutside = useCallbackRef(onFocusOutside);
|
|
59
|
+
const handleInteractOutside = useCallbackRef(onInteractOutside);
|
|
60
|
+
const isOpen = useCallbackRef(() => open);
|
|
61
|
+
const {
|
|
62
|
+
hasLayerAbove,
|
|
63
|
+
hasBlockingLayerAbove
|
|
64
|
+
} = useLayer('overlay', open, disableOutsidePointerEvents);
|
|
65
|
+
const isPointerInsideReactTreeRef = useRef(false);
|
|
66
|
+
const isFocusInsideReactTreeRef = useRef(false);
|
|
67
|
+
const hasInteractedOutsideRef = useRef(false);
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
if (open) {
|
|
70
|
+
hasInteractedOutsideRef.current = false;
|
|
71
|
+
}
|
|
72
|
+
}, [open]);
|
|
73
|
+
// Like with Radix, outside pointer downs are reported as long as the content is mounted, also while it closes,
|
|
74
|
+
// and dismiss it while it's open. A pointer down that is stopped before it bubbles to the document (React Aria's
|
|
75
|
+
// `usePress` does that) is no outside interaction.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
let wasOpenOnPointerDown = false;
|
|
78
|
+
let handleClick;
|
|
79
|
+
const removeClickListener = () => {
|
|
80
|
+
if (handleClick) {
|
|
81
|
+
document.removeEventListener('click', handleClick);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
// A pointer down that opens the layer again while it closes, like one on its trigger, mustn't dismiss it.
|
|
85
|
+
const handlePointerDownCapture = () => {
|
|
86
|
+
wasOpenOnPointerDown = isOpen();
|
|
87
|
+
};
|
|
88
|
+
const handlePointerDown = event => {
|
|
89
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
90
|
+
const wasOpen = wasOpenOnPointerDown;
|
|
91
|
+
const handlePointerDownOutsideEvent = () => {
|
|
92
|
+
if (isInsidePersistentElement(event.target) || hasBlockingLayerAbove()) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const outsideEvent = dispatchOutsideEvent(POINTER_DOWN_OUTSIDE, event, customEvent => {
|
|
96
|
+
handlePointerDownOutside(customEvent);
|
|
97
|
+
handleInteractOutside(customEvent);
|
|
98
|
+
}, true);
|
|
99
|
+
if (!outsideEvent.defaultPrevented) {
|
|
100
|
+
hasInteractedOutsideRef.current = true;
|
|
101
|
+
if (wasOpen && isOpen()) {
|
|
102
|
+
handleDismiss();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
// Browsers fire the click of a touch about 350ms after it ends; dismissing earlier could let that
|
|
107
|
+
// click reach what was below the overlay.
|
|
108
|
+
if (event.pointerType === 'touch') {
|
|
109
|
+
removeClickListener();
|
|
110
|
+
handleClick = handlePointerDownOutsideEvent;
|
|
111
|
+
document.addEventListener('click', handleClick, {
|
|
112
|
+
once: true
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
handlePointerDownOutsideEvent();
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
removeClickListener();
|
|
119
|
+
}
|
|
120
|
+
isPointerInsideReactTreeRef.current = false;
|
|
121
|
+
};
|
|
122
|
+
// The pointer down that opened the layer must not count as an outside interaction.
|
|
123
|
+
const timerId = window.setTimeout(() => {
|
|
124
|
+
document.addEventListener('pointerdown', handlePointerDownCapture, true);
|
|
125
|
+
document.addEventListener('pointerdown', handlePointerDown);
|
|
126
|
+
}, 0);
|
|
127
|
+
return () => {
|
|
128
|
+
window.clearTimeout(timerId);
|
|
129
|
+
document.removeEventListener('pointerdown', handlePointerDownCapture, true);
|
|
130
|
+
document.removeEventListener('pointerdown', handlePointerDown);
|
|
131
|
+
removeClickListener();
|
|
132
|
+
};
|
|
133
|
+
}, [handleDismiss, handlePointerDownOutside, handleInteractOutside, hasBlockingLayerAbove, isOpen]);
|
|
134
|
+
// Like with Radix, focus moving outside is reported as long as the content is mounted, and dismisses it while it's
|
|
135
|
+
// open; reporting it while the content closes keeps focus where it moved to when the content unmounts. Focus that
|
|
136
|
+
// moves into the React tree, such as a nested menu in a portal, isn't outside: React marks it in its capture
|
|
137
|
+
// phase, before the event bubbles to the document.
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
const handleFocusIn = event => {
|
|
140
|
+
if (!event.target || isFocusInsideReactTreeRef.current || isInsidePersistentElement(event.target)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const outsideEvent = dispatchOutsideEvent(FOCUS_OUTSIDE, event, customEvent => {
|
|
144
|
+
handleFocusOutside(customEvent);
|
|
145
|
+
handleInteractOutside(customEvent);
|
|
146
|
+
}, false);
|
|
147
|
+
if (!outsideEvent.defaultPrevented) {
|
|
148
|
+
hasInteractedOutsideRef.current = true;
|
|
149
|
+
if (open) {
|
|
150
|
+
handleDismiss();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
document.addEventListener('focusin', handleFocusIn);
|
|
155
|
+
return () => document.removeEventListener('focusin', handleFocusIn);
|
|
156
|
+
}, [open, handleDismiss, handleFocusOutside, handleInteractOutside]);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!open) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
const handleKeyDown = event => {
|
|
162
|
+
if (event.key !== 'Escape' || hasLayerAbove('overlay') || hasLayerAbove('notification')) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
handleEscapeKeyDown(event);
|
|
166
|
+
if (!event.defaultPrevented) {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
handleDismiss();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
172
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
173
|
+
}, [open, handleDismiss, handleEscapeKeyDown, hasLayerAbove]);
|
|
174
|
+
const onPointerDownCapture = useCallback(() => {
|
|
175
|
+
isPointerInsideReactTreeRef.current = true;
|
|
176
|
+
}, []);
|
|
177
|
+
const onFocusCapture = useCallback(() => {
|
|
178
|
+
isFocusInsideReactTreeRef.current = true;
|
|
179
|
+
}, []);
|
|
180
|
+
const onBlurCapture = useCallback(() => {
|
|
181
|
+
isFocusInsideReactTreeRef.current = false;
|
|
182
|
+
}, []);
|
|
183
|
+
return {
|
|
184
|
+
hideOnInteractOutside: false,
|
|
185
|
+
hasInteractedOutsideRef,
|
|
186
|
+
contentProps: {
|
|
187
|
+
onPointerDownCapture,
|
|
188
|
+
onFocusCapture,
|
|
189
|
+
onBlurCapture
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/** Composes a Radix style outside handler so that right clicks and Ctrl + left clicks never dismiss. */
|
|
194
|
+
function preventRightClickDismiss(event) {
|
|
195
|
+
const {
|
|
196
|
+
originalEvent
|
|
197
|
+
} = event.detail;
|
|
198
|
+
const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
|
|
199
|
+
const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
|
|
200
|
+
if (isRightClick) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { preventRightClickDismiss, useDismissable };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import * as MenuPrimitive from './menu';
|
|
3
|
+
import { type Direction, type PrimitiveProps } from './types';
|
|
4
|
+
export interface DropdownMenuProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
dir?: Direction;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
defaultOpen?: boolean;
|
|
9
|
+
onOpenChange?(open: boolean): void;
|
|
10
|
+
modal?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Dropdown menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
|
|
13
|
+
export declare const Root: {
|
|
14
|
+
(props: DropdownMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
export type DropdownMenuTriggerProps = PrimitiveProps<'button'>;
|
|
18
|
+
export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
19
|
+
asChild?: boolean;
|
|
20
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
21
|
+
export type DropdownMenuPortalProps = MenuPrimitive.MenuPortalProps;
|
|
22
|
+
export declare const Portal: {
|
|
23
|
+
({ forceMount, children, container }: MenuPrimitive.MenuPortalProps): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
displayName: string;
|
|
25
|
+
};
|
|
26
|
+
export type DropdownMenuContentProps = Omit<MenuPrimitive.MenuContentProps, 'onEntryFocus'>;
|
|
27
|
+
export declare const Content: import("react").ForwardRefExoticComponent<DropdownMenuContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
28
|
+
export type DropdownMenuGroupProps = MenuPrimitive.MenuGroupProps;
|
|
29
|
+
export type DropdownMenuLabelProps = MenuPrimitive.MenuLabelProps;
|
|
30
|
+
export type DropdownMenuItemProps = MenuPrimitive.MenuItemProps;
|
|
31
|
+
export type DropdownMenuCheckboxItemProps = MenuPrimitive.MenuCheckboxItemProps;
|
|
32
|
+
export type DropdownMenuRadioGroupProps = MenuPrimitive.MenuRadioGroupProps;
|
|
33
|
+
export type DropdownMenuRadioItemProps = MenuPrimitive.MenuRadioItemProps;
|
|
34
|
+
export type DropdownMenuItemIndicatorProps = MenuPrimitive.MenuItemIndicatorProps;
|
|
35
|
+
export type DropdownMenuSeparatorProps = MenuPrimitive.MenuSeparatorProps;
|
|
36
|
+
export type DropdownMenuArrowProps = MenuPrimitive.MenuArrowProps;
|
|
37
|
+
export type DropdownMenuSubTriggerProps = MenuPrimitive.MenuSubTriggerProps;
|
|
38
|
+
export type { MenuSubContentProps } from './menu';
|
|
39
|
+
export declare const Group: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
40
|
+
asChild?: boolean;
|
|
41
|
+
} & import("react").RefAttributes<HTMLDivElement>>, Label: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
42
|
+
asChild?: boolean;
|
|
43
|
+
} & import("react").RefAttributes<HTMLDivElement>>, Item: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemProps & import("react").RefAttributes<HTMLDivElement>>, CheckboxItem: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuCheckboxItemProps & import("react").RefAttributes<HTMLDivElement>>, RadioGroup: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuRadioGroupProps & import("react").RefAttributes<HTMLDivElement>>, RadioItem: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuRadioItemProps & import("react").RefAttributes<HTMLDivElement>>, ItemIndicator: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemIndicatorProps & import("react").RefAttributes<HTMLSpanElement>>, Separator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
44
|
+
asChild?: boolean;
|
|
45
|
+
} & import("react").RefAttributes<HTMLDivElement>>, Arrow: import("react").ForwardRefExoticComponent<Omit<import("./popper").PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>, SubTrigger: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemImplProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
46
|
+
export interface DropdownMenuSubProps {
|
|
47
|
+
children?: ReactNode;
|
|
48
|
+
open?: boolean;
|
|
49
|
+
defaultOpen?: boolean;
|
|
50
|
+
onOpenChange?(open: boolean): void;
|
|
51
|
+
}
|
|
52
|
+
export declare const Sub: {
|
|
53
|
+
(props: DropdownMenuSubProps): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
displayName: string;
|
|
55
|
+
};
|
|
56
|
+
export type DropdownMenuSubContentProps = MenuPrimitive.MenuSubContentProps;
|
|
57
|
+
export declare const SubContent: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuSubContentProps & import("react").RefAttributes<HTMLDivElement>>;
|