@box/blueprint-web 19.6.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 +6 -6
- package/dist/lib-esm/accordion/types.d.ts +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/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/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/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/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,191 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { forwardRef, useRef, useCallback, useEffect, useContext, createContext, useState, useMemo } from 'react';
|
|
3
|
+
import { composeEventHandlers } from '../composeEventHandlers.js';
|
|
4
|
+
import { useCallbackRef } from '../useCallbackRef.js';
|
|
5
|
+
import { useControllableState } from '../useControllableState.js';
|
|
6
|
+
import * as menu from './menu.js';
|
|
7
|
+
import { Anchor, Content as Content$1, SubContent as SubContent$1, Sub as Sub$1, Root as Root$1 } from './menu.js';
|
|
8
|
+
import { getPopperCssVariables } from './popper.js';
|
|
9
|
+
import { Slot } from './slot.js';
|
|
10
|
+
|
|
11
|
+
const contentCssVariables = getPopperCssVariables('context-menu');
|
|
12
|
+
function whenTouchOrPen(handler) {
|
|
13
|
+
return event => event.pointerType !== 'mouse' ? handler(event) : undefined;
|
|
14
|
+
}
|
|
15
|
+
const ContextMenuContext = /*#__PURE__*/createContext(null);
|
|
16
|
+
function useContextMenuContext(consumerName) {
|
|
17
|
+
const context = useContext(ContextMenuContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error(`\`${consumerName}\` must be used within \`ContextMenu\``);
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
/** Context menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
|
|
24
|
+
const Root = props => {
|
|
25
|
+
const {
|
|
26
|
+
children,
|
|
27
|
+
onOpenChange,
|
|
28
|
+
dir,
|
|
29
|
+
modal = true
|
|
30
|
+
} = props;
|
|
31
|
+
const [open, setOpen] = useState(false);
|
|
32
|
+
const handleOpenChangeProp = useCallbackRef(onOpenChange);
|
|
33
|
+
const handleOpenChange = useCallback(nextOpen => {
|
|
34
|
+
setOpen(nextOpen);
|
|
35
|
+
handleOpenChangeProp(nextOpen);
|
|
36
|
+
}, [handleOpenChangeProp]);
|
|
37
|
+
const value = useMemo(() => ({
|
|
38
|
+
open,
|
|
39
|
+
onOpenChange: handleOpenChange,
|
|
40
|
+
modal
|
|
41
|
+
}), [open, handleOpenChange, modal]);
|
|
42
|
+
return jsx(ContextMenuContext.Provider, {
|
|
43
|
+
value: value,
|
|
44
|
+
children: jsx(Root$1, {
|
|
45
|
+
dir: dir,
|
|
46
|
+
modal: modal,
|
|
47
|
+
onOpenChange: handleOpenChange,
|
|
48
|
+
open: open,
|
|
49
|
+
children: children
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
Root.displayName = 'ContextMenu';
|
|
54
|
+
const getPointAnchor = (x, y) => ({
|
|
55
|
+
getBoundingClientRect: () => DOMRect.fromRect({
|
|
56
|
+
width: 0,
|
|
57
|
+
height: 0,
|
|
58
|
+
x,
|
|
59
|
+
y
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
/** Opens the menu at the pointer position on `contextmenu`, or after a 700ms touch or pen press. */
|
|
63
|
+
const Trigger = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
64
|
+
const {
|
|
65
|
+
disabled = false,
|
|
66
|
+
asChild,
|
|
67
|
+
...triggerProps
|
|
68
|
+
} = props;
|
|
69
|
+
const Comp = asChild ? Slot : 'span';
|
|
70
|
+
const context = useContextMenuContext('ContextMenuTrigger');
|
|
71
|
+
const virtualRef = useRef(getPointAnchor(0, 0));
|
|
72
|
+
const longPressTimerRef = useRef(0);
|
|
73
|
+
const clearLongPress = useCallback(() => window.clearTimeout(longPressTimerRef.current), []);
|
|
74
|
+
const handleOpen = event => {
|
|
75
|
+
// The popper can't observe a virtual anchor's coordinates, so mounted content only moves for a new anchor.
|
|
76
|
+
virtualRef.current = getPointAnchor(event.clientX, event.clientY);
|
|
77
|
+
context.onOpenChange(true);
|
|
78
|
+
};
|
|
79
|
+
useEffect(() => clearLongPress, [clearLongPress]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (disabled) {
|
|
82
|
+
clearLongPress();
|
|
83
|
+
}
|
|
84
|
+
}, [disabled, clearLongPress]);
|
|
85
|
+
return jsxs(Fragment, {
|
|
86
|
+
children: [jsx(Anchor, {
|
|
87
|
+
virtualRef: virtualRef
|
|
88
|
+
}), jsx(Comp, {
|
|
89
|
+
"data-disabled": disabled ? '' : undefined,
|
|
90
|
+
"data-state": context.open ? 'open' : 'closed',
|
|
91
|
+
...triggerProps,
|
|
92
|
+
ref: forwardedRef,
|
|
93
|
+
// Prevent the iOS context menu from appearing.
|
|
94
|
+
style: {
|
|
95
|
+
WebkitTouchCallout: 'none',
|
|
96
|
+
...props.style
|
|
97
|
+
},
|
|
98
|
+
// A disabled trigger lets the native context menu open.
|
|
99
|
+
onContextMenu: disabled ? props.onContextMenu : composeEventHandlers(props.onContextMenu, event => {
|
|
100
|
+
// Some platforms already fire `contextmenu` on long press.
|
|
101
|
+
clearLongPress();
|
|
102
|
+
handleOpen(event);
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
}),
|
|
105
|
+
onPointerCancel: disabled ? props.onPointerCancel : composeEventHandlers(props.onPointerCancel, whenTouchOrPen(clearLongPress)),
|
|
106
|
+
onPointerDown: disabled ? props.onPointerDown : composeEventHandlers(props.onPointerDown, whenTouchOrPen(event => {
|
|
107
|
+
// Clear the long press in case there are several touch points.
|
|
108
|
+
clearLongPress();
|
|
109
|
+
longPressTimerRef.current = window.setTimeout(() => handleOpen(event), 700);
|
|
110
|
+
})),
|
|
111
|
+
onPointerMove: disabled ? props.onPointerMove : composeEventHandlers(props.onPointerMove, whenTouchOrPen(clearLongPress)),
|
|
112
|
+
onPointerUp: disabled ? props.onPointerUp : composeEventHandlers(props.onPointerUp, whenTouchOrPen(clearLongPress))
|
|
113
|
+
})]
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
Trigger.displayName = 'ContextMenuTrigger';
|
|
117
|
+
const {
|
|
118
|
+
Portal
|
|
119
|
+
} = menu;
|
|
120
|
+
const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
121
|
+
const {
|
|
122
|
+
onCloseAutoFocus,
|
|
123
|
+
onInteractOutside
|
|
124
|
+
} = props;
|
|
125
|
+
const {
|
|
126
|
+
modal
|
|
127
|
+
} = useContextMenuContext('ContextMenuContent');
|
|
128
|
+
const hasInteractedOutsideRef = useRef(false);
|
|
129
|
+
const handleCloseAutoFocus = useCallback(event => {
|
|
130
|
+
onCloseAutoFocus?.(event);
|
|
131
|
+
if (!event.defaultPrevented && hasInteractedOutsideRef.current) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
}
|
|
134
|
+
hasInteractedOutsideRef.current = false;
|
|
135
|
+
}, [onCloseAutoFocus]);
|
|
136
|
+
const handleInteractOutside = useCallback(event => {
|
|
137
|
+
onInteractOutside?.(event);
|
|
138
|
+
if (!event.defaultPrevented && !modal) {
|
|
139
|
+
hasInteractedOutsideRef.current = true;
|
|
140
|
+
}
|
|
141
|
+
}, [modal, onInteractOutside]);
|
|
142
|
+
return jsx(Content$1, {
|
|
143
|
+
...props,
|
|
144
|
+
ref: forwardedRef,
|
|
145
|
+
align: "start",
|
|
146
|
+
onCloseAutoFocus: handleCloseAutoFocus,
|
|
147
|
+
onInteractOutside: handleInteractOutside,
|
|
148
|
+
side: "right",
|
|
149
|
+
sideOffset: 2,
|
|
150
|
+
style: {
|
|
151
|
+
...props.style,
|
|
152
|
+
...contentCssVariables
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
Content.displayName = 'ContextMenuContent';
|
|
157
|
+
const {
|
|
158
|
+
Item,
|
|
159
|
+
SubTrigger,
|
|
160
|
+
useMenuClose
|
|
161
|
+
} = menu;
|
|
162
|
+
const Sub = props => {
|
|
163
|
+
const {
|
|
164
|
+
children,
|
|
165
|
+
onOpenChange,
|
|
166
|
+
open: openProp,
|
|
167
|
+
defaultOpen
|
|
168
|
+
} = props;
|
|
169
|
+
const [open = false, setOpen] = useControllableState({
|
|
170
|
+
prop: openProp,
|
|
171
|
+
defaultProp: defaultOpen,
|
|
172
|
+
onChange: onOpenChange
|
|
173
|
+
});
|
|
174
|
+
return jsx(Sub$1, {
|
|
175
|
+
onOpenChange: setOpen,
|
|
176
|
+
open: open,
|
|
177
|
+
children: children
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
Sub.displayName = 'ContextMenuSub';
|
|
181
|
+
const SubContent = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(SubContent$1, {
|
|
182
|
+
...props,
|
|
183
|
+
ref: forwardedRef,
|
|
184
|
+
style: {
|
|
185
|
+
...props.style,
|
|
186
|
+
...contentCssVariables
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
SubContent.displayName = 'ContextMenuSubContent';
|
|
190
|
+
|
|
191
|
+
export { Content, Item, Portal, Root, Sub, SubContent, SubTrigger, Trigger, useMenuClose };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type DismissableLayerProps, type FocusScopeProps, type PortalProps, type PrimitiveProps } from './types';
|
|
3
|
+
export interface DialogProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
defaultOpen?: boolean;
|
|
7
|
+
onOpenChange?(open: boolean): void;
|
|
8
|
+
modal?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Dialog with the Radix API and DOM, rendered by the Ariakit `Dialog`. Focus management and dismiss callbacks
|
|
12
|
+
* follow Radix; modality (inert outside content, scroll lock) is Ariakit's.
|
|
13
|
+
*/
|
|
14
|
+
export declare const Root: {
|
|
15
|
+
(props: DialogProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
displayName: string;
|
|
17
|
+
};
|
|
18
|
+
export type DialogTriggerProps = PrimitiveProps<'button'>;
|
|
19
|
+
export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
20
|
+
asChild?: boolean;
|
|
21
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
22
|
+
export interface DialogPortalProps extends PortalProps {
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
/** Portals each child separately, like Radix, so the overlay and the content can be siblings. */
|
|
26
|
+
export declare const Portal: {
|
|
27
|
+
({ forceMount, children, container }: DialogPortalProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
export interface DialogOverlayProps extends PrimitiveProps<'div'> {
|
|
31
|
+
forceMount?: true;
|
|
32
|
+
}
|
|
33
|
+
export declare const Overlay: import("react").ForwardRefExoticComponent<DialogOverlayProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
34
|
+
export interface DialogContentProps extends PrimitiveProps<'div'>, DismissableLayerProps, FocusScopeProps {
|
|
35
|
+
/** Keeps the content mounted when closed, for animations controlled from the outside. */
|
|
36
|
+
forceMount?: true;
|
|
37
|
+
}
|
|
38
|
+
export declare const Content: import("react").ForwardRefExoticComponent<DialogContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
39
|
+
export type DialogTitleProps = PrimitiveProps<'h2'>;
|
|
40
|
+
export declare const Title: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & {
|
|
41
|
+
asChild?: boolean;
|
|
42
|
+
} & import("react").RefAttributes<HTMLHeadingElement>>;
|
|
43
|
+
export type DialogDescriptionProps = PrimitiveProps<'p'>;
|
|
44
|
+
export declare const Description: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLParagraphElement>, HTMLParagraphElement>, "ref"> & {
|
|
45
|
+
asChild?: boolean;
|
|
46
|
+
} & import("react").RefAttributes<HTMLParagraphElement>>;
|
|
47
|
+
export type DialogCloseProps = PrimitiveProps<'button'>;
|
|
48
|
+
export declare const Close: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
49
|
+
asChild?: boolean;
|
|
50
|
+
} & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -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 {};
|