@sentry/scraps 0.6.0 → 0.7.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 +27 -0
- package/dist/alert/alert.js +10 -7
- package/dist/compactSelect/compactSelect.d.ts +2 -2
- package/dist/compactSelect/compactSelect.js +37 -23
- package/dist/compactSelect/control.js +12 -9
- package/dist/compactSelect/gridList/index.js +35 -36
- package/dist/compactSelect/gridList/option.d.ts +4 -1
- package/dist/compactSelect/gridList/option.js +4 -3
- package/dist/compactSelect/gridList/section.d.ts +10 -3
- package/dist/compactSelect/gridList/section.js +16 -33
- package/dist/compactSelect/listBox/index.d.ts +1 -1
- package/dist/compactSelect/listBox/index.js +46 -58
- package/dist/compactSelect/listBox/section.d.ts +10 -8
- package/dist/compactSelect/listBox/section.js +11 -30
- package/dist/compactSelect/styles.d.ts +6 -7
- package/dist/compactSelect/styles.js +1 -23
- package/dist/diagnostics/context.d.ts +12 -0
- package/dist/diagnostics/context.js +11 -0
- package/dist/diagnostics/index.d.ts +2 -0
- package/dist/diagnostics/index.js +1 -0
- package/dist/disclosure/disclosure.js +1 -1
- package/dist/dragHandle/dragHandle.js +3 -5
- package/dist/dropdownMenu/context.d.ts +10 -0
- package/dist/dropdownMenu/context.js +2 -1
- package/dist/dropdownMenu/item.d.ts +2 -7
- package/dist/dropdownMenu/item.js +13 -7
- package/dist/dropdownMenu/list.js +25 -23
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +6 -14
- package/dist/form/field/radioGroupField.d.ts +7 -0
- package/dist/form/field/radioGroupField.js +14 -0
- package/dist/form/field/selectField.d.ts +3 -4
- package/dist/form/field/selectField.js +16 -24
- package/dist/layout/container.d.ts +18 -7
- package/dist/layout/container.js +8 -11
- package/dist/layout/flex.js +1 -1
- package/dist/layout/grid.js +2 -2
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/layout/stack.js +1 -1
- package/dist/layout/styles.d.ts +28 -8
- package/dist/layout/styles.js +67 -13
- package/dist/layout/surface.d.ts +2 -2
- package/dist/layout/surface.js +6 -3
- package/dist/menu/menu.js +4 -4
- package/dist/menu/selectValue.d.ts +2 -6
- package/dist/modal/components.js +2 -2
- package/dist/overlayArrow.js +2 -2
- package/dist/select/chips.d.ts +14 -0
- package/dist/select/chips.js +45 -0
- package/dist/select/filter.js +7 -11
- package/dist/select/index.d.ts +1 -1
- package/dist/select/indicators.d.ts +11 -0
- package/dist/select/indicators.js +61 -0
- package/dist/select/menu.d.ts +44 -0
- package/dist/select/menu.js +103 -0
- package/dist/select/option.d.ts +23 -15
- package/dist/select/option.js +66 -58
- package/dist/select/options.d.ts +31 -0
- package/dist/select/options.js +74 -0
- package/dist/select/select.d.ts +24 -11
- package/dist/select/select.js +527 -429
- package/dist/select/styles.d.ts +148 -2
- package/dist/select/styles.js +156 -1
- package/dist/select/types.d.ts +6 -7
- package/dist/select/types.js +4 -0
- package/dist/select/utils.d.ts +2 -0
- package/dist/select/utils.js +4 -0
- package/dist/separator/separator.d.ts +2 -2
- package/dist/separator/separator.js +4 -3
- package/dist/slot/slot.js +16 -12
- package/dist/tabs/tab.js +3 -1
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/dist/theme/types.d.ts +1 -0
- package/dist/theme/useResolvedTheme.d.ts +12 -0
- package/dist/theme/useResolvedTheme.js +20 -0
- package/dist/theme/variables.css +1116 -0
- package/dist/theme/variables.d.ts +985 -0
- package/dist/theme/variables.js +455 -0
- package/dist/useVirtualCollection.d.ts +14 -1
- package/dist/useVirtualCollection.js +59 -3
- package/package.json +12 -6
- package/dist/compactSelect/useVirtualizedItems.d.ts +0 -52
- package/dist/compactSelect/useVirtualizedItems.js +0 -74
- package/dist/select/reactSelectWrapper.d.ts +0 -8
- package/dist/select/reactSelectWrapper.js +0 -25
- package/dist/select/virtualizedMenuList.d.ts +0 -24
- package/dist/select/virtualizedMenuList.js +0 -123
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { css } from "@emotion/react";
|
|
3
|
+
import { IconChevron } from "@sentry/icons/chevron";
|
|
4
|
+
import { IconClose } from "@sentry/icons/close";
|
|
5
|
+
import { Button } from "../button/index.js";
|
|
6
|
+
import { Flex, Grid } from "../layout/index.js";
|
|
7
|
+
import { Spinner } from "../spinner/index.js";
|
|
8
|
+
import { useTranslation } from "../translation/index.js";
|
|
9
|
+
import { isRenderable } from "./utils.js";
|
|
10
|
+
function SelectIndicators({ dropdownIndicator, isLoading, isOpen, onClear, selectStyles, showClearButton, trailingItems }) {
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
if (null === dropdownIndicator && !showClearButton && !isLoading && !isRenderable(trailingItems)) return null;
|
|
13
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
14
|
+
align: "center",
|
|
15
|
+
gap: "xs",
|
|
16
|
+
css: selectStyles.indicators,
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsxs(Grid, {
|
|
19
|
+
flow: "column",
|
|
20
|
+
autoColumns: "minmax(24px, max-content)",
|
|
21
|
+
align: "center",
|
|
22
|
+
justifyItems: "center",
|
|
23
|
+
gap: "xs",
|
|
24
|
+
css: css`
|
|
25
|
+
&:empty {
|
|
26
|
+
display: none;
|
|
27
|
+
}
|
|
28
|
+
`,
|
|
29
|
+
children: [
|
|
30
|
+
trailingItems,
|
|
31
|
+
showClearButton && /*#__PURE__*/ jsx(Button, {
|
|
32
|
+
size: "zero",
|
|
33
|
+
variant: "transparent",
|
|
34
|
+
"aria-label": t('Clear choices'),
|
|
35
|
+
icon: /*#__PURE__*/ jsx(IconClose, {
|
|
36
|
+
css: selectStyles.clearIcon
|
|
37
|
+
}),
|
|
38
|
+
onMouseDown: (event)=>event.preventDefault(),
|
|
39
|
+
onClick: onClear
|
|
40
|
+
}),
|
|
41
|
+
isLoading && /*#__PURE__*/ jsx(Spinner, {
|
|
42
|
+
size: 14,
|
|
43
|
+
css: css`
|
|
44
|
+
margin: 0;
|
|
45
|
+
`
|
|
46
|
+
})
|
|
47
|
+
]
|
|
48
|
+
}),
|
|
49
|
+
null !== dropdownIndicator && /*#__PURE__*/ jsx(Flex, {
|
|
50
|
+
as: "span",
|
|
51
|
+
align: "center",
|
|
52
|
+
"aria-hidden": "true",
|
|
53
|
+
children: dropdownIndicator ?? /*#__PURE__*/ jsx(IconChevron, {
|
|
54
|
+
direction: isOpen ? 'up' : 'down',
|
|
55
|
+
size: "xs"
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { SelectIndicators };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type CSSObject } from '@emotion/react';
|
|
3
|
+
import type { useListBox } from '@react-aria/listbox';
|
|
4
|
+
import type { ListState } from '@react-stately/list';
|
|
5
|
+
import type { Key } from '@react-types/shared';
|
|
6
|
+
import type { FormSize } from '../theme/index.js';
|
|
7
|
+
import { type VirtualCollection } from '../useVirtualCollection.js';
|
|
8
|
+
import type { getSelectStyles } from './styles.js';
|
|
9
|
+
import type { SelectComponents, SelectValue, StylesConfig } from './types.js';
|
|
10
|
+
export declare const MENU_GAP = 8;
|
|
11
|
+
export declare function SelectMenu<TValue, TOption extends SelectValue<TValue>>({ controlRef, footerRef, isInsideModal, isLoading, listBoxProps, listRef, loadingMessage, lockedMenuWidth, maxMenuHeight, menuFooter, menuPortalTarget, menuRef, menuStyle, minMenuHeight, multiple, noOptionsMessage, onClose, OptionLabel, overlayStyle, query, rowsByKey, selectStyles, setOverlayElement, showCreateOptionIcon, showDividers, size, state, styles, virtual, virtualized, }: {
|
|
12
|
+
controlRef: React.RefObject<HTMLDivElement | null>;
|
|
13
|
+
footerRef: React.Ref<HTMLDivElement>;
|
|
14
|
+
listBoxProps: ReturnType<typeof useListBox>['listBoxProps'];
|
|
15
|
+
listRef: React.Ref<HTMLUListElement>;
|
|
16
|
+
maxMenuHeight: number;
|
|
17
|
+
menuRef: React.Ref<HTMLDivElement>;
|
|
18
|
+
menuStyle: CSSObject;
|
|
19
|
+
multiple: boolean;
|
|
20
|
+
onClose: () => void;
|
|
21
|
+
query: string;
|
|
22
|
+
rowsByKey: ReadonlyMap<Key, TOption>;
|
|
23
|
+
selectStyles: Pick<ReturnType<typeof getSelectStyles>, 'heading' | 'menuList' | 'message'>;
|
|
24
|
+
setOverlayElement: React.Ref<HTMLDivElement>;
|
|
25
|
+
size: FormSize;
|
|
26
|
+
state: ListState<unknown>;
|
|
27
|
+
virtual: VirtualCollection<unknown>;
|
|
28
|
+
virtualized: boolean;
|
|
29
|
+
OptionLabel?: SelectComponents<TOption>['OptionLabel'];
|
|
30
|
+
isInsideModal?: boolean;
|
|
31
|
+
isLoading?: boolean;
|
|
32
|
+
loadingMessage?: () => React.ReactNode;
|
|
33
|
+
lockedMenuWidth?: number;
|
|
34
|
+
menuFooter?: React.ReactNode;
|
|
35
|
+
menuPortalTarget?: HTMLElement | null;
|
|
36
|
+
minMenuHeight?: number;
|
|
37
|
+
noOptionsMessage?: (state: {
|
|
38
|
+
inputValue: string;
|
|
39
|
+
}) => React.ReactNode;
|
|
40
|
+
overlayStyle?: React.CSSProperties;
|
|
41
|
+
showCreateOptionIcon?: boolean;
|
|
42
|
+
showDividers?: boolean;
|
|
43
|
+
styles?: StylesConfig<TValue, TOption>;
|
|
44
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { useTheme } from "@emotion/react";
|
|
4
|
+
import { PanelProvider } from "../panelProvider.js";
|
|
5
|
+
import { useTranslation } from "../translation/index.js";
|
|
6
|
+
import { VirtualRows } from "../useVirtualCollection.js";
|
|
7
|
+
import { SelectOption, SelectSection } from "./option.js";
|
|
8
|
+
import { CREATE_KEY } from "./options.js";
|
|
9
|
+
import { applyStyleSlot } from "./types.js";
|
|
10
|
+
import { isRenderable } from "./utils.js";
|
|
11
|
+
const MENU_GAP = 8;
|
|
12
|
+
function SelectMenu({ controlRef, footerRef, isInsideModal, isLoading, listBoxProps, listRef, loadingMessage, lockedMenuWidth, maxMenuHeight, menuFooter, menuPortalTarget, menuRef, menuStyle, minMenuHeight, multiple, noOptionsMessage, onClose, OptionLabel, overlayStyle, query, rowsByKey, selectStyles, setOverlayElement, showCreateOptionIcon, showDividers, size, state, styles, virtual, virtualized }) {
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
const lockedMenuStyle = void 0 === lockedMenuWidth ? void 0 : {
|
|
15
|
+
width: lockedMenuWidth,
|
|
16
|
+
maxWidth: menuStyle.maxWidth ?? '100%'
|
|
17
|
+
};
|
|
18
|
+
const positionStyle = {
|
|
19
|
+
...'initial' === menuStyle.position ? {
|
|
20
|
+
marginBlockStart: MENU_GAP
|
|
21
|
+
} : overlayStyle,
|
|
22
|
+
display: 'flex',
|
|
23
|
+
flexDirection: 'column',
|
|
24
|
+
zIndex: isInsideModal ? theme.zIndex.modal + 1 : theme.zIndex.dropdown
|
|
25
|
+
};
|
|
26
|
+
const isEmpty = 0 === state.collection.size;
|
|
27
|
+
const menuListStyle = {
|
|
28
|
+
...selectStyles.menuList,
|
|
29
|
+
padding: isEmpty ? 0 : selectStyles.menuList.padding,
|
|
30
|
+
maxHeight: maxMenuHeight,
|
|
31
|
+
minHeight: minMenuHeight ?? 0
|
|
32
|
+
};
|
|
33
|
+
const menu = /*#__PURE__*/ jsx("div", {
|
|
34
|
+
ref: setOverlayElement,
|
|
35
|
+
"data-overlay-root": "",
|
|
36
|
+
css: menuPortalTarget ? applyStyleSlot(styles, 'menuPortal', positionStyle, {}) : positionStyle,
|
|
37
|
+
onBlur: (event)=>{
|
|
38
|
+
if (!event.currentTarget.contains(event.relatedTarget) && !controlRef.current?.contains(event.relatedTarget)) onClose();
|
|
39
|
+
},
|
|
40
|
+
children: /*#__PURE__*/ jsx(PanelProvider, {
|
|
41
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
42
|
+
ref: menuRef,
|
|
43
|
+
css: [
|
|
44
|
+
menuStyle,
|
|
45
|
+
lockedMenuStyle
|
|
46
|
+
],
|
|
47
|
+
children: [
|
|
48
|
+
/*#__PURE__*/ jsx("ul", {
|
|
49
|
+
...listBoxProps,
|
|
50
|
+
ref: listRef,
|
|
51
|
+
css: menuListStyle,
|
|
52
|
+
children: /*#__PURE__*/ jsx(VirtualRows, {
|
|
53
|
+
virtual: virtual,
|
|
54
|
+
renderRow: (row)=>/*#__PURE__*/ jsx(SelectOption, {
|
|
55
|
+
row: row,
|
|
56
|
+
state: state,
|
|
57
|
+
option: rowsByKey.get(row.node.key),
|
|
58
|
+
size: size,
|
|
59
|
+
multiple: multiple,
|
|
60
|
+
virtualized: virtualized,
|
|
61
|
+
showDividers: showDividers,
|
|
62
|
+
showCreateOptionIcon: showCreateOptionIcon,
|
|
63
|
+
OptionLabel: OptionLabel,
|
|
64
|
+
styleOption: styles?.option,
|
|
65
|
+
create: row.node.key === CREATE_KEY
|
|
66
|
+
}),
|
|
67
|
+
renderSection: (section, children)=>/*#__PURE__*/ jsx(SelectSection, {
|
|
68
|
+
row: section,
|
|
69
|
+
headingStyle: selectStyles.heading,
|
|
70
|
+
children: children
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
}),
|
|
74
|
+
isEmpty && /*#__PURE__*/ jsx(EmptyMessage, {
|
|
75
|
+
isLoading: isLoading,
|
|
76
|
+
loadingMessage: loadingMessage,
|
|
77
|
+
noOptionsMessage: noOptionsMessage,
|
|
78
|
+
query: query,
|
|
79
|
+
style: selectStyles.message
|
|
80
|
+
}),
|
|
81
|
+
menuFooter && /*#__PURE__*/ jsx("div", {
|
|
82
|
+
ref: footerRef,
|
|
83
|
+
children: menuFooter
|
|
84
|
+
})
|
|
85
|
+
]
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
return menuPortalTarget ? /*#__PURE__*/ createPortal(menu, menuPortalTarget) : menu;
|
|
90
|
+
}
|
|
91
|
+
function EmptyMessage({ isLoading, loadingMessage, noOptionsMessage, query, style }) {
|
|
92
|
+
const { t } = useTranslation();
|
|
93
|
+
const message = isLoading ? loadingMessage ? loadingMessage() : t('Loading...') : noOptionsMessage ? noOptionsMessage({
|
|
94
|
+
inputValue: query
|
|
95
|
+
}) : t('No options');
|
|
96
|
+
if (!isRenderable(message)) return null;
|
|
97
|
+
return /*#__PURE__*/ jsx("div", {
|
|
98
|
+
role: "status",
|
|
99
|
+
css: style,
|
|
100
|
+
children: message
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
export { MENU_GAP, SelectMenu };
|
package/dist/select/option.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
import { type CSSObject } from '@emotion/react';
|
|
3
|
+
import type { ListState } from '@react-stately/list';
|
|
4
|
+
import type { FormSize } from '../theme/index.js';
|
|
5
|
+
import type { VirtualRow } from '../useVirtualCollection.js';
|
|
6
|
+
import type { SelectComponents, SelectValue, StylesConfig } from './types.js';
|
|
7
|
+
export declare function SelectOption<TValue, TOption extends SelectValue<TValue>>({ row, state, option, size, multiple, virtualized, showDividers, showCreateOptionIcon, OptionLabel, styleOption, create, }: {
|
|
8
|
+
create: boolean;
|
|
9
|
+
multiple: boolean;
|
|
10
|
+
option: TOption | undefined;
|
|
11
|
+
row: VirtualRow<unknown>;
|
|
12
|
+
size: FormSize;
|
|
13
|
+
state: ListState<unknown>;
|
|
14
|
+
virtualized: boolean;
|
|
15
|
+
OptionLabel?: SelectComponents<TOption>['OptionLabel'];
|
|
16
|
+
showCreateOptionIcon?: boolean;
|
|
17
|
+
showDividers?: boolean;
|
|
18
|
+
styleOption?: StylesConfig<TValue, TOption>['option'];
|
|
19
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare function SelectSection({ row, headingStyle, children, }: {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
headingStyle: CSSObject;
|
|
23
|
+
row: VirtualRow<unknown>;
|
|
24
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
package/dist/select/option.js
CHANGED
|
@@ -1,81 +1,89 @@
|
|
|
1
1
|
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { Fragment } from "react";
|
|
2
|
+
import { Fragment, useRef } from "react";
|
|
3
3
|
import { ClassNames } from "@emotion/react";
|
|
4
|
-
import
|
|
4
|
+
import { useListBoxSection, useOption } from "@react-aria/listbox";
|
|
5
|
+
import { mergeProps, mergeRefs } from "@react-aria/utils";
|
|
5
6
|
import { IconAdd } from "@sentry/icons/add";
|
|
6
7
|
import { IconCheckmark } from "@sentry/icons/checkmark";
|
|
7
|
-
import { ListItem } from "../menu/index.js";
|
|
8
|
+
import { ListItem, SectionGroup, SectionList } from "../menu/index.js";
|
|
8
9
|
import { CheckWrap } from "./styles.js";
|
|
9
|
-
function SelectOption(
|
|
10
|
-
const
|
|
11
|
-
const {
|
|
12
|
-
|
|
10
|
+
function SelectOption({ row, state, option, size, multiple, virtualized, showDividers, showCreateOptionIcon, OptionLabel, styleOption, create }) {
|
|
11
|
+
const ref = useRef(null);
|
|
12
|
+
const { optionProps, labelProps, descriptionProps, isSelected, isFocused, isPressed, isDisabled } = useOption({
|
|
13
|
+
key: row.node.key,
|
|
14
|
+
isVirtualized: virtualized,
|
|
15
|
+
shouldUseVirtualFocus: true
|
|
16
|
+
}, state, ref);
|
|
17
|
+
const leading = 'function' == typeof option?.leadingItems ? option.leadingItems({
|
|
13
18
|
disabled: isDisabled,
|
|
14
19
|
isFocused,
|
|
15
20
|
isSelected
|
|
16
|
-
}) :
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}) : label;
|
|
21
|
-
const { value, selectionMode, priority, ...itemProps } = data;
|
|
22
|
-
const isMultiple = null == selectionMode ? isMulti : 'multiple' === selectionMode;
|
|
23
|
-
const itemPriority = priority ?? 'default';
|
|
24
|
-
const innerWrapProps = {
|
|
25
|
-
'data-test-id': null == value ? void 0 : String(value)
|
|
26
|
-
};
|
|
21
|
+
}) : option?.leadingItems;
|
|
22
|
+
const label = OptionLabel && option ? /*#__PURE__*/ jsx(OptionLabel, {
|
|
23
|
+
option: option
|
|
24
|
+
}) : row.node.rendered;
|
|
27
25
|
return /*#__PURE__*/ jsx(ClassNames, {
|
|
28
|
-
children: ({
|
|
29
|
-
|
|
30
|
-
...
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
className: cx({
|
|
34
|
-
option: true,
|
|
35
|
-
'option--is-disabled': isDisabled,
|
|
36
|
-
'option--is-focused': isFocused,
|
|
37
|
-
'option--is-selected': isSelected
|
|
26
|
+
children: ({ css })=>/*#__PURE__*/ jsx(ListItem, {
|
|
27
|
+
"data-test-id": option?.value == null ? void 0 : String(option.value),
|
|
28
|
+
...option,
|
|
29
|
+
...mergeProps(optionProps, {
|
|
30
|
+
onClick: (event)=>event.preventDefault()
|
|
38
31
|
}),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
32
|
+
...row.props,
|
|
33
|
+
ref: mergeRefs(ref, row.props?.ref),
|
|
34
|
+
className: option && styleOption ? css(styleOption({}, {
|
|
35
|
+
data: option,
|
|
36
|
+
isDisabled,
|
|
37
|
+
isSelected
|
|
38
|
+
})) : void 0,
|
|
39
|
+
label: label,
|
|
40
|
+
labelProps: labelProps,
|
|
41
|
+
detailsProps: descriptionProps,
|
|
44
42
|
disabled: isDisabled,
|
|
45
43
|
isFocused: isFocused,
|
|
46
|
-
|
|
44
|
+
isSelected: isSelected,
|
|
45
|
+
isPressed: isPressed,
|
|
46
|
+
showDivider: showDividers,
|
|
47
47
|
size: size,
|
|
48
|
-
|
|
49
|
-
labelProps: {
|
|
50
|
-
as: 'string' == typeof renderedLabel ? 'p' : 'div'
|
|
51
|
-
},
|
|
52
|
-
leadingItems: itemProps.__isNew__ && false !== selectProps.showCreateOptionIcon ? /*#__PURE__*/ jsxs(Fragment, {
|
|
48
|
+
leadingItems: /*#__PURE__*/ jsxs(Fragment, {
|
|
53
49
|
children: [
|
|
54
|
-
/*#__PURE__*/ jsx(IconAdd, {
|
|
50
|
+
create && false !== showCreateOptionIcon ? /*#__PURE__*/ jsx(IconAdd, {
|
|
55
51
|
size: "sm"
|
|
56
|
-
}),
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}) : /*#__PURE__*/ jsxs(Fragment, {
|
|
60
|
-
children: [
|
|
61
|
-
/*#__PURE__*/ jsx(CheckWrap, {
|
|
62
|
-
isMultiple: isMultiple,
|
|
52
|
+
}) : /*#__PURE__*/ jsx(CheckWrap, {
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
isMultiple: multiple,
|
|
63
55
|
isSelected: isSelected,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
size: isMultiple ? 'xs' : 'sm',
|
|
67
|
-
isMultiple: isMultiple
|
|
56
|
+
children: isSelected && /*#__PURE__*/ jsx(IconCheckmark, {
|
|
57
|
+
size: multiple ? 'xs' : 'sm'
|
|
68
58
|
})
|
|
69
59
|
}),
|
|
70
|
-
|
|
60
|
+
leading
|
|
71
61
|
]
|
|
72
62
|
})
|
|
73
63
|
})
|
|
74
64
|
});
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
function SelectSection({ row, headingStyle, children }) {
|
|
67
|
+
const heading = row.node.rendered;
|
|
68
|
+
const { itemProps, headingProps, groupProps } = useListBoxSection({
|
|
69
|
+
heading
|
|
70
|
+
});
|
|
71
|
+
return /*#__PURE__*/ jsxs(SectionGroup, {
|
|
72
|
+
...itemProps,
|
|
73
|
+
children: [
|
|
74
|
+
/*#__PURE__*/ jsx("div", {
|
|
75
|
+
...row.props,
|
|
76
|
+
children: heading && /*#__PURE__*/ jsx("div", {
|
|
77
|
+
...headingProps,
|
|
78
|
+
css: headingStyle,
|
|
79
|
+
children: heading
|
|
80
|
+
})
|
|
81
|
+
}),
|
|
82
|
+
/*#__PURE__*/ jsx(SectionList, {
|
|
83
|
+
...groupProps,
|
|
84
|
+
children: children
|
|
85
|
+
})
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
export { SelectOption, SelectSection };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { SelectValue } from './types.js';
|
|
3
|
+
export declare const CREATE_KEY = "create";
|
|
4
|
+
export type OptionRow<T> = {
|
|
5
|
+
key: string;
|
|
6
|
+
option: T;
|
|
7
|
+
};
|
|
8
|
+
type OptionEntry<T> = OptionRow<T> | {
|
|
9
|
+
rows: Array<OptionRow<T>>;
|
|
10
|
+
label?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
type Options<T> = ReadonlyArray<T | {
|
|
13
|
+
options: readonly T[];
|
|
14
|
+
label?: ReactNode;
|
|
15
|
+
}>;
|
|
16
|
+
export declare function useOptionIndex<TValue, TOption extends SelectValue<TValue>>(options: Options<TOption>, { creatable, isLoading, isValueEqual, query, values, }: {
|
|
17
|
+
query: string;
|
|
18
|
+
values: ReadonlyArray<TValue | null>;
|
|
19
|
+
creatable?: boolean;
|
|
20
|
+
isLoading?: boolean;
|
|
21
|
+
isValueEqual?: (a: TValue, b: TValue) => boolean;
|
|
22
|
+
}): {
|
|
23
|
+
entries: OptionEntry<TOption>[];
|
|
24
|
+
rows: OptionRow<TOption>[];
|
|
25
|
+
selectedRows: {
|
|
26
|
+
option: SelectValue<TValue> | TOption;
|
|
27
|
+
key?: string;
|
|
28
|
+
}[];
|
|
29
|
+
canCreate: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
const CREATE_KEY = 'create';
|
|
3
|
+
function matchesValue(optionValue, value, isValueEqual) {
|
|
4
|
+
return null != value && null != optionValue && isValueEqual ? isValueEqual(optionValue, value) : optionValue === value;
|
|
5
|
+
}
|
|
6
|
+
function indexOptions(options, previousRows, nextId, isValueEqual) {
|
|
7
|
+
const keysByValue = new Map();
|
|
8
|
+
for (const { key, option } of previousRows){
|
|
9
|
+
const keys = keysByValue.get(option.value) ?? [];
|
|
10
|
+
keys.push(key);
|
|
11
|
+
keysByValue.set(option.value, keys);
|
|
12
|
+
}
|
|
13
|
+
const used = new Set();
|
|
14
|
+
const rows = [];
|
|
15
|
+
function indexOption(option) {
|
|
16
|
+
const previousKey = keysByValue.get(option.value)?.find((key)=>!used.has(key)) ?? (isValueEqual && null != option.value && previousRows.find((row)=>!used.has(row.key) && matchesValue(row.option.value, option.value, isValueEqual))?.key);
|
|
17
|
+
const key = previousKey || `option-${nextId++}`;
|
|
18
|
+
used.add(key);
|
|
19
|
+
const row = {
|
|
20
|
+
key,
|
|
21
|
+
option
|
|
22
|
+
};
|
|
23
|
+
rows.push(row);
|
|
24
|
+
return row;
|
|
25
|
+
}
|
|
26
|
+
const entries = options.map((entry)=>'options' in entry ? {
|
|
27
|
+
label: entry.label,
|
|
28
|
+
rows: entry.options.map(indexOption)
|
|
29
|
+
} : indexOption(entry));
|
|
30
|
+
return {
|
|
31
|
+
options,
|
|
32
|
+
entries,
|
|
33
|
+
rows,
|
|
34
|
+
nextId
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function useOptionIndex(options, { creatable, isLoading, isValueEqual, query, values }) {
|
|
38
|
+
const [previousIndex, setIndex] = useState(()=>indexOptions(options, [], 0, isValueEqual));
|
|
39
|
+
const index = options === previousIndex.options ? previousIndex : indexOptions(options, previousIndex.rows, previousIndex.nextId, isValueEqual);
|
|
40
|
+
if (index !== previousIndex) setIndex(index);
|
|
41
|
+
const findRow = (value)=>index.rows.find((row)=>matchesValue(row.option.value, value, isValueEqual));
|
|
42
|
+
const selectedRows = values.flatMap((value)=>{
|
|
43
|
+
const existing = findRow(value);
|
|
44
|
+
if (existing) return [
|
|
45
|
+
existing
|
|
46
|
+
];
|
|
47
|
+
if (creatable && null != value) return [
|
|
48
|
+
{
|
|
49
|
+
option: {
|
|
50
|
+
value,
|
|
51
|
+
label: String(value)
|
|
52
|
+
},
|
|
53
|
+
key: void 0
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
return [];
|
|
57
|
+
});
|
|
58
|
+
const normalizedQuery = query.toLowerCase();
|
|
59
|
+
const canCreate = creatable && '' !== query && !isLoading && ![
|
|
60
|
+
...index.rows,
|
|
61
|
+
...selectedRows
|
|
62
|
+
].some(({ option })=>[
|
|
63
|
+
option.label,
|
|
64
|
+
option.value,
|
|
65
|
+
option.textValue
|
|
66
|
+
].some((value)=>'string' == typeof value && value.toLowerCase() === normalizedQuery));
|
|
67
|
+
return {
|
|
68
|
+
entries: index.entries,
|
|
69
|
+
rows: index.rows,
|
|
70
|
+
selectedRows,
|
|
71
|
+
canCreate
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export { CREATE_KEY, useOptionIndex };
|
package/dist/select/select.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
2
|
import type { FormSize } from '../theme/index.js';
|
|
3
3
|
import type { SelectComponents, SelectHandle, SelectSelectionProps, SelectValue, StylesConfig } from './types.js';
|
|
4
|
-
|
|
5
|
-
export interface BaseSelectProps<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>> {
|
|
4
|
+
export interface BaseSelectProps<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>, TSelected extends SelectValue<TValue | string> = TOption> {
|
|
6
5
|
options: ReadonlyArray<(TOption & SelectValue<TValue>) | {
|
|
7
6
|
options: ReadonlyArray<TOption & SelectValue<TValue>>;
|
|
8
7
|
label?: React.ReactNode;
|
|
@@ -16,9 +15,7 @@ export interface BaseSelectProps<TValue, TOption extends SelectValue<TValue> = S
|
|
|
16
15
|
blurInputOnSelect?: boolean;
|
|
17
16
|
className?: string;
|
|
18
17
|
/** Customize content while Select retains input, option, and chip behavior. */
|
|
19
|
-
components?: SelectComponents<TOption>;
|
|
20
|
-
/** Content inside the control, before the selected value and input. */
|
|
21
|
-
controlLeadingItems?: React.ReactNode;
|
|
18
|
+
components?: Pick<SelectComponents<TOption>, 'OptionLabel'> & Omit<SelectComponents<TSelected>, 'OptionLabel'>;
|
|
22
19
|
/** Allow values that are not in `options`. */
|
|
23
20
|
creatable?: boolean;
|
|
24
21
|
disabled?: boolean;
|
|
@@ -37,9 +34,14 @@ export interface BaseSelectProps<TValue, TOption extends SelectValue<TValue> = S
|
|
|
37
34
|
isOpen?: boolean;
|
|
38
35
|
/** Compare object values. Values are compared with === by default. */
|
|
39
36
|
isValueEqual?: (a: TValue, b: TValue) => boolean;
|
|
37
|
+
/** Centered content inside the control, before the selected value and input. */
|
|
38
|
+
leadingItems?: React.ReactNode;
|
|
40
39
|
loadingMessage?: () => React.ReactNode;
|
|
41
40
|
maxMenuHeight?: number;
|
|
42
|
-
|
|
41
|
+
/** Maximum menu width in pixels, or '100%' to use the control width. */
|
|
42
|
+
maxMenuWidth?: number | '100%';
|
|
43
|
+
/** Align the menu with the start or end edge of the control. Defaults to start. */
|
|
44
|
+
menuAlign?: 'start' | 'end';
|
|
43
45
|
/** Content after the options, outside the scroll container. */
|
|
44
46
|
menuFooter?: React.ReactNode;
|
|
45
47
|
menuPortalTarget?: HTMLElement | null;
|
|
@@ -63,10 +65,12 @@ export interface BaseSelectProps<TValue, TOption extends SelectValue<TValue> = S
|
|
|
63
65
|
showCreateOptionIcon?: boolean;
|
|
64
66
|
showDividers?: boolean;
|
|
65
67
|
size?: FormSize;
|
|
66
|
-
styles?: StylesConfig<NoInfer<TValue>, NoInfer<
|
|
68
|
+
styles?: StylesConfig<NoInfer<TValue | string>, NoInfer<TSelected>>;
|
|
67
69
|
tabIndex?: number;
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
+
/** Content beside the clear button and dropdown indicator. Each item is centered in a slot at least 24px wide. */
|
|
71
|
+
trailingItems?: React.ReactNode;
|
|
72
|
+
/** Virtualize when the number of options, including grouped options, exceeds this threshold. Defaults to 150. */
|
|
73
|
+
virtualizeThreshold?: number;
|
|
70
74
|
}
|
|
71
75
|
type DisabledSelectionProps<Props extends {
|
|
72
76
|
onChange: unknown;
|
|
@@ -74,6 +78,15 @@ type DisabledSelectionProps<Props extends {
|
|
|
74
78
|
disabled: true;
|
|
75
79
|
onChange?: Props['onChange'];
|
|
76
80
|
} : never;
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
type SelectionProps<TValue, TOption> = SelectSelectionProps<TValue, TOption> | DisabledSelectionProps<SelectSelectionProps<TValue, TOption>>;
|
|
82
|
+
type ResolvedOption<TValue, TOption> = TOption | SelectValue<TValue | string>;
|
|
83
|
+
export type ControlProps<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>> = BaseSelectProps<TValue, TOption> & SelectionProps<TValue, TOption> & {
|
|
84
|
+
creatable?: false;
|
|
85
|
+
};
|
|
86
|
+
export type CreatableControlProps<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>> = BaseSelectProps<TValue, TOption, ResolvedOption<TValue, TOption>> & SelectionProps<TValue, ResolvedOption<TValue, TOption>> & {
|
|
87
|
+
creatable: boolean | undefined;
|
|
88
|
+
};
|
|
89
|
+
export declare function Select<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>>(props: ControlProps<TValue, TOption>): React.JSX.Element;
|
|
90
|
+
export declare function Select<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>>(props: CreatableControlProps<TValue, TOption>): React.JSX.Element;
|
|
91
|
+
export declare function Select<TValue, TOption extends SelectValue<TValue> = SelectValue<TValue>>(props: ControlProps<TValue, TOption> | CreatableControlProps<TValue, TOption>): React.JSX.Element;
|
|
79
92
|
export {};
|