@react-spectrum/table 3.10.1-nightly.4028 → 3.10.1-nightly.4036
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +282 -105
- package/dist/main.css +1 -1
- package/dist/main.js +279 -102
- package/dist/main.js.map +1 -1
- package/dist/module.js +282 -105
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +28 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +32 -31
- package/src/InsertionIndicator.tsx +1 -1
- package/src/Resizer.tsx +1 -1
- package/src/RootDropIndicator.tsx +1 -1
- package/src/TableView.tsx +12 -1418
- package/src/TableViewBase.tsx +1493 -0
- package/src/TableViewWrapper.tsx +101 -0
- package/src/TreeGridTableView.tsx +47 -0
- package/src/index.ts +2 -2
- package/src/table.css +7 -0
|
@@ -0,0 +1,101 @@
|
|
|
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, DOMProps, DOMRef, 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, {Key, 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
|
+
/** Handler that is called when a user performs an action on a row. */
|
|
37
|
+
onAction?: (key: Key) => void,
|
|
38
|
+
/**
|
|
39
|
+
* Handler that is called when a user starts a column resize.
|
|
40
|
+
*/
|
|
41
|
+
onResizeStart?: (widths: Map<Key, ColumnSize>) => void,
|
|
42
|
+
/**
|
|
43
|
+
* Handler that is called when a user performs a column resize.
|
|
44
|
+
* Can be used with the width property on columns to put the column widths into
|
|
45
|
+
* a controlled state.
|
|
46
|
+
*/
|
|
47
|
+
onResize?: (widths: Map<Key, ColumnSize>) => void,
|
|
48
|
+
/**
|
|
49
|
+
* Handler that is called after a user performs a column resize.
|
|
50
|
+
* Can be used to store the widths of columns for another future session.
|
|
51
|
+
*/
|
|
52
|
+
onResizeEnd?: (widths: Map<Key, ColumnSize>) => void,
|
|
53
|
+
/**
|
|
54
|
+
* The drag and drop hooks returned by `useDragAndDrop` used to enable drag and drop behavior for the TableView.
|
|
55
|
+
* @version beta
|
|
56
|
+
*/
|
|
57
|
+
dragAndDropHooks?: DragAndDropHooks['dragAndDropHooks'],
|
|
58
|
+
/**
|
|
59
|
+
* 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.
|
|
60
|
+
* @version alpha
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
UNSTABLE_allowsExpandableRows?: boolean,
|
|
64
|
+
/**
|
|
65
|
+
* The currently expanded keys in the collection (controlled). Requires the feature flag to be
|
|
66
|
+
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
|
|
67
|
+
* @version alpha
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
UNSTABLE_expandedKeys?: 'all' | Iterable<Key>,
|
|
71
|
+
/**
|
|
72
|
+
* The initial expanded keys in the collection (uncontrolled). Requires the feature flag to be
|
|
73
|
+
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
|
|
74
|
+
* @version alpha
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>,
|
|
78
|
+
/**
|
|
79
|
+
* Handler that is called when items are expanded or collapsed. Requires the feature flag to be
|
|
80
|
+
* enabled along with UNSTABLE_allowsExpandableRows, see https://react-spectrum.adobe.com/react-spectrum/TableView.html#expandable-rows.
|
|
81
|
+
* @version alpha
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function TableViewWrapper<T extends object>(props: SpectrumTableProps<T>, ref: DOMRef<HTMLDivElement>) {
|
|
88
|
+
let {UNSTABLE_allowsExpandableRows, ...otherProps} = props;
|
|
89
|
+
if (tableNestedRows() && UNSTABLE_allowsExpandableRows) {
|
|
90
|
+
return <TreeGridTableView {...otherProps} ref={ref} />;
|
|
91
|
+
} else {
|
|
92
|
+
return <TableView {...otherProps} ref={ref} />;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Tables are containers for displaying information. They allow users to quickly scan, sort, compare, and take action on large amounts of data.
|
|
98
|
+
*/
|
|
99
|
+
const _TableViewWrapper = React.forwardRef(TableViewWrapper) as <T>(props: SpectrumTableProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
|
|
100
|
+
|
|
101
|
+
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};
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
/// <reference types="css-module-types" />
|
|
14
14
|
|
|
15
|
-
export {TableView} from './
|
|
15
|
+
export {TableView} from './TableViewWrapper';
|
|
16
16
|
import {Column} from '@react-stately/table';
|
|
17
17
|
import {SpectrumColumnProps} from '@react-types/table';
|
|
18
18
|
|
|
@@ -29,4 +29,4 @@ export {
|
|
|
29
29
|
} from '@react-stately/table';
|
|
30
30
|
|
|
31
31
|
export type {SpectrumColumnProps, TableHeaderProps, TableBodyProps, RowProps, CellProps} from '@react-types/table';
|
|
32
|
-
export type {SpectrumTableProps} from './
|
|
32
|
+
export type {SpectrumTableProps} from './TableViewWrapper';
|
package/src/table.css
CHANGED
|
@@ -34,6 +34,13 @@
|
|
|
34
34
|
.react-spectrum-Table-cell {
|
|
35
35
|
display: flex;
|
|
36
36
|
align-items: center;
|
|
37
|
+
|
|
38
|
+
&.react-spectrum-Table-cell--hasExpandCollapseButton {
|
|
39
|
+
display: grid;
|
|
40
|
+
grid-template-columns: var(--spectrum-global-dimension-size-400) 1fr;
|
|
41
|
+
grid-template-rows: 1fr;
|
|
42
|
+
grid-template-areas: "expand-button contents";
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
.react-spectrum-Table-cellWrapper > .react-spectrum-Table-cell {
|