@react-spectrum/table 3.0.0-beta.1 → 3.0.0-nightly-641446f65-240905

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 (266) hide show
  1. package/dist/DragPreview.main.js +54 -0
  2. package/dist/DragPreview.main.js.map +1 -0
  3. package/dist/DragPreview.mjs +49 -0
  4. package/dist/DragPreview.module.js +49 -0
  5. package/dist/DragPreview.module.js.map +1 -0
  6. package/dist/InsertionIndicator.main.js +63 -0
  7. package/dist/InsertionIndicator.main.js.map +1 -0
  8. package/dist/InsertionIndicator.mjs +58 -0
  9. package/dist/InsertionIndicator.module.js +58 -0
  10. package/dist/InsertionIndicator.module.js.map +1 -0
  11. package/dist/Nubbin.main.js +62 -0
  12. package/dist/Nubbin.main.js.map +1 -0
  13. package/dist/Nubbin.mjs +53 -0
  14. package/dist/Nubbin.module.js +53 -0
  15. package/dist/Nubbin.module.js.map +1 -0
  16. package/dist/Resizer.main.js +150 -0
  17. package/dist/Resizer.main.js.map +1 -0
  18. package/dist/Resizer.mjs +144 -0
  19. package/dist/Resizer.module.js +144 -0
  20. package/dist/Resizer.module.js.map +1 -0
  21. package/dist/RootDropIndicator.main.js +57 -0
  22. package/dist/RootDropIndicator.main.js.map +1 -0
  23. package/dist/RootDropIndicator.mjs +48 -0
  24. package/dist/RootDropIndicator.module.js +48 -0
  25. package/dist/RootDropIndicator.module.js.map +1 -0
  26. package/dist/TableView.main.js +50 -0
  27. package/dist/TableView.main.js.map +1 -0
  28. package/dist/TableView.mjs +41 -0
  29. package/dist/TableView.module.js +41 -0
  30. package/dist/TableView.module.js.map +1 -0
  31. package/dist/TableViewBase.main.js +1238 -0
  32. package/dist/TableViewBase.main.js.map +1 -0
  33. package/dist/TableViewBase.mjs +1231 -0
  34. package/dist/TableViewBase.module.js +1231 -0
  35. package/dist/TableViewBase.module.js.map +1 -0
  36. package/dist/TableViewLayout.main.js +97 -0
  37. package/dist/TableViewLayout.main.js.map +1 -0
  38. package/dist/TableViewLayout.mjs +92 -0
  39. package/dist/TableViewLayout.module.js +92 -0
  40. package/dist/TableViewLayout.module.js.map +1 -0
  41. package/dist/TableViewWrapper.main.js +46 -0
  42. package/dist/TableViewWrapper.main.js.map +1 -0
  43. package/dist/TableViewWrapper.mjs +37 -0
  44. package/dist/TableViewWrapper.module.js +37 -0
  45. package/dist/TableViewWrapper.module.js.map +1 -0
  46. package/dist/TreeGridTableView.main.js +50 -0
  47. package/dist/TreeGridTableView.main.js.map +1 -0
  48. package/dist/TreeGridTableView.mjs +41 -0
  49. package/dist/TreeGridTableView.module.js +41 -0
  50. package/dist/TreeGridTableView.module.js.map +1 -0
  51. package/dist/ar-AE.main.js +14 -0
  52. package/dist/ar-AE.main.js.map +1 -0
  53. package/dist/ar-AE.mjs +16 -0
  54. package/dist/ar-AE.module.js +16 -0
  55. package/dist/ar-AE.module.js.map +1 -0
  56. package/dist/bg-BG.main.js +14 -0
  57. package/dist/bg-BG.main.js.map +1 -0
  58. package/dist/bg-BG.mjs +16 -0
  59. package/dist/bg-BG.module.js +16 -0
  60. package/dist/bg-BG.module.js.map +1 -0
  61. package/dist/cs-CZ.main.js +14 -0
  62. package/dist/cs-CZ.main.js.map +1 -0
  63. package/dist/cs-CZ.mjs +16 -0
  64. package/dist/cs-CZ.module.js +16 -0
  65. package/dist/cs-CZ.module.js.map +1 -0
  66. package/dist/da-DK.main.js +14 -0
  67. package/dist/da-DK.main.js.map +1 -0
  68. package/dist/da-DK.mjs +16 -0
  69. package/dist/da-DK.module.js +16 -0
  70. package/dist/da-DK.module.js.map +1 -0
  71. package/dist/de-DE.main.js +14 -0
  72. package/dist/de-DE.main.js.map +1 -0
  73. package/dist/de-DE.mjs +16 -0
  74. package/dist/de-DE.module.js +16 -0
  75. package/dist/de-DE.module.js.map +1 -0
  76. package/dist/el-GR.main.js +14 -0
  77. package/dist/el-GR.main.js.map +1 -0
  78. package/dist/el-GR.mjs +16 -0
  79. package/dist/el-GR.module.js +16 -0
  80. package/dist/el-GR.module.js.map +1 -0
  81. package/dist/en-US.main.js +14 -0
  82. package/dist/en-US.main.js.map +1 -0
  83. package/dist/en-US.mjs +16 -0
  84. package/dist/en-US.module.js +16 -0
  85. package/dist/en-US.module.js.map +1 -0
  86. package/dist/es-ES.main.js +14 -0
  87. package/dist/es-ES.main.js.map +1 -0
  88. package/dist/es-ES.mjs +16 -0
  89. package/dist/es-ES.module.js +16 -0
  90. package/dist/es-ES.module.js.map +1 -0
  91. package/dist/et-EE.main.js +14 -0
  92. package/dist/et-EE.main.js.map +1 -0
  93. package/dist/et-EE.mjs +16 -0
  94. package/dist/et-EE.module.js +16 -0
  95. package/dist/et-EE.module.js.map +1 -0
  96. package/dist/fi-FI.main.js +14 -0
  97. package/dist/fi-FI.main.js.map +1 -0
  98. package/dist/fi-FI.mjs +16 -0
  99. package/dist/fi-FI.module.js +16 -0
  100. package/dist/fi-FI.module.js.map +1 -0
  101. package/dist/fr-FR.main.js +14 -0
  102. package/dist/fr-FR.main.js.map +1 -0
  103. package/dist/fr-FR.mjs +16 -0
  104. package/dist/fr-FR.module.js +16 -0
  105. package/dist/fr-FR.module.js.map +1 -0
  106. package/dist/he-IL.main.js +14 -0
  107. package/dist/he-IL.main.js.map +1 -0
  108. package/dist/he-IL.mjs +16 -0
  109. package/dist/he-IL.module.js +16 -0
  110. package/dist/he-IL.module.js.map +1 -0
  111. package/dist/hr-HR.main.js +14 -0
  112. package/dist/hr-HR.main.js.map +1 -0
  113. package/dist/hr-HR.mjs +16 -0
  114. package/dist/hr-HR.module.js +16 -0
  115. package/dist/hr-HR.module.js.map +1 -0
  116. package/dist/hu-HU.main.js +14 -0
  117. package/dist/hu-HU.main.js.map +1 -0
  118. package/dist/hu-HU.mjs +16 -0
  119. package/dist/hu-HU.module.js +16 -0
  120. package/dist/hu-HU.module.js.map +1 -0
  121. package/dist/import.mjs +22 -0
  122. package/dist/intlStrings.main.js +108 -0
  123. package/dist/intlStrings.main.js.map +1 -0
  124. package/dist/intlStrings.mjs +110 -0
  125. package/dist/intlStrings.module.js +110 -0
  126. package/dist/intlStrings.module.js.map +1 -0
  127. package/dist/it-IT.main.js +14 -0
  128. package/dist/it-IT.main.js.map +1 -0
  129. package/dist/it-IT.mjs +16 -0
  130. package/dist/it-IT.module.js +16 -0
  131. package/dist/it-IT.module.js.map +1 -0
  132. package/dist/ja-JP.main.js +14 -0
  133. package/dist/ja-JP.main.js.map +1 -0
  134. package/dist/ja-JP.mjs +16 -0
  135. package/dist/ja-JP.module.js +16 -0
  136. package/dist/ja-JP.module.js.map +1 -0
  137. package/dist/ko-KR.main.js +14 -0
  138. package/dist/ko-KR.main.js.map +1 -0
  139. package/dist/ko-KR.mjs +16 -0
  140. package/dist/ko-KR.module.js +16 -0
  141. package/dist/ko-KR.module.js.map +1 -0
  142. package/dist/lt-LT.main.js +14 -0
  143. package/dist/lt-LT.main.js.map +1 -0
  144. package/dist/lt-LT.mjs +16 -0
  145. package/dist/lt-LT.module.js +16 -0
  146. package/dist/lt-LT.module.js.map +1 -0
  147. package/dist/lv-LV.main.js +14 -0
  148. package/dist/lv-LV.main.js.map +1 -0
  149. package/dist/lv-LV.mjs +16 -0
  150. package/dist/lv-LV.module.js +16 -0
  151. package/dist/lv-LV.module.js.map +1 -0
  152. package/dist/main.js +28 -884
  153. package/dist/main.js.map +1 -1
  154. package/dist/module.js +17 -792
  155. package/dist/module.js.map +1 -1
  156. package/dist/nb-NO.main.js +14 -0
  157. package/dist/nb-NO.main.js.map +1 -0
  158. package/dist/nb-NO.mjs +16 -0
  159. package/dist/nb-NO.module.js +16 -0
  160. package/dist/nb-NO.module.js.map +1 -0
  161. package/dist/nl-NL.main.js +14 -0
  162. package/dist/nl-NL.main.js.map +1 -0
  163. package/dist/nl-NL.mjs +16 -0
  164. package/dist/nl-NL.module.js +16 -0
  165. package/dist/nl-NL.module.js.map +1 -0
  166. package/dist/pl-PL.main.js +14 -0
  167. package/dist/pl-PL.main.js.map +1 -0
  168. package/dist/pl-PL.mjs +16 -0
  169. package/dist/pl-PL.module.js +16 -0
  170. package/dist/pl-PL.module.js.map +1 -0
  171. package/dist/pt-BR.main.js +14 -0
  172. package/dist/pt-BR.main.js.map +1 -0
  173. package/dist/pt-BR.mjs +16 -0
  174. package/dist/pt-BR.module.js +16 -0
  175. package/dist/pt-BR.module.js.map +1 -0
  176. package/dist/pt-PT.main.js +14 -0
  177. package/dist/pt-PT.main.js.map +1 -0
  178. package/dist/pt-PT.mjs +16 -0
  179. package/dist/pt-PT.module.js +16 -0
  180. package/dist/pt-PT.module.js.map +1 -0
  181. package/dist/ro-RO.main.js +14 -0
  182. package/dist/ro-RO.main.js.map +1 -0
  183. package/dist/ro-RO.mjs +16 -0
  184. package/dist/ro-RO.module.js +16 -0
  185. package/dist/ro-RO.module.js.map +1 -0
  186. package/dist/ru-RU.main.js +14 -0
  187. package/dist/ru-RU.main.js.map +1 -0
  188. package/dist/ru-RU.mjs +16 -0
  189. package/dist/ru-RU.module.js +16 -0
  190. package/dist/ru-RU.module.js.map +1 -0
  191. package/dist/sk-SK.main.js +14 -0
  192. package/dist/sk-SK.main.js.map +1 -0
  193. package/dist/sk-SK.mjs +16 -0
  194. package/dist/sk-SK.module.js +16 -0
  195. package/dist/sk-SK.module.js.map +1 -0
  196. package/dist/sl-SI.main.js +14 -0
  197. package/dist/sl-SI.main.js.map +1 -0
  198. package/dist/sl-SI.mjs +16 -0
  199. package/dist/sl-SI.module.js +16 -0
  200. package/dist/sl-SI.module.js.map +1 -0
  201. package/dist/sr-SP.main.js +14 -0
  202. package/dist/sr-SP.main.js.map +1 -0
  203. package/dist/sr-SP.mjs +16 -0
  204. package/dist/sr-SP.module.js +16 -0
  205. package/dist/sr-SP.module.js.map +1 -0
  206. package/dist/sv-SE.main.js +14 -0
  207. package/dist/sv-SE.main.js.map +1 -0
  208. package/dist/sv-SE.mjs +16 -0
  209. package/dist/sv-SE.module.js +16 -0
  210. package/dist/sv-SE.module.js.map +1 -0
  211. package/dist/table.b13eee90.css +220 -0
  212. package/dist/table.b13eee90.css.map +1 -0
  213. package/dist/table_css.main.js +74 -0
  214. package/dist/table_css.main.js.map +1 -0
  215. package/dist/table_css.mjs +76 -0
  216. package/dist/table_css.module.js +76 -0
  217. package/dist/table_css.module.js.map +1 -0
  218. package/dist/table_vars_css.main.js +197 -0
  219. package/dist/table_vars_css.main.js.map +1 -0
  220. package/dist/table_vars_css.mjs +199 -0
  221. package/dist/table_vars_css.module.js +199 -0
  222. package/dist/table_vars_css.module.js.map +1 -0
  223. package/dist/tr-TR.main.js +14 -0
  224. package/dist/tr-TR.main.js.map +1 -0
  225. package/dist/tr-TR.mjs +16 -0
  226. package/dist/tr-TR.module.js +16 -0
  227. package/dist/tr-TR.module.js.map +1 -0
  228. package/dist/types.d.ts +77 -4
  229. package/dist/types.d.ts.map +1 -1
  230. package/dist/uk-UA.main.js +14 -0
  231. package/dist/uk-UA.main.js.map +1 -0
  232. package/dist/uk-UA.mjs +16 -0
  233. package/dist/uk-UA.module.js +16 -0
  234. package/dist/uk-UA.module.js.map +1 -0
  235. package/dist/vars.ce47d5ba.css +992 -0
  236. package/dist/vars.ce47d5ba.css.map +1 -0
  237. package/dist/zh-CN.main.js +14 -0
  238. package/dist/zh-CN.main.js.map +1 -0
  239. package/dist/zh-CN.mjs +16 -0
  240. package/dist/zh-CN.module.js +16 -0
  241. package/dist/zh-CN.module.js.map +1 -0
  242. package/dist/zh-TW.main.js +14 -0
  243. package/dist/zh-TW.main.js.map +1 -0
  244. package/dist/zh-TW.mjs +16 -0
  245. package/dist/zh-TW.module.js +16 -0
  246. package/dist/zh-TW.module.js.map +1 -0
  247. package/package.json +40 -28
  248. package/src/DragPreview.tsx +77 -0
  249. package/src/InsertionIndicator.tsx +62 -0
  250. package/src/Nubbin.tsx +28 -0
  251. package/src/Resizer.tsx +139 -0
  252. package/src/RootDropIndicator.tsx +40 -0
  253. package/src/TableView.tsx +24 -630
  254. package/src/TableViewBase.tsx +1552 -0
  255. package/src/TableViewLayout.ts +95 -0
  256. package/src/TableViewWrapper.tsx +106 -0
  257. package/src/TreeGridTableView.tsx +47 -0
  258. package/src/cursors/Cur_MoveHorizontal_9_9.svg +10 -0
  259. package/src/cursors/Cur_MoveToLeft_9_9.svg +10 -0
  260. package/src/cursors/Cur_MoveToRight_9_9.svg +10 -0
  261. package/src/index.ts +5 -1
  262. package/src/table.css +191 -0
  263. package/LICENSE +0 -201
  264. package/dist/main.css +0 -2
  265. package/dist/main.css.map +0 -1
  266. package/src/.DS_Store +0 -0
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright 2024 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
+ import {DropTarget} from '@react-types/shared';
13
+ import {GridNode} from '@react-types/grid';
14
+ import {LayoutInfo, Rect} from '@react-stately/virtualizer';
15
+ import {LayoutNode, TableLayout} from '@react-stately/layout';
16
+
17
+ export class TableViewLayout<T> extends TableLayout<T> {
18
+ private isLoading: boolean = false;
19
+
20
+ protected buildCollection(): LayoutNode[] {
21
+ let loadingState = this.collection.body.props.loadingState;
22
+ this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
23
+ return super.buildCollection();
24
+ }
25
+
26
+ protected buildColumn(node: GridNode<T>, x: number, y: number): LayoutNode {
27
+ let res = super.buildColumn(node, x, y);
28
+ res.layoutInfo.allowOverflow = true; // for resizer nubbin
29
+ return res;
30
+ }
31
+
32
+ protected buildBody(): LayoutNode {
33
+ let node = super.buildBody(0);
34
+ let {children, layoutInfo} = node;
35
+ let width = node.layoutInfo.rect.width;
36
+
37
+ if (this.isLoading) {
38
+ // Add some margin around the loader to ensure that scrollbars don't flicker in and out.
39
+ let rect = new Rect(40, children.length === 0 ? 40 : layoutInfo.rect.maxY, (width || this.virtualizer.visibleRect.width) - 80, children.length === 0 ? this.virtualizer.visibleRect.height - 80 : 60);
40
+ let loader = new LayoutInfo('loader', 'loader', rect);
41
+ loader.parentKey = layoutInfo.key;
42
+ loader.isSticky = children.length === 0;
43
+ let node = {
44
+ layoutInfo: loader,
45
+ validRect: loader.rect
46
+ };
47
+ children.push(node);
48
+ this.layoutNodes.set(loader.key, node);
49
+ layoutInfo.rect.height = loader.rect.maxY;
50
+ width = Math.max(width, rect.width);
51
+ } else if (children.length === 0) {
52
+ let rect = new Rect(40, 40, this.virtualizer.visibleRect.width - 80, this.virtualizer.visibleRect.height - 80);
53
+ let empty = new LayoutInfo('empty', 'empty', rect);
54
+ empty.parentKey = layoutInfo.key;
55
+ empty.isSticky = true;
56
+ let node = {
57
+ layoutInfo: empty,
58
+ validRect: empty.rect
59
+ };
60
+ children.push(node);
61
+ layoutInfo.rect.height = empty.rect.maxY;
62
+ width = Math.max(width, rect.width);
63
+ }
64
+
65
+ return node;
66
+ }
67
+
68
+ protected buildRow(node: GridNode<T>, x: number, y: number): LayoutNode {
69
+ let res = super.buildRow(node, x, y);
70
+ res.layoutInfo.rect.height += 1; // for bottom border
71
+ return res;
72
+ }
73
+
74
+ protected buildCell(node: GridNode<T>, x: number, y: number): LayoutNode {
75
+ let res = super.buildCell(node, x, y);
76
+ if (node.column?.props.hideHeader) {
77
+ res.layoutInfo.allowOverflow = true;
78
+ }
79
+ return res;
80
+ }
81
+
82
+ protected getEstimatedRowHeight(): number {
83
+ return super.getEstimatedRowHeight() + 1; // for bottom border
84
+ }
85
+
86
+ protected isStickyColumn(node: GridNode<T>) {
87
+ return node.props?.isDragButtonCell || node.props?.isSelectionCell;
88
+ }
89
+
90
+ getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {
91
+ // Offset for height of header row
92
+ y -= this.virtualizer.layout.getVisibleLayoutInfos(new Rect(x, y, 1, 1)).find(info => info.type === 'headerrow')?.rect.height;
93
+ return super.getDropTargetFromPoint(x, y, isValidDropTarget);
94
+ }
95
+ }
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Copyright 2023 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 type {AriaLabelingProps, DisabledBehavior, DOMProps, DOMRef, Key, SpectrumSelectionProps, StyleProps} from '@react-types/shared';
14
+ import type {ColumnSize, TableProps} from '@react-types/table';
15
+ import type {DragAndDropHooks} from '@react-spectrum/dnd';
16
+ import React, {JSX, ReactElement} from 'react';
17
+ import {tableNestedRows} from '@react-stately/flags';
18
+ import {TableView} from './TableView';
19
+ import {TreeGridTableView} from './TreeGridTableView';
20
+
21
+ export interface SpectrumTableProps<T> extends TableProps<T>, SpectrumSelectionProps, DOMProps, AriaLabelingProps, StyleProps {
22
+ /**
23
+ * Sets the amount of vertical padding within each cell.
24
+ * @default 'regular'
25
+ */
26
+ density?: 'compact' | 'regular' | 'spacious',
27
+ /**
28
+ * Sets the overflow behavior for the cell contents.
29
+ * @default 'truncate'
30
+ */
31
+ overflowMode?: 'wrap' | 'truncate',
32
+ /** Whether the TableView should be displayed with a quiet style. */
33
+ isQuiet?: boolean,
34
+ /** Sets what the TableView should render when there is no content to display. */
35
+ renderEmptyState?: () => JSX.Element,
36
+ /**
37
+ * Whether `disabledKeys` applies to all interactions, or only selection.
38
+ * @default "selection"
39
+ */
40
+ disabledBehavior?: DisabledBehavior,
41
+ /** Handler that is called when a user performs an action on a row. */
42
+ onAction?: (key: Key) => void,
43
+ /**
44
+ * Handler that is called when a user starts a column resize.
45
+ */
46
+ onResizeStart?: (widths: Map<Key, ColumnSize>) => void,
47
+ /**
48
+ * Handler that is called when a user performs a column resize.
49
+ * Can be used with the width property on columns to put the column widths into
50
+ * a controlled state.
51
+ */
52
+ onResize?: (widths: Map<Key, ColumnSize>) => void,
53
+ /**
54
+ * Handler that is called after a user performs a column resize.
55
+ * Can be used to store the widths of columns for another future session.
56
+ */
57
+ onResizeEnd?: (widths: Map<Key, ColumnSize>) => void,
58
+ /**
59
+ * The drag and drop hooks returned by `useDragAndDrop` used to enable drag and drop behavior for the TableView.
60
+ * @version beta
61
+ */
62
+ dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks'],
63
+ /**
64
+ * Whether the TableView should support expandable rows. Requires the feature flag to be enabled first, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
65
+ * @version alpha
66
+ * @private
67
+ */
68
+ UNSTABLE_allowsExpandableRows?: boolean,
69
+ /**
70
+ * The currently expanded keys in the collection (controlled). Requires the feature flag to be
71
+ * enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
72
+ * @version alpha
73
+ * @private
74
+ */
75
+ UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,
76
+ /**
77
+ * The initial expanded keys in the collection (uncontrolled). Requires the feature flag to be
78
+ * enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
79
+ * @version alpha
80
+ * @private
81
+ */
82
+ UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,
83
+ /**
84
+ * Handler that is called when items are expanded or collapsed. Requires the feature flag to be
85
+ * enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
86
+ * @version alpha
87
+ * @private
88
+ */
89
+ UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any
90
+ }
91
+
92
+ function TableViewWrapper<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<HTMLDivElement>) {
93
+ let {UNSTABLE_allowsExpandableRows, ...otherProps} = props;
94
+ if (tableNestedRows() && UNSTABLE_allowsExpandableRows) {
95
+ return <TreeGridTableView {...otherProps} ref={ref} />;
96
+ } else {
97
+ return <TableView {...otherProps} ref={ref} />;
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Tables are containers for displaying information. They allow users to quickly scan, sort, compare, and take action on large amounts of data.
103
+ */
104
+ const _TableViewWrapper = React.forwardRef(TableViewWrapper) as <T>(props: SpectrumTableProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
105
+
106
+ export {_TableViewWrapper as TableView};
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright 2023 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 React, {ReactElement, useState} from 'react';
15
+ import {SpectrumTableProps} from './TableViewWrapper';
16
+ import {TableViewBase} from './TableViewBase';
17
+ import {UNSTABLE_useTreeGridState} from '@react-stately/table';
18
+
19
+ export interface TreeGridTableProps<T> extends Omit<SpectrumTableProps<T>, 'UNSTABLE_allowsExpandableRows'> {}
20
+
21
+ function TreeGridTableView<T extends object>(props: TreeGridTableProps<T>, ref: DOMRef<HTMLDivElement>) {
22
+ let {
23
+ selectionStyle,
24
+ dragAndDropHooks
25
+ } = props;
26
+ let [showSelectionCheckboxes, setShowSelectionCheckboxes] = useState(selectionStyle !== 'highlight');
27
+ let isTableDraggable = !!dragAndDropHooks?.useDraggableCollectionState;
28
+ let state = UNSTABLE_useTreeGridState({
29
+ ...props,
30
+ showSelectionCheckboxes,
31
+ showDragButtons: isTableDraggable,
32
+ selectionBehavior: props.selectionStyle === 'highlight' ? 'replace' : 'toggle'
33
+ });
34
+
35
+ // If the selection behavior changes in state, we need to update showSelectionCheckboxes here due to the circular dependency...
36
+ let shouldShowCheckboxes = state.selectionManager.selectionBehavior !== 'replace';
37
+ if (shouldShowCheckboxes !== showSelectionCheckboxes) {
38
+ setShowSelectionCheckboxes(shouldShowCheckboxes);
39
+ }
40
+
41
+ return (
42
+ <TableViewBase {...props} state={state} ref={ref} />
43
+ );
44
+ }
45
+
46
+ const _TreeGridTableView = React.forwardRef(TreeGridTableView) as <T>(props: TreeGridTableProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
47
+ export {_TreeGridTableView as TreeGridTableView};
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="-1 0 31 32">
3
+ <filter id="shadow">
4
+ <feDropShadow dx="0" dy="0.5" stdDeviation="1.2" flood-opacity="0.7"/>
5
+ </filter>
6
+ <g filter="url(#shadow)" transform="translate(.5 0)">
7
+ <path fill="#fff" d="M9.5,2a.5.5,0,0,1,.5.5V9h3V7.2505A.25014.25014,0,0,1,13.24978,7h.00152a.246.246,0,0,1,.15875.05847L16,9.5l-2.58995,2.44153A.24611.24611,0,0,1,13.2513,12,.25016.25016,0,0,1,13,11.751V10H10v6.5a.5.5,0,0,1-.5.5h-1a.5.5,0,0,1-.5-.5V10H5v1.7495A.25014.25014,0,0,1,4.75022,12H4.7487A.246.246,0,0,1,4.59,11.94153L2,9.5,4.59,7.05847A.246.246,0,0,1,4.7487,7,.25016.25016,0,0,1,5,7.249V9H8V2.5A.5.5,0,0,1,8.5,2Zm0-1h-1A1.5,1.5,0,0,0,7,2.5V8H6V7.32389a1.33,1.33,0,0,0-.4816-1.05444,1.23962,1.23962,0,0,0-1.56876.021l-.02344.01953-.0222.02088L.92812,9.13618A.5.5,0,0,0,.90726,9.843l.02086.02085L3.904,12.66919l.02221.02088.02345.01965a1.23986,1.23986,0,0,0,1.56836.02116A1.3294,1.3294,0,0,0,6,11.6765V11H7v5.5A1.5,1.5,0,0,0,8.5,18h1A1.5,1.5,0,0,0,11,16.5V11h1v.67757a1.32792,1.32792,0,0,0,.482,1.05347,1.24,1.24,0,0,0,1.56839-.02144l.02343-.01953.02221-.02088,2.97588-2.80537a.5.5,0,0,0,.02086-.70679l-.02086-.02085L14.096,6.33081l-.02221-.02087-.02345-.01965A1.24978,1.24978,0,0,0,12,7.2505V8H11V2.5A1.5,1.5,0,0,0,9.5,1Z"/>
8
+ <path d="M10,16.5V10h3v1.7495a.25.25,0,0,0,.41.19206L16,9.5,13.41,7.05842A.25.25,0,0,0,13,7.2505V9H10V2.5A.5.5,0,0,0,9.5,2h-1a.5.5,0,0,0-.5.5V9H5V7.2505a.25.25,0,0,0-.41-.19206L2,9.5l2.59,2.44158A.25.25,0,0,0,5,11.7495V10H8v6.5a.5.5,0,0,0,.5.5h1A.5.5,0,0,0,10,16.5Z"/>
9
+ </g>
10
+ </svg>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="-1 0 31 32">
3
+ <filter id="shadow">
4
+ <feDropShadow dx="0" dy="0.5" stdDeviation="1.2" flood-opacity="0.7"/>
5
+ </filter>
6
+ <g filter="url(#shadow)" transform="translate(.5 0)">
7
+ <path d="M9.5,2c.27614,0,.5,.22388,.5,.5v14c0,.27612-.22386,.5-.5,.5h-1c-.27614,0-.5-.22388-.5-.5v-6.5h-3v1.74951c0,.14893-.12215,.25049-.2513,.25049-.05457,0-.1104-.01819-.15875-.05847l-2.58995-2.44153,2.58995-2.44153c.04837-.04028,.10419-.05847,.15875-.05847,.12914,0,.2513,.10156,.2513,.25049v1.74951h3V2.5c0-.27612,.22386-.5,.5-.5h1Zm0-1h-1c-.82843,0-1.5,.67157-1.5,1.5v5.5h-1v-.67611c0-.40436-.1629-.80555-.48159-1.05444-.4961-.38744-1.14015-.33635-1.56876,.02095l-.02344,.01953-.0222,.02087L.92811,9.13618c-.20937,.19737-.20937,.53028,0,.72765l2.97589,2.80537,.0222,.02087,.02345,.01965c.42839,.35694,1.07208,.40833,1.56837,.02116,.31886-.24875,.48198-.64994,.48198-1.05435v-.67652s.99999,0,.99999,0v5.5c0,.82843,.67157,1.5,1.5,1.5h1c.82843,0,1.5-.67157,1.5-1.5V2.5c0-.82843-.67157-1.5-1.5-1.5Z" fill="#fff" />
8
+ <path d="M10,16.5V2.5c0-.27614-.22386-.5-.5-.5h-1c-.27614,0-.5,.22386-.5,.5v6.5h-3v-1.74952c0-.21196-.24721-.32775-.41005-.19206l-2.58995,2.44158,2.58995,2.44158c.16283,.13569,.41005,.0199,.41005-.19206v-1.74952h3v6.5c0,.27614,.22386,.5,.5,.5h1c.27614,0,.5-.22386,.5-.5Z"/>
9
+ </g>
10
+ </svg>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="-1 0 31 32">
3
+ <filter id="shadow">
4
+ <feDropShadow dx="0" dy="0.5" stdDeviation="1.2" flood-opacity="0.7"/>
5
+ </filter>
6
+ <g filter="url(#shadow)" transform="translate(.5 0)">
7
+ <path d="M9.5,2c.27614,0,.5,.22388,.5,.5v6.5h3v-1.74951c0-.14893,.12215-.25049,.2513-.25049,.05457,0,.1104,.01819,.15875,.05847l2.58995,2.44153-2.58995,2.44153c-.04837,.04028-.10419,.05847-.15875,.05847-.12914,0-.2513-.10156-.2513-.25049v-1.74951h-3v6.5c0,.27612-.22386,.5-.5,.5h-1c-.27614,0-.5-.22388-.5-.5V2.5c0-.27612,.22386-.5,.5-.5h1Zm0-1h-1c-.82843,0-1.5,.67157-1.5,1.5v14c0,.82843,.67157,1.5,1.5,1.5h1c.82843,0,1.5-.67157,1.5-1.5v-5.5h1v.67757c0,.40416,.1632,.80501,.48197,1.05347,.49639,.3869,1.14001,.33571,1.56838-.02144l.02344-.01953,.0222-.02087,2.97589-2.80537c.20937-.19737,.20937-.53028,0-.72765l-2.97589-2.80537-.0222-.02087-.02345-.01965c-.22456-.18713-.5083-.29028-.79895-.29028-.3208,0-.62624,.12134-.86003,.34167-.24872,.23438-.39136,.56567-.39136,.90881v.74951h-1V2.5c0-.82843-.67157-1.5-1.5-1.5Z" fill="#fff" />
8
+ <path d="M10,16.5v-6.5h3v1.74952c0,.21196,.24721,.32775,.41005,.19206l2.58995-2.44158-2.58995-2.44158c-.16283-.13569-.41005-.0199-.41005,.19206v1.74952h-3V2.5c0-.27614-.22386-.5-.5-.5h-1c-.27614,0-.5,.22386-.5,.5v14c0,.27614,.22386,.5,.5,.5h1c.27614,0,.5-.22386,.5-.5Z"/>
9
+ </g>
10
+ </svg>
package/src/index.ts CHANGED
@@ -12,8 +12,9 @@
12
12
 
13
13
  /// <reference types="css-module-types" />
14
14
 
15
- export * from './TableView';
15
+ export {TableView} from './TableViewWrapper';
16
16
  import {Column} from '@react-stately/table';
17
+ import {JSX} from 'react';
17
18
  import {SpectrumColumnProps} from '@react-types/table';
18
19
 
19
20
  // Override TS for Column to support spectrum specific props.
@@ -27,3 +28,6 @@ export {
27
28
  Row,
28
29
  Cell
29
30
  } from '@react-stately/table';
31
+
32
+ export type {SpectrumColumnProps, TableHeaderProps, TableBodyProps, RowProps, CellProps} from '@react-types/table';
33
+ export type {SpectrumTableProps} from './TableViewWrapper';
package/src/table.css CHANGED
@@ -10,6 +10,19 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ .react-spectrum-Table {
14
+ --spectrum-table-droptarget-background-color: var(--spectrum-alias-highlight-selected);
15
+ --spectrum-table-dropindicator-border-color: var(--spectrum-dropzone-border-color-selected-hover);
16
+ --spectrum-table-dropindicator-circle-border-color: var(--spectrum-dropindicator-circle-border-color);
17
+
18
+ --spectrum-table-dropindicator-circle-size: var(--spectrum-dropindicator-circle-size);
19
+ --spectrum-table-dropindicator-border-size: var(--spectrum-dropindicator-border-size);
20
+
21
+ --spectrum-table-dropzone-border-color-selected-hover: var(--spectrum-dropzone-border-color-selected-hover);
22
+
23
+ --spectrum-table-item-draghandle-border-color-key-focus: var(--spectrum-table-item-border-color-key-focus);
24
+ }
25
+
13
26
  .react-spectrum-Table {
14
27
  user-select: none;
15
28
  display: flex;
@@ -27,11 +40,18 @@
27
40
  height: 100%;
28
41
  }
29
42
 
43
+ .react-spectrum-Table-cell--alignStart {
44
+ text-align: start;
45
+ justify-content: flex-start;
46
+ }
47
+
30
48
  .react-spectrum-Table-cell--alignCenter {
49
+ text-align: center;
31
50
  justify-content: center;
32
51
  }
33
52
 
34
53
  .react-spectrum-Table-cell--alignEnd {
54
+ text-align: end;
35
55
  justify-content: flex-end;
36
56
  }
37
57
 
@@ -42,3 +62,174 @@
42
62
  width: 100%;
43
63
  height: 100%;
44
64
  }
65
+
66
+ .react-spectrum-Table-row-dragPreview {
67
+ --spectrum-table-row-badge-text-color: var(--spectrum-global-color-static-white);
68
+ --spectrum-table-row-badge-background-color: var(--spectrum-global-color-blue-400);
69
+
70
+ width: var(--spectrum-global-dimension-size-2400);
71
+ border: 1px solid var(--spectrum-dropzone-border-color-selected-hover);
72
+ border-radius: var(--spectrum-alias-border-radius-regular);
73
+ background-color: var(--spectrum-table-background-color);
74
+
75
+ /* forced-color-adjust: none, so that background-color style will render */
76
+ forced-color-adjust: none;
77
+
78
+ &::after {
79
+ box-shadow: none;
80
+ }
81
+
82
+ .react-spectrum-Table-cell {
83
+ overflow: hidden;
84
+ white-space: nowrap;
85
+ text-overflow: ellipsis;
86
+ }
87
+
88
+ &.react-spectrum-Table-row-dragPreview--multiple {
89
+ position: relative;
90
+
91
+ &:after {
92
+ content: '';
93
+ display: block;
94
+ position: absolute;
95
+ z-index: -1;
96
+ top: 4px;
97
+ inset-inline-start: 4px;
98
+ width: 100%;
99
+ height: 100%;
100
+ border: 1px solid var(--spectrum-dropzone-border-color-selected-hover);
101
+ border-radius: var(--spectrum-alias-border-radius-regular);
102
+ background-color: var(--spectrum-table-background-color);
103
+
104
+ /* forced-color-adjust: none, so that box-shadow style will render */
105
+ forced-color-adjust: none;
106
+ }
107
+ }
108
+
109
+ .react-spectrum-Table-row-badge {
110
+ color: var(--spectrum-table-row-badge-text-color);
111
+ background: var(--spectrum-table-row-badge-background-color);
112
+ padding: 0 var(--spectrum-global-dimension-size-100);
113
+ border-radius: var(--spectrum-alias-border-radius-regular);
114
+ margin-inline-end: var(--spectrum-global-dimension-size-100);
115
+ margin-top: auto;
116
+ margin-bottom: auto;
117
+ height: fit-content;
118
+ }
119
+ }
120
+
121
+ .react-spectrum-Table-body {
122
+ &.react-spectrum-Table-body--dropTarget {
123
+ border-color: var(--spectrum-table-dropindicator-border-color);
124
+ background-color: var(--spectrum-alias-highlight-selected);
125
+ box-shadow: inset 0 0 0 1px var(--spectrum-table-cell-border-color-key-focus);
126
+
127
+ /* forced-color-adjust: none, so that box-shadow style will render */
128
+ forced-color-adjust: none;
129
+ }
130
+ }
131
+
132
+ .react-spectrum-Table-InsertionIndicator {
133
+ z-index: 3;
134
+ width: calc(100% - (2 * var(--spectrum-table-dropindicator-circle-size)));
135
+ inset-inline-start: var(--spectrum-table-dropindicator-circle-size);
136
+ position: absolute;
137
+ outline: none;
138
+
139
+ &.react-spectrum-Table-InsertionIndicator--dropTarget {
140
+ background: var(--spectrum-table-dropindicator-border-color);
141
+ border-bottom: 2px solid var(--spectrum-table-dropindicator-border-color);
142
+
143
+ /* forced-color-adjust: none, so that background color
144
+ will render border for insertion indicator. */
145
+ forced-color-adjust: none;
146
+
147
+ &:before {
148
+ left: calc(var(--spectrum-table-dropindicator-circle-size) * -1);
149
+ }
150
+
151
+ &:after {
152
+ right: calc(var(--spectrum-table-dropindicator-circle-size) * -1);
153
+ }
154
+
155
+ &:before,
156
+ &:after {
157
+ content: '';
158
+ position: absolute;
159
+ top: calc(var(--spectrum-table-dropindicator-circle-size) * -1 / 2 + var(--spectrum-table-dropindicator-border-size) / 2);
160
+ width: var(--spectrum-table-dropindicator-circle-size);
161
+ height: var(--spectrum-table-dropindicator-circle-size);
162
+ border-radius: 50%;
163
+ border: var(--spectrum-table-dropindicator-border-size) solid;
164
+ box-sizing: border-box;
165
+ border-color: var(--spectrum-table-dropindicator-circle-border-color);
166
+ background-color: var(--spectrum-table-background-color);
167
+ z-index: 5;
168
+
169
+ /* forced-color-adjust: none, so that box-shadow and background-color styles will render */
170
+ forced-color-adjust: none;
171
+ }
172
+ }
173
+ }
174
+
175
+ .react-spectrum-Table-headCell {
176
+ &.react-spectrum-Table-dragButtonHeadCell {
177
+ padding: 0;
178
+ height: inherit;
179
+ }
180
+ }
181
+
182
+ .react-spectrum-Table-cell {
183
+ &.react-spectrum-Table-dragButtonCell {
184
+ padding: var(--spectrum-global-dimension-size-40);
185
+
186
+ .react-spectrum-Table-dragButton {
187
+ border-radius: var(--spectrum-alias-border-radius-regular);
188
+ padding: var(--spectrum-global-dimension-size-10);
189
+
190
+ &:focus-visible {
191
+ box-shadow: inset 0 0 0 2px var(--spectrum-table-cell-border-color-key-focus);
192
+ outline: none;
193
+
194
+ /* forced-color-adjust: none, so that box-shadow style will render */
195
+ forced-color-adjust: none;
196
+ }
197
+
198
+ svg {
199
+ margin: auto 0;
200
+ display: block;
201
+ padding: var(--spectrum-global-dimension-size-40);
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ .react-spectrum-Table-row {
208
+ &.react-spectrum-Table-row--dropTarget {
209
+ border: 1px var(--spectrum-table-dropindicator-border-color);
210
+ box-shadow: inset 2px 0 0 0 var(--spectrum-table-dropindicator-border-color),
211
+ inset -2px 0 0 0 var(--spectrum-table-dropindicator-border-color),
212
+ inset 0 -3px 0 0 var(--spectrum-table-dropindicator-border-color),
213
+ inset 0 2px 0 0 var(--spectrum-table-dropindicator-border-color);
214
+
215
+ /* forced-color-adjust: none, so that box-shadow style will render */
216
+ forced-color-adjust: none;
217
+ }
218
+
219
+ .react-spectrum-Table-cellWrapper.react-spectrum-Table-cellWrapper--dropTarget {
220
+ background-color: var(--spectrum-table-droptarget-background-color);
221
+ }
222
+ }
223
+
224
+ @media (forced-colors: active) {
225
+ .react-spectrum-Table,
226
+ .react-spectrum-Table-row {
227
+ --spectrum-table-droptarget-background-color: var(--spectrum-alias-global-color-transparent);
228
+ --spectrum-table-dropindicator-border-color: Highlight;
229
+ --spectrum-dropzone-border-color-selected-hover: Highlight;
230
+ --spectrum-table-dropindicator-circle-border-color: Highlight;
231
+ --spectrum-table-dropzone-border-color-selected-hover: Highlight;
232
+ --spectrum-table-row-badge-text-color: HighlightText;
233
+ --spectrum-table-row-badge-background-color: Highlight;
234
+ }
235
+ }