@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,133 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useDisclosureStore, DisclosureContent } from '@ariakit/react';
|
|
3
|
+
import { forwardRef, useId, useCallback, createContext, useContext, useRef } from 'react';
|
|
4
|
+
import { composeEventHandlers } from '../composeEventHandlers.js';
|
|
5
|
+
import { useControllableState } from '../useControllableState.js';
|
|
6
|
+
import { useComposedRefs } from './compose-refs.js';
|
|
7
|
+
import { useCollapsibleContentSize } from './content-size.js';
|
|
8
|
+
import { Presence } from './presence.js';
|
|
9
|
+
import { Slot, getAsChildRender } from './slot.js';
|
|
10
|
+
|
|
11
|
+
const getOpenState = open => open ? 'open' : 'closed';
|
|
12
|
+
const CollapsibleContext = /*#__PURE__*/createContext(null);
|
|
13
|
+
const useCollapsibleContext = () => {
|
|
14
|
+
const context = useContext(CollapsibleContext);
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error('Collapsible parts must be used within Collapsible.Root');
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Collapsible section with the Radix API and DOM (`data-state`, size CSS variables, content unmounted
|
|
22
|
+
* after its exit animation), with its state in an Ariakit disclosure store.
|
|
23
|
+
*/
|
|
24
|
+
const Root = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
25
|
+
const {
|
|
26
|
+
open: openProp,
|
|
27
|
+
defaultOpen,
|
|
28
|
+
disabled,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
asChild,
|
|
31
|
+
...collapsibleProps
|
|
32
|
+
} = props;
|
|
33
|
+
const [open = false, setOpen] = useControllableState({
|
|
34
|
+
prop: openProp,
|
|
35
|
+
defaultProp: defaultOpen,
|
|
36
|
+
onChange: onOpenChange
|
|
37
|
+
});
|
|
38
|
+
const store = useDisclosureStore({
|
|
39
|
+
open
|
|
40
|
+
});
|
|
41
|
+
const contentId = useId();
|
|
42
|
+
const onOpenToggle = useCallback(() => setOpen(prevOpen => !prevOpen), [setOpen]);
|
|
43
|
+
const Comp = asChild ? Slot : 'div';
|
|
44
|
+
return jsx(CollapsibleContext.Provider, {
|
|
45
|
+
value: {
|
|
46
|
+
contentId,
|
|
47
|
+
disabled,
|
|
48
|
+
open,
|
|
49
|
+
onOpenToggle,
|
|
50
|
+
store
|
|
51
|
+
},
|
|
52
|
+
children: jsx(Comp, {
|
|
53
|
+
"data-disabled": disabled ? '' : undefined,
|
|
54
|
+
"data-state": getOpenState(open),
|
|
55
|
+
...collapsibleProps,
|
|
56
|
+
ref: forwardedRef
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
Root.displayName = 'Collapsible';
|
|
61
|
+
const Trigger = /*#__PURE__*/forwardRef(({
|
|
62
|
+
asChild,
|
|
63
|
+
...triggerProps
|
|
64
|
+
}, forwardedRef) => {
|
|
65
|
+
const context = useCollapsibleContext();
|
|
66
|
+
const Comp = asChild ? Slot : 'button';
|
|
67
|
+
return jsx(Comp, {
|
|
68
|
+
"aria-controls": context.contentId,
|
|
69
|
+
"aria-expanded": context.open || false,
|
|
70
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
71
|
+
"data-state": getOpenState(context.open),
|
|
72
|
+
disabled: context.disabled,
|
|
73
|
+
type: "button",
|
|
74
|
+
...triggerProps,
|
|
75
|
+
ref: forwardedRef,
|
|
76
|
+
onClick: composeEventHandlers(triggerProps.onClick, context.onOpenToggle)
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
Trigger.displayName = 'CollapsibleTrigger';
|
|
80
|
+
const ContentImpl = /*#__PURE__*/forwardRef(({
|
|
81
|
+
present,
|
|
82
|
+
children,
|
|
83
|
+
asChild,
|
|
84
|
+
...contentProps
|
|
85
|
+
}, forwardedRef) => {
|
|
86
|
+
const context = useCollapsibleContext();
|
|
87
|
+
const ref = useRef(null);
|
|
88
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
89
|
+
const {
|
|
90
|
+
isOpen,
|
|
91
|
+
style
|
|
92
|
+
} = useCollapsibleContentSize(ref, {
|
|
93
|
+
open: context.open,
|
|
94
|
+
present,
|
|
95
|
+
cssVariablePrefixes: ['--radix-collapsible']
|
|
96
|
+
});
|
|
97
|
+
const asChildRender = getAsChildRender(asChild, children, contentChildren => isOpen && contentChildren);
|
|
98
|
+
return jsx(DisclosureContent, {
|
|
99
|
+
alwaysVisible: true,
|
|
100
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
101
|
+
"data-state": getOpenState(context.open),
|
|
102
|
+
hidden: !isOpen,
|
|
103
|
+
id: context.contentId,
|
|
104
|
+
render: asChildRender.render,
|
|
105
|
+
store: context.store,
|
|
106
|
+
...contentProps,
|
|
107
|
+
ref: composedRefs,
|
|
108
|
+
style: {
|
|
109
|
+
...style,
|
|
110
|
+
...contentProps.style
|
|
111
|
+
},
|
|
112
|
+
children: asChildRender.children
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
const Content = /*#__PURE__*/forwardRef(({
|
|
116
|
+
forceMount,
|
|
117
|
+
...contentProps
|
|
118
|
+
}, forwardedRef) => {
|
|
119
|
+
const context = useCollapsibleContext();
|
|
120
|
+
return jsx(Presence, {
|
|
121
|
+
present: Boolean(forceMount) || context.open,
|
|
122
|
+
children: ({
|
|
123
|
+
present
|
|
124
|
+
}) => jsx(ContentImpl, {
|
|
125
|
+
...contentProps,
|
|
126
|
+
ref: forwardedRef,
|
|
127
|
+
present: present
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
Content.displayName = 'CollapsibleContent';
|
|
132
|
+
|
|
133
|
+
export { Content, Root, Trigger, getOpenState, useCollapsibleContext };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReactNode, type RefObject } from 'react';
|
|
2
|
+
export declare const COLLECTION_ITEM_ATTRIBUTE = "data-radix-collection-item";
|
|
3
|
+
type ItemData = Record<string, unknown>;
|
|
4
|
+
export type CollectionItem<T extends ItemData> = T & {
|
|
5
|
+
ref: RefObject<HTMLElement | null>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A registry of items ordered like their elements in the DOM, as in the Radix `Collection`.
|
|
9
|
+
* Items rendered outside the collection element (for example in a portal) are listed first.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createCollection<T extends ItemData>(): {
|
|
12
|
+
CollectionProvider: ({ children }: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
useCollection: () => () => CollectionItem<T>[];
|
|
16
|
+
useCollectionItem: (ref: RefObject<HTMLElement | null>, data: T) => {
|
|
17
|
+
"data-radix-collection-item": string;
|
|
18
|
+
};
|
|
19
|
+
useCollectionRef: () => (node: HTMLElement | null) => void;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useCallback, useEffect, useRef, useMemo, useContext, createContext } from 'react';
|
|
3
|
+
|
|
4
|
+
const COLLECTION_ITEM_ATTRIBUTE = 'data-radix-collection-item';
|
|
5
|
+
/**
|
|
6
|
+
* A registry of items ordered like their elements in the DOM, as in the Radix `Collection`.
|
|
7
|
+
* Items rendered outside the collection element (for example in a portal) are listed first.
|
|
8
|
+
*/
|
|
9
|
+
function createCollection() {
|
|
10
|
+
const Context = /*#__PURE__*/createContext(null);
|
|
11
|
+
const CollectionProvider = ({
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
const collectionRef = useRef(null);
|
|
15
|
+
const itemMap = useRef(new Map()).current;
|
|
16
|
+
const value = useMemo(() => ({
|
|
17
|
+
collectionRef,
|
|
18
|
+
itemMap
|
|
19
|
+
}), [itemMap]);
|
|
20
|
+
return jsx(Context.Provider, {
|
|
21
|
+
value: value,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const useCollectionContext = () => {
|
|
26
|
+
const context = useContext(Context);
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error('Collection item must be used within its collection provider');
|
|
29
|
+
}
|
|
30
|
+
return context;
|
|
31
|
+
};
|
|
32
|
+
/** Ref callback for the element that contains the collection items. */
|
|
33
|
+
const useCollectionRef = () => {
|
|
34
|
+
const {
|
|
35
|
+
collectionRef
|
|
36
|
+
} = useCollectionContext();
|
|
37
|
+
return useCallback(node => {
|
|
38
|
+
collectionRef.current = node;
|
|
39
|
+
}, [collectionRef]);
|
|
40
|
+
};
|
|
41
|
+
/** Registers an item. Returns the props to spread on the item element. */
|
|
42
|
+
const useCollectionItem = (ref, data) => {
|
|
43
|
+
const {
|
|
44
|
+
itemMap
|
|
45
|
+
} = useCollectionContext();
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
itemMap.set(ref, {
|
|
48
|
+
ref,
|
|
49
|
+
...data
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
useEffect(() => () => {
|
|
53
|
+
itemMap.delete(ref);
|
|
54
|
+
}, [itemMap, ref]);
|
|
55
|
+
return {
|
|
56
|
+
[COLLECTION_ITEM_ATTRIBUTE]: ''
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const useCollection = () => {
|
|
60
|
+
const {
|
|
61
|
+
collectionRef,
|
|
62
|
+
itemMap
|
|
63
|
+
} = useCollectionContext();
|
|
64
|
+
return useCallback(() => {
|
|
65
|
+
const collectionNode = collectionRef.current;
|
|
66
|
+
if (!collectionNode) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const orderedNodes = Array.from(collectionNode.querySelectorAll(`[${COLLECTION_ITEM_ATTRIBUTE}]`));
|
|
70
|
+
const items = Array.from(itemMap.values());
|
|
71
|
+
return items.sort((a, b) => orderedNodes.indexOf(a.ref.current) - orderedNodes.indexOf(b.ref.current));
|
|
72
|
+
}, [collectionRef, itemMap]);
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
CollectionProvider,
|
|
76
|
+
useCollection,
|
|
77
|
+
useCollectionItem,
|
|
78
|
+
useCollectionRef
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { COLLECTION_ITEM_ATTRIBUTE, createCollection };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Ref, type RefCallback } from 'react';
|
|
2
|
+
type PossibleRef<T> = Ref<T> | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Combines refs into one callback ref. React 19 cleanup functions returned by callback refs are honored.
|
|
5
|
+
*/
|
|
6
|
+
export declare function composeRefs<T>(...refs: PossibleRef<T>[]): RefCallback<T>;
|
|
7
|
+
export declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): RefCallback<T>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
function setRef(ref, value) {
|
|
4
|
+
if (typeof ref === 'function') {
|
|
5
|
+
return ref(value);
|
|
6
|
+
}
|
|
7
|
+
if (ref !== null && ref !== undefined) {
|
|
8
|
+
ref.current = value;
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Combines refs into one callback ref. React 19 cleanup functions returned by callback refs are honored.
|
|
14
|
+
*/
|
|
15
|
+
function composeRefs(...refs) {
|
|
16
|
+
return node => {
|
|
17
|
+
let hasCleanup = false;
|
|
18
|
+
const cleanups = refs.map(ref => {
|
|
19
|
+
const cleanup = setRef(ref, node);
|
|
20
|
+
if (typeof cleanup === 'function') {
|
|
21
|
+
hasCleanup = true;
|
|
22
|
+
}
|
|
23
|
+
return cleanup;
|
|
24
|
+
});
|
|
25
|
+
if (!hasCleanup) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return () => {
|
|
29
|
+
cleanups.forEach((cleanup, index) => {
|
|
30
|
+
if (typeof cleanup === 'function') {
|
|
31
|
+
cleanup();
|
|
32
|
+
} else {
|
|
33
|
+
setRef(refs[index], null);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function useComposedRefs(...refs) {
|
|
40
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
|
+
return useCallback(composeRefs(...refs), refs);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { composeRefs, useComposedRefs };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type CSSProperties, type RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Measures collapsible content so CSS animations can use its size, like the Radix `Collapsible`.
|
|
4
|
+
* Content that starts open doesn't animate on mount.
|
|
5
|
+
*
|
|
6
|
+
* Returns whether the content should render (open, or still animating closed) and the size CSS variables.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useCollapsibleContentSize(contentRef: RefObject<HTMLElement | null>, { open, present, cssVariablePrefixes }: {
|
|
9
|
+
open: boolean;
|
|
10
|
+
present: boolean;
|
|
11
|
+
cssVariablePrefixes: string[];
|
|
12
|
+
}): {
|
|
13
|
+
isOpen: boolean;
|
|
14
|
+
style: CSSProperties;
|
|
15
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { useEnhancedEffect } from '../useEnhancedEffect.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Measures collapsible content so CSS animations can use its size, like the Radix `Collapsible`.
|
|
6
|
+
* Content that starts open doesn't animate on mount.
|
|
7
|
+
*
|
|
8
|
+
* Returns whether the content should render (open, or still animating closed) and the size CSS variables.
|
|
9
|
+
*/
|
|
10
|
+
function useCollapsibleContentSize(contentRef, {
|
|
11
|
+
open,
|
|
12
|
+
present,
|
|
13
|
+
cssVariablePrefixes
|
|
14
|
+
}) {
|
|
15
|
+
const [isPresent, setIsPresent] = useState(present);
|
|
16
|
+
const heightRef = useRef(0);
|
|
17
|
+
const widthRef = useRef(0);
|
|
18
|
+
const isOpen = open || isPresent;
|
|
19
|
+
const isMountAnimationPreventedRef = useRef(isOpen);
|
|
20
|
+
const originalStylesRef = useRef(undefined);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const rAF = requestAnimationFrame(() => {
|
|
23
|
+
isMountAnimationPreventedRef.current = false;
|
|
24
|
+
});
|
|
25
|
+
return () => cancelAnimationFrame(rAF);
|
|
26
|
+
}, []);
|
|
27
|
+
useEnhancedEffect(() => {
|
|
28
|
+
const node = contentRef.current;
|
|
29
|
+
if (!node) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
originalStylesRef.current = originalStylesRef.current || {
|
|
33
|
+
transitionDuration: node.style.transitionDuration,
|
|
34
|
+
animationName: node.style.animationName
|
|
35
|
+
};
|
|
36
|
+
// Block animations to measure the full size of the content.
|
|
37
|
+
node.style.transitionDuration = '0s';
|
|
38
|
+
node.style.animationName = 'none';
|
|
39
|
+
const rect = node.getBoundingClientRect();
|
|
40
|
+
heightRef.current = rect.height;
|
|
41
|
+
widthRef.current = rect.width;
|
|
42
|
+
if (!isMountAnimationPreventedRef.current) {
|
|
43
|
+
node.style.transitionDuration = originalStylesRef.current.transitionDuration;
|
|
44
|
+
node.style.animationName = originalStylesRef.current.animationName;
|
|
45
|
+
}
|
|
46
|
+
setIsPresent(present);
|
|
47
|
+
}, [contentRef, open, present]);
|
|
48
|
+
const height = heightRef.current;
|
|
49
|
+
const width = widthRef.current;
|
|
50
|
+
const style = {};
|
|
51
|
+
cssVariablePrefixes.forEach(prefix => {
|
|
52
|
+
style[`${prefix}-content-height`] = height ? `${height}px` : undefined;
|
|
53
|
+
style[`${prefix}-content-width`] = width ? `${width}px` : undefined;
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
isOpen,
|
|
57
|
+
style: style
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { useCollapsibleContentSize };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import * as MenuPrimitive from './menu';
|
|
3
|
+
import { type Direction, type PrimitiveProps } from './types';
|
|
4
|
+
export interface ContextMenuProps {
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
onOpenChange?(open: boolean): void;
|
|
7
|
+
dir?: Direction;
|
|
8
|
+
modal?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** Context menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
|
|
11
|
+
export declare const Root: {
|
|
12
|
+
(props: ContextMenuProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
displayName: string;
|
|
14
|
+
};
|
|
15
|
+
export interface ContextMenuTriggerProps extends PrimitiveProps<'span'> {
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Opens the menu at the pointer position on `contextmenu`, or after a 700ms touch or pen press. */
|
|
19
|
+
export declare const Trigger: import("react").ForwardRefExoticComponent<ContextMenuTriggerProps & import("react").RefAttributes<HTMLSpanElement>>;
|
|
20
|
+
export type ContextMenuPortalProps = MenuPrimitive.MenuPortalProps;
|
|
21
|
+
export declare const Portal: {
|
|
22
|
+
({ forceMount, children, container }: MenuPrimitive.MenuPortalProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
displayName: string;
|
|
24
|
+
};
|
|
25
|
+
export type ContextMenuContentProps = Omit<MenuPrimitive.MenuContentProps, 'onEntryFocus' | 'side' | 'sideOffset' | 'align'>;
|
|
26
|
+
export declare const Content: import("react").ForwardRefExoticComponent<ContextMenuContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
27
|
+
export type ContextMenuGroupProps = MenuPrimitive.MenuGroupProps;
|
|
28
|
+
export type ContextMenuLabelProps = MenuPrimitive.MenuLabelProps;
|
|
29
|
+
export type ContextMenuItemProps = MenuPrimitive.MenuItemProps;
|
|
30
|
+
export type ContextMenuCheckboxItemProps = MenuPrimitive.MenuCheckboxItemProps;
|
|
31
|
+
export type ContextMenuRadioGroupProps = MenuPrimitive.MenuRadioGroupProps;
|
|
32
|
+
export type ContextMenuRadioItemProps = MenuPrimitive.MenuRadioItemProps;
|
|
33
|
+
export type ContextMenuItemIndicatorProps = MenuPrimitive.MenuItemIndicatorProps;
|
|
34
|
+
export type ContextMenuSeparatorProps = MenuPrimitive.MenuSeparatorProps;
|
|
35
|
+
export type ContextMenuArrowProps = MenuPrimitive.MenuArrowProps;
|
|
36
|
+
export type ContextMenuSubTriggerProps = MenuPrimitive.MenuSubTriggerProps;
|
|
37
|
+
export type { MenuSubContentProps } from './menu';
|
|
38
|
+
export declare const Group: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
39
|
+
asChild?: boolean;
|
|
40
|
+
} & import("react").RefAttributes<HTMLDivElement>>, Label: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
41
|
+
asChild?: boolean;
|
|
42
|
+
} & 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"> & {
|
|
43
|
+
asChild?: boolean;
|
|
44
|
+
} & 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>>, useMenuClose: typeof MenuPrimitive.useMenuClose;
|
|
45
|
+
export interface ContextMenuSubProps {
|
|
46
|
+
children?: ReactNode;
|
|
47
|
+
open?: boolean;
|
|
48
|
+
defaultOpen?: boolean;
|
|
49
|
+
onOpenChange?(open: boolean): void;
|
|
50
|
+
}
|
|
51
|
+
export declare const Sub: {
|
|
52
|
+
(props: ContextMenuSubProps): import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
displayName: string;
|
|
54
|
+
};
|
|
55
|
+
export type ContextMenuSubContentProps = MenuPrimitive.MenuSubContentProps;
|
|
56
|
+
export declare const SubContent: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuSubContentProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -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>>;
|