@sentry/scraps 0.4.0 → 0.5.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/README.md +6 -5
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +0 -2
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
- package/dist/clipboard/copyToClipboardButton.js +32 -0
- package/dist/clipboard/index.d.ts +1 -0
- package/dist/clipboard/index.js +1 -0
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.js +1 -0
- package/dist/codeBlock/codeBlock.d.ts +68 -0
- package/dist/codeBlock/codeBlock.js +242 -0
- package/dist/codeBlock/index.d.ts +2 -0
- package/dist/codeBlock/index.js +2 -0
- package/dist/codeBlock/prism.d.ts +11 -0
- package/dist/codeBlock/prism.js +101 -0
- package/dist/codeBlock/styles.d.ts +2 -0
- package/dist/codeBlock/styles.js +133 -0
- package/dist/compactSelect/compactSelect.d.ts +21 -0
- package/dist/compactSelect/compactSelect.js +150 -0
- package/dist/compactSelect/composite.d.ts +54 -0
- package/dist/compactSelect/composite.js +101 -0
- package/dist/compactSelect/control.d.ts +112 -0
- package/dist/compactSelect/control.js +354 -0
- package/dist/compactSelect/fzf.d.ts +8 -0
- package/dist/compactSelect/fzf.js +151 -0
- package/dist/compactSelect/gridList/index.d.ts +46 -0
- package/dist/compactSelect/gridList/index.js +102 -0
- package/dist/compactSelect/gridList/option.d.ts +15 -0
- package/dist/compactSelect/gridList/option.js +111 -0
- package/dist/compactSelect/gridList/section.d.ts +15 -0
- package/dist/compactSelect/gridList/section.js +58 -0
- package/dist/compactSelect/highlightText.d.ts +6 -0
- package/dist/compactSelect/highlightText.js +33 -0
- package/dist/compactSelect/index.d.ts +9 -0
- package/dist/compactSelect/index.js +8 -0
- package/dist/compactSelect/list.d.ts +94 -0
- package/dist/compactSelect/list.js +167 -0
- package/dist/compactSelect/listBox/index.d.ts +84 -0
- package/dist/compactSelect/listBox/index.js +175 -0
- package/dist/compactSelect/listBox/option.d.ts +19 -0
- package/dist/compactSelect/listBox/option.js +101 -0
- package/dist/compactSelect/listBox/section.d.ts +21 -0
- package/dist/compactSelect/listBox/section.js +58 -0
- package/dist/compactSelect/menuComponents.d.ts +89 -0
- package/dist/compactSelect/menuComponents.js +117 -0
- package/dist/compactSelect/selectFilterContext.d.ts +2 -0
- package/dist/compactSelect/selectFilterContext.js +3 -0
- package/dist/compactSelect/styles.d.ts +39 -0
- package/dist/compactSelect/styles.js +155 -0
- package/dist/compactSelect/types.d.ts +1 -0
- package/dist/compactSelect/types.js +0 -0
- package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
- package/dist/compactSelect/useVirtualizedItems.js +74 -0
- package/dist/compactSelect/utils.d.ts +80 -0
- package/dist/compactSelect/utils.js +268 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/descriptionList/descriptionList.js +4 -3
- package/dist/disclosure/disclosure.js +2 -2
- package/dist/dragHandle/dragHandle.d.ts +3 -1
- package/dist/dragHandle/dragHandle.js +8 -5
- package/dist/drawer/components.d.ts +46 -0
- package/dist/drawer/components.js +265 -0
- package/dist/drawer/globalDrawer.d.ts +106 -0
- package/dist/drawer/globalDrawer.js +173 -0
- package/dist/drawer/index.d.ts +3 -0
- package/dist/drawer/index.js +2 -0
- package/dist/drawer/useDrawerResizing.d.ts +19 -0
- package/dist/drawer/useDrawerResizing.js +111 -0
- package/dist/drawer/useDrawerWidth.d.ts +1 -0
- package/dist/drawer/useDrawerWidth.js +42 -0
- package/dist/dropdownMenu/content.d.ts +1 -0
- package/dist/dropdownMenu/content.js +1 -0
- package/dist/dropdownMenu/context.d.ts +24 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +103 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +136 -0
- package/dist/dropdownMenu/item.js +182 -0
- package/dist/dropdownMenu/list.d.ts +59 -0
- package/dist/dropdownMenu/list.js +410 -0
- package/dist/dropdownMenu/search.d.ts +16 -0
- package/dist/dropdownMenu/search.js +16 -0
- package/dist/dropdownMenu/section.d.ts +21 -0
- package/dist/dropdownMenu/section.js +40 -0
- package/dist/dropdownMenu/separator.d.ts +7 -0
- package/dist/dropdownMenu/separator.js +15 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +260 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +55 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useSafetyTriangle.d.ts +12 -0
- package/dist/dropdownMenu/useSafetyTriangle.js +119 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +57 -0
- package/dist/form/FormSearch.d.ts +19 -0
- package/dist/form/FormSearch.js +4 -0
- package/dist/form/autoSaveForm.d.ts +110 -0
- package/dist/form/autoSaveForm.js +100 -0
- package/dist/{formPresentation → form}/displayField.js +2 -2
- package/dist/form/field/baseField.d.ts +23 -0
- package/dist/form/field/baseField.js +116 -0
- package/dist/form/field/checkboxField.d.ts +11 -0
- package/dist/form/field/checkboxField.js +42 -0
- package/dist/form/field/checkboxGroupField.d.ts +16 -0
- package/dist/form/field/checkboxGroupField.js +80 -0
- package/dist/form/field/compactSelectField.d.ts +19 -0
- package/dist/form/field/compactSelectField.js +77 -0
- package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
- package/dist/form/field/inputField.d.ts +19 -0
- package/dist/form/field/inputField.js +31 -0
- package/dist/{formPresentation → form/field}/meta.js +6 -6
- package/dist/form/field/numberField.d.ts +5 -0
- package/dist/form/field/numberField.js +11 -0
- package/dist/form/field/passwordField.d.ts +3 -0
- package/dist/form/field/passwordField.js +27 -0
- package/dist/form/field/radioGroupField.d.ts +16 -0
- package/dist/form/field/radioGroupField.js +92 -0
- package/dist/form/field/rangeField.d.ts +8 -0
- package/dist/form/field/rangeField.js +34 -0
- package/dist/form/field/selectAsyncField.d.ts +31 -0
- package/dist/form/field/selectAsyncField.js +22 -0
- package/dist/form/field/selectField.d.ts +9 -0
- package/dist/form/field/selectField.js +72 -0
- package/dist/form/field/switchField.d.ts +7 -0
- package/dist/form/field/switchField.js +37 -0
- package/dist/form/field/textAreaField.d.ts +7 -0
- package/dist/form/field/textAreaField.js +25 -0
- package/dist/{formPresentation → form}/formContext.js +1 -1
- package/dist/form/formErrorContext/index.d.ts +9 -0
- package/dist/form/formErrorContext/index.js +7 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.js +8 -0
- package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
- package/dist/{formPresentation → form/layout}/base.js +1 -1
- package/dist/form/layout/fieldGroup.d.ts +6 -0
- package/dist/form/layout/fieldGroup.js +60 -0
- package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
- package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
- package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
- package/dist/form/scrapsForm.d.ts +220 -0
- package/dist/form/scrapsForm.js +126 -0
- package/dist/hotkey/hotkey.d.ts +9 -8
- package/dist/hotkey/hotkey.js +13 -6
- package/dist/hotkey/index.d.ts +2 -1
- package/dist/hotkey/index.js +2 -1
- package/dist/hotkey/keyMappings.d.ts +1 -15
- package/dist/hotkey/keyMappings.js +29 -174
- package/dist/hotkey/useHotkeys.d.ts +3 -47
- package/dist/hotkey/useHotkeys.js +8 -42
- package/dist/image/image.js +2 -1
- package/dist/info/infoTip.d.ts +1 -1
- package/dist/info/infoTip.js +4 -3
- package/dist/input/index.d.ts +0 -3
- package/dist/input/index.js +0 -2
- package/dist/input/input.d.ts +2 -0
- package/dist/input/input.js +2 -0
- package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
- package/dist/input/passwordManagerIgnoreProps.js +8 -0
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +2 -0
- package/dist/link/linkBehaviorContext.js +17 -10
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -6
- package/dist/menu/menu.js +160 -56
- package/dist/modal/components.d.ts +19 -0
- package/dist/modal/components.js +99 -0
- package/dist/modal/errorBoundary.d.ts +2 -0
- package/dist/modal/errorBoundary.js +35 -0
- package/dist/modal/index.d.ts +33 -0
- package/dist/modal/index.js +260 -0
- package/dist/modal/portal.d.ts +1 -0
- package/dist/modal/portal.js +10 -0
- package/dist/modal/state.d.ts +17 -0
- package/dist/modal/state.js +41 -0
- package/dist/modal/types.d.ts +75 -0
- package/dist/modal/types.js +0 -0
- package/dist/numberInput/index.d.ts +3 -0
- package/dist/numberInput/index.js +2 -0
- package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberDragInput.js +1 -1
- package/dist/{input → numberInput}/numberInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberInput.js +1 -1
- package/dist/overlayContext.d.ts +29 -0
- package/dist/overlayContext.js +7 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/pagination.d.ts +24 -0
- package/dist/pagination/pagination.js +63 -0
- package/dist/pictureInPicture/index.d.ts +2 -0
- package/dist/pictureInPicture/index.js +2 -0
- package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
- package/dist/pictureInPicture/pictureInPicture.js +100 -0
- package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
- package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
- package/dist/pictureInPicture/portalContext.d.ts +2 -0
- package/dist/pictureInPicture/portalContext.js +3 -0
- package/dist/revealOnHover/revealOnHover.js +1 -1
- package/dist/segmentedControl/segmentedControl.js +1 -1
- package/dist/select/filter.d.ts +4 -0
- package/dist/select/filter.js +12 -0
- package/dist/select/index.d.ts +3 -0
- package/dist/select/index.js +2 -0
- package/dist/select/option.d.ts +16 -0
- package/dist/select/option.js +81 -0
- package/dist/select/reactSelectWrapper.d.ts +8 -0
- package/dist/select/reactSelectWrapper.js +25 -0
- package/dist/select/select.d.ts +79 -0
- package/dist/select/select.js +454 -0
- package/dist/select/styles.d.ts +9 -0
- package/dist/select/styles.js +27 -0
- package/dist/select/types.d.ts +60 -0
- package/dist/select/types.js +0 -0
- package/dist/select/virtualizedMenuList.d.ts +24 -0
- package/dist/select/virtualizedMenuList.js +123 -0
- package/dist/slideOverPanel.d.ts +20 -0
- package/dist/slideOverPanel.js +141 -0
- package/dist/splitPanel/splitPanel.d.ts +3 -1
- package/dist/splitPanel/splitPanel.js +2 -1
- package/dist/table/table.d.ts +1 -1
- package/dist/table/table.js +39 -20
- package/dist/table/useColumnResize.d.ts +6 -5
- package/dist/table/useColumnResize.js +5 -4
- package/dist/tabs/index.d.ts +4 -0
- package/dist/tabs/index.js +3 -0
- package/dist/tabs/item.d.ts +13 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +205 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +256 -0
- package/dist/tabs/tabPanels.d.ts +14 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +38 -0
- package/dist/tabs/tabs.js +56 -0
- package/dist/tabs/utils.d.ts +3 -0
- package/dist/tabs/utils.js +6 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/heading.js +1 -1
- package/dist/text/styles.js +1 -1
- package/dist/text/text.d.ts +1 -1
- package/dist/text/text.js +1 -1
- package/dist/theme/dark.js +9 -9
- package/dist/theme/light.js +9 -9
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/useMedia.d.ts +15 -0
- package/dist/useMedia.js +24 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnClickOutside.js +22 -0
- package/dist/useOverlay.d.ts +1 -0
- package/dist/useOverlay.js +1 -0
- package/dist/useVirtualCollection.d.ts +154 -0
- package/dist/useVirtualCollection.js +143 -0
- package/dist/useVirtualRows.d.ts +26 -0
- package/dist/useVirtualRows.js +26 -0
- package/dist/virtualCollectionLayout.d.ts +51 -0
- package/dist/virtualCollectionLayout.js +49 -0
- package/package.json +115 -16
- package/dist/formPresentation/index.d.ts +0 -8
- package/dist/formPresentation/index.js +0 -8
- package/dist/interactionStateLayer/index.d.ts +0 -1
- package/dist/interactionStateLayer/index.js +0 -1
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
- package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
- package/dist/unreachable.d.ts +0 -1
- package/dist/unreachable.js +0 -4
- /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
- /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
- /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
- /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.js +0 -0
- /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type OverlayLocation } from '../overlayContext.js';
|
|
3
|
+
export interface DrawerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Accessbility label for the drawer
|
|
6
|
+
*/
|
|
7
|
+
ariaLabel: string;
|
|
8
|
+
/**
|
|
9
|
+
* Key to identify the drawer and enable persistence of the drawer width
|
|
10
|
+
*/
|
|
11
|
+
drawerKey?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom max width for the drawer, as any CSS length. Applies on top of the
|
|
14
|
+
* default percentage ceiling rather than replacing it.
|
|
15
|
+
*/
|
|
16
|
+
drawerMaxWidth?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Custom width for the drawer
|
|
19
|
+
*/
|
|
20
|
+
drawerWidth?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Controls scroll locking, click-outside close, and location-change close behavior.
|
|
23
|
+
* - 'blocking' (default): scroll locked, click outside closes, location change closes
|
|
24
|
+
* - 'passive': scroll not locked, click outside does NOT close, location change does NOT close
|
|
25
|
+
*/
|
|
26
|
+
mode?: 'blocking' | 'passive';
|
|
27
|
+
/**
|
|
28
|
+
* Callback for when the drawer closes
|
|
29
|
+
*/
|
|
30
|
+
onClose?: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Callback for when the drawer opens
|
|
33
|
+
*/
|
|
34
|
+
onOpen?: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* If true (default), allows the drawer to be resized - requires `drawerKey`
|
|
37
|
+
* to be defined
|
|
38
|
+
*/
|
|
39
|
+
resizable?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Function to determine whether the drawer should close when interacting with
|
|
42
|
+
* other elements. Only applies in 'blocking' mode.
|
|
43
|
+
*/
|
|
44
|
+
shouldCloseOnInteractOutside?: (interactedElement: Element) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Callback to determine whether the drawer should close when the location changes.
|
|
47
|
+
* Defaults to closing in 'blocking' mode, staying open in 'passive' mode.
|
|
48
|
+
*/
|
|
49
|
+
shouldCloseOnLocationChange?: (nextLocation: OverlayLocation) => boolean;
|
|
50
|
+
}
|
|
51
|
+
interface DrawerRenderProps {
|
|
52
|
+
/**
|
|
53
|
+
* Close the drawer
|
|
54
|
+
*/
|
|
55
|
+
closeDrawer: () => void;
|
|
56
|
+
}
|
|
57
|
+
type DrawerRenderer = (renderProps: DrawerRenderProps) => React.ReactNode;
|
|
58
|
+
export interface DrawerConfig {
|
|
59
|
+
options: DrawerOptions;
|
|
60
|
+
renderer: DrawerRenderer | null;
|
|
61
|
+
}
|
|
62
|
+
interface DrawerPlacement {
|
|
63
|
+
minWidth: number;
|
|
64
|
+
topOffset: number;
|
|
65
|
+
}
|
|
66
|
+
export interface GlobalDrawerProps {
|
|
67
|
+
children: React.ReactNode;
|
|
68
|
+
}
|
|
69
|
+
export declare function GlobalDrawer({ children }: GlobalDrawerProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
70
|
+
/**
|
|
71
|
+
* Returns helper functions to control the slide out drawer above the page content. For example:
|
|
72
|
+
* ```
|
|
73
|
+
* const {openDrawer, closeDrawer} = useDrawer()
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* The `openDrawer` function accepts a renderer, and options. By default (`mode: 'blocking'`),
|
|
77
|
+
* the drawer locks scroll, closes on outside clicks, closes on location changes, and closes
|
|
78
|
+
* on 'Escape'. Use `mode: 'passive'` to opt out of scroll locking, outside-click close, and
|
|
79
|
+
* location-change close — useful for drawers that coexist with page interaction.
|
|
80
|
+
*
|
|
81
|
+
* The `closeDrawer` function accepts no parameters and closes the drawer, unmounting its contents.
|
|
82
|
+
* For example:
|
|
83
|
+
* ```
|
|
84
|
+
* openDrawer(() => <button onClick={closeDrawer}>Close!</button>)
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* `isDrawerOpen` is scoped to this call-site: it is `true` only when the drawer
|
|
88
|
+
* currently open was opened via the `openDrawer` returned by *this* `useDrawer`
|
|
89
|
+
* call (including calls made through a shared wrapper hook). Use
|
|
90
|
+
* `isAnyDrawerOpen` if you need to know whether *any* drawer is open.
|
|
91
|
+
*/
|
|
92
|
+
export declare function useDrawer(): {
|
|
93
|
+
openDrawer: (renderer: DrawerConfig["renderer"], options: DrawerConfig["options"]) => void;
|
|
94
|
+
closeDrawer: () => void;
|
|
95
|
+
panelRef: React.RefObject<HTMLDivElement | null>;
|
|
96
|
+
isDrawerOpen: boolean;
|
|
97
|
+
isAnyDrawerOpen: boolean;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Lets the app layout place global drawers around its own chrome. Drawers start
|
|
101
|
+
* `topOffset` pixels from the viewport top (below page banners) and, while
|
|
102
|
+
* `minWidth` is positive, are at least that many pixels wide (to cover a pane
|
|
103
|
+
* docked against the viewport's right edge, such as Seer).
|
|
104
|
+
*/
|
|
105
|
+
export declare function useDrawerPlacement({ minWidth, topOffset }: DrawerPlacement): void;
|
|
106
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import { AnimatePresence } from "framer-motion";
|
|
4
|
+
import { Backdrop } from "../backdrop/index.js";
|
|
5
|
+
import { useHotkeys } from "../hotkey/index.js";
|
|
6
|
+
import { useOverlayContext } from "../overlayContext.js";
|
|
7
|
+
import { useOnClickOutside } from "../useOnClickOutside.js";
|
|
8
|
+
import { useScrollLock } from "../useScrollLock.js";
|
|
9
|
+
import { DrawerComponents } from "./components.js";
|
|
10
|
+
const DrawerContext = /*#__PURE__*/ createContext({
|
|
11
|
+
openDrawer: ()=>{},
|
|
12
|
+
activeDrawerId: null,
|
|
13
|
+
closeDrawer: ()=>{},
|
|
14
|
+
panelRef: {
|
|
15
|
+
current: null
|
|
16
|
+
},
|
|
17
|
+
setPlacement: ()=>{}
|
|
18
|
+
});
|
|
19
|
+
function getTargetElement(target) {
|
|
20
|
+
if (target instanceof Element) return target;
|
|
21
|
+
if (target instanceof Node && target.parentElement) return target.parentElement;
|
|
22
|
+
return document.documentElement;
|
|
23
|
+
}
|
|
24
|
+
function shouldCloseOnInteractOutsideByDefault(element) {
|
|
25
|
+
const overlay = element.closest('[data-overlay]');
|
|
26
|
+
return !overlay || overlay.hasAttribute('data-drawer-backdrop');
|
|
27
|
+
}
|
|
28
|
+
function DrawerBoundary({ children }) {
|
|
29
|
+
return children;
|
|
30
|
+
}
|
|
31
|
+
function GlobalDrawer({ children }) {
|
|
32
|
+
const { drawer, location } = useOverlayContext();
|
|
33
|
+
const Boundary = drawer?.boundaryComponent ?? DrawerBoundary;
|
|
34
|
+
const [currentDrawerConfig, overwriteDrawerConfig] = useState();
|
|
35
|
+
const currentDrawerConfigRef = useRef(currentDrawerConfig);
|
|
36
|
+
const [placement, setPlacement] = useState(null);
|
|
37
|
+
const isDrawerOpen = !!currentDrawerConfig;
|
|
38
|
+
const activeDrawerId = currentDrawerConfig?.callerId ?? null;
|
|
39
|
+
const scrollLock = useScrollLock(document.body);
|
|
40
|
+
const openDrawer = useCallback((renderer, options, callerId)=>{
|
|
41
|
+
if ('passive' !== options.mode) scrollLock.acquire();
|
|
42
|
+
overwriteDrawerConfig({
|
|
43
|
+
renderer,
|
|
44
|
+
options,
|
|
45
|
+
callerId
|
|
46
|
+
});
|
|
47
|
+
options.onOpen?.();
|
|
48
|
+
}, [
|
|
49
|
+
scrollLock
|
|
50
|
+
]);
|
|
51
|
+
const closeDrawer = useCallback(()=>{
|
|
52
|
+
scrollLock.release();
|
|
53
|
+
overwriteDrawerConfig(void 0);
|
|
54
|
+
}, [
|
|
55
|
+
scrollLock
|
|
56
|
+
]);
|
|
57
|
+
const handleClose = useCallback(()=>{
|
|
58
|
+
currentDrawerConfig?.options?.onClose?.();
|
|
59
|
+
closeDrawer();
|
|
60
|
+
}, [
|
|
61
|
+
currentDrawerConfig,
|
|
62
|
+
closeDrawer
|
|
63
|
+
]);
|
|
64
|
+
useEffect(()=>{
|
|
65
|
+
currentDrawerConfigRef.current = currentDrawerConfig;
|
|
66
|
+
}, [
|
|
67
|
+
currentDrawerConfig
|
|
68
|
+
]);
|
|
69
|
+
useLayoutEffect(()=>{
|
|
70
|
+
if (void 0 !== location && void 0 !== currentDrawerConfigRef.current && (currentDrawerConfigRef.current.options?.shouldCloseOnLocationChange?.(location) ?? currentDrawerConfigRef.current.options?.mode !== 'passive')) closeDrawer();
|
|
71
|
+
}, [
|
|
72
|
+
closeDrawer,
|
|
73
|
+
location
|
|
74
|
+
]);
|
|
75
|
+
const panelRef = useRef(null);
|
|
76
|
+
const handleClickOutside = useCallback(()=>{
|
|
77
|
+
if (currentDrawerConfig?.options?.mode !== 'passive') handleClose();
|
|
78
|
+
}, [
|
|
79
|
+
currentDrawerConfig,
|
|
80
|
+
handleClose
|
|
81
|
+
]);
|
|
82
|
+
const { shouldCloseOnInteractOutside = shouldCloseOnInteractOutsideByDefault } = currentDrawerConfig?.options ?? {};
|
|
83
|
+
useOnClickOutside(panelRef, (e)=>{
|
|
84
|
+
if (!shouldCloseOnInteractOutside(getTargetElement(e.target))) return;
|
|
85
|
+
handleClickOutside();
|
|
86
|
+
});
|
|
87
|
+
useHotkeys([
|
|
88
|
+
{
|
|
89
|
+
hotkey: 'Escape',
|
|
90
|
+
options: {
|
|
91
|
+
enabled: isDrawerOpen
|
|
92
|
+
},
|
|
93
|
+
callback: ()=>{
|
|
94
|
+
handleClose();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
]);
|
|
98
|
+
const renderedChild = currentDrawerConfig?.renderer ? currentDrawerConfig.renderer({
|
|
99
|
+
closeDrawer: handleClose
|
|
100
|
+
}) : null;
|
|
101
|
+
return /*#__PURE__*/ jsxs(DrawerContext, {
|
|
102
|
+
value: {
|
|
103
|
+
closeDrawer,
|
|
104
|
+
activeDrawerId,
|
|
105
|
+
openDrawer,
|
|
106
|
+
panelRef,
|
|
107
|
+
setPlacement
|
|
108
|
+
},
|
|
109
|
+
children: [
|
|
110
|
+
/*#__PURE__*/ jsx(Boundary, {
|
|
111
|
+
children: /*#__PURE__*/ jsxs(AnimatePresence, {
|
|
112
|
+
children: [
|
|
113
|
+
isDrawerOpen && 'passive' !== currentDrawerConfig.options.mode ? /*#__PURE__*/ jsx(Backdrop, {
|
|
114
|
+
zIndex: "drawer",
|
|
115
|
+
"data-drawer-backdrop": ""
|
|
116
|
+
}, "backdrop") : null,
|
|
117
|
+
isDrawerOpen && /*#__PURE__*/ jsx(DrawerComponents.DrawerPanel, {
|
|
118
|
+
ariaLabel: currentDrawerConfig.options.ariaLabel,
|
|
119
|
+
onClose: handleClose,
|
|
120
|
+
ref: panelRef,
|
|
121
|
+
mode: currentDrawerConfig.options.mode ?? 'blocking',
|
|
122
|
+
minPanelWidth: placement?.minWidth,
|
|
123
|
+
topOffset: placement?.topOffset,
|
|
124
|
+
drawerWidth: currentDrawerConfig?.options?.drawerWidth,
|
|
125
|
+
drawerMaxWidth: currentDrawerConfig?.options?.drawerMaxWidth,
|
|
126
|
+
drawerKey: currentDrawerConfig?.options?.drawerKey,
|
|
127
|
+
resizable: currentDrawerConfig?.options?.resizable,
|
|
128
|
+
children: renderedChild
|
|
129
|
+
}, "panel")
|
|
130
|
+
]
|
|
131
|
+
})
|
|
132
|
+
}),
|
|
133
|
+
children
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function useDrawer() {
|
|
138
|
+
const context = useContext(DrawerContext);
|
|
139
|
+
const callerId = useId();
|
|
140
|
+
const openDrawerRef = useRef(context.openDrawer);
|
|
141
|
+
useEffect(()=>{
|
|
142
|
+
openDrawerRef.current = context.openDrawer;
|
|
143
|
+
});
|
|
144
|
+
const openDrawer = useCallback((renderer, options)=>{
|
|
145
|
+
openDrawerRef.current(renderer, options, callerId);
|
|
146
|
+
}, [
|
|
147
|
+
callerId
|
|
148
|
+
]);
|
|
149
|
+
return {
|
|
150
|
+
openDrawer,
|
|
151
|
+
closeDrawer: context.closeDrawer,
|
|
152
|
+
panelRef: context.panelRef,
|
|
153
|
+
isDrawerOpen: context.activeDrawerId === callerId,
|
|
154
|
+
isAnyDrawerOpen: null !== context.activeDrawerId
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function useDrawerPlacement({ minWidth, topOffset }) {
|
|
158
|
+
const { setPlacement } = useContext(DrawerContext);
|
|
159
|
+
useLayoutEffect(()=>{
|
|
160
|
+
setPlacement({
|
|
161
|
+
minWidth,
|
|
162
|
+
topOffset
|
|
163
|
+
});
|
|
164
|
+
return ()=>{
|
|
165
|
+
setPlacement(null);
|
|
166
|
+
};
|
|
167
|
+
}, [
|
|
168
|
+
setPlacement,
|
|
169
|
+
minWidth,
|
|
170
|
+
topOffset
|
|
171
|
+
]);
|
|
172
|
+
}
|
|
173
|
+
export { GlobalDrawer, useDrawer, useDrawerPlacement };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { DrawerBody, DrawerHeader, DrawerPanel, useDrawerContentContext, type DrawerHeaderProps, type DrawerPanelProps, } from './components.js';
|
|
2
|
+
export { GlobalDrawer, useDrawer, useDrawerPlacement, type DrawerOptions, type DrawerConfig, type GlobalDrawerProps, } from './globalDrawer.js';
|
|
3
|
+
export type { OverlayLocation } from '../overlayContext.js';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
declare const MIN_WIDTH_PERCENT = 20;
|
|
3
|
+
declare const MAX_WIDTH_PERCENT = 85;
|
|
4
|
+
declare const DEFAULT_WIDTH_PERCENT = 50;
|
|
5
|
+
interface UseDrawerResizingOptions {
|
|
6
|
+
drawerKey?: string;
|
|
7
|
+
drawerMaxWidth?: string;
|
|
8
|
+
drawerWidth?: string;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface UseDrawerResizingResult {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
handleResizeStart: (e: React.MouseEvent) => void;
|
|
14
|
+
panelRef: React.RefObject<HTMLDivElement>;
|
|
15
|
+
persistedWidthPercent: number;
|
|
16
|
+
resizeHandleRef: React.RefObject<HTMLDivElement>;
|
|
17
|
+
}
|
|
18
|
+
export declare function useDrawerResizing({ drawerKey, drawerWidth, drawerMaxWidth, enabled, }: UseDrawerResizingOptions): UseDrawerResizingResult;
|
|
19
|
+
export { MIN_WIDTH_PERCENT, MAX_WIDTH_PERCENT, DEFAULT_WIDTH_PERCENT };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
import { useTheme } from "@emotion/react";
|
|
3
|
+
import { useMedia } from "../useMedia.js";
|
|
4
|
+
import { useDrawerWidth } from "./useDrawerWidth.js";
|
|
5
|
+
const MIN_WIDTH_PERCENT = 20;
|
|
6
|
+
const MAX_WIDTH_PERCENT = 85;
|
|
7
|
+
const DEFAULT_WIDTH_PERCENT = 50;
|
|
8
|
+
function getDrawerWidthKey(drawerKey) {
|
|
9
|
+
return `drawer-width:${drawerKey}`;
|
|
10
|
+
}
|
|
11
|
+
function useDrawerResizing({ drawerKey, drawerWidth, drawerMaxWidth, enabled = true }) {
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
const isSmallScreen = useMedia(`(max-width: ${theme.breakpoints.sm})`);
|
|
14
|
+
const resizeHandleRef = useRef(null);
|
|
15
|
+
const panelRef = useRef(null);
|
|
16
|
+
const rafIdRef = useRef(null);
|
|
17
|
+
const initialMousePositionRef = useRef(null);
|
|
18
|
+
const calculateInitialWidth = (savedWidth)=>{
|
|
19
|
+
if (void 0 !== savedWidth) return Math.min(Math.max(savedWidth, MIN_WIDTH_PERCENT), MAX_WIDTH_PERCENT);
|
|
20
|
+
if (drawerWidth) {
|
|
21
|
+
if (drawerWidth.endsWith('%')) {
|
|
22
|
+
const parsedPercent = parseFloat(drawerWidth);
|
|
23
|
+
return Math.min(Math.max(parsedPercent, MIN_WIDTH_PERCENT), MAX_WIDTH_PERCENT);
|
|
24
|
+
}
|
|
25
|
+
const viewportWidth = window.innerWidth;
|
|
26
|
+
const parsedPixels = parseFloat(drawerWidth);
|
|
27
|
+
const percentValue = parsedPixels / viewportWidth * 100;
|
|
28
|
+
return Math.min(Math.max(percentValue, MIN_WIDTH_PERCENT), MAX_WIDTH_PERCENT);
|
|
29
|
+
}
|
|
30
|
+
return DEFAULT_WIDTH_PERCENT;
|
|
31
|
+
};
|
|
32
|
+
const [persistedWidthPercent, setPersistedWidthPercent] = useDrawerWidth(drawerKey ? getDrawerWidthKey(drawerKey) : 'drawer-width:default', (value)=>{
|
|
33
|
+
const savedWidth = 'number' == typeof value ? value : void 0;
|
|
34
|
+
return calculateInitialWidth(savedWidth);
|
|
35
|
+
});
|
|
36
|
+
useLayoutEffect(()=>{
|
|
37
|
+
if (isSmallScreen) {
|
|
38
|
+
panelRef.current?.style.setProperty('--drawer-width', '100%');
|
|
39
|
+
panelRef.current?.style.setProperty('--drawer-min-width', '100%');
|
|
40
|
+
panelRef.current?.style.setProperty('--drawer-max-width', '100%');
|
|
41
|
+
} else if (!enabled && drawerWidth) {
|
|
42
|
+
panelRef.current?.style.setProperty('--drawer-width', drawerWidth);
|
|
43
|
+
panelRef.current?.style.setProperty('--drawer-min-width', drawerWidth);
|
|
44
|
+
panelRef.current?.style.setProperty('--drawer-max-width', drawerWidth);
|
|
45
|
+
} else {
|
|
46
|
+
panelRef.current?.style.setProperty('--drawer-width', `${persistedWidthPercent}%`);
|
|
47
|
+
panelRef.current?.style.setProperty('--drawer-min-width', `${MIN_WIDTH_PERCENT}%`);
|
|
48
|
+
panelRef.current?.style.setProperty('--drawer-max-width', drawerMaxWidth ? `min(${MAX_WIDTH_PERCENT}%, ${drawerMaxWidth})` : `${MAX_WIDTH_PERCENT}%`);
|
|
49
|
+
}
|
|
50
|
+
}, [
|
|
51
|
+
persistedWidthPercent,
|
|
52
|
+
isSmallScreen,
|
|
53
|
+
drawerWidth,
|
|
54
|
+
drawerMaxWidth,
|
|
55
|
+
enabled
|
|
56
|
+
]);
|
|
57
|
+
const handleResizeStart = useCallback((e)=>{
|
|
58
|
+
if (isSmallScreen || !enabled) return;
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
const handle = resizeHandleRef.current;
|
|
61
|
+
const panel = panelRef.current;
|
|
62
|
+
if (!handle || !panel) return;
|
|
63
|
+
handle.setAttribute('data-resizing', '');
|
|
64
|
+
panel.setAttribute('data-resizing', '');
|
|
65
|
+
initialMousePositionRef.current = e.clientX;
|
|
66
|
+
const viewportWidth = "u" < typeof window ? 1000 : window.innerWidth;
|
|
67
|
+
const handleMouseMove = (moveEvent)=>{
|
|
68
|
+
moveEvent.preventDefault();
|
|
69
|
+
if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
|
|
70
|
+
rafIdRef.current = window.requestAnimationFrame(()=>{
|
|
71
|
+
if (!panel || !handle || null === initialMousePositionRef.current) return;
|
|
72
|
+
const newWidthPercent = (viewportWidth - moveEvent.clientX) / viewportWidth * 100;
|
|
73
|
+
panel.style.setProperty('--drawer-width', `${newWidthPercent}%`);
|
|
74
|
+
handle.setAttribute('data-at-min-width', (newWidthPercent <= MIN_WIDTH_PERCENT).toString());
|
|
75
|
+
handle.setAttribute('data-at-max-width', (Math.abs(newWidthPercent - MAX_WIDTH_PERCENT) < 1).toString());
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const handleMouseUp = ()=>{
|
|
79
|
+
if (null !== rafIdRef.current) {
|
|
80
|
+
window.cancelAnimationFrame(rafIdRef.current);
|
|
81
|
+
rafIdRef.current = null;
|
|
82
|
+
}
|
|
83
|
+
if (handle) handle.removeAttribute('data-resizing');
|
|
84
|
+
if (panel) {
|
|
85
|
+
panel.removeAttribute('data-resizing');
|
|
86
|
+
const computedStyle = window.getComputedStyle(panel);
|
|
87
|
+
const widthValue = parseFloat(computedStyle.width) / viewportWidth * 100;
|
|
88
|
+
setPersistedWidthPercent(widthValue);
|
|
89
|
+
}
|
|
90
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
91
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
92
|
+
};
|
|
93
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
94
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
95
|
+
}, [
|
|
96
|
+
isSmallScreen,
|
|
97
|
+
enabled,
|
|
98
|
+
setPersistedWidthPercent
|
|
99
|
+
]);
|
|
100
|
+
useLayoutEffect(()=>()=>{
|
|
101
|
+
if (null !== rafIdRef.current) window.cancelAnimationFrame(rafIdRef.current);
|
|
102
|
+
}, []);
|
|
103
|
+
return {
|
|
104
|
+
panelRef,
|
|
105
|
+
resizeHandleRef,
|
|
106
|
+
handleResizeStart,
|
|
107
|
+
persistedWidthPercent,
|
|
108
|
+
enabled: !isSmallScreen && !!drawerKey && enabled
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export { DEFAULT_WIDTH_PERCENT, MAX_WIDTH_PERCENT, MIN_WIDTH_PERCENT, useDrawerResizing };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDrawerWidth(key: string, initialize: (value?: unknown) => number): readonly [number, (nextWidth: number) => void];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { useOverlayContext } from "../overlayContext.js";
|
|
3
|
+
function useDrawerWidth(key, initialize) {
|
|
4
|
+
const { drawer } = useOverlayContext();
|
|
5
|
+
const storage = drawer?.widthStorage;
|
|
6
|
+
const subscribe = useCallback((listener)=>storage?.subscribe(key, listener) ?? (()=>{}), [
|
|
7
|
+
storage,
|
|
8
|
+
key
|
|
9
|
+
]);
|
|
10
|
+
const getSnapshot = useCallback(()=>storage?.get(key), [
|
|
11
|
+
storage,
|
|
12
|
+
key
|
|
13
|
+
]);
|
|
14
|
+
const savedWidth = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
15
|
+
const [state, setState] = useState(()=>({
|
|
16
|
+
key,
|
|
17
|
+
savedWidth,
|
|
18
|
+
value: initialize(savedWidth)
|
|
19
|
+
}));
|
|
20
|
+
const changed = state.key !== key || !Object.is(state.savedWidth, savedWidth);
|
|
21
|
+
const value = changed ? initialize(savedWidth) : state.value;
|
|
22
|
+
if (changed) setState({
|
|
23
|
+
key,
|
|
24
|
+
savedWidth,
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
const setWidth = useCallback((nextWidth)=>{
|
|
28
|
+
setState((previous)=>({
|
|
29
|
+
...previous,
|
|
30
|
+
value: nextWidth
|
|
31
|
+
}));
|
|
32
|
+
storage?.set(key, nextWidth);
|
|
33
|
+
}, [
|
|
34
|
+
storage,
|
|
35
|
+
key
|
|
36
|
+
]);
|
|
37
|
+
return [
|
|
38
|
+
value,
|
|
39
|
+
setWidth
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
export { useDrawerWidth };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DropdownMenuContent } from './list.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DropdownMenuContent } from "./list.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TreeState } from '@react-stately/tree';
|
|
2
|
+
import type { useOverlay } from '../useOverlay.js';
|
|
3
|
+
import type { MenuItemProps } from './item.js';
|
|
4
|
+
import type { useSafetyTriangle } from './useSafetyTriangle.js';
|
|
5
|
+
export type OverlayState = ReturnType<typeof useOverlay>['state'];
|
|
6
|
+
interface DropdownMenuContextValue {
|
|
7
|
+
/**
|
|
8
|
+
* Menu state (from @react-aria's useTreeState) of the parent menu. To be used to
|
|
9
|
+
* close the current submenu.
|
|
10
|
+
*/
|
|
11
|
+
parentMenuState?: TreeState<MenuItemProps>;
|
|
12
|
+
/**
|
|
13
|
+
* Overlay state manager (from useOverlay) for the root (top-most) menu. To be used to
|
|
14
|
+
* close the entire menu system.
|
|
15
|
+
*/
|
|
16
|
+
rootOverlayState?: OverlayState;
|
|
17
|
+
safetyTriangle?: ReturnType<typeof useSafetyTriangle>;
|
|
18
|
+
/**
|
|
19
|
+
* `virtualizeThreshold` of the parent menu, inherited by its submenus.
|
|
20
|
+
*/
|
|
21
|
+
virtualizeThreshold?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare const DropdownMenuContext: import("react").Context<DropdownMenuContextValue>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { TriggerProps } from '../overlayTrigger.js';
|
|
3
|
+
import type { UseOverlayProps } from '../useOverlay.js';
|
|
4
|
+
import type { MenuItemProps } from './item.js';
|
|
5
|
+
import type { DropdownMenuContentProps, DropdownMenuListProps } from './list.js';
|
|
6
|
+
export type { MenuItemProps };
|
|
7
|
+
interface BaseDropdownMenuProps extends Omit<DropdownMenuContentProps, 'overlayState' | 'overlayPositionProps' | 'items' | 'children' | 'menuTitle'>, Pick<UseOverlayProps, 'isOpen' | 'offset' | 'position' | 'isDismissable' | 'shouldCloseOnBlur' | 'shouldCloseOnInteractOutside' | 'onInteractOutside' | 'onOpenChange' | 'preventOverflowOptions' | 'flipOptions' | 'shouldApplyMinWidth' | 'strategy'> {
|
|
8
|
+
/**
|
|
9
|
+
* Items to display inside the dropdown menu. If the item has a `children`
|
|
10
|
+
* prop, it will be rendered as a menu section. If it has a `children` prop
|
|
11
|
+
* and its `submenu` prop is set, it will be rendered as a submenu.
|
|
12
|
+
*/
|
|
13
|
+
items: MenuItemProps[];
|
|
14
|
+
/**
|
|
15
|
+
* Pass class name to the outer wrap
|
|
16
|
+
*/
|
|
17
|
+
className?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the trigger is disabled.
|
|
20
|
+
*/
|
|
21
|
+
isDisabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Title for the current menu.
|
|
24
|
+
*/
|
|
25
|
+
menuTitle?: React.ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* Minimum menu width
|
|
28
|
+
*/
|
|
29
|
+
minMenuWidth?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Reference to the container element that the portal should be rendered into.
|
|
32
|
+
*/
|
|
33
|
+
portalContainerRef?: React.RefObject<HTMLElement | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Tag name for the outer wrap, defaults to `div`
|
|
36
|
+
*/
|
|
37
|
+
renderWrapAs?: React.ElementType;
|
|
38
|
+
/**
|
|
39
|
+
* Affects the size of the trigger button and menu items.
|
|
40
|
+
* When omitted, custom triggers inherit their surrounding size, while the
|
|
41
|
+
* default trigger and menu items use md.
|
|
42
|
+
*/
|
|
43
|
+
size?: DropdownMenuListProps['size'];
|
|
44
|
+
/**
|
|
45
|
+
* Whether to render the menu inside a React portal (false by default). This should
|
|
46
|
+
* only be enabled if necessary, e.g. when the dropdown menu is inside a small,
|
|
47
|
+
* scrollable container that messes with the menu's position. Some features, namely
|
|
48
|
+
* submenus, will not work correctly inside portals.
|
|
49
|
+
*
|
|
50
|
+
* Consider passing `strategy` as `'fixed'` before using `usePortal`
|
|
51
|
+
*/
|
|
52
|
+
usePortal?: boolean;
|
|
53
|
+
}
|
|
54
|
+
type DropdownMenuTriggerProps = {
|
|
55
|
+
/**
|
|
56
|
+
* Label for the default trigger button.
|
|
57
|
+
*/
|
|
58
|
+
triggerLabel: React.ReactNode;
|
|
59
|
+
trigger?: never;
|
|
60
|
+
} | {
|
|
61
|
+
trigger: (props: TriggerProps, isOpen: boolean) => React.ReactNode;
|
|
62
|
+
triggerLabel?: never;
|
|
63
|
+
};
|
|
64
|
+
export type DropdownMenuProps = BaseDropdownMenuProps & DropdownMenuTriggerProps;
|
|
65
|
+
/**
|
|
66
|
+
* A menu component that renders both the trigger button and the dropdown
|
|
67
|
+
* menu. See: https://react-spectrum.adobe.com/react-aria/useMenuTrigger.html
|
|
68
|
+
*/
|
|
69
|
+
declare function DropdownMenu({ items, disabledKeys, trigger, triggerLabel, isDisabled: disabledProp, isOpen: isOpenProp, renderWrapAs, size: explicitSize, className, usePortal, offset, position, isDismissable, shouldCloseOnBlur, shouldCloseOnInteractOutside, onInteractOutside, onOpenChange, preventOverflowOptions, flipOptions, portalContainerRef, shouldApplyMinWidth, minMenuWidth, strategy, ...props }: DropdownMenuProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
70
|
+
export { DropdownMenu };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useContext, useMemo } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { useButton } from "@react-aria/button";
|
|
6
|
+
import { useMenuTrigger } from "@react-aria/menu";
|
|
7
|
+
import { ControlContext, DropdownButton } from "../menu/index.js";
|
|
8
|
+
import { useOverlay } from "../useOverlay.js";
|
|
9
|
+
import { DropdownMenuContent } from "./content.js";
|
|
10
|
+
import { DropdownMenuContext } from "./context.js";
|
|
11
|
+
function DropdownMenu({ items, disabledKeys, trigger, triggerLabel, isDisabled: disabledProp, isOpen: isOpenProp, renderWrapAs = 'div', size: explicitSize, className, usePortal = false, offset = 8, position = 'bottom-start', isDismissable = true, shouldCloseOnBlur = true, shouldCloseOnInteractOutside, onInteractOutside, onOpenChange, preventOverflowOptions, flipOptions, portalContainerRef, shouldApplyMinWidth, minMenuWidth, strategy, ...props }) {
|
|
12
|
+
const size = explicitSize ?? 'md';
|
|
13
|
+
const isDisabled = disabledProp ?? (!items || 0 === items.length);
|
|
14
|
+
const { rootOverlayState } = useContext(DropdownMenuContext);
|
|
15
|
+
const { isOpen, state: overlayState, triggerRef, triggerProps: overlayTriggerProps, overlayProps } = useOverlay({
|
|
16
|
+
type: 'menu',
|
|
17
|
+
isOpen: isOpenProp,
|
|
18
|
+
onClose: rootOverlayState?.close,
|
|
19
|
+
offset,
|
|
20
|
+
position,
|
|
21
|
+
isDismissable,
|
|
22
|
+
disableTrigger: isDisabled,
|
|
23
|
+
shouldCloseOnBlur,
|
|
24
|
+
shouldCloseOnInteractOutside,
|
|
25
|
+
onInteractOutside,
|
|
26
|
+
preventOverflowOptions,
|
|
27
|
+
flipOptions,
|
|
28
|
+
onOpenChange,
|
|
29
|
+
shouldApplyMinWidth,
|
|
30
|
+
strategy
|
|
31
|
+
});
|
|
32
|
+
const { menuTriggerProps, menuProps } = useMenuTrigger({
|
|
33
|
+
type: 'menu',
|
|
34
|
+
isDisabled
|
|
35
|
+
}, {
|
|
36
|
+
...overlayState,
|
|
37
|
+
focusStrategy: 'first'
|
|
38
|
+
}, triggerRef);
|
|
39
|
+
const resolvedMenuProps = {
|
|
40
|
+
...menuProps,
|
|
41
|
+
autoFocus: false
|
|
42
|
+
};
|
|
43
|
+
const { buttonProps } = useButton({
|
|
44
|
+
isDisabled,
|
|
45
|
+
...menuTriggerProps
|
|
46
|
+
}, triggerRef);
|
|
47
|
+
function renderMenu() {
|
|
48
|
+
if (!isOpen) return null;
|
|
49
|
+
const menu = /*#__PURE__*/ jsx(DropdownMenuContent, {
|
|
50
|
+
...props,
|
|
51
|
+
...resolvedMenuProps,
|
|
52
|
+
size: size,
|
|
53
|
+
disabledKeys: disabledKeys,
|
|
54
|
+
overlayPositionProps: {
|
|
55
|
+
...overlayProps,
|
|
56
|
+
style: {
|
|
57
|
+
...overlayProps.style,
|
|
58
|
+
minWidth: minMenuWidth ?? overlayProps.style?.minWidth
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
overlayState: overlayState,
|
|
62
|
+
items: items
|
|
63
|
+
});
|
|
64
|
+
return usePortal ? /*#__PURE__*/ createPortal(menu, portalContainerRef?.current ?? document.body) : menu;
|
|
65
|
+
}
|
|
66
|
+
const controlContextValue = useMemo(()=>({
|
|
67
|
+
overlayIsOpen: isOpen,
|
|
68
|
+
disabled: isDisabled,
|
|
69
|
+
size: explicitSize,
|
|
70
|
+
search: '',
|
|
71
|
+
searchable: false
|
|
72
|
+
}), [
|
|
73
|
+
isOpen,
|
|
74
|
+
explicitSize,
|
|
75
|
+
isDisabled
|
|
76
|
+
]);
|
|
77
|
+
return /*#__PURE__*/ jsx(DropdownMenuWrap, {
|
|
78
|
+
className: className,
|
|
79
|
+
as: renderWrapAs,
|
|
80
|
+
role: "presentation",
|
|
81
|
+
children: /*#__PURE__*/ jsxs(ControlContext, {
|
|
82
|
+
value: controlContextValue,
|
|
83
|
+
children: [
|
|
84
|
+
trigger ? trigger({
|
|
85
|
+
...buttonProps,
|
|
86
|
+
...overlayTriggerProps
|
|
87
|
+
}, isOpen) : /*#__PURE__*/ jsx(DropdownButton, {
|
|
88
|
+
size: size,
|
|
89
|
+
isOpen: isOpen,
|
|
90
|
+
...buttonProps,
|
|
91
|
+
...overlayTriggerProps,
|
|
92
|
+
children: triggerLabel
|
|
93
|
+
}),
|
|
94
|
+
renderMenu()
|
|
95
|
+
]
|
|
96
|
+
})
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const DropdownMenuWrap = styled('div')`
|
|
100
|
+
display: contents;
|
|
101
|
+
list-style-type: none;
|
|
102
|
+
`;
|
|
103
|
+
export { DropdownMenu };
|