@react-spectrum/listbox 3.15.11 → 3.16.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/dist/import.mjs +6 -4
- package/dist/main.js +10 -8
- package/dist/main.js.map +1 -1
- package/dist/module.js +6 -4
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +5 -0
- package/package.json +14 -42
- package/src/index.ts +6 -4
- package/dist/ListBox.main.js +0 -43
- package/dist/ListBox.main.js.map +0 -1
- package/dist/ListBox.mjs +0 -34
- package/dist/ListBox.module.js +0 -34
- package/dist/ListBox.module.js.map +0 -1
- package/dist/ListBoxBase.main.js +0 -165
- package/dist/ListBoxBase.main.js.map +0 -1
- package/dist/ListBoxBase.mjs +0 -159
- package/dist/ListBoxBase.module.js +0 -159
- package/dist/ListBoxBase.module.js.map +0 -1
- package/dist/ListBoxContext.main.js +0 -27
- package/dist/ListBoxContext.main.js.map +0 -1
- package/dist/ListBoxContext.mjs +0 -18
- package/dist/ListBoxContext.module.js +0 -18
- package/dist/ListBoxContext.module.js.map +0 -1
- package/dist/ListBoxLayout.main.js +0 -79
- package/dist/ListBoxLayout.main.js.map +0 -1
- package/dist/ListBoxLayout.mjs +0 -74
- package/dist/ListBoxLayout.module.js +0 -74
- package/dist/ListBoxLayout.module.js.map +0 -1
- package/dist/ListBoxOption.main.js +0 -105
- package/dist/ListBoxOption.main.js.map +0 -1
- package/dist/ListBoxOption.mjs +0 -100
- package/dist/ListBoxOption.module.js +0 -100
- package/dist/ListBoxOption.module.js.map +0 -1
- package/dist/ListBoxSection.main.js +0 -69
- package/dist/ListBoxSection.main.js.map +0 -1
- package/dist/ListBoxSection.mjs +0 -64
- package/dist/ListBoxSection.module.js +0 -64
- package/dist/ListBoxSection.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -7
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -9
- package/dist/ar-AE.module.js +0 -9
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -7
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -9
- package/dist/bg-BG.module.js +0 -9
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -7
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -9
- package/dist/cs-CZ.module.js +0 -9
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -7
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -9
- package/dist/da-DK.module.js +0 -9
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -7
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -9
- package/dist/de-DE.module.js +0 -9
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -7
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -9
- package/dist/el-GR.module.js +0 -9
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -7
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -9
- package/dist/en-US.module.js +0 -9
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -7
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -9
- package/dist/es-ES.module.js +0 -9
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -7
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -9
- package/dist/et-EE.module.js +0 -9
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -7
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -9
- package/dist/fi-FI.module.js +0 -9
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -7
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -9
- package/dist/fr-FR.module.js +0 -9
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -7
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -9
- package/dist/he-IL.module.js +0 -9
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -7
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -9
- package/dist/hr-HR.module.js +0 -9
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -7
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -9
- package/dist/hu-HU.module.js +0 -9
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -7
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -9
- package/dist/it-IT.module.js +0 -9
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -7
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -9
- package/dist/ja-JP.module.js +0 -9
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -7
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -9
- package/dist/ko-KR.module.js +0 -9
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/listbox.a566c7a6.css +0 -570
- package/dist/listbox.a566c7a6.css.map +0 -1
- package/dist/lt-LT.main.js +0 -7
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -9
- package/dist/lt-LT.module.js +0 -9
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -7
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -9
- package/dist/lv-LV.module.js +0 -9
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/menu_vars_css.main.js +0 -177
- package/dist/menu_vars_css.main.js.map +0 -1
- package/dist/menu_vars_css.mjs +0 -179
- package/dist/menu_vars_css.module.js +0 -179
- package/dist/menu_vars_css.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -7
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -9
- package/dist/nb-NO.module.js +0 -9
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -7
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -9
- package/dist/nl-NL.module.js +0 -9
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -7
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -9
- package/dist/pl-PL.module.js +0 -9
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -7
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -9
- package/dist/pt-BR.module.js +0 -9
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -7
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -9
- package/dist/pt-PT.module.js +0 -9
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -7
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -9
- package/dist/ro-RO.module.js +0 -9
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -7
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -9
- package/dist/ru-RU.module.js +0 -9
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -7
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -9
- package/dist/sk-SK.module.js +0 -9
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -7
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -9
- package/dist/sl-SI.module.js +0 -9
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -7
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -9
- package/dist/sr-SP.module.js +0 -9
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -7
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -9
- package/dist/sv-SE.module.js +0 -9
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -7
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -9
- package/dist/tr-TR.module.js +0 -9
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -52
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -7
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -9
- package/dist/uk-UA.module.js +0 -9
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -7
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -9
- package/dist/zh-CN.module.js +0 -9
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -7
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -9
- package/dist/zh-TW.module.js +0 -9
- package/dist/zh-TW.module.js.map +0 -1
- package/src/ListBox.tsx +0 -39
- package/src/ListBoxBase.tsx +0 -183
- package/src/ListBoxContext.ts +0 -23
- package/src/ListBoxLayout.ts +0 -88
- package/src/ListBoxOption.tsx +0 -113
- package/src/ListBoxSection.tsx +0 -85
package/src/ListBox.tsx
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {DOMRef} from '@react-types/shared';
|
|
14
|
-
import {ListBoxBase, useListBoxLayout} from './ListBoxBase';
|
|
15
|
-
import React, {ReactElement} from 'react';
|
|
16
|
-
import {SpectrumListBoxProps} from '@react-types/listbox';
|
|
17
|
-
import {useDOMRef} from '@react-spectrum/utils';
|
|
18
|
-
import {useListState} from '@react-stately/list';
|
|
19
|
-
|
|
20
|
-
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
21
|
-
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A list of options that can allow selection of one or more.
|
|
26
|
-
*/
|
|
27
|
-
export const ListBox = React.forwardRef(function ListBox<T extends object>(props: SpectrumListBoxProps<T>, ref: DOMRef<HTMLDivElement>) {
|
|
28
|
-
let state = useListState(props);
|
|
29
|
-
let layout = useListBoxLayout();
|
|
30
|
-
let domRef = useDOMRef(ref);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<ListBoxBase
|
|
34
|
-
{...props}
|
|
35
|
-
ref={domRef}
|
|
36
|
-
state={state}
|
|
37
|
-
layout={layout} />
|
|
38
|
-
);
|
|
39
|
-
}) as <T>(props: SpectrumListBoxProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
|
package/src/ListBoxBase.tsx
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaLabelingProps, DOMProps, FocusStrategy, Node, RefObject, StyleProps} from '@react-types/shared';
|
|
14
|
-
import {AriaListBoxOptions, useListBox} from '@react-aria/listbox';
|
|
15
|
-
import {classNames, useStyleProps} from '@react-spectrum/utils';
|
|
16
|
-
import {FocusScope} from '@react-aria/focus';
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import intlMessages from '../intl/*.json';
|
|
19
|
-
import {ListBoxContext} from './ListBoxContext';
|
|
20
|
-
import {ListBoxLayout} from './ListBoxLayout';
|
|
21
|
-
import {ListBoxOption} from './ListBoxOption';
|
|
22
|
-
import {ListBoxSection} from './ListBoxSection';
|
|
23
|
-
import {ListState} from '@react-stately/list';
|
|
24
|
-
import {mergeProps, useObjectRef} from '@react-aria/utils';
|
|
25
|
-
import {ProgressCircle} from '@react-spectrum/progress';
|
|
26
|
-
import React, {ForwardedRef, HTMLAttributes, ReactElement, ReactNode, useCallback, useContext, useMemo} from 'react';
|
|
27
|
-
import {ReusableView} from '@react-stately/virtualizer';
|
|
28
|
-
import styles from '@adobe/spectrum-css-temp/components/menu/vars.css';
|
|
29
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
30
|
-
import {useProvider} from '@react-spectrum/provider';
|
|
31
|
-
import {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';
|
|
32
|
-
|
|
33
|
-
interface ListBoxBaseProps<T> extends AriaListBoxOptions<T>, DOMProps, AriaLabelingProps, StyleProps {
|
|
34
|
-
layout: ListBoxLayout<T>,
|
|
35
|
-
state: ListState<T>,
|
|
36
|
-
autoFocus?: boolean | FocusStrategy,
|
|
37
|
-
shouldFocusWrap?: boolean,
|
|
38
|
-
shouldSelectOnPressUp?: boolean,
|
|
39
|
-
focusOnPointerEnter?: boolean,
|
|
40
|
-
domProps?: HTMLAttributes<HTMLElement>,
|
|
41
|
-
disallowEmptySelection?: boolean,
|
|
42
|
-
shouldUseVirtualFocus?: boolean,
|
|
43
|
-
isLoading?: boolean,
|
|
44
|
-
showLoadingSpinner?: boolean,
|
|
45
|
-
onLoadMore?: () => void,
|
|
46
|
-
renderEmptyState?: () => ReactNode,
|
|
47
|
-
onScroll?: () => void
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** @private */
|
|
51
|
-
export function useListBoxLayout<T>(): ListBoxLayout<T> {
|
|
52
|
-
let {scale} = useProvider();
|
|
53
|
-
let layout = useMemo(() =>
|
|
54
|
-
new ListBoxLayout<T>({
|
|
55
|
-
estimatedRowHeight: scale === 'large' ? 48 : 32,
|
|
56
|
-
estimatedHeadingHeight: scale === 'large' ? 33 : 26,
|
|
57
|
-
paddingY: scale === 'large' ? 5 : 4, // TODO: get from DNA
|
|
58
|
-
placeholderHeight: scale === 'large' ? 48 : 32
|
|
59
|
-
})
|
|
60
|
-
, [scale]);
|
|
61
|
-
|
|
62
|
-
return layout;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// forwardRef doesn't support generic parameters, so cast the result to the correct type
|
|
66
|
-
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
67
|
-
/** @private */
|
|
68
|
-
export const ListBoxBase = React.forwardRef(function ListBoxBase<T extends object>(props: ListBoxBaseProps<T>, ref: ForwardedRef<HTMLDivElement | null>) {
|
|
69
|
-
let {layout, state, shouldFocusOnHover = false, shouldUseVirtualFocus = false, domProps = {}, isLoading, showLoadingSpinner = isLoading, onScroll, renderEmptyState} = props;
|
|
70
|
-
let objectRef = useObjectRef(ref);
|
|
71
|
-
let {listBoxProps} = useListBox({
|
|
72
|
-
...props,
|
|
73
|
-
layoutDelegate: layout,
|
|
74
|
-
isVirtualized: true
|
|
75
|
-
}, state, objectRef);
|
|
76
|
-
let {styleProps} = useStyleProps(props);
|
|
77
|
-
|
|
78
|
-
// This overrides collection view's renderWrapper to support hierarchy of items in sections.
|
|
79
|
-
// The header is extracted from the children so it can receive ARIA labeling properties.
|
|
80
|
-
type View = ReusableView<Node<T>, ReactNode>;
|
|
81
|
-
let renderWrapper = useCallback((parent: View | null, reusableView: View, children: View[], renderChildren: (views: View[]) => ReactElement[]) => {
|
|
82
|
-
if (reusableView.viewType === 'section') {
|
|
83
|
-
return (
|
|
84
|
-
<ListBoxSection
|
|
85
|
-
key={reusableView.key}
|
|
86
|
-
item={reusableView.content!}
|
|
87
|
-
layoutInfo={reusableView.layoutInfo!}
|
|
88
|
-
virtualizer={reusableView.virtualizer}
|
|
89
|
-
headerLayoutInfo={children.find(c => c.viewType === 'header')?.layoutInfo ?? null}>
|
|
90
|
-
{renderChildren(children.filter(c => c.viewType === 'item'))}
|
|
91
|
-
</ListBoxSection>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return (
|
|
96
|
-
<VirtualizerItem
|
|
97
|
-
key={reusableView.key}
|
|
98
|
-
layoutInfo={reusableView.layoutInfo!}
|
|
99
|
-
virtualizer={reusableView.virtualizer}
|
|
100
|
-
parent={parent?.layoutInfo}>
|
|
101
|
-
{reusableView.rendered}
|
|
102
|
-
</VirtualizerItem>
|
|
103
|
-
);
|
|
104
|
-
}, []);
|
|
105
|
-
|
|
106
|
-
let focusedKey = state.selectionManager.focusedKey;
|
|
107
|
-
let persistedKeys = useMemo(() => focusedKey != null ? new Set([focusedKey]) : null, [focusedKey]);
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<ListBoxContext.Provider value={{state, renderEmptyState, shouldFocusOnHover, shouldUseVirtualFocus}}>
|
|
111
|
-
<FocusScope>
|
|
112
|
-
<Virtualizer
|
|
113
|
-
{...styleProps}
|
|
114
|
-
{...mergeProps(listBoxProps, domProps)}
|
|
115
|
-
ref={objectRef}
|
|
116
|
-
persistedKeys={persistedKeys}
|
|
117
|
-
autoFocus={!!props.autoFocus || undefined}
|
|
118
|
-
scrollDirection="vertical"
|
|
119
|
-
className={
|
|
120
|
-
classNames(
|
|
121
|
-
styles,
|
|
122
|
-
'spectrum-Menu',
|
|
123
|
-
styleProps.className
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
layout={layout}
|
|
127
|
-
layoutOptions={useMemo(() => ({
|
|
128
|
-
isLoading: showLoadingSpinner
|
|
129
|
-
}), [showLoadingSpinner])}
|
|
130
|
-
collection={state.collection}
|
|
131
|
-
renderWrapper={renderWrapper}
|
|
132
|
-
isLoading={isLoading}
|
|
133
|
-
onLoadMore={props.onLoadMore}
|
|
134
|
-
onScroll={onScroll}>
|
|
135
|
-
{useCallback((type, item: Node<T>): ReactNode => {
|
|
136
|
-
if (type === 'item') {
|
|
137
|
-
return <ListBoxOption item={item} />;
|
|
138
|
-
} else if (type === 'loader') {
|
|
139
|
-
return <LoadingState />;
|
|
140
|
-
} else if (type === 'placeholder') {
|
|
141
|
-
return <EmptyState />;
|
|
142
|
-
} else {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
}, [])}
|
|
146
|
-
</Virtualizer>
|
|
147
|
-
</FocusScope>
|
|
148
|
-
</ListBoxContext.Provider>
|
|
149
|
-
);
|
|
150
|
-
}) as <T>(props: ListBoxBaseProps<T> & {ref?: RefObject<HTMLDivElement | null>}) => ReactElement;
|
|
151
|
-
|
|
152
|
-
function LoadingState() {
|
|
153
|
-
let {state} = useContext(ListBoxContext)!;
|
|
154
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/listbox');
|
|
155
|
-
return (
|
|
156
|
-
// aria-selected isn't needed here since this option is not selectable.
|
|
157
|
-
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props
|
|
158
|
-
<div role="option" style={{display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%'}}>
|
|
159
|
-
<ProgressCircle
|
|
160
|
-
isIndeterminate
|
|
161
|
-
size="S"
|
|
162
|
-
aria-label={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')}
|
|
163
|
-
UNSAFE_className={classNames(styles, 'spectrum-Dropdown-progressCircle')} />
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function EmptyState() {
|
|
169
|
-
let {renderEmptyState} = useContext(ListBoxContext)!;
|
|
170
|
-
let emptyState = renderEmptyState ? renderEmptyState() : null;
|
|
171
|
-
if (emptyState == null) {
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<div
|
|
177
|
-
// aria-selected isn't needed here since this option is not selectable.
|
|
178
|
-
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props
|
|
179
|
-
role="option">
|
|
180
|
-
{emptyState}
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
}
|
package/src/ListBoxContext.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {ListState} from '@react-stately/list';
|
|
14
|
-
import React, {ReactNode} from 'react';
|
|
15
|
-
|
|
16
|
-
interface ListBoxContextValue {
|
|
17
|
-
state: ListState<unknown>,
|
|
18
|
-
renderEmptyState?: () => ReactNode,
|
|
19
|
-
shouldFocusOnHover: boolean,
|
|
20
|
-
shouldUseVirtualFocus: boolean
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const ListBoxContext = React.createContext<ListBoxContextValue | null>(null);
|
package/src/ListBoxLayout.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {InvalidationContext, LayoutInfo, Rect} from '@react-stately/virtualizer';
|
|
2
|
-
import {LayoutNode, ListLayout, ListLayoutOptions} from '@react-stately/layout';
|
|
3
|
-
import {Node} from '@react-types/shared';
|
|
4
|
-
|
|
5
|
-
interface ListBoxLayoutProps extends ListLayoutOptions {
|
|
6
|
-
isLoading?: boolean
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface ListBoxLayoutOptions extends ListLayoutOptions {
|
|
10
|
-
placeholderHeight: number,
|
|
11
|
-
paddingY: number
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class ListBoxLayout<T> extends ListLayout<T, ListBoxLayoutProps> {
|
|
15
|
-
private isLoading: boolean = false;
|
|
16
|
-
private placeholderHeight: number;
|
|
17
|
-
private paddingY: number;
|
|
18
|
-
|
|
19
|
-
constructor(opts: ListBoxLayoutOptions) {
|
|
20
|
-
super(opts);
|
|
21
|
-
this.placeholderHeight = opts.placeholderHeight;
|
|
22
|
-
this.paddingY = opts.paddingY;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
update(invalidationContext: InvalidationContext<ListBoxLayoutProps>): void {
|
|
26
|
-
this.isLoading = invalidationContext.layoutOptions?.isLoading || false;
|
|
27
|
-
super.update(invalidationContext);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected buildCollection(): LayoutNode[] {
|
|
31
|
-
let nodes = super.buildCollection(this.paddingY);
|
|
32
|
-
let y = this.contentSize.height;
|
|
33
|
-
|
|
34
|
-
if (this.isLoading) {
|
|
35
|
-
let rect = new Rect(0, y, this.virtualizer!.visibleRect.width, 40);
|
|
36
|
-
let loader = new LayoutInfo('loader', 'loader', rect);
|
|
37
|
-
let node = {
|
|
38
|
-
layoutInfo: loader,
|
|
39
|
-
validRect: loader.rect
|
|
40
|
-
};
|
|
41
|
-
nodes.push(node);
|
|
42
|
-
this.layoutNodes.set(loader.key, node);
|
|
43
|
-
y = loader.rect.maxY;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (nodes.length === 0) {
|
|
47
|
-
let rect = new Rect(0, y, this.virtualizer!.visibleRect.width, this.placeholderHeight ?? this.virtualizer!.visibleRect.height);
|
|
48
|
-
let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
|
|
49
|
-
let node = {
|
|
50
|
-
layoutInfo: placeholder,
|
|
51
|
-
validRect: placeholder.rect
|
|
52
|
-
};
|
|
53
|
-
nodes.push(node);
|
|
54
|
-
this.layoutNodes.set(placeholder.key, node);
|
|
55
|
-
y = placeholder.rect.maxY;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.contentSize.height = y + this.paddingY;
|
|
59
|
-
return nodes;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
protected buildSection(node: Node<T>, x: number, y: number): LayoutNode {
|
|
63
|
-
// Synthesize a collection node for the header.
|
|
64
|
-
let headerNode = {
|
|
65
|
-
type: 'header',
|
|
66
|
-
key: node.key + ':header',
|
|
67
|
-
parentKey: node.key,
|
|
68
|
-
value: null,
|
|
69
|
-
level: node.level,
|
|
70
|
-
index: node.index,
|
|
71
|
-
hasChildNodes: false,
|
|
72
|
-
childNodes: [],
|
|
73
|
-
rendered: node.rendered,
|
|
74
|
-
textValue: node.textValue
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// Build layout node for it and adjust y offset of section children.
|
|
78
|
-
let header = this.buildSectionHeader(headerNode, x, y);
|
|
79
|
-
header.node = headerNode;
|
|
80
|
-
header.layoutInfo.parentKey = node.key;
|
|
81
|
-
this.layoutNodes.set(headerNode.key, header);
|
|
82
|
-
y += header.layoutInfo.rect.height;
|
|
83
|
-
|
|
84
|
-
let section = super.buildSection(node, x, y);
|
|
85
|
-
section.children!.unshift(header);
|
|
86
|
-
return section;
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/ListBoxOption.tsx
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import CheckmarkMedium from '@spectrum-icons/ui/CheckmarkMedium';
|
|
14
|
-
import {classNames, ClearSlots, SlotProvider} from '@react-spectrum/utils';
|
|
15
|
-
import {FocusRing} from '@react-aria/focus';
|
|
16
|
-
import {Grid} from '@react-spectrum/layout';
|
|
17
|
-
import {isFocusVisible, useHover} from '@react-aria/interactions';
|
|
18
|
-
import {ListBoxContext} from './ListBoxContext';
|
|
19
|
-
import {mergeProps} from '@react-aria/utils';
|
|
20
|
-
import {Node} from '@react-types/shared';
|
|
21
|
-
import React, {JSX, useContext, useRef} from 'react';
|
|
22
|
-
import styles from '@adobe/spectrum-css-temp/components/menu/vars.css';
|
|
23
|
-
import {Text} from '@react-spectrum/text';
|
|
24
|
-
import {useOption} from '@react-aria/listbox';
|
|
25
|
-
|
|
26
|
-
interface OptionProps<T> {
|
|
27
|
-
item: Node<T>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** @private */
|
|
31
|
-
export function ListBoxOption<T>(props: OptionProps<T>): JSX.Element {
|
|
32
|
-
let {item} = props;
|
|
33
|
-
|
|
34
|
-
let {
|
|
35
|
-
rendered,
|
|
36
|
-
key
|
|
37
|
-
} = item;
|
|
38
|
-
let ElementType: React.ElementType = item.props.href ? 'a' : 'div';
|
|
39
|
-
let {state, shouldFocusOnHover, shouldUseVirtualFocus} = useContext(ListBoxContext)!;
|
|
40
|
-
|
|
41
|
-
let ref = useRef<any>(undefined);
|
|
42
|
-
let {optionProps, labelProps, descriptionProps, isSelected, isDisabled, isFocused} = useOption(
|
|
43
|
-
{
|
|
44
|
-
'aria-label': item['aria-label'],
|
|
45
|
-
key,
|
|
46
|
-
isVirtualized: true
|
|
47
|
-
},
|
|
48
|
-
state,
|
|
49
|
-
ref
|
|
50
|
-
);
|
|
51
|
-
let {hoverProps, isHovered} = useHover({
|
|
52
|
-
...props,
|
|
53
|
-
isDisabled
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
let contents = typeof rendered === 'string'
|
|
57
|
-
? <Text>{rendered}</Text>
|
|
58
|
-
: rendered;
|
|
59
|
-
|
|
60
|
-
let isKeyboardModality = isFocusVisible();
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
|
|
64
|
-
<ElementType
|
|
65
|
-
{...mergeProps(optionProps, shouldFocusOnHover ? {} : hoverProps)}
|
|
66
|
-
ref={ref}
|
|
67
|
-
className={classNames(
|
|
68
|
-
styles,
|
|
69
|
-
'spectrum-Menu-item',
|
|
70
|
-
{
|
|
71
|
-
// If using virtual focus, apply focused styles to the item when the user is interacting with keyboard modality
|
|
72
|
-
'is-focused': shouldUseVirtualFocus && isFocused && isKeyboardModality,
|
|
73
|
-
'is-disabled': isDisabled,
|
|
74
|
-
'is-selected': isSelected,
|
|
75
|
-
'is-selectable': state.selectionManager.selectionMode !== 'none',
|
|
76
|
-
// When shouldFocusOnHover is false, apply hover styles both when hovered with the mouse.
|
|
77
|
-
// Otherwise, apply hover styles when focused using non-keyboard modality.
|
|
78
|
-
'is-hovered': (isHovered && !shouldFocusOnHover) || (isFocused && !isKeyboardModality)
|
|
79
|
-
}
|
|
80
|
-
)}>
|
|
81
|
-
<Grid
|
|
82
|
-
UNSAFE_className={
|
|
83
|
-
classNames(
|
|
84
|
-
styles,
|
|
85
|
-
'spectrum-Menu-itemGrid'
|
|
86
|
-
)
|
|
87
|
-
}>
|
|
88
|
-
<ClearSlots>
|
|
89
|
-
<SlotProvider
|
|
90
|
-
slots={{
|
|
91
|
-
text: {UNSAFE_className: styles['spectrum-Menu-itemLabel'], ...labelProps},
|
|
92
|
-
icon: {size: 'S', UNSAFE_className: styles['spectrum-Menu-icon']},
|
|
93
|
-
avatar: {size: 'avatar-size-100', UNSAFE_className: styles['spectrum-Menu-avatar']},
|
|
94
|
-
description: {UNSAFE_className: styles['spectrum-Menu-description'], ...descriptionProps}
|
|
95
|
-
}}>
|
|
96
|
-
{contents}
|
|
97
|
-
{isSelected &&
|
|
98
|
-
<CheckmarkMedium
|
|
99
|
-
slot="checkmark"
|
|
100
|
-
UNSAFE_className={
|
|
101
|
-
classNames(
|
|
102
|
-
styles,
|
|
103
|
-
'spectrum-Menu-checkmark'
|
|
104
|
-
)
|
|
105
|
-
} />
|
|
106
|
-
}
|
|
107
|
-
</SlotProvider>
|
|
108
|
-
</ClearSlots>
|
|
109
|
-
</Grid>
|
|
110
|
-
</ElementType>
|
|
111
|
-
</FocusRing>
|
|
112
|
-
);
|
|
113
|
-
}
|
package/src/ListBoxSection.tsx
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {classNames} from '@react-spectrum/utils';
|
|
14
|
-
import {LayoutInfo} from '@react-stately/virtualizer';
|
|
15
|
-
import {layoutInfoToStyle, useVirtualizerItem, VirtualizerItemOptions} from '@react-aria/virtualizer';
|
|
16
|
-
import {ListBoxContext} from './ListBoxContext';
|
|
17
|
-
import {Node} from '@react-types/shared';
|
|
18
|
-
import React, {Fragment, JSX, ReactNode, useContext, useRef} from 'react';
|
|
19
|
-
import styles from '@adobe/spectrum-css-temp/components/menu/vars.css';
|
|
20
|
-
import {useListBoxSection} from '@react-aria/listbox';
|
|
21
|
-
import {useLocale} from '@react-aria/i18n';
|
|
22
|
-
|
|
23
|
-
interface ListBoxSectionProps<T> extends Omit<VirtualizerItemOptions, 'ref' | 'layoutInfo'> {
|
|
24
|
-
layoutInfo: LayoutInfo,
|
|
25
|
-
headerLayoutInfo: LayoutInfo | null,
|
|
26
|
-
item: Node<T>,
|
|
27
|
-
children?: ReactNode
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** @private */
|
|
31
|
-
export function ListBoxSection<T>(props: ListBoxSectionProps<T>): JSX.Element {
|
|
32
|
-
let {children, layoutInfo, headerLayoutInfo, virtualizer, item} = props;
|
|
33
|
-
let {headingProps, groupProps} = useListBoxSection({
|
|
34
|
-
heading: item.rendered,
|
|
35
|
-
'aria-label': item['aria-label']
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
let headerRef = useRef<HTMLDivElement | null>(null);
|
|
39
|
-
useVirtualizerItem({
|
|
40
|
-
layoutInfo: headerLayoutInfo,
|
|
41
|
-
virtualizer,
|
|
42
|
-
ref: headerRef
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
let {direction} = useLocale();
|
|
46
|
-
let {state} = useContext(ListBoxContext)!;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<Fragment>
|
|
50
|
-
{headerLayoutInfo && <div role="presentation" ref={headerRef} style={layoutInfoToStyle(headerLayoutInfo, direction)}>
|
|
51
|
-
{item.key !== state.collection.getFirstKey() &&
|
|
52
|
-
<div
|
|
53
|
-
role="presentation"
|
|
54
|
-
className={classNames(
|
|
55
|
-
styles,
|
|
56
|
-
'spectrum-Menu-divider'
|
|
57
|
-
)} />
|
|
58
|
-
}
|
|
59
|
-
{item.rendered &&
|
|
60
|
-
<div
|
|
61
|
-
{...headingProps}
|
|
62
|
-
className={
|
|
63
|
-
classNames(
|
|
64
|
-
styles,
|
|
65
|
-
'spectrum-Menu-sectionHeading'
|
|
66
|
-
)
|
|
67
|
-
}>
|
|
68
|
-
{item.rendered}
|
|
69
|
-
</div>
|
|
70
|
-
}
|
|
71
|
-
</div>}
|
|
72
|
-
<div
|
|
73
|
-
{...groupProps}
|
|
74
|
-
style={layoutInfoToStyle(layoutInfo, direction)}
|
|
75
|
-
className={
|
|
76
|
-
classNames(
|
|
77
|
-
styles,
|
|
78
|
-
'spectrum-Menu'
|
|
79
|
-
)
|
|
80
|
-
}>
|
|
81
|
-
{children}
|
|
82
|
-
</div>
|
|
83
|
-
</Fragment>
|
|
84
|
-
);
|
|
85
|
-
}
|