@react-spectrum/card 3.0.0-alpha.52 → 3.0.0-alpha.54

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 (240) hide show
  1. package/dist/import.mjs +6 -6
  2. package/dist/main.js +10 -10
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +6 -6
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +9 -0
  7. package/package.json +12 -40
  8. package/src/index.ts +9 -9
  9. package/dist/BaseLayout.main.js +0 -213
  10. package/dist/BaseLayout.main.js.map +0 -1
  11. package/dist/BaseLayout.mjs +0 -208
  12. package/dist/BaseLayout.module.js +0 -208
  13. package/dist/BaseLayout.module.js.map +0 -1
  14. package/dist/Card.main.js +0 -52
  15. package/dist/Card.main.js.map +0 -1
  16. package/dist/Card.mjs +0 -43
  17. package/dist/Card.module.js +0 -43
  18. package/dist/Card.module.js.map +0 -1
  19. package/dist/CardBase.main.js +0 -205
  20. package/dist/CardBase.main.js.map +0 -1
  21. package/dist/CardBase.mjs +0 -200
  22. package/dist/CardBase.module.js +0 -200
  23. package/dist/CardBase.module.js.map +0 -1
  24. package/dist/CardView.main.js +0 -238
  25. package/dist/CardView.main.js.map +0 -1
  26. package/dist/CardView.mjs +0 -233
  27. package/dist/CardView.module.js +0 -233
  28. package/dist/CardView.module.js.map +0 -1
  29. package/dist/CardViewContext.main.js +0 -32
  30. package/dist/CardViewContext.main.js.map +0 -1
  31. package/dist/CardViewContext.mjs +0 -22
  32. package/dist/CardViewContext.module.js +0 -22
  33. package/dist/CardViewContext.module.js.map +0 -1
  34. package/dist/GalleryLayout.main.js +0 -230
  35. package/dist/GalleryLayout.main.js.map +0 -1
  36. package/dist/GalleryLayout.mjs +0 -225
  37. package/dist/GalleryLayout.module.js +0 -225
  38. package/dist/GalleryLayout.module.js.map +0 -1
  39. package/dist/GridLayout.main.js +0 -175
  40. package/dist/GridLayout.main.js.map +0 -1
  41. package/dist/GridLayout.mjs +0 -170
  42. package/dist/GridLayout.module.js +0 -170
  43. package/dist/GridLayout.module.js.map +0 -1
  44. package/dist/WaterfallLayout.main.js +0 -182
  45. package/dist/WaterfallLayout.main.js.map +0 -1
  46. package/dist/WaterfallLayout.mjs +0 -177
  47. package/dist/WaterfallLayout.module.js +0 -177
  48. package/dist/WaterfallLayout.module.js.map +0 -1
  49. package/dist/ar-AE.main.js +0 -7
  50. package/dist/ar-AE.main.js.map +0 -1
  51. package/dist/ar-AE.mjs +0 -9
  52. package/dist/ar-AE.module.js +0 -9
  53. package/dist/ar-AE.module.js.map +0 -1
  54. package/dist/bg-BG.main.js +0 -7
  55. package/dist/bg-BG.main.js.map +0 -1
  56. package/dist/bg-BG.mjs +0 -9
  57. package/dist/bg-BG.module.js +0 -9
  58. package/dist/bg-BG.module.js.map +0 -1
  59. package/dist/card.4d5d6544.css +0 -1671
  60. package/dist/card.4d5d6544.css.map +0 -1
  61. package/dist/card_vars_css.main.js +0 -116
  62. package/dist/card_vars_css.main.js.map +0 -1
  63. package/dist/card_vars_css.mjs +0 -118
  64. package/dist/card_vars_css.module.js +0 -118
  65. package/dist/card_vars_css.module.js.map +0 -1
  66. package/dist/cs-CZ.main.js +0 -7
  67. package/dist/cs-CZ.main.js.map +0 -1
  68. package/dist/cs-CZ.mjs +0 -9
  69. package/dist/cs-CZ.module.js +0 -9
  70. package/dist/cs-CZ.module.js.map +0 -1
  71. package/dist/da-DK.main.js +0 -7
  72. package/dist/da-DK.main.js.map +0 -1
  73. package/dist/da-DK.mjs +0 -9
  74. package/dist/da-DK.module.js +0 -9
  75. package/dist/da-DK.module.js.map +0 -1
  76. package/dist/de-DE.main.js +0 -7
  77. package/dist/de-DE.main.js.map +0 -1
  78. package/dist/de-DE.mjs +0 -9
  79. package/dist/de-DE.module.js +0 -9
  80. package/dist/de-DE.module.js.map +0 -1
  81. package/dist/el-GR.main.js +0 -7
  82. package/dist/el-GR.main.js.map +0 -1
  83. package/dist/el-GR.mjs +0 -9
  84. package/dist/el-GR.module.js +0 -9
  85. package/dist/el-GR.module.js.map +0 -1
  86. package/dist/en-US.main.js +0 -7
  87. package/dist/en-US.main.js.map +0 -1
  88. package/dist/en-US.mjs +0 -9
  89. package/dist/en-US.module.js +0 -9
  90. package/dist/en-US.module.js.map +0 -1
  91. package/dist/es-ES.main.js +0 -7
  92. package/dist/es-ES.main.js.map +0 -1
  93. package/dist/es-ES.mjs +0 -9
  94. package/dist/es-ES.module.js +0 -9
  95. package/dist/es-ES.module.js.map +0 -1
  96. package/dist/et-EE.main.js +0 -7
  97. package/dist/et-EE.main.js.map +0 -1
  98. package/dist/et-EE.mjs +0 -9
  99. package/dist/et-EE.module.js +0 -9
  100. package/dist/et-EE.module.js.map +0 -1
  101. package/dist/fi-FI.main.js +0 -7
  102. package/dist/fi-FI.main.js.map +0 -1
  103. package/dist/fi-FI.mjs +0 -9
  104. package/dist/fi-FI.module.js +0 -9
  105. package/dist/fi-FI.module.js.map +0 -1
  106. package/dist/fr-FR.main.js +0 -7
  107. package/dist/fr-FR.main.js.map +0 -1
  108. package/dist/fr-FR.mjs +0 -9
  109. package/dist/fr-FR.module.js +0 -9
  110. package/dist/fr-FR.module.js.map +0 -1
  111. package/dist/he-IL.main.js +0 -7
  112. package/dist/he-IL.main.js.map +0 -1
  113. package/dist/he-IL.mjs +0 -9
  114. package/dist/he-IL.module.js +0 -9
  115. package/dist/he-IL.module.js.map +0 -1
  116. package/dist/hr-HR.main.js +0 -7
  117. package/dist/hr-HR.main.js.map +0 -1
  118. package/dist/hr-HR.mjs +0 -9
  119. package/dist/hr-HR.module.js +0 -9
  120. package/dist/hr-HR.module.js.map +0 -1
  121. package/dist/hu-HU.main.js +0 -7
  122. package/dist/hu-HU.main.js.map +0 -1
  123. package/dist/hu-HU.mjs +0 -9
  124. package/dist/hu-HU.module.js +0 -9
  125. package/dist/hu-HU.module.js.map +0 -1
  126. package/dist/intlStrings.main.js +0 -108
  127. package/dist/intlStrings.main.js.map +0 -1
  128. package/dist/intlStrings.mjs +0 -110
  129. package/dist/intlStrings.module.js +0 -110
  130. package/dist/intlStrings.module.js.map +0 -1
  131. package/dist/it-IT.main.js +0 -7
  132. package/dist/it-IT.main.js.map +0 -1
  133. package/dist/it-IT.mjs +0 -9
  134. package/dist/it-IT.module.js +0 -9
  135. package/dist/it-IT.module.js.map +0 -1
  136. package/dist/ja-JP.main.js +0 -7
  137. package/dist/ja-JP.main.js.map +0 -1
  138. package/dist/ja-JP.mjs +0 -9
  139. package/dist/ja-JP.module.js +0 -9
  140. package/dist/ja-JP.module.js.map +0 -1
  141. package/dist/ko-KR.main.js +0 -7
  142. package/dist/ko-KR.main.js.map +0 -1
  143. package/dist/ko-KR.mjs +0 -9
  144. package/dist/ko-KR.module.js +0 -9
  145. package/dist/ko-KR.module.js.map +0 -1
  146. package/dist/lt-LT.main.js +0 -7
  147. package/dist/lt-LT.main.js.map +0 -1
  148. package/dist/lt-LT.mjs +0 -9
  149. package/dist/lt-LT.module.js +0 -9
  150. package/dist/lt-LT.module.js.map +0 -1
  151. package/dist/lv-LV.main.js +0 -7
  152. package/dist/lv-LV.main.js.map +0 -1
  153. package/dist/lv-LV.mjs +0 -9
  154. package/dist/lv-LV.module.js +0 -9
  155. package/dist/lv-LV.module.js.map +0 -1
  156. package/dist/nb-NO.main.js +0 -7
  157. package/dist/nb-NO.main.js.map +0 -1
  158. package/dist/nb-NO.mjs +0 -9
  159. package/dist/nb-NO.module.js +0 -9
  160. package/dist/nb-NO.module.js.map +0 -1
  161. package/dist/nl-NL.main.js +0 -7
  162. package/dist/nl-NL.main.js.map +0 -1
  163. package/dist/nl-NL.mjs +0 -9
  164. package/dist/nl-NL.module.js +0 -9
  165. package/dist/nl-NL.module.js.map +0 -1
  166. package/dist/pl-PL.main.js +0 -7
  167. package/dist/pl-PL.main.js.map +0 -1
  168. package/dist/pl-PL.mjs +0 -9
  169. package/dist/pl-PL.module.js +0 -9
  170. package/dist/pl-PL.module.js.map +0 -1
  171. package/dist/pt-BR.main.js +0 -7
  172. package/dist/pt-BR.main.js.map +0 -1
  173. package/dist/pt-BR.mjs +0 -9
  174. package/dist/pt-BR.module.js +0 -9
  175. package/dist/pt-BR.module.js.map +0 -1
  176. package/dist/pt-PT.main.js +0 -7
  177. package/dist/pt-PT.main.js.map +0 -1
  178. package/dist/pt-PT.mjs +0 -9
  179. package/dist/pt-PT.module.js +0 -9
  180. package/dist/pt-PT.module.js.map +0 -1
  181. package/dist/ro-RO.main.js +0 -7
  182. package/dist/ro-RO.main.js.map +0 -1
  183. package/dist/ro-RO.mjs +0 -9
  184. package/dist/ro-RO.module.js +0 -9
  185. package/dist/ro-RO.module.js.map +0 -1
  186. package/dist/ru-RU.main.js +0 -7
  187. package/dist/ru-RU.main.js.map +0 -1
  188. package/dist/ru-RU.mjs +0 -9
  189. package/dist/ru-RU.module.js +0 -9
  190. package/dist/ru-RU.module.js.map +0 -1
  191. package/dist/sk-SK.main.js +0 -7
  192. package/dist/sk-SK.main.js.map +0 -1
  193. package/dist/sk-SK.mjs +0 -9
  194. package/dist/sk-SK.module.js +0 -9
  195. package/dist/sk-SK.module.js.map +0 -1
  196. package/dist/sl-SI.main.js +0 -7
  197. package/dist/sl-SI.main.js.map +0 -1
  198. package/dist/sl-SI.mjs +0 -9
  199. package/dist/sl-SI.module.js +0 -9
  200. package/dist/sl-SI.module.js.map +0 -1
  201. package/dist/sr-SP.main.js +0 -7
  202. package/dist/sr-SP.main.js.map +0 -1
  203. package/dist/sr-SP.mjs +0 -9
  204. package/dist/sr-SP.module.js +0 -9
  205. package/dist/sr-SP.module.js.map +0 -1
  206. package/dist/sv-SE.main.js +0 -7
  207. package/dist/sv-SE.main.js.map +0 -1
  208. package/dist/sv-SE.mjs +0 -9
  209. package/dist/sv-SE.module.js +0 -9
  210. package/dist/sv-SE.module.js.map +0 -1
  211. package/dist/tr-TR.main.js +0 -7
  212. package/dist/tr-TR.main.js.map +0 -1
  213. package/dist/tr-TR.mjs +0 -9
  214. package/dist/tr-TR.module.js +0 -9
  215. package/dist/tr-TR.module.js.map +0 -1
  216. package/dist/types.d.ts +0 -194
  217. package/dist/types.d.ts.map +0 -1
  218. package/dist/uk-UA.main.js +0 -7
  219. package/dist/uk-UA.main.js.map +0 -1
  220. package/dist/uk-UA.mjs +0 -9
  221. package/dist/uk-UA.module.js +0 -9
  222. package/dist/uk-UA.module.js.map +0 -1
  223. package/dist/zh-CN.main.js +0 -7
  224. package/dist/zh-CN.main.js.map +0 -1
  225. package/dist/zh-CN.mjs +0 -9
  226. package/dist/zh-CN.module.js +0 -9
  227. package/dist/zh-CN.module.js.map +0 -1
  228. package/dist/zh-TW.main.js +0 -7
  229. package/dist/zh-TW.main.js.map +0 -1
  230. package/dist/zh-TW.mjs +0 -9
  231. package/dist/zh-TW.module.js +0 -9
  232. package/dist/zh-TW.module.js.map +0 -1
  233. package/src/BaseLayout.tsx +0 -290
  234. package/src/Card.tsx +0 -48
  235. package/src/CardBase.tsx +0 -188
  236. package/src/CardView.tsx +0 -250
  237. package/src/CardViewContext.tsx +0 -27
  238. package/src/GalleryLayout.tsx +0 -321
  239. package/src/GridLayout.tsx +0 -242
  240. package/src/WaterfallLayout.tsx +0 -241
package/src/CardBase.tsx DELETED
@@ -1,188 +0,0 @@
1
- // @ts-nocheck
2
- /*
3
- * Copyright 2021 Adobe. All rights reserved.
4
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License. You may obtain a copy
6
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software distributed under
9
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- * OF ANY KIND, either express or implied. See the License for the specific language
11
- * governing permissions and limitations under the License.
12
- */
13
-
14
- import {AriaCardProps, SpectrumCardProps} from '@react-types/card';
15
- import {Checkbox} from '@react-spectrum/checkbox';
16
- import {classNames, SlotProvider, useDOMRef, useHasChild, useStyleProps} from '@react-spectrum/utils';
17
- import {DOMRef, Node} from '@react-types/shared';
18
- import {filterDOMProps, mergeProps, nodeContains, useLayoutEffect, useResizeObserver, useSlotId} from '@react-aria/utils';
19
- import {FocusRing, getFocusableTreeWalker} from '@react-aria/focus';
20
- import React, {HTMLAttributes, useCallback, useMemo, useRef, useState} from 'react';
21
- import styles from '@adobe/spectrum-css-temp/components/card/vars.css';
22
- import {useCardViewContext} from './CardViewContext';
23
- import {useFocusWithin, useHover} from '@react-aria/interactions';
24
- import {useProviderProps} from '@react-spectrum/provider';
25
-
26
- interface CardBaseProps<T> extends SpectrumCardProps {
27
- articleProps?: HTMLAttributes<HTMLElement>,
28
- item?: Node<T>
29
- }
30
-
31
- /**
32
- * TODO: Add description of component here.
33
- */
34
- export const CardBase = React.forwardRef(function CardBase<T extends object>(props: CardBaseProps<T>, ref: DOMRef<HTMLDivElement>) {
35
- props = useProviderProps(props);
36
- let context = useCardViewContext() || {}; // we can call again here, won't change from Card.tsx
37
- let {state} = context;
38
- let manager = state?.selectionManager;
39
- let {
40
- isQuiet,
41
- orientation = 'vertical',
42
- articleProps = {role: 'article'},
43
- item,
44
- layout,
45
- children
46
- } = props;
47
-
48
- let key = item?.key;
49
- let isSelected = manager?.isSelected(key);
50
- let isDisabled = state?.disabledKeys.has(key);
51
- let onChange = () => manager?.select(key);
52
-
53
- let {styleProps} = useStyleProps(props);
54
- let {cardProps, titleProps, contentProps} = useCard(props);
55
- let domRef = useDOMRef(ref);
56
- let gridRef = useRef<HTMLDivElement>(undefined);
57
- let checkboxRef = useRef(null);
58
-
59
- // cards are only interactive if there is a selection manager and it allows selection
60
- let {hoverProps, isHovered} = useHover({isDisabled: manager === undefined || manager?.selectionMode === 'none' || isDisabled});
61
- let [isFocused, setIsFocused] = useState(false);
62
- let {focusWithinProps} = useFocusWithin({
63
- onFocusWithinChange: setIsFocused,
64
- isDisabled
65
- });
66
-
67
- // ToDo: see css for comment about avatar under selector .spectrum-Card--noLayout.spectrum-Card--default
68
- let hasPreviewImage = useHasChild(`.${styles['spectrum-Card-image']}`, gridRef);
69
- let hasPreviewIllustration = useHasChild(`.${styles['spectrum-Card-illustration']}`, gridRef);
70
- let hasPreview = hasPreviewImage || hasPreviewIllustration;
71
-
72
- // this is for horizontal cards
73
- let [height, setHeight] = useState(NaN);
74
- let updateHeight = useCallback(() => {
75
- if (orientation !== 'horizontal') {
76
- return;
77
- }
78
-
79
- let cardHeight = gridRef.current.getBoundingClientRect().height;
80
- setHeight(cardHeight);
81
- }, [orientation, gridRef, setHeight]);
82
- useResizeObserver({ref: gridRef, onResize: updateHeight});
83
-
84
- let aspectRatioEnforce = undefined;
85
- if (orientation === 'horizontal' && !isNaN(height)) {
86
- aspectRatioEnforce = {
87
- height: `${height}px`,
88
- width: `${height}px`
89
- };
90
- }
91
-
92
- let slots = useMemo(() => ({
93
- image: {UNSAFE_className: classNames(styles, 'spectrum-Card-image'), objectFit: orientation === 'horizontal' ? 'cover' : 'contain', alt: '', ...aspectRatioEnforce},
94
- illustration: {UNSAFE_className: classNames(styles, 'spectrum-Card-illustration'), ...aspectRatioEnforce},
95
- avatar: {UNSAFE_className: classNames(styles, 'spectrum-Card-avatar'), size: 'avatar-size-400'},
96
- heading: {UNSAFE_className: classNames(styles, 'spectrum-Card-heading'), ...titleProps},
97
- content: {UNSAFE_className: classNames(styles, 'spectrum-Card-content'), ...contentProps},
98
- detail: {UNSAFE_className: classNames(styles, 'spectrum-Card-detail')}
99
- // eslint-disable-next-line react-hooks/exhaustive-deps
100
- }), [titleProps, contentProps, height, isQuiet, orientation]);
101
-
102
- useLayoutEffect(() => {
103
- if (gridRef?.current) {
104
- let walker = getFocusableTreeWalker(gridRef.current);
105
- let nextNode = walker.nextNode();
106
- while (nextNode != null) {
107
- if (checkboxRef.current && !nodeContains(checkboxRef.current.UNSAFE_getDOMNode(), nextNode)) {
108
- console.warn('Card does not support focusable elements, please contact the team regarding your use case.');
109
- break;
110
- }
111
- nextNode = walker.nextNode();
112
- }
113
- }
114
- }, [children]);
115
-
116
- return (
117
- <FocusRing focusRingClass={classNames(styles, 'focus-ring')}>
118
- <div
119
- {...styleProps}
120
- {...mergeProps(cardProps, focusWithinProps, hoverProps, filterDOMProps(props), articleProps)}
121
- ref={domRef}
122
- className={classNames(styles, 'spectrum-Card', {
123
- 'spectrum-Card--default': !isQuiet && orientation !== 'horizontal',
124
- 'spectrum-Card--isQuiet': isQuiet && orientation !== 'horizontal',
125
- 'spectrum-Card--horizontal': orientation === 'horizontal',
126
- 'spectrum-Card--noPreview': !hasPreview,
127
- 'is-hovered': isHovered,
128
- 'is-focused': isFocused,
129
- 'is-selected': isSelected,
130
- 'spectrum-Card--waterfall': layout === 'waterfall',
131
- 'spectrum-Card--gallery': layout === 'gallery',
132
- 'spectrum-Card--grid': layout === 'grid',
133
- 'spectrum-Card--noLayout': layout !== 'waterfall' && layout !== 'gallery' && layout !== 'grid'
134
- }, styleProps.className)}>
135
- <div ref={gridRef} className={classNames(styles, 'spectrum-Card-grid')}>
136
- {manager && manager.selectionMode !== 'none' && (
137
- <div className={classNames(styles, 'spectrum-Card-checkboxWrapper')}>
138
- <Checkbox
139
- ref={checkboxRef}
140
- isDisabled={isDisabled}
141
- excludeFromTabOrder
142
- isSelected={isSelected}
143
- onChange={onChange}
144
- UNSAFE_className={classNames(styles, 'spectrum-Card-checkbox')}
145
- isEmphasized
146
- aria-label="select" />
147
- </div>
148
- )}
149
- <SlotProvider slots={slots}>
150
- {children}
151
- </SlotProvider>
152
- <div className={classNames(styles, 'spectrum-Card-decoration')} />
153
- </div>
154
- </div>
155
- </FocusRing>
156
- );
157
- });
158
-
159
- interface AriaCardOptions extends AriaCardProps {
160
- }
161
-
162
- interface CardAria {
163
- cardProps: HTMLAttributes<HTMLDivElement>,
164
- titleProps: HTMLAttributes<HTMLDivElement>,
165
- contentProps: HTMLAttributes<HTMLDivElement>
166
- }
167
-
168
- function useCard(props: AriaCardOptions): CardAria {
169
- let titleId = useSlotId();
170
- let descriptionId = useSlotId();
171
- let titleProps = useMemo(() => ({
172
- id: titleId
173
- }), [titleId]);
174
- let contentProps = useMemo(() => ({
175
- id: descriptionId
176
- }), [descriptionId]);
177
-
178
- return {
179
- cardProps: {
180
- ...filterDOMProps(props),
181
- 'aria-labelledby': titleId,
182
- 'aria-describedby': descriptionId,
183
- tabIndex: 0
184
- },
185
- titleProps,
186
- contentProps
187
- };
188
- }
package/src/CardView.tsx DELETED
@@ -1,250 +0,0 @@
1
- // @ts-nocheck
2
- /*
3
- * Copyright 2021 Adobe. All rights reserved.
4
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License. You may obtain a copy
6
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software distributed under
9
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- * OF ANY KIND, either express or implied. See the License for the specific language
11
- * governing permissions and limitations under the License.
12
- */
13
-
14
- import {CardBase} from './CardBase';
15
- import {CardViewContext, useCardViewContext} from './CardViewContext';
16
- import {classNames, useDOMRef, useStyleProps, useUnwrapDOMRef} from '@react-spectrum/utils';
17
- import {DOMRef, DOMRefValue, Node} from '@react-types/shared';
18
- import {GridCollection, useGridState} from '@react-stately/grid';
19
- // @ts-ignore
20
- import intlMessages from '../intl/*.json';
21
- import {mergeProps} from '@react-aria/utils';
22
- import {ProgressCircle} from '@react-spectrum/progress';
23
- import React, {ReactElement, ReactNode, useCallback, useMemo, useRef} from 'react';
24
- import {ReusableView} from '@react-stately/virtualizer';
25
- import {SpectrumCardViewProps} from '@react-types/card';
26
- import styles from '@adobe/spectrum-css-temp/components/card/vars.css';
27
- import {useCollator, useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';
28
- import {useGrid, useGridCell, useGridRow} from '@react-aria/grid';
29
- import {useListState} from '@react-stately/list';
30
- import {useProvider} from '@react-spectrum/provider';
31
- import {Virtualizer, VirtualizerItem} from '@react-aria/virtualizer';
32
-
33
- /**
34
- * TODO: Add description of component here.
35
- */
36
- export const CardView = React.forwardRef(function CardView<T extends object>(props: SpectrumCardViewProps<T>, ref: DOMRef<HTMLDivElement>) {
37
- let {scale} = useProvider();
38
- let {styleProps} = useStyleProps(props);
39
- let domRef = useDOMRef(ref);
40
- let {
41
- isQuiet,
42
- renderEmptyState,
43
- layout,
44
- loadingState,
45
- onLoadMore,
46
- cardOrientation = 'vertical'
47
- } = props;
48
-
49
- let collator = useCollator({usage: 'search', sensitivity: 'base'});
50
- let isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
51
- let cardViewLayout = useMemo(() => typeof layout === 'function' ? new layout({collator, cardOrientation, scale}) : layout, [layout, collator, cardOrientation, scale]);
52
- let layoutType = cardViewLayout.layoutType;
53
-
54
- let {direction} = useLocale();
55
- let {collection} = useListState(props);
56
-
57
- let gridCollection = useMemo(() => new GridCollection<T>({
58
- columnCount: 1,
59
- items: [...collection].map(item => ({
60
- // Makes the Grid row use the keys the user provides to the cards so that selection change via interactions returns the card keys
61
- ...item,
62
- hasChildNodes: true,
63
- childNodes: [{
64
- key: `cell-${item.key}`,
65
- type: 'cell',
66
- value: null,
67
- level: 0,
68
- rendered: null,
69
- textValue: item.textValue,
70
- hasChildNodes: false,
71
- childNodes: []
72
- }]
73
- }))
74
- }), [collection]);
75
-
76
- let state = useGridState({
77
- ...props,
78
- selectionMode: cardOrientation === 'horizontal' && layoutType === 'grid' ? 'none' : props.selectionMode,
79
- collection: gridCollection,
80
- focusMode: 'cell'
81
- });
82
-
83
- cardViewLayout.collection = gridCollection;
84
- cardViewLayout.disabledKeys = state.disabledKeys;
85
-
86
- let {gridProps} = useGrid({
87
- ...props,
88
- isVirtualized: true,
89
- keyboardDelegate: cardViewLayout
90
- }, state, domRef);
91
-
92
- type View = ReusableView<Node<T>, ReactNode>;
93
- let renderWrapper = useCallback((parent: View, reusableView: View) => (
94
- <VirtualizerItem
95
- key={reusableView.key}
96
- layoutInfo={reusableView.layoutInfo}
97
- virtualizer={reusableView.virtualizer}
98
- parent={parent?.layoutInfo}>
99
- {reusableView.rendered}
100
- </VirtualizerItem>
101
- ), []);
102
-
103
- let focusedKey = state.selectionManager.focusedKey;
104
- let focusedItem = gridCollection.getItem(state.selectionManager.focusedKey);
105
- if (focusedItem?.parentKey != null) {
106
- focusedKey = focusedItem.parentKey;
107
- }
108
-
109
- let persistedKeys = useMemo(() => focusedKey != null ? new Set([focusedKey]) : null, [focusedKey]);
110
-
111
- // TODO: does aria-row count and aria-col count need to be modified? Perhaps aria-col count needs to be omitted
112
- return (
113
- <CardViewContext.Provider value={{state, isQuiet, layout: cardViewLayout, cardOrientation, renderEmptyState}}>
114
- <Virtualizer
115
- {...gridProps}
116
- {...styleProps}
117
- className={classNames(styles, 'spectrum-CardView')}
118
- ref={domRef}
119
- persistedKeys={persistedKeys}
120
- scrollDirection="vertical"
121
- layout={cardViewLayout}
122
- collection={gridCollection}
123
- isLoading={isLoading}
124
- onLoadMore={onLoadMore}
125
- layoutOptions={useMemo(() => ({isLoading, direction}), [isLoading, direction])}
126
- renderWrapper={renderWrapper}
127
- style={{
128
- ...styleProps.style,
129
- scrollPaddingTop: cardViewLayout.margin || 0
130
- }}>
131
- {useCallback((type, item) => {
132
- if (type === 'item') {
133
- return (
134
- <InternalCard item={item} />
135
- );
136
- } else if (type === 'loader') {
137
- return <LoadingState />;
138
- } else if (type === 'placeholder') {
139
- return <EmptyState />;
140
- }
141
- }, [])}
142
- </Virtualizer>
143
- </CardViewContext.Provider>
144
-
145
- );
146
- }) as <T>(props: SpectrumCardViewProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
147
-
148
- function LoadingState() {
149
- let {state} = useCardViewContext();
150
- let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/card');
151
- return (
152
- <CenteredWrapper>
153
- <ProgressCircle
154
- isIndeterminate
155
- aria-label={state.collection.size > 0 ? stringFormatter.format('loadingMore') : stringFormatter.format('loading')} />
156
- </CenteredWrapper>
157
- );
158
- }
159
-
160
- function EmptyState() {
161
- let {renderEmptyState} = useCardViewContext();
162
- let emptyState = renderEmptyState ? renderEmptyState() : null;
163
- if (emptyState == null) {
164
- return null;
165
- }
166
-
167
- return (
168
- <CenteredWrapper>
169
- {emptyState}
170
- </CenteredWrapper>
171
- );
172
- }
173
-
174
- function CenteredWrapper({children}) {
175
- let {state} = useCardViewContext();
176
- return (
177
- <div
178
- role="row"
179
- aria-rowindex={state.collection.size + 1}
180
- className={classNames(styles, 'spectrum-CardView-centeredWrapper')}>
181
- <div role="gridcell">
182
- {children}
183
- </div>
184
- </div>
185
- );
186
- }
187
-
188
- function InternalCard(props) {
189
- let {
190
- item
191
- } = props;
192
- let cellNode = [...item.childNodes][0];
193
- let {state, cardOrientation, isQuiet, layout} = useCardViewContext();
194
-
195
- let layoutType = layout.layoutType;
196
- let rowRef = useRef(undefined);
197
- let cellRef = useRef<DOMRefValue<HTMLDivElement>>(undefined);
198
- let unwrappedRef = useUnwrapDOMRef(cellRef);
199
-
200
- let {rowProps: gridRowProps} = useGridRow({
201
- node: item,
202
- isVirtualized: true
203
- }, state, rowRef);
204
-
205
- let {gridCellProps} = useGridCell({
206
- node: cellNode,
207
- focusMode: 'cell'
208
- }, state, unwrappedRef);
209
-
210
- // Prevent space key from scrolling the CardView if triggered on a disabled item or on a Card in a selectionMode="none" CardView.
211
- let allowsInteraction = state.selectionManager.selectionMode !== 'none';
212
- let isDisabled = !allowsInteraction || state.disabledKeys.has(item.key);
213
-
214
- let onKeyDown = (e) => {
215
- if (e.key === ' ' && isDisabled) {
216
- e.preventDefault();
217
- }
218
- };
219
-
220
- let rowProps = mergeProps(
221
- gridRowProps,
222
- {onKeyDown}
223
- );
224
-
225
- if (layoutType === 'grid' || layoutType === 'gallery') {
226
- isQuiet = true;
227
- }
228
-
229
- if (layoutType !== 'grid') {
230
- cardOrientation = 'vertical';
231
- }
232
-
233
- // We don't want to focus the checkbox (or any other focusable elements) within the Card
234
- // when pressing the arrow keys so we delete the key down handler here. Arrow key navigation between
235
- // the cards in the CardView is handled by useGrid => useSelectableCollection instead.
236
- delete gridCellProps.onKeyDownCapture;
237
- return (
238
- <div {...rowProps} ref={rowRef} className={classNames(styles, 'spectrum-CardView-row')}>
239
- <CardBase
240
- ref={cellRef}
241
- articleProps={gridCellProps}
242
- isQuiet={isQuiet}
243
- orientation={cardOrientation}
244
- item={item}
245
- layout={layoutType}>
246
- {item.rendered}
247
- </CardBase>
248
- </div>
249
- );
250
- }
@@ -1,27 +0,0 @@
1
- // @ts-nocheck
2
- /*
3
- * Copyright 2020 Adobe. All rights reserved.
4
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License. You may obtain a copy
6
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
7
- *
8
- * Unless required by applicable law or agreed to in writing, software distributed under
9
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10
- * OF ANY KIND, either express or implied. See the License for the specific language
11
- * governing permissions and limitations under the License.
12
- */
13
-
14
- import React, {useContext} from 'react';
15
-
16
- export interface CardViewContextValue {
17
- state: 'idle' | 'loading' | 'error',
18
- isQuiet: boolean,
19
- layout: 'grid' | 'gallery' | 'waterfall',
20
- cardOrientation: 'horizontal' | 'vertical',
21
- renderEmptyState: () => React.ReactNode
22
- }
23
- export const CardViewContext = React.createContext<CardViewContextValue>(null);
24
-
25
- export function useCardViewContext(): CardViewContextValue | null {
26
- return useContext(CardViewContext);
27
- }