@sentry/scraps 0.4.0 → 0.6.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 +74 -8
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +4 -4
- package/dist/button/button.js +1 -0
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/button/linkButton.js +1 -0
- package/dist/button/styles.js +157 -152
- 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 +243 -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 +355 -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 +264 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/dateTime/config.d.ts +23 -0
- package/dist/dateTime/config.js +50 -0
- package/dist/dateTime/context.d.ts +18 -0
- package/dist/dateTime/context.js +46 -0
- package/dist/dateTime/dateTime.d.ts +6 -0
- package/dist/dateTime/dateTime.js +30 -0
- package/dist/dateTime/format.d.ts +24 -0
- package/dist/dateTime/format.js +45 -0
- package/dist/dateTime/index.d.ts +6 -0
- package/dist/dateTime/index.js +6 -0
- package/dist/dateTime/intlFormatter.d.ts +9 -0
- package/dist/dateTime/intlFormatter.js +16 -0
- package/dist/dateTime/parseDate.d.ts +3 -0
- package/dist/dateTime/parseDate.js +12 -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 +39 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +109 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +140 -0
- package/dist/dropdownMenu/item.js +142 -0
- package/dist/dropdownMenu/list.d.ts +85 -0
- package/dist/dropdownMenu/list.js +429 -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 +24 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +31 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +55 -0
- package/dist/duration/formatElapsedDuration.d.ts +4 -0
- package/dist/duration/formatElapsedDuration.js +10 -0
- package/dist/duration/getDuration.d.ts +68 -0
- package/dist/duration/getDuration.js +80 -0
- package/dist/duration/index.d.ts +2 -0
- package/dist/duration/index.js +2 -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/fzf.d.ts +9 -0
- package/dist/fzf.js +155 -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/container.d.ts +8 -2
- package/dist/layout/container.js +2 -2
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/layout/styles.d.ts +2 -1
- package/dist/layout/styles.js +11 -5
- package/dist/legacyDatetime.d.ts +21 -0
- package/dist/legacyDatetime.js +13 -0
- package/dist/link/index.d.ts +1 -1
- package/dist/link/index.js +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +11 -0
- package/dist/link/linkBehaviorContext.js +48 -11
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -8
- package/dist/menu/menu.js +163 -60
- 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/relativeTime/getRelativeDate.d.ts +14 -0
- package/dist/relativeTime/getRelativeDate.js +107 -0
- package/dist/relativeTime/index.d.ts +3 -0
- package/dist/relativeTime/index.js +3 -0
- package/dist/relativeTime/relativeTime.d.ts +55 -0
- package/dist/relativeTime/relativeTime.js +102 -0
- package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
- package/dist/relativeTime/useRelativeTimeFormatter.js +10 -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/context.d.ts +9 -0
- package/dist/tabs/context.js +9 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +1 -0
- package/dist/tabs/item.d.ts +24 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +208 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +258 -0
- package/dist/tabs/tabPanels.d.ts +13 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +53 -0
- package/dist/tabs/tabs.js +59 -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/prose.d.ts +2 -2
- 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/theme/theme.d.ts +34 -34
- package/dist/theme/theme.js +9 -0
- package/dist/theme/types.d.ts +20 -2
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/translation/index.d.ts +1 -0
- package/dist/translation/index.js +1 -0
- package/dist/translation/translate.d.ts +9 -0
- package/dist/translation/translate.js +5 -0
- package/dist/translation/translationContext.d.ts +2 -1
- package/dist/translation/translationContext.js +2 -1
- 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/fonts/OFL.txt +94 -0
- package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
- package/fonts/roboto-mono-variable-greek.woff2 +0 -0
- package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
- package/fonts/roboto-mono-variable.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic.woff2 +0 -0
- package/fonts/rubik-variable-latin-ext.woff2 +0 -0
- package/fonts/rubik-variable.woff2 +0 -0
- package/fonts.css +211 -0
- package/package.json +140 -23
- package/dist/datetime.d.ts +0 -39
- package/dist/datetime.js +0 -20
- 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,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,39 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { RootMenuTriggerState } from '@react-stately/menu';
|
|
3
|
+
interface DropdownMenuContextValue {
|
|
4
|
+
/**
|
|
5
|
+
* `isDismissable` of the root menu. Dismissing a submenu closes the root menu,
|
|
6
|
+
* so submenus follow it.
|
|
7
|
+
*/
|
|
8
|
+
isDismissable?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Ref to the menu element (the `ul` with `role="menu"`) that renders the
|
|
11
|
+
* current items. Submenu triggers pass it to `useSubmenuTrigger` as their
|
|
12
|
+
* parent menu.
|
|
13
|
+
*/
|
|
14
|
+
parentMenuRef?: React.RefObject<HTMLElement | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Element that submenus are portaled into. Submenus render outside their
|
|
17
|
+
* parent menu element, so focus moving into a submenu is not mistaken for
|
|
18
|
+
* focus moving to another item of the parent menu, but they stay inside the
|
|
19
|
+
* root overlay, so the root menu does not close on blur.
|
|
20
|
+
*/
|
|
21
|
+
portalContainer?: HTMLElement | null;
|
|
22
|
+
/**
|
|
23
|
+
* Menu trigger state (from react-stately's `useMenuTriggerState` shape) for
|
|
24
|
+
* the root (top-most) menu. Tracks which submenus are open, and closes the
|
|
25
|
+
* entire menu system.
|
|
26
|
+
*/
|
|
27
|
+
rootMenuState?: RootMenuTriggerState;
|
|
28
|
+
/**
|
|
29
|
+
* Level of the submenus opened from the current menu's items: 0 in the root
|
|
30
|
+
* menu, 1 in its submenus, and so on.
|
|
31
|
+
*/
|
|
32
|
+
submenuLevel?: number;
|
|
33
|
+
/**
|
|
34
|
+
* `virtualizeThreshold` of the parent menu, inherited by its submenus.
|
|
35
|
+
*/
|
|
36
|
+
virtualizeThreshold?: number;
|
|
37
|
+
}
|
|
38
|
+
export declare const DropdownMenuContext: React.Context<DropdownMenuContextValue>;
|
|
39
|
+
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, 'menuLevel' | '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<Element | DocumentFragment | 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,109 @@
|
|
|
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
|
+
import { useDropdownRootMenuState } from "./useDropdownRootMenuState.js";
|
|
12
|
+
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 }) {
|
|
13
|
+
const size = explicitSize ?? 'md';
|
|
14
|
+
const isDisabled = disabledProp ?? (!items || 0 === items.length);
|
|
15
|
+
const { rootMenuState: parentRootMenuState } = useContext(DropdownMenuContext);
|
|
16
|
+
const { isOpen, state: overlayState, triggerRef, triggerProps: overlayTriggerProps, overlayProps } = useOverlay({
|
|
17
|
+
type: 'menu',
|
|
18
|
+
isOpen: isOpenProp,
|
|
19
|
+
onClose: parentRootMenuState?.close,
|
|
20
|
+
offset,
|
|
21
|
+
position,
|
|
22
|
+
isDismissable,
|
|
23
|
+
disableTrigger: isDisabled,
|
|
24
|
+
shouldCloseOnBlur,
|
|
25
|
+
shouldCloseOnInteractOutside,
|
|
26
|
+
onInteractOutside,
|
|
27
|
+
preventOverflowOptions,
|
|
28
|
+
flipOptions,
|
|
29
|
+
onOpenChange,
|
|
30
|
+
shouldApplyMinWidth,
|
|
31
|
+
strategy
|
|
32
|
+
});
|
|
33
|
+
const rootMenuState = useDropdownRootMenuState(overlayState, parentRootMenuState);
|
|
34
|
+
const { menuTriggerProps, menuProps } = useMenuTrigger({
|
|
35
|
+
type: 'menu',
|
|
36
|
+
isDisabled
|
|
37
|
+
}, {
|
|
38
|
+
...overlayState,
|
|
39
|
+
focusStrategy: 'first'
|
|
40
|
+
}, triggerRef);
|
|
41
|
+
const resolvedMenuProps = {
|
|
42
|
+
...menuProps,
|
|
43
|
+
autoFocus: false
|
|
44
|
+
};
|
|
45
|
+
const { buttonProps } = useButton({
|
|
46
|
+
isDisabled,
|
|
47
|
+
...menuTriggerProps
|
|
48
|
+
}, triggerRef);
|
|
49
|
+
function renderMenu() {
|
|
50
|
+
if (!isOpen) return null;
|
|
51
|
+
const menu = /*#__PURE__*/ jsx(DropdownMenuContent, {
|
|
52
|
+
...props,
|
|
53
|
+
...resolvedMenuProps,
|
|
54
|
+
size: size,
|
|
55
|
+
disabledKeys: disabledKeys,
|
|
56
|
+
overlayPositionProps: {
|
|
57
|
+
...overlayProps,
|
|
58
|
+
style: {
|
|
59
|
+
...overlayProps.style,
|
|
60
|
+
minWidth: minMenuWidth ?? overlayProps.style?.minWidth
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
menuLevel: {
|
|
64
|
+
type: 'root',
|
|
65
|
+
state: rootMenuState
|
|
66
|
+
},
|
|
67
|
+
isDismissable: isDismissable,
|
|
68
|
+
items: items
|
|
69
|
+
});
|
|
70
|
+
return usePortal ? /*#__PURE__*/ createPortal(menu, portalContainerRef?.current ?? document.body) : menu;
|
|
71
|
+
}
|
|
72
|
+
const controlContextValue = useMemo(()=>({
|
|
73
|
+
overlayIsOpen: isOpen,
|
|
74
|
+
disabled: isDisabled,
|
|
75
|
+
size: explicitSize,
|
|
76
|
+
search: '',
|
|
77
|
+
searchable: false
|
|
78
|
+
}), [
|
|
79
|
+
isOpen,
|
|
80
|
+
explicitSize,
|
|
81
|
+
isDisabled
|
|
82
|
+
]);
|
|
83
|
+
return /*#__PURE__*/ jsx(DropdownMenuWrap, {
|
|
84
|
+
className: className,
|
|
85
|
+
as: renderWrapAs,
|
|
86
|
+
role: "presentation",
|
|
87
|
+
children: /*#__PURE__*/ jsxs(ControlContext, {
|
|
88
|
+
value: controlContextValue,
|
|
89
|
+
children: [
|
|
90
|
+
trigger ? trigger({
|
|
91
|
+
...buttonProps,
|
|
92
|
+
...overlayTriggerProps
|
|
93
|
+
}, isOpen) : /*#__PURE__*/ jsx(DropdownButton, {
|
|
94
|
+
size: size,
|
|
95
|
+
isOpen: isOpen,
|
|
96
|
+
...buttonProps,
|
|
97
|
+
...overlayTriggerProps,
|
|
98
|
+
children: triggerLabel
|
|
99
|
+
}),
|
|
100
|
+
renderMenu()
|
|
101
|
+
]
|
|
102
|
+
})
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const DropdownMenuWrap = styled('div')`
|
|
106
|
+
display: contents;
|
|
107
|
+
list-style-type: none;
|
|
108
|
+
`;
|
|
109
|
+
export { DropdownMenu };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DropdownMenu } from "./dropdownMenu.js";
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { SubmenuTriggerAria } from '@react-aria/menu';
|
|
3
|
+
import type { TreeState } from '@react-stately/tree';
|
|
4
|
+
import type { Node } from '@react-types/shared';
|
|
5
|
+
import { type LinkProps } from '../link/index.js';
|
|
6
|
+
import { type ListItemProps, type MenuItemTrailingAction } from '../menu/index.js';
|
|
7
|
+
import type { UseOverlayProps } from '../useOverlay.js';
|
|
8
|
+
import { type VirtualRowProps } from '../useVirtualCollection.js';
|
|
9
|
+
export type DropdownMenuSearchOptions = {
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
};
|
|
12
|
+
export type DropdownMenuContentSizeOptions = {
|
|
13
|
+
maxHeight?: string | number;
|
|
14
|
+
maxWidth?: string | number;
|
|
15
|
+
};
|
|
16
|
+
export interface MenuItemProps extends ListItemProps {
|
|
17
|
+
/**
|
|
18
|
+
* Item key. Must be unique across the entire menu, including sub-menus.
|
|
19
|
+
*/
|
|
20
|
+
key: string;
|
|
21
|
+
/**
|
|
22
|
+
* Sub-items that are nested inside this item. By default, sub-items are
|
|
23
|
+
* rendered collectively as menu sections inside the current menu. If
|
|
24
|
+
* `submenu` is set, then they will be rendered together in a sub-menu.
|
|
25
|
+
*/
|
|
26
|
+
children?: MenuItemProps[];
|
|
27
|
+
/**
|
|
28
|
+
* Pass a class name to the menu item.
|
|
29
|
+
*/
|
|
30
|
+
className?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to close the menu when this item is clicked. Overrides the list-level
|
|
33
|
+
* `closeOnSelect` prop when set.
|
|
34
|
+
*/
|
|
35
|
+
closeOnSelect?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Destination if this menu item is an external link.
|
|
38
|
+
*/
|
|
39
|
+
externalHref?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Hide item from the dropdown menu. Note: this will also remove the item
|
|
42
|
+
* from the selection manager.
|
|
43
|
+
*/
|
|
44
|
+
hidden?: boolean;
|
|
45
|
+
/** Shows a selection checkmark and reserves its space when false. */
|
|
46
|
+
isSelected?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Menu item label. Should preferably be a string. If not, provide a `textValue` prop
|
|
49
|
+
* to enable search & keyboard select.
|
|
50
|
+
*/
|
|
51
|
+
label?: ListItemProps['label'];
|
|
52
|
+
/**
|
|
53
|
+
* Function to call when user selects/clicks/taps on the menu item. The
|
|
54
|
+
* item's key is passed as an argument.
|
|
55
|
+
*/
|
|
56
|
+
onAction?: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Ref to the item's root element. For a section, this is the element that
|
|
59
|
+
* wraps its label and items.
|
|
60
|
+
*/
|
|
61
|
+
ref?: React.Ref<HTMLLIElement>;
|
|
62
|
+
/**
|
|
63
|
+
* Renders this item as a trigger for a nested sub-menu (only works when
|
|
64
|
+
* `children` is also defined). Pass `true` for the defaults, or an object to
|
|
65
|
+
* customize the sub-menu: `title` is shown as its header, and `position`
|
|
66
|
+
* overrides where it opens relative to this item (defaults to `right-start`).
|
|
67
|
+
* `maxHeight` and `maxWidth` cap its size without forcing smaller
|
|
68
|
+
* menus to fill those dimensions.
|
|
69
|
+
*/
|
|
70
|
+
submenu?: boolean | (DropdownMenuContentSizeOptions & {
|
|
71
|
+
emptyMessage?: React.ReactNode;
|
|
72
|
+
position?: UseOverlayProps['position'];
|
|
73
|
+
search?: DropdownMenuSearchOptions;
|
|
74
|
+
title?: string;
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* A plain text version of the `label` prop if the label is not a string. Used for
|
|
78
|
+
* filtering and keyboard select (quick-focusing on options by typing the first letter).
|
|
79
|
+
*/
|
|
80
|
+
textValue?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Destination if this menu item is a link.
|
|
83
|
+
*/
|
|
84
|
+
to?: LinkProps['to'];
|
|
85
|
+
/**
|
|
86
|
+
* An icon-only button rendered beside, rather than inside, the focusable menu item.
|
|
87
|
+
*/
|
|
88
|
+
trailingAction?: MenuItemTrailingAction;
|
|
89
|
+
}
|
|
90
|
+
interface DropdownMenuItemProps<T extends React.ElementType = 'li'> {
|
|
91
|
+
/**
|
|
92
|
+
* Whether to close the menu when an item has been clicked/selected
|
|
93
|
+
*/
|
|
94
|
+
closeOnSelect: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Node representation (from @react-aria) of the item
|
|
97
|
+
*/
|
|
98
|
+
node: Node<MenuItemProps>;
|
|
99
|
+
/**
|
|
100
|
+
* Tree state (from @react-stately) inherited from parent menu
|
|
101
|
+
*/
|
|
102
|
+
state: TreeState<MenuItemProps>;
|
|
103
|
+
id?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Whether the item is in a virtualized menu. React Aria then sets
|
|
106
|
+
* `aria-posinset` and `aria-setsize`, so assistive technology knows the
|
|
107
|
+
* item's position in the full menu rather than among the mounted rows.
|
|
108
|
+
*/
|
|
109
|
+
isVirtualized?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Ref to the inner focusable menu item.
|
|
112
|
+
*/
|
|
113
|
+
menuItemRef?: React.Ref<HTMLElement>;
|
|
114
|
+
/**
|
|
115
|
+
* Handler that is called when the menu should close after selecting an item
|
|
116
|
+
*/
|
|
117
|
+
onClose?: () => void;
|
|
118
|
+
ref?: React.ComponentPropsWithRef<NoInfer<T>>['ref'];
|
|
119
|
+
/**
|
|
120
|
+
* Tag name for item wrapper
|
|
121
|
+
*/
|
|
122
|
+
renderAs?: T;
|
|
123
|
+
/**
|
|
124
|
+
* Measurement props from a virtualized list, applied to the item's root
|
|
125
|
+
* element. The root is measured rather than a wrapper, since submenu
|
|
126
|
+
* wrappers use `display: contents` and have no height of their own.
|
|
127
|
+
*/
|
|
128
|
+
rowProps?: VirtualRowProps;
|
|
129
|
+
/**
|
|
130
|
+
* Props from `useSubmenuTrigger`, set when this item opens a submenu.
|
|
131
|
+
*/
|
|
132
|
+
submenuTriggerProps?: SubmenuTriggerAria<MenuItemProps>['submenuTriggerProps'];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A menu item with a label, optional details, leading and trailing elements.
|
|
136
|
+
* Can also be used as a trigger button for a submenu. See:
|
|
137
|
+
* https://react-spectrum.adobe.com/react-aria/useMenu.html
|
|
138
|
+
*/
|
|
139
|
+
export declare function DropdownMenuItem<T extends React.ElementType = 'li'>({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuTriggerProps, isVirtualized, rowProps, ...props }: DropdownMenuItemProps<T>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, useContext, useRef } from "react";
|
|
3
|
+
import { useKeyboard } from "@react-aria/interactions";
|
|
4
|
+
import { useMenuItem } from "@react-aria/menu";
|
|
5
|
+
import { mergeProps, mergeRefs } from "@react-aria/utils";
|
|
6
|
+
import { IconCheckmark } from "@sentry/icons/checkmark";
|
|
7
|
+
import { IconChevron } from "@sentry/icons/chevron";
|
|
8
|
+
import { ExternalLink, Link } from "../link/index.js";
|
|
9
|
+
import { ListItem } from "../menu/index.js";
|
|
10
|
+
import { isAfterFirstInSection } from "../useVirtualCollection.js";
|
|
11
|
+
import { DropdownMenuContext } from "./context.js";
|
|
12
|
+
function getSectionItemAttributes(node, state) {
|
|
13
|
+
const section = null === node.parentKey || void 0 === node.parentKey ? null : state.collection.getItem(node.parentKey);
|
|
14
|
+
if (section?.type !== 'section') return {};
|
|
15
|
+
return {
|
|
16
|
+
'data-section-item': true,
|
|
17
|
+
'data-first-in-section': isAfterFirstInSection(node, section) ? void 0 : true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function DropdownMenuItem({ node, state, closeOnSelect, onClose, renderAs, ref, menuItemRef, submenuTriggerProps, isVirtualized, rowProps, ...props }) {
|
|
21
|
+
const innerWrapRef = useRef(null);
|
|
22
|
+
const trailingActionRef = useRef(null);
|
|
23
|
+
const isDisabled = state.disabledKeys.has(node.key);
|
|
24
|
+
const isFocused = state.selectionManager.focusedKey === node.key;
|
|
25
|
+
const { key, onAction, to, label, isSelected, leadingItems, submenu, trailingItems, trailingAction, externalHref, closeOnSelect: itemCloseOnSelect, ref: itemRef, ...itemProps } = node.value ?? {};
|
|
26
|
+
const isSubmenu = !!submenu;
|
|
27
|
+
const { size } = node.props;
|
|
28
|
+
const { rootMenuState } = useContext(DropdownMenuContext);
|
|
29
|
+
const isLink = to || externalHref;
|
|
30
|
+
const resolvedCloseOnSelect = itemCloseOnSelect ?? closeOnSelect;
|
|
31
|
+
const actionHandler = ()=>{
|
|
32
|
+
if (isLink) {
|
|
33
|
+
if (resolvedCloseOnSelect) requestAnimationFrame(()=>rootMenuState?.close());
|
|
34
|
+
onAction?.();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
onAction?.();
|
|
38
|
+
};
|
|
39
|
+
const { keyboardProps } = useKeyboard({
|
|
40
|
+
onKeyDown: (e)=>{
|
|
41
|
+
if ('ArrowRight' === e.key && document.activeElement === innerWrapRef.current && trailingActionRef.current) {
|
|
42
|
+
trailingActionRef.current.focus();
|
|
43
|
+
if (document.activeElement === trailingActionRef.current) return void e.preventDefault();
|
|
44
|
+
}
|
|
45
|
+
e.continuePropagation();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const { isOpen: _isSubmenuOpen, ...submenuTriggerAriaProps } = submenuTriggerProps ?? {};
|
|
49
|
+
const { menuItemProps, labelProps, descriptionProps } = useMenuItem({
|
|
50
|
+
...submenuTriggerAriaProps,
|
|
51
|
+
key: node.key,
|
|
52
|
+
onAction: actionHandler,
|
|
53
|
+
onClose: ()=>{
|
|
54
|
+
onClose?.();
|
|
55
|
+
rootMenuState?.close();
|
|
56
|
+
},
|
|
57
|
+
closeOnSelect: isLink ? false : resolvedCloseOnSelect,
|
|
58
|
+
isDisabled,
|
|
59
|
+
isVirtualized
|
|
60
|
+
}, state, innerWrapRef);
|
|
61
|
+
const makeInnerWrapProps = ()=>{
|
|
62
|
+
if (to) return {
|
|
63
|
+
as: Link,
|
|
64
|
+
to
|
|
65
|
+
};
|
|
66
|
+
if (externalHref) return {
|
|
67
|
+
as: ExternalLink,
|
|
68
|
+
href: externalHref
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
as: 'div',
|
|
72
|
+
onClick: (e)=>{
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
e.stopPropagation();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const mergedMenuItemContentProps = mergeProps(props, menuItemProps, keyboardProps, makeInnerWrapProps(), {
|
|
79
|
+
ref: mergeRefs(menuItemRef, innerWrapRef),
|
|
80
|
+
'data-test-id': key
|
|
81
|
+
});
|
|
82
|
+
const { onPointerEnter, onPointerMove, onPointerLeave, ...menuItemContentProps } = mergedMenuItemContentProps;
|
|
83
|
+
const itemLabel = node.rendered ?? label;
|
|
84
|
+
const isFromRow = (event)=>event.target instanceof Node && event.currentTarget.contains(event.target);
|
|
85
|
+
const rowEventProps = {
|
|
86
|
+
onPointerEnter: (event)=>{
|
|
87
|
+
if (isFromRow(event)) onPointerEnter?.(event);
|
|
88
|
+
},
|
|
89
|
+
onPointerMove: (event)=>{
|
|
90
|
+
if (isFromRow(event)) onPointerMove?.(event);
|
|
91
|
+
},
|
|
92
|
+
onPointerLeave: (event)=>{
|
|
93
|
+
if (isFromRow(event)) onPointerLeave?.(event);
|
|
94
|
+
},
|
|
95
|
+
onKeyDown: (event)=>{
|
|
96
|
+
if ('ArrowLeft' === event.key && event.target === trailingActionRef.current) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopPropagation();
|
|
99
|
+
innerWrapRef.current?.focus();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return /*#__PURE__*/ jsx(ListItem, {
|
|
104
|
+
ref: mergeRefs(ref, itemRef, rowProps?.ref),
|
|
105
|
+
"data-index": rowProps?.['data-index'],
|
|
106
|
+
...getSectionItemAttributes(node, state),
|
|
107
|
+
as: renderAs,
|
|
108
|
+
label: itemLabel,
|
|
109
|
+
leadingItems: void 0 === isSelected ? leadingItems : (itemState)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
110
|
+
children: [
|
|
111
|
+
/*#__PURE__*/ jsx(IconCheckmark, {
|
|
112
|
+
size: "md",
|
|
113
|
+
variant: "accent",
|
|
114
|
+
"aria-hidden": true,
|
|
115
|
+
visibility: isSelected ? 'visible' : 'hidden'
|
|
116
|
+
}),
|
|
117
|
+
'function' == typeof leadingItems ? leadingItems(itemState) : leadingItems
|
|
118
|
+
]
|
|
119
|
+
}),
|
|
120
|
+
disabled: isDisabled,
|
|
121
|
+
isFocused: isFocused,
|
|
122
|
+
innerWrapProps: menuItemContentProps,
|
|
123
|
+
labelProps: labelProps,
|
|
124
|
+
detailsProps: descriptionProps,
|
|
125
|
+
trailingAction: trailingAction,
|
|
126
|
+
trailingActionRef: trailingActionRef,
|
|
127
|
+
trailingItems: isSubmenu ? /*#__PURE__*/ jsxs(Fragment, {
|
|
128
|
+
children: [
|
|
129
|
+
trailingItems,
|
|
130
|
+
/*#__PURE__*/ jsx(IconChevron, {
|
|
131
|
+
size: "md",
|
|
132
|
+
direction: "right",
|
|
133
|
+
"aria-hidden": "true"
|
|
134
|
+
})
|
|
135
|
+
]
|
|
136
|
+
}) : trailingItems,
|
|
137
|
+
size: size,
|
|
138
|
+
...rowEventProps,
|
|
139
|
+
...itemProps
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export { DropdownMenuItem };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { AriaMenuOptions } from '@react-aria/menu';
|
|
3
|
+
import type { RootMenuTriggerState } from '@react-stately/menu';
|
|
4
|
+
import type { TreeProps } from '@react-stately/tree';
|
|
5
|
+
import type { DropdownMenuContentSizeOptions, DropdownMenuSearchOptions, MenuItemProps } from './item.js';
|
|
6
|
+
export interface DropdownMenuListProps extends Omit<AriaMenuOptions<MenuItemProps>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange' | 'disallowEmptySelection'>, TreeProps<MenuItemProps>, DropdownMenuContentSizeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Where this menu sits in the menu tree.
|
|
9
|
+
*/
|
|
10
|
+
menuLevel: DropdownMenuLevel;
|
|
11
|
+
overlayPositionProps: React.HTMLAttributes<HTMLDivElement>;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the menu should close when an item has been clicked/selected
|
|
14
|
+
*/
|
|
15
|
+
closeOnSelect?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Prevent users from highlighting text inside the menu.
|
|
18
|
+
*/
|
|
19
|
+
disableTextSelection?: boolean;
|
|
20
|
+
emptyMessage?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Whether interacting outside the menu closes it. Submenus inherit the
|
|
23
|
+
* setting of their parent menu.
|
|
24
|
+
*/
|
|
25
|
+
isDismissable?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether only the items near the viewport are rendered. Computed by
|
|
28
|
+
* `DropdownMenuContent` from `virtualizeThreshold`, so it is not part of the
|
|
29
|
+
* public API: consumers set the threshold instead.
|
|
30
|
+
*/
|
|
31
|
+
isVirtualized?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* To be displayed below the menu items
|
|
34
|
+
*/
|
|
35
|
+
menuFooter?: React.ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* Title to display on top of the menu
|
|
38
|
+
*/
|
|
39
|
+
menuTitle?: React.ReactNode;
|
|
40
|
+
/** Controlled input state supplied by DropdownMenuContent. */
|
|
41
|
+
searchState?: DropdownMenuSearchOptions & {
|
|
42
|
+
onChange: (value: string) => void;
|
|
43
|
+
value: string;
|
|
44
|
+
};
|
|
45
|
+
size?: MenuItemProps['size'];
|
|
46
|
+
/**
|
|
47
|
+
* Number of items, counting the items inside sections, above which only the
|
|
48
|
+
* items near the viewport are rendered. Submenus inherit the threshold of
|
|
49
|
+
* their parent menu. Pass `Infinity` to never virtualize.
|
|
50
|
+
* @default 150
|
|
51
|
+
*/
|
|
52
|
+
virtualizeThreshold?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Style overrides applied to the position wrapper. Useful for overriding
|
|
55
|
+
* the default z-index (e.g. when the menu is inside a high z-index container
|
|
56
|
+
* like a sidebar).
|
|
57
|
+
*/
|
|
58
|
+
zIndex?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A root menu starts a menu tree, even when it renders inside another menu.
|
|
62
|
+
* A submenu belongs to the tree of the menu that contains its trigger, and
|
|
63
|
+
* reads the root menu state from context.
|
|
64
|
+
*/
|
|
65
|
+
type DropdownMenuLevel = {
|
|
66
|
+
state: RootMenuTriggerState;
|
|
67
|
+
type: 'root';
|
|
68
|
+
} | {
|
|
69
|
+
/** Closes this submenu and returns focus to its trigger. */
|
|
70
|
+
close: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Index of this submenu in the root menu's `expandedKeysStack`: 0 for a
|
|
73
|
+
* submenu of the root menu, 1 for a submenu of that submenu, and so on.
|
|
74
|
+
*/
|
|
75
|
+
level: number;
|
|
76
|
+
/** Ref for the menu element, so the trigger can move focus into it. */
|
|
77
|
+
ref: React.RefObject<HTMLUListElement | null>;
|
|
78
|
+
type: 'submenu';
|
|
79
|
+
};
|
|
80
|
+
export type DropdownMenuContentProps = Omit<DropdownMenuListProps, 'searchState' | 'isVirtualized'> & {
|
|
81
|
+
items: MenuItemProps[];
|
|
82
|
+
search?: DropdownMenuSearchOptions;
|
|
83
|
+
};
|
|
84
|
+
export declare function DropdownMenuContent({ items, disabledKeys, size, search, isDismissable, virtualizeThreshold, ...props }: DropdownMenuContentProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
85
|
+
export {};
|