@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,74 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { useVirtualRows } from "../useVirtualRows.js";
|
|
3
|
+
const heightEstimations = {
|
|
4
|
+
sm: {
|
|
5
|
+
regular: 32,
|
|
6
|
+
large: 49
|
|
7
|
+
},
|
|
8
|
+
md: {
|
|
9
|
+
regular: 36,
|
|
10
|
+
large: 53
|
|
11
|
+
},
|
|
12
|
+
xs: {
|
|
13
|
+
regular: 25,
|
|
14
|
+
large: 42
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const listPaddingVertical = 4;
|
|
18
|
+
function useVirtualizedItems({ listItems, listPadding = listPaddingVertical, virtualized = false, size }) {
|
|
19
|
+
const scrollElementRef = useRef(null);
|
|
20
|
+
const heightEstimation = heightEstimations[size];
|
|
21
|
+
const { totalSize, virtualItems, virtualizer } = useVirtualRows({
|
|
22
|
+
count: listItems.length,
|
|
23
|
+
getScrollElement: ()=>scrollElementRef?.current,
|
|
24
|
+
estimateSize: (index)=>{
|
|
25
|
+
const item = listItems[index];
|
|
26
|
+
if (item?.props?.details) return heightEstimation.large;
|
|
27
|
+
return heightEstimation.regular;
|
|
28
|
+
},
|
|
29
|
+
enabled: virtualized,
|
|
30
|
+
overscan: 1
|
|
31
|
+
});
|
|
32
|
+
if (virtualized) return {
|
|
33
|
+
items: virtualItems,
|
|
34
|
+
scrollToIndex: (index)=>{
|
|
35
|
+
virtualizer.scrollToIndex(index, {
|
|
36
|
+
align: 'auto'
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
scrollElementRef,
|
|
40
|
+
itemProps: (index)=>({
|
|
41
|
+
ref: virtualizer.measureElement,
|
|
42
|
+
'data-index': index
|
|
43
|
+
}),
|
|
44
|
+
wrapperProps: {
|
|
45
|
+
'data-is-virtualized': true,
|
|
46
|
+
style: {
|
|
47
|
+
height: totalSize + 2 * listPadding,
|
|
48
|
+
width: '100%',
|
|
49
|
+
position: 'relative'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
listWrapStyle: {
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
top: 0,
|
|
55
|
+
left: 0,
|
|
56
|
+
width: '100%',
|
|
57
|
+
transform: `translateY(${virtualItems[0]?.start ?? 0}px)`
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
items: listItems.map((_, index)=>({
|
|
62
|
+
index,
|
|
63
|
+
start: 0
|
|
64
|
+
})),
|
|
65
|
+
scrollToIndex: ()=>{},
|
|
66
|
+
scrollElementRef: void 0,
|
|
67
|
+
itemProps: ()=>{},
|
|
68
|
+
wrapperProps: {
|
|
69
|
+
'data-is-virtualized': false
|
|
70
|
+
},
|
|
71
|
+
listWrapStyle: {}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { useVirtualizedItems };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ListState } from '@react-stately/list';
|
|
2
|
+
import type { Node, Selection } from '@react-types/shared';
|
|
3
|
+
import type { SelectProps } from './compactSelect.js';
|
|
4
|
+
import type { SearchConfig, SearchMatchResult, SelectKey, SelectOption, SelectOptionOrSection, SelectOptionOrSectionWithKey, SelectOptionWithKey, SelectSectionWithKey } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Whether any visible option has custom leading items, so options without them
|
|
7
|
+
* should reserve matching space to keep labels aligned.
|
|
8
|
+
*/
|
|
9
|
+
export declare function hasVisibleLeadingItems(listItems: Array<Node<unknown>>, hiddenOptions: Set<SelectKey>): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Normalises the `search` prop into a plain config object (or `undefined` if
|
|
12
|
+
* search is disabled). Accepts `true` as shorthand for `{}` and treats
|
|
13
|
+
* `false`/`undefined` as "no search".
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSearchConfig<Value extends SelectKey>(search: boolean | SearchConfig<Value> | undefined): SearchConfig<Value> | undefined;
|
|
16
|
+
export declare function getEscapedKey(value: SelectKey): string;
|
|
17
|
+
export declare function getItemsWithKeys<Value extends SelectKey>(options: Array<SelectOption<Value>>): Array<SelectOptionWithKey<Value>>;
|
|
18
|
+
export declare function getItemsWithKeys<Value extends SelectKey>(options: Array<SelectOptionOrSection<Value>>): Array<SelectOptionOrSectionWithKey<Value>>;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively finds the selected option(s) from an options array. Useful for
|
|
21
|
+
* non-flat arrays that contain sections (groups of options).
|
|
22
|
+
*/
|
|
23
|
+
export declare function getSelectedOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, selection: Selection): Array<SelectOption<Value>>;
|
|
24
|
+
/**
|
|
25
|
+
* Recursively finds the selected option(s) from an options array. Useful for non-flat
|
|
26
|
+
* arrays that contain sections (groups of options). Returns the values of options that
|
|
27
|
+
* were removed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDisabledOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, isOptionDisabled?: (opt: SelectOptionWithKey<Value>) => boolean): SelectKey[];
|
|
30
|
+
/**
|
|
31
|
+
* Recursively finds the option(s) that don't match the designated search string or are
|
|
32
|
+
* outside the list box's count limit. Also collects match scores for use in sorting.
|
|
33
|
+
*
|
|
34
|
+
* An option is considered a match when its score is greater than 0. The default matcher
|
|
35
|
+
* uses fzf and always returns a positive score for any subsequence match, 0 when there
|
|
36
|
+
* is no match. Custom matchers can return any positive score to influence sort order —
|
|
37
|
+
* higher scores appear first.
|
|
38
|
+
*
|
|
39
|
+
* Returns both the set of hidden option keys and a map of key → score for matched
|
|
40
|
+
* options.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getHiddenOptions<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, search: string, limit?: number, searchMatcher?: (option: SelectOptionWithKey<Value>, search: string) => SearchMatchResult): {
|
|
43
|
+
hidden: Set<SelectKey>;
|
|
44
|
+
scores: Map<SelectKey, number>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Sorts items by their match scores (descending). Options with higher scores appear
|
|
48
|
+
* first. Options without a score entry maintain their original relative order.
|
|
49
|
+
*
|
|
50
|
+
* For sectioned lists, options are sorted within each section. For flat lists, all
|
|
51
|
+
* options are sorted globally.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getSortedItems<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>, scores: Map<SelectKey, number>): Array<SelectOptionOrSectionWithKey<Value>>;
|
|
54
|
+
interface SectionToggleProps {
|
|
55
|
+
item: Node<any>;
|
|
56
|
+
listState: ListState<any>;
|
|
57
|
+
listId?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A visible toggle button to select/unselect all options within a given section. See
|
|
61
|
+
* also: `HiddenSectionToggle`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function SectionToggle({ item, listState }: SectionToggleProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
64
|
+
/**
|
|
65
|
+
* A visually hidden but keyboard-focusable button to toggle (select/unselect) all
|
|
66
|
+
* options in a given section. We need these hidden buttons because the visible toggle
|
|
67
|
+
* buttons inside ListBox/GridList are not keyboard-focusable (due to them implementing
|
|
68
|
+
* roving `tabindex`).
|
|
69
|
+
*/
|
|
70
|
+
export declare function HiddenSectionToggle({ item, listState, listId, ...props }: SectionToggleProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
71
|
+
export declare function itemIsSectionWithKey<T extends SelectKey>(item: SelectOptionOrSectionWithKey<T>): item is SelectSectionWithKey<T>;
|
|
72
|
+
export declare function shouldCloseOnSelect({ multiple, closeOnSelect, selectedOptions, }: Pick<SelectProps<any>, 'multiple' | 'closeOnSelect'> & {
|
|
73
|
+
selectedOptions: Array<SelectOption<any>>;
|
|
74
|
+
}): boolean;
|
|
75
|
+
export declare function getDuplicateOptionKeysInfo<Value extends SelectKey>(items: Array<SelectOptionOrSectionWithKey<Value>>): {
|
|
76
|
+
duplicateOptionKeys: string[];
|
|
77
|
+
hasSections: boolean;
|
|
78
|
+
optionCount: number;
|
|
79
|
+
};
|
|
80
|
+
export {};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
|
+
import { useFocus, usePress } from "@react-aria/interactions";
|
|
4
|
+
import { mergeProps } from "@react-aria/utils";
|
|
5
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
|
+
import { useTranslation } from "../translation/index.js";
|
|
7
|
+
import { getSearchScore } from "../fzf.js";
|
|
8
|
+
import { SectionToggleButton } from "./styles.js";
|
|
9
|
+
function hasVisibleLeadingItems(listItems, hiddenOptions) {
|
|
10
|
+
return listItems.flatMap((node)=>'section' === node.type ? [
|
|
11
|
+
...node.childNodes
|
|
12
|
+
] : [
|
|
13
|
+
node
|
|
14
|
+
]).some((node)=>{
|
|
15
|
+
const { leadingItems } = node.props;
|
|
16
|
+
return !hiddenOptions.has(node.key) && Boolean(leadingItems);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const SIMPLE_CSS_IDENTIFIER = /^-?(?!\d)\w[-\w]*$/;
|
|
20
|
+
function getSearchConfig(search) {
|
|
21
|
+
if (!search) return;
|
|
22
|
+
if (true === search) return {};
|
|
23
|
+
return search;
|
|
24
|
+
}
|
|
25
|
+
function getEscapedKey(value) {
|
|
26
|
+
const stringValue = String(value);
|
|
27
|
+
return SIMPLE_CSS_IDENTIFIER.test(stringValue) ? stringValue : CSS.escape(stringValue);
|
|
28
|
+
}
|
|
29
|
+
function getItemsWithKeys(options) {
|
|
30
|
+
return options.map((item, i)=>{
|
|
31
|
+
if ('options' in item) return {
|
|
32
|
+
...item,
|
|
33
|
+
key: item.key ?? `options-${i}`,
|
|
34
|
+
options: getItemsWithKeys(item.options)
|
|
35
|
+
};
|
|
36
|
+
const existingKey = 'key' in item && 'string' == typeof item.key ? item.key : void 0;
|
|
37
|
+
return {
|
|
38
|
+
...item,
|
|
39
|
+
key: existingKey ?? getEscapedKey(item.value)
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function getSelectedOptions(items, selection) {
|
|
44
|
+
return items.reduce((acc, cur)=>{
|
|
45
|
+
if ('options' in cur) return acc.concat(getSelectedOptions(cur.options, selection));
|
|
46
|
+
if ('all' === selection || selection.has(cur.key)) {
|
|
47
|
+
const { key: _key, ...opt } = cur;
|
|
48
|
+
acc.push(opt);
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
}, []);
|
|
52
|
+
}
|
|
53
|
+
function getDisabledOptions(items, isOptionDisabled) {
|
|
54
|
+
return items.reduce((acc, cur)=>{
|
|
55
|
+
if ('options' in cur) {
|
|
56
|
+
if (cur.disabled) {
|
|
57
|
+
for (const opt of cur.options)acc.push(opt.key);
|
|
58
|
+
return acc;
|
|
59
|
+
}
|
|
60
|
+
return acc.concat(getDisabledOptions(cur.options, isOptionDisabled));
|
|
61
|
+
}
|
|
62
|
+
if (isOptionDisabled?.(cur) ?? cur.disabled) acc.push(cur.key);
|
|
63
|
+
return acc;
|
|
64
|
+
}, []);
|
|
65
|
+
}
|
|
66
|
+
function defaultSearchMatcher(option, search) {
|
|
67
|
+
const text = option.textValue ?? ('string' == typeof option.label ? option.label : '');
|
|
68
|
+
if (!text) return {
|
|
69
|
+
score: 0
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
score: getSearchScore(text, search)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function getHiddenOptions(items, search, limit = 1 / 0, searchMatcher) {
|
|
76
|
+
const scores = new Map();
|
|
77
|
+
const matcher = searchMatcher ?? defaultSearchMatcher;
|
|
78
|
+
const filterOption = (opt)=>{
|
|
79
|
+
if (!search) return true;
|
|
80
|
+
const result = matcher(opt, search);
|
|
81
|
+
if (result.score > 0) {
|
|
82
|
+
scores.set(opt.key, result.score);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
const hiddenOptionsSet = new Set();
|
|
88
|
+
const remainingItems = items.flatMap((item)=>{
|
|
89
|
+
if ('options' in item) {
|
|
90
|
+
const filteredOptions = item.options.map((opt)=>{
|
|
91
|
+
if (filterOption(opt)) return opt;
|
|
92
|
+
hiddenOptionsSet.add(opt.key);
|
|
93
|
+
return null;
|
|
94
|
+
}).filter((opt)=>!!opt);
|
|
95
|
+
return filteredOptions.length > 0 ? {
|
|
96
|
+
...item,
|
|
97
|
+
options: filteredOptions
|
|
98
|
+
} : null;
|
|
99
|
+
}
|
|
100
|
+
if (filterOption(item)) return item;
|
|
101
|
+
hiddenOptionsSet.add(item.key);
|
|
102
|
+
return null;
|
|
103
|
+
}).filter((item)=>!!item);
|
|
104
|
+
const orderedRemainingItems = scores.size > 0 ? getSortedItems(remainingItems, scores) : remainingItems;
|
|
105
|
+
let threshold = [
|
|
106
|
+
1 / 0,
|
|
107
|
+
1 / 0
|
|
108
|
+
];
|
|
109
|
+
let accumulator = 0;
|
|
110
|
+
let currentIndex = 0;
|
|
111
|
+
while(currentIndex < orderedRemainingItems.length){
|
|
112
|
+
const item = orderedRemainingItems[currentIndex];
|
|
113
|
+
const delta = item && 'options' in item ? item.options.length : 1;
|
|
114
|
+
if (accumulator + delta > limit) {
|
|
115
|
+
threshold = [
|
|
116
|
+
currentIndex,
|
|
117
|
+
limit - accumulator
|
|
118
|
+
];
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
accumulator += delta;
|
|
122
|
+
currentIndex += 1;
|
|
123
|
+
}
|
|
124
|
+
for(let i = threshold[0]; i < orderedRemainingItems.length; i++){
|
|
125
|
+
const item = orderedRemainingItems[i];
|
|
126
|
+
if (item) if ('options' in item) {
|
|
127
|
+
const startingIndex = i === threshold[0] ? threshold[1] : 0;
|
|
128
|
+
for (const option of item.options.slice(startingIndex))hiddenOptionsSet.add(option.key);
|
|
129
|
+
} else hiddenOptionsSet.add(item.key);
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
hidden: hiddenOptionsSet,
|
|
133
|
+
scores
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function getSortedItems(items, scores) {
|
|
137
|
+
const hasSections = items.some((item)=>'options' in item);
|
|
138
|
+
if (hasSections) return items.map((item)=>{
|
|
139
|
+
if ('options' in item) return {
|
|
140
|
+
...item,
|
|
141
|
+
options: item.options.toSorted((a, b)=>(scores.get(b.key) ?? 0) - (scores.get(a.key) ?? 0))
|
|
142
|
+
};
|
|
143
|
+
return item;
|
|
144
|
+
});
|
|
145
|
+
return items.toSorted((a, b)=>(scores.get(b.key) ?? 0) - (scores.get(a.key) ?? 0));
|
|
146
|
+
}
|
|
147
|
+
function toggleOptions(optionKeys, selectionManager) {
|
|
148
|
+
const { selectedKeys } = selectionManager;
|
|
149
|
+
const newSelectedKeys = new Set(selectedKeys);
|
|
150
|
+
const allOptionsSelected = optionKeys.every((val)=>selectionManager.isSelected(val));
|
|
151
|
+
optionKeys.forEach((val)=>allOptionsSelected ? newSelectedKeys.delete(val) : newSelectedKeys.add(val));
|
|
152
|
+
selectionManager.setSelectedKeys(newSelectedKeys);
|
|
153
|
+
}
|
|
154
|
+
function SectionToggle({ item, listState }) {
|
|
155
|
+
const { t } = useTranslation();
|
|
156
|
+
const allOptionsSelected = useMemo(()=>[
|
|
157
|
+
...item.childNodes
|
|
158
|
+
].every((n)=>listState.selectionManager.isSelected(n.key)), [
|
|
159
|
+
item,
|
|
160
|
+
listState.selectionManager
|
|
161
|
+
]);
|
|
162
|
+
const visible = useMemo(()=>{
|
|
163
|
+
const listHasFocus = listState.selectionManager.isFocused;
|
|
164
|
+
const sectionHasFocus = [
|
|
165
|
+
...item.childNodes
|
|
166
|
+
].some((n)=>listState.selectionManager.focusedKey === n.key);
|
|
167
|
+
return listHasFocus && sectionHasFocus;
|
|
168
|
+
}, [
|
|
169
|
+
item,
|
|
170
|
+
listState.selectionManager.focusedKey,
|
|
171
|
+
listState.selectionManager.isFocused
|
|
172
|
+
]);
|
|
173
|
+
const toggleAllOptions = useCallback(()=>{
|
|
174
|
+
toggleOptions(Array.from(item.childNodes, (n)=>n.key), listState.selectionManager);
|
|
175
|
+
}, [
|
|
176
|
+
item,
|
|
177
|
+
listState.selectionManager
|
|
178
|
+
]);
|
|
179
|
+
return /*#__PURE__*/ jsx(SectionToggleButton, {
|
|
180
|
+
"data-key": item.key,
|
|
181
|
+
visible: visible,
|
|
182
|
+
size: "zero",
|
|
183
|
+
variant: "transparent",
|
|
184
|
+
"aria-hidden": true,
|
|
185
|
+
tabIndex: -1,
|
|
186
|
+
onClick: toggleAllOptions,
|
|
187
|
+
children: allOptionsSelected ? t('Unselect All') : t('Select All')
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function HiddenSectionToggle({ item, listState, listId = '', ...props }) {
|
|
191
|
+
const { t } = useTranslation();
|
|
192
|
+
const { focusProps } = useFocus({
|
|
193
|
+
onFocus: ()=>{
|
|
194
|
+
const visibleCounterpart = document.getElementById(listId)?.querySelector(`button[aria-hidden][data-key="${item.key}"]`);
|
|
195
|
+
if (!visibleCounterpart) return;
|
|
196
|
+
visibleCounterpart.classList.add('focus-visible');
|
|
197
|
+
},
|
|
198
|
+
onBlur: ()=>{
|
|
199
|
+
const visibleCounterpart = document.getElementById(listId)?.querySelector(`button[aria-hidden][data-key="${item.key}"]`);
|
|
200
|
+
if (!visibleCounterpart) return;
|
|
201
|
+
visibleCounterpart.classList.remove('focus-visible');
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const allOptionsSelected = useMemo(()=>[
|
|
205
|
+
...item.childNodes
|
|
206
|
+
].every((n)=>listState.selectionManager.isSelected(n.key)), [
|
|
207
|
+
item,
|
|
208
|
+
listState.selectionManager
|
|
209
|
+
]);
|
|
210
|
+
const { pressProps } = usePress({
|
|
211
|
+
onPress: ()=>{
|
|
212
|
+
toggleOptions(Array.from(item.childNodes, (n)=>n.key), listState.selectionManager);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return /*#__PURE__*/ jsx(VisuallyHidden, {
|
|
216
|
+
role: "presentation",
|
|
217
|
+
children: /*#__PURE__*/ jsxs("button", {
|
|
218
|
+
...props,
|
|
219
|
+
...mergeProps(focusProps, pressProps),
|
|
220
|
+
"aria-controls": listId,
|
|
221
|
+
id: `${listId}-section-toggle-${item.key}`,
|
|
222
|
+
children: [
|
|
223
|
+
allOptionsSelected ? t('Unselect All in ') : t('Select All in '),
|
|
224
|
+
item.textValue || item.rendered
|
|
225
|
+
]
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function itemIsSectionWithKey(item) {
|
|
230
|
+
return 'options' in item;
|
|
231
|
+
}
|
|
232
|
+
function shouldCloseOnSelect({ multiple, closeOnSelect, selectedOptions }) {
|
|
233
|
+
if ('function' == typeof closeOnSelect) return closeOnSelect(multiple ? selectedOptions : selectedOptions[0]);
|
|
234
|
+
if (null != closeOnSelect) return closeOnSelect;
|
|
235
|
+
return !multiple;
|
|
236
|
+
}
|
|
237
|
+
function getDuplicateOptionKeysInfo(items) {
|
|
238
|
+
const seen = new Set();
|
|
239
|
+
const duplicates = new Set();
|
|
240
|
+
let optionCount = 0;
|
|
241
|
+
let hasSections = false;
|
|
242
|
+
const collect = (list)=>{
|
|
243
|
+
for (const item of list){
|
|
244
|
+
if ('options' in item) {
|
|
245
|
+
hasSections = true;
|
|
246
|
+
collect(item.options);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
optionCount += 1;
|
|
250
|
+
const key = String(item.key);
|
|
251
|
+
if (!duplicates.has(key)) if (seen.has(key)) duplicates.add(key);
|
|
252
|
+
else seen.add(key);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
collect(items);
|
|
256
|
+
return {
|
|
257
|
+
duplicateOptionKeys: [
|
|
258
|
+
...duplicates
|
|
259
|
+
],
|
|
260
|
+
hasSections,
|
|
261
|
+
optionCount
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
export { HiddenSectionToggle, SectionToggle, getDisabledOptions, getDuplicateOptionKeysInfo, getEscapedKey, getHiddenOptions, getItemsWithKeys, getSearchConfig, getSelectedOptions, getSortedItems, hasVisibleLeadingItems, itemIsSectionWithKey, shouldCloseOnSelect };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { ButtonProps } from '../button/index.js';
|
|
3
|
+
export type ConfirmMessageRenderProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Closes the modal, if `bypass` is true, will call `onConfirm` callback
|
|
6
|
+
*/
|
|
7
|
+
close: (e: React.MouseEvent) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Confirms the modal
|
|
10
|
+
*/
|
|
11
|
+
confirm: () => void;
|
|
12
|
+
/**
|
|
13
|
+
* Set the disabled state of the confirm button
|
|
14
|
+
*/
|
|
15
|
+
disableConfirmButton: (disable: boolean) => void;
|
|
16
|
+
/**
|
|
17
|
+
* When the modal is confirmed the function registered will be called.
|
|
18
|
+
*
|
|
19
|
+
* Useful if your rendered message contains some functionality that should be
|
|
20
|
+
* triggered upon the modal being confirmed.
|
|
21
|
+
*
|
|
22
|
+
* This should be called in the components componentDidMount.
|
|
23
|
+
*/
|
|
24
|
+
setConfirmCallback: (cb: () => void) => void;
|
|
25
|
+
};
|
|
26
|
+
type ConfirmButtonsRenderProps = {
|
|
27
|
+
/**
|
|
28
|
+
* Applications can call this function to manually close the modal.
|
|
29
|
+
*/
|
|
30
|
+
closeModal: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* The default onClick behavior, including closing the modal and triggering the
|
|
33
|
+
* onConfirm / onCancel callbacks.
|
|
34
|
+
*/
|
|
35
|
+
defaultOnClick: () => void;
|
|
36
|
+
};
|
|
37
|
+
type ChildrenRenderProps = {
|
|
38
|
+
open: () => void;
|
|
39
|
+
};
|
|
40
|
+
export type OpenConfirmOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* If true, will skip the confirmation modal and call `onConfirm` callback
|
|
43
|
+
*/
|
|
44
|
+
bypass?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Text to show in the cancel button
|
|
47
|
+
*/
|
|
48
|
+
cancelText?: React.ReactNode;
|
|
49
|
+
/**
|
|
50
|
+
* Text to show in the confirmation button
|
|
51
|
+
*/
|
|
52
|
+
confirmText?: React.ReactNode;
|
|
53
|
+
/**
|
|
54
|
+
* Disables the confirm button.
|
|
55
|
+
*
|
|
56
|
+
* XXX: Once the modal has been opened mutating this property will _not_
|
|
57
|
+
* propagate into the modal.
|
|
58
|
+
*
|
|
59
|
+
* If you need the confirm buttons disabled state to be reactively
|
|
60
|
+
* controlled, consider using the renderMessage prop, which receives a
|
|
61
|
+
* `disableConfirmButton` function that you may use to control the state of it.
|
|
62
|
+
*/
|
|
63
|
+
disableConfirmButton?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Message to display to user when an error occurs. Only used if `onConfirmAsync` is
|
|
66
|
+
* provided and the promise rejects.
|
|
67
|
+
*/
|
|
68
|
+
errorMessage?: React.ReactNode;
|
|
69
|
+
/**
|
|
70
|
+
* Header of modal
|
|
71
|
+
*/
|
|
72
|
+
header?: React.ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* By default, the Confirm button has autofocus.
|
|
75
|
+
* However, if `isDangerous` is true, the Cancel button receives autofocus instead,
|
|
76
|
+
* preventing users from accidental modification of dangerous settings.
|
|
77
|
+
*/
|
|
78
|
+
isDangerous?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Message to display to user when asking for confirmation
|
|
81
|
+
*/
|
|
82
|
+
message?: React.ReactNode;
|
|
83
|
+
/**
|
|
84
|
+
* User cancels the modal
|
|
85
|
+
*/
|
|
86
|
+
onCancel?: () => void;
|
|
87
|
+
/**
|
|
88
|
+
* User closes the modal
|
|
89
|
+
*/
|
|
90
|
+
onClose?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Callback when user confirms
|
|
93
|
+
*
|
|
94
|
+
* If you pass a promise, the modal will not close until it resolves.
|
|
95
|
+
* To customize the error message in case of rejection, pass the `errorMessage` prop.
|
|
96
|
+
*/
|
|
97
|
+
onConfirm?: () => void | Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Callback function when user is in the confirming state called when the
|
|
100
|
+
* confirm modal is opened
|
|
101
|
+
*/
|
|
102
|
+
onConfirming?: () => void;
|
|
103
|
+
/**
|
|
104
|
+
* Modal is rendered
|
|
105
|
+
*/
|
|
106
|
+
onRender?: () => void;
|
|
107
|
+
/**
|
|
108
|
+
* Button priority
|
|
109
|
+
*/
|
|
110
|
+
priority?: ButtonProps['variant'];
|
|
111
|
+
/**
|
|
112
|
+
* Custom function to render the cancel button
|
|
113
|
+
*/
|
|
114
|
+
renderCancelButton?: (props: ConfirmButtonsRenderProps) => React.ReactNode;
|
|
115
|
+
/**
|
|
116
|
+
* Custom function to render the confirm button
|
|
117
|
+
*/
|
|
118
|
+
renderConfirmButton?: (props: ConfirmButtonsRenderProps) => React.ReactNode;
|
|
119
|
+
/**
|
|
120
|
+
* Used to render a message instead of using the static `message` prop.
|
|
121
|
+
*/
|
|
122
|
+
renderMessage?: (renderProps: ConfirmMessageRenderProps) => React.ReactNode;
|
|
123
|
+
};
|
|
124
|
+
interface Props extends OpenConfirmOptions {
|
|
125
|
+
/**
|
|
126
|
+
* Render props to control rendering of the modal in its entirety
|
|
127
|
+
*/
|
|
128
|
+
children?: ((renderProps: ChildrenRenderProps) => React.ReactNode) | React.ReactElement<{
|
|
129
|
+
disabled: boolean;
|
|
130
|
+
onClick: (e: React.MouseEvent) => void;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Passed to `children` render function
|
|
134
|
+
*/
|
|
135
|
+
disabled?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Stop event propagation when opening the confirm modal
|
|
138
|
+
*/
|
|
139
|
+
stopPropagation?: boolean;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Opens a confirmation modal when called. The procedural version of the
|
|
143
|
+
* `Confirm` component
|
|
144
|
+
*/
|
|
145
|
+
export declare const openConfirmModal: ({ bypass, onConfirming, priority, cancelText, confirmText, disableConfirmButton, onClose, ...rest }: OpenConfirmOptions) => void;
|
|
146
|
+
/**
|
|
147
|
+
* The confirm component is somewhat special in that you can wrap any
|
|
148
|
+
* onClick-able element with this to trigger a interstitial confirmation modal.
|
|
149
|
+
*
|
|
150
|
+
* This is the declarative alternative to using openConfirmModal
|
|
151
|
+
*/
|
|
152
|
+
export declare function Confirm({ disabled, children, stopPropagation, ...openConfirmOptions }: Props): React.ReactNode;
|
|
153
|
+
export {};
|