@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.
Files changed (228) hide show
  1. package/dist/import.mjs +6 -4
  2. package/dist/main.js +10 -8
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -4
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +5 -0
  7. package/package.json +14 -42
  8. package/src/index.ts +6 -4
  9. package/dist/ListBox.main.js +0 -43
  10. package/dist/ListBox.main.js.map +0 -1
  11. package/dist/ListBox.mjs +0 -34
  12. package/dist/ListBox.module.js +0 -34
  13. package/dist/ListBox.module.js.map +0 -1
  14. package/dist/ListBoxBase.main.js +0 -165
  15. package/dist/ListBoxBase.main.js.map +0 -1
  16. package/dist/ListBoxBase.mjs +0 -159
  17. package/dist/ListBoxBase.module.js +0 -159
  18. package/dist/ListBoxBase.module.js.map +0 -1
  19. package/dist/ListBoxContext.main.js +0 -27
  20. package/dist/ListBoxContext.main.js.map +0 -1
  21. package/dist/ListBoxContext.mjs +0 -18
  22. package/dist/ListBoxContext.module.js +0 -18
  23. package/dist/ListBoxContext.module.js.map +0 -1
  24. package/dist/ListBoxLayout.main.js +0 -79
  25. package/dist/ListBoxLayout.main.js.map +0 -1
  26. package/dist/ListBoxLayout.mjs +0 -74
  27. package/dist/ListBoxLayout.module.js +0 -74
  28. package/dist/ListBoxLayout.module.js.map +0 -1
  29. package/dist/ListBoxOption.main.js +0 -105
  30. package/dist/ListBoxOption.main.js.map +0 -1
  31. package/dist/ListBoxOption.mjs +0 -100
  32. package/dist/ListBoxOption.module.js +0 -100
  33. package/dist/ListBoxOption.module.js.map +0 -1
  34. package/dist/ListBoxSection.main.js +0 -69
  35. package/dist/ListBoxSection.main.js.map +0 -1
  36. package/dist/ListBoxSection.mjs +0 -64
  37. package/dist/ListBoxSection.module.js +0 -64
  38. package/dist/ListBoxSection.module.js.map +0 -1
  39. package/dist/ar-AE.main.js +0 -7
  40. package/dist/ar-AE.main.js.map +0 -1
  41. package/dist/ar-AE.mjs +0 -9
  42. package/dist/ar-AE.module.js +0 -9
  43. package/dist/ar-AE.module.js.map +0 -1
  44. package/dist/bg-BG.main.js +0 -7
  45. package/dist/bg-BG.main.js.map +0 -1
  46. package/dist/bg-BG.mjs +0 -9
  47. package/dist/bg-BG.module.js +0 -9
  48. package/dist/bg-BG.module.js.map +0 -1
  49. package/dist/cs-CZ.main.js +0 -7
  50. package/dist/cs-CZ.main.js.map +0 -1
  51. package/dist/cs-CZ.mjs +0 -9
  52. package/dist/cs-CZ.module.js +0 -9
  53. package/dist/cs-CZ.module.js.map +0 -1
  54. package/dist/da-DK.main.js +0 -7
  55. package/dist/da-DK.main.js.map +0 -1
  56. package/dist/da-DK.mjs +0 -9
  57. package/dist/da-DK.module.js +0 -9
  58. package/dist/da-DK.module.js.map +0 -1
  59. package/dist/de-DE.main.js +0 -7
  60. package/dist/de-DE.main.js.map +0 -1
  61. package/dist/de-DE.mjs +0 -9
  62. package/dist/de-DE.module.js +0 -9
  63. package/dist/de-DE.module.js.map +0 -1
  64. package/dist/el-GR.main.js +0 -7
  65. package/dist/el-GR.main.js.map +0 -1
  66. package/dist/el-GR.mjs +0 -9
  67. package/dist/el-GR.module.js +0 -9
  68. package/dist/el-GR.module.js.map +0 -1
  69. package/dist/en-US.main.js +0 -7
  70. package/dist/en-US.main.js.map +0 -1
  71. package/dist/en-US.mjs +0 -9
  72. package/dist/en-US.module.js +0 -9
  73. package/dist/en-US.module.js.map +0 -1
  74. package/dist/es-ES.main.js +0 -7
  75. package/dist/es-ES.main.js.map +0 -1
  76. package/dist/es-ES.mjs +0 -9
  77. package/dist/es-ES.module.js +0 -9
  78. package/dist/es-ES.module.js.map +0 -1
  79. package/dist/et-EE.main.js +0 -7
  80. package/dist/et-EE.main.js.map +0 -1
  81. package/dist/et-EE.mjs +0 -9
  82. package/dist/et-EE.module.js +0 -9
  83. package/dist/et-EE.module.js.map +0 -1
  84. package/dist/fi-FI.main.js +0 -7
  85. package/dist/fi-FI.main.js.map +0 -1
  86. package/dist/fi-FI.mjs +0 -9
  87. package/dist/fi-FI.module.js +0 -9
  88. package/dist/fi-FI.module.js.map +0 -1
  89. package/dist/fr-FR.main.js +0 -7
  90. package/dist/fr-FR.main.js.map +0 -1
  91. package/dist/fr-FR.mjs +0 -9
  92. package/dist/fr-FR.module.js +0 -9
  93. package/dist/fr-FR.module.js.map +0 -1
  94. package/dist/he-IL.main.js +0 -7
  95. package/dist/he-IL.main.js.map +0 -1
  96. package/dist/he-IL.mjs +0 -9
  97. package/dist/he-IL.module.js +0 -9
  98. package/dist/he-IL.module.js.map +0 -1
  99. package/dist/hr-HR.main.js +0 -7
  100. package/dist/hr-HR.main.js.map +0 -1
  101. package/dist/hr-HR.mjs +0 -9
  102. package/dist/hr-HR.module.js +0 -9
  103. package/dist/hr-HR.module.js.map +0 -1
  104. package/dist/hu-HU.main.js +0 -7
  105. package/dist/hu-HU.main.js.map +0 -1
  106. package/dist/hu-HU.mjs +0 -9
  107. package/dist/hu-HU.module.js +0 -9
  108. package/dist/hu-HU.module.js.map +0 -1
  109. package/dist/intlStrings.main.js +0 -108
  110. package/dist/intlStrings.main.js.map +0 -1
  111. package/dist/intlStrings.mjs +0 -110
  112. package/dist/intlStrings.module.js +0 -110
  113. package/dist/intlStrings.module.js.map +0 -1
  114. package/dist/it-IT.main.js +0 -7
  115. package/dist/it-IT.main.js.map +0 -1
  116. package/dist/it-IT.mjs +0 -9
  117. package/dist/it-IT.module.js +0 -9
  118. package/dist/it-IT.module.js.map +0 -1
  119. package/dist/ja-JP.main.js +0 -7
  120. package/dist/ja-JP.main.js.map +0 -1
  121. package/dist/ja-JP.mjs +0 -9
  122. package/dist/ja-JP.module.js +0 -9
  123. package/dist/ja-JP.module.js.map +0 -1
  124. package/dist/ko-KR.main.js +0 -7
  125. package/dist/ko-KR.main.js.map +0 -1
  126. package/dist/ko-KR.mjs +0 -9
  127. package/dist/ko-KR.module.js +0 -9
  128. package/dist/ko-KR.module.js.map +0 -1
  129. package/dist/listbox.a566c7a6.css +0 -570
  130. package/dist/listbox.a566c7a6.css.map +0 -1
  131. package/dist/lt-LT.main.js +0 -7
  132. package/dist/lt-LT.main.js.map +0 -1
  133. package/dist/lt-LT.mjs +0 -9
  134. package/dist/lt-LT.module.js +0 -9
  135. package/dist/lt-LT.module.js.map +0 -1
  136. package/dist/lv-LV.main.js +0 -7
  137. package/dist/lv-LV.main.js.map +0 -1
  138. package/dist/lv-LV.mjs +0 -9
  139. package/dist/lv-LV.module.js +0 -9
  140. package/dist/lv-LV.module.js.map +0 -1
  141. package/dist/menu_vars_css.main.js +0 -177
  142. package/dist/menu_vars_css.main.js.map +0 -1
  143. package/dist/menu_vars_css.mjs +0 -179
  144. package/dist/menu_vars_css.module.js +0 -179
  145. package/dist/menu_vars_css.module.js.map +0 -1
  146. package/dist/nb-NO.main.js +0 -7
  147. package/dist/nb-NO.main.js.map +0 -1
  148. package/dist/nb-NO.mjs +0 -9
  149. package/dist/nb-NO.module.js +0 -9
  150. package/dist/nb-NO.module.js.map +0 -1
  151. package/dist/nl-NL.main.js +0 -7
  152. package/dist/nl-NL.main.js.map +0 -1
  153. package/dist/nl-NL.mjs +0 -9
  154. package/dist/nl-NL.module.js +0 -9
  155. package/dist/nl-NL.module.js.map +0 -1
  156. package/dist/pl-PL.main.js +0 -7
  157. package/dist/pl-PL.main.js.map +0 -1
  158. package/dist/pl-PL.mjs +0 -9
  159. package/dist/pl-PL.module.js +0 -9
  160. package/dist/pl-PL.module.js.map +0 -1
  161. package/dist/pt-BR.main.js +0 -7
  162. package/dist/pt-BR.main.js.map +0 -1
  163. package/dist/pt-BR.mjs +0 -9
  164. package/dist/pt-BR.module.js +0 -9
  165. package/dist/pt-BR.module.js.map +0 -1
  166. package/dist/pt-PT.main.js +0 -7
  167. package/dist/pt-PT.main.js.map +0 -1
  168. package/dist/pt-PT.mjs +0 -9
  169. package/dist/pt-PT.module.js +0 -9
  170. package/dist/pt-PT.module.js.map +0 -1
  171. package/dist/ro-RO.main.js +0 -7
  172. package/dist/ro-RO.main.js.map +0 -1
  173. package/dist/ro-RO.mjs +0 -9
  174. package/dist/ro-RO.module.js +0 -9
  175. package/dist/ro-RO.module.js.map +0 -1
  176. package/dist/ru-RU.main.js +0 -7
  177. package/dist/ru-RU.main.js.map +0 -1
  178. package/dist/ru-RU.mjs +0 -9
  179. package/dist/ru-RU.module.js +0 -9
  180. package/dist/ru-RU.module.js.map +0 -1
  181. package/dist/sk-SK.main.js +0 -7
  182. package/dist/sk-SK.main.js.map +0 -1
  183. package/dist/sk-SK.mjs +0 -9
  184. package/dist/sk-SK.module.js +0 -9
  185. package/dist/sk-SK.module.js.map +0 -1
  186. package/dist/sl-SI.main.js +0 -7
  187. package/dist/sl-SI.main.js.map +0 -1
  188. package/dist/sl-SI.mjs +0 -9
  189. package/dist/sl-SI.module.js +0 -9
  190. package/dist/sl-SI.module.js.map +0 -1
  191. package/dist/sr-SP.main.js +0 -7
  192. package/dist/sr-SP.main.js.map +0 -1
  193. package/dist/sr-SP.mjs +0 -9
  194. package/dist/sr-SP.module.js +0 -9
  195. package/dist/sr-SP.module.js.map +0 -1
  196. package/dist/sv-SE.main.js +0 -7
  197. package/dist/sv-SE.main.js.map +0 -1
  198. package/dist/sv-SE.mjs +0 -9
  199. package/dist/sv-SE.module.js +0 -9
  200. package/dist/sv-SE.module.js.map +0 -1
  201. package/dist/tr-TR.main.js +0 -7
  202. package/dist/tr-TR.main.js.map +0 -1
  203. package/dist/tr-TR.mjs +0 -9
  204. package/dist/tr-TR.module.js +0 -9
  205. package/dist/tr-TR.module.js.map +0 -1
  206. package/dist/types.d.ts +0 -52
  207. package/dist/types.d.ts.map +0 -1
  208. package/dist/uk-UA.main.js +0 -7
  209. package/dist/uk-UA.main.js.map +0 -1
  210. package/dist/uk-UA.mjs +0 -9
  211. package/dist/uk-UA.module.js +0 -9
  212. package/dist/uk-UA.module.js.map +0 -1
  213. package/dist/zh-CN.main.js +0 -7
  214. package/dist/zh-CN.main.js.map +0 -1
  215. package/dist/zh-CN.mjs +0 -9
  216. package/dist/zh-CN.module.js +0 -9
  217. package/dist/zh-CN.module.js.map +0 -1
  218. package/dist/zh-TW.main.js +0 -7
  219. package/dist/zh-TW.main.js.map +0 -1
  220. package/dist/zh-TW.mjs +0 -9
  221. package/dist/zh-TW.module.js +0 -9
  222. package/dist/zh-TW.module.js.map +0 -1
  223. package/src/ListBox.tsx +0 -39
  224. package/src/ListBoxBase.tsx +0 -183
  225. package/src/ListBoxContext.ts +0 -23
  226. package/src/ListBoxLayout.ts +0 -88
  227. package/src/ListBoxOption.tsx +0 -113
  228. 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;
@@ -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
- }
@@ -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);
@@ -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
- }
@@ -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
- }
@@ -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
- }