@atlaskit/table-tree 9.12.2 → 10.0.1
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/CHANGELOG.md +18 -0
- package/dist/cjs/components/cell.js +19 -41
- package/dist/cjs/components/header.js +25 -38
- package/dist/cjs/components/headers.js +31 -40
- package/dist/cjs/components/internal/chevron.js +32 -59
- package/dist/cjs/components/internal/item.js +38 -52
- package/dist/cjs/components/internal/items.js +32 -84
- package/dist/cjs/components/internal/loader-item.js +35 -67
- package/dist/cjs/components/internal/with-column-width.js +3 -5
- package/dist/cjs/components/row.js +121 -178
- package/dist/cjs/components/rows.js +17 -37
- package/dist/cjs/components/table-tree.js +76 -120
- package/dist/es2019/components/cell.js +18 -22
- package/dist/es2019/components/header.js +18 -21
- package/dist/es2019/components/headers.js +22 -19
- package/dist/es2019/components/internal/chevron.js +25 -35
- package/dist/es2019/components/internal/item.js +32 -36
- package/dist/es2019/components/internal/items.js +24 -60
- package/dist/es2019/components/internal/loader-item.js +29 -46
- package/dist/es2019/components/internal/with-column-width.js +2 -4
- package/dist/es2019/components/row.js +95 -147
- package/dist/es2019/components/rows.js +17 -17
- package/dist/es2019/components/table-tree.js +66 -90
- package/dist/esm/components/cell.js +19 -38
- package/dist/esm/components/header.js +19 -36
- package/dist/esm/components/headers.js +26 -40
- package/dist/esm/components/internal/chevron.js +29 -57
- package/dist/esm/components/internal/item.js +33 -53
- package/dist/esm/components/internal/items.js +32 -86
- package/dist/esm/components/internal/loader-item.js +33 -68
- package/dist/esm/components/internal/with-column-width.js +2 -4
- package/dist/esm/components/row.js +116 -179
- package/dist/esm/components/rows.js +17 -35
- package/dist/esm/components/table-tree.js +75 -121
- package/dist/types/components/header.d.ts +12 -1
- package/dist/types/components/headers.d.ts +13 -3
- package/dist/types/components/internal/chevron.d.ts +15 -13
- package/dist/types/components/internal/item.d.ts +24 -12
- package/dist/types/components/internal/items.d.ts +12 -23
- package/dist/types/components/internal/loader-item.d.ts +7 -16
- package/dist/types/components/row.d.ts +11 -39
- package/dist/types/components/rows.d.ts +15 -10
- package/dist/types/components/table-tree.d.ts +10 -20
- package/dist/types-ts4.5/components/header.d.ts +12 -1
- package/dist/types-ts4.5/components/headers.d.ts +13 -3
- package/dist/types-ts4.5/components/internal/chevron.d.ts +15 -13
- package/dist/types-ts4.5/components/internal/item.d.ts +24 -12
- package/dist/types-ts4.5/components/internal/items.d.ts +12 -23
- package/dist/types-ts4.5/components/internal/loader-item.d.ts +7 -16
- package/dist/types-ts4.5/components/row.d.ts +11 -39
- package/dist/types-ts4.5/components/rows.d.ts +15 -10
- package/dist/types-ts4.5/components/table-tree.d.ts +10 -20
- package/package.json +5 -9
|
@@ -1,51 +1,34 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
/* eslint-disable react/prop-types */
|
|
3
|
-
import React, {
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
4
3
|
import Spinner from '@atlaskit/spinner';
|
|
5
4
|
import CommonCell from './common-cell';
|
|
6
5
|
import { indentBase, LoaderItemContainer, TreeRowContainer } from './styled';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const LoaderItem = ({
|
|
7
|
+
depth = 1,
|
|
8
|
+
loadingLabel,
|
|
9
|
+
isCompleting,
|
|
10
|
+
onComplete
|
|
11
|
+
}) => {
|
|
12
|
+
const [phase, setPhase] = useState('loading');
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (phase === 'loading' && isCompleting) {
|
|
15
|
+
setPhase(() => {
|
|
16
|
+
onComplete();
|
|
17
|
+
return 'complete';
|
|
18
|
+
});
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
phase
|
|
36
|
-
} = this.state;
|
|
37
|
-
return phase === 'loading' ? /*#__PURE__*/React.createElement(TreeRowContainer, null, /*#__PURE__*/React.createElement(CommonCell, {
|
|
38
|
-
indent: `calc(${indentBase} * ${depth})`,
|
|
39
|
-
width: "100%"
|
|
40
|
-
}, /*#__PURE__*/React.createElement(LoaderItemContainer, {
|
|
41
|
-
isRoot: depth === 1
|
|
42
|
-
}, /*#__PURE__*/React.createElement(Spinner, {
|
|
43
|
-
size: "small",
|
|
44
|
-
testId: "table-tree-spinner",
|
|
45
|
-
label: loadingLabel
|
|
46
|
-
})))) : null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
_defineProperty(LoaderItem, "defaultProps", {
|
|
50
|
-
depth: 1
|
|
51
|
-
});
|
|
20
|
+
}, [isCompleting, onComplete, phase]);
|
|
21
|
+
return phase === 'loading' ? /*#__PURE__*/React.createElement(TreeRowContainer, null, /*#__PURE__*/React.createElement(CommonCell, {
|
|
22
|
+
indent: `calc(${indentBase} * ${depth})`,
|
|
23
|
+
width: "100%"
|
|
24
|
+
}, /*#__PURE__*/React.createElement(LoaderItemContainer, {
|
|
25
|
+
isRoot: depth === 1
|
|
26
|
+
}, /*#__PURE__*/React.createElement(Spinner, {
|
|
27
|
+
size: "small",
|
|
28
|
+
testId: "table-tree-spinner",
|
|
29
|
+
label: loadingLabel
|
|
30
|
+
})))) : null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
34
|
+
export default LoaderItem;
|
|
@@ -20,10 +20,8 @@ export default function withColumnWidth(Cell) {
|
|
|
20
20
|
let columnWidth;
|
|
21
21
|
if (width !== null && width !== undefined) {
|
|
22
22
|
columnWidth = width;
|
|
23
|
-
} else {
|
|
24
|
-
|
|
25
|
-
columnWidth = getColumnWidth(columnIndex);
|
|
26
|
-
}
|
|
23
|
+
} else if (columnIndex !== undefined) {
|
|
24
|
+
columnWidth = getColumnWidth(columnIndex);
|
|
27
25
|
}
|
|
28
26
|
return /*#__PURE__*/React.createElement(Cell, _extends({
|
|
29
27
|
width: columnWidth
|
|
@@ -1,182 +1,130 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
1
|
/**
|
|
4
2
|
* @jsxRuntime classic
|
|
5
3
|
* @jsx jsx
|
|
6
4
|
*/
|
|
7
|
-
|
|
8
|
-
import React, { Component, Fragment } from 'react';
|
|
5
|
+
import React, { Fragment, useEffect, useState } from 'react';
|
|
9
6
|
|
|
10
7
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
11
8
|
import { css, jsx } from '@emotion/react';
|
|
12
|
-
import {
|
|
9
|
+
import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next';
|
|
13
10
|
import toItemId from '../utils/to-item-id';
|
|
14
11
|
import Chevron from './internal/chevron';
|
|
15
12
|
import { TreeRowContainer } from './internal/styled';
|
|
16
13
|
const treeRowClickableStyles = css({
|
|
17
14
|
cursor: 'pointer'
|
|
18
15
|
});
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* Defining it here for now lets us provide *something* without much headache.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
class RowComponent extends Component {
|
|
32
|
-
constructor(...args) {
|
|
33
|
-
super(...args);
|
|
34
|
-
_defineProperty(this, "state", {
|
|
35
|
-
isExpanded: this.props.isDefaultExpanded || false
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* This ensures a user won't trigger a click event and expand the accordion
|
|
39
|
-
* when making a text selection.
|
|
40
|
-
*/
|
|
41
|
-
_defineProperty(this, "onClickHandler", e => {
|
|
42
|
-
var _window$getSelection;
|
|
43
|
-
const selection = ((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString()) || '';
|
|
44
|
-
if ((selection === null || selection === void 0 ? void 0 : selection.length) === 0) {
|
|
45
|
-
this.onExpandToggle();
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
_defineProperty(this, "onExpandToggle", () => {
|
|
49
|
-
const {
|
|
50
|
-
isExpanded
|
|
51
|
-
} = this.props;
|
|
52
|
-
if (isExpanded !== undefined) {
|
|
53
|
-
this.onExpandStateChange(!isExpanded);
|
|
54
|
-
} else {
|
|
55
|
-
this.setState({
|
|
56
|
-
isExpanded: !this.state.isExpanded
|
|
57
|
-
});
|
|
58
|
-
this.onExpandStateChange(!this.state.isExpanded);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
_defineProperty(this, "getExtendedLabel", (cellContent, cellIndex, mainColumnForExpandCollapseLabel) => {
|
|
62
|
-
/**
|
|
63
|
-
* First condition - when we pass data via `items` property in `<TableTree />`
|
|
64
|
-
* Second condition - when we pass data via `<Rows />` as children in `<TableTree />`.
|
|
65
|
-
*/
|
|
66
|
-
if (cellContent.hasOwnProperty('props')) {
|
|
67
|
-
return cellContent === null || cellContent === void 0 ? void 0 : cellContent.props[mainColumnForExpandCollapseLabel === null || mainColumnForExpandCollapseLabel === void 0 ? void 0 : mainColumnForExpandCollapseLabel.toLowerCase()];
|
|
68
|
-
} else if (cellIndex === mainColumnForExpandCollapseLabel) {
|
|
69
|
-
return cellContent;
|
|
70
|
-
}
|
|
71
|
-
return undefined;
|
|
72
|
-
});
|
|
16
|
+
const getExtendedLabel = (cellContent, cellIndex, mainColumnForExpandCollapseLabel) => {
|
|
17
|
+
/**
|
|
18
|
+
* First condition - when we pass data via `items` property in `<TableTree />`
|
|
19
|
+
* Second condition - when we pass data via `<Rows />` as children in `<TableTree />`.
|
|
20
|
+
*/
|
|
21
|
+
if (cellContent.hasOwnProperty('props')) {
|
|
22
|
+
return cellContent === null || cellContent === void 0 ? void 0 : cellContent.props[mainColumnForExpandCollapseLabel === null || mainColumnForExpandCollapseLabel === void 0 ? void 0 : mainColumnForExpandCollapseLabel.toLowerCase()];
|
|
23
|
+
} else if (cellIndex === mainColumnForExpandCollapseLabel) {
|
|
24
|
+
return cellContent;
|
|
73
25
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
26
|
+
return undefined;
|
|
27
|
+
};
|
|
28
|
+
function Row({
|
|
29
|
+
shouldExpandOnClick,
|
|
30
|
+
hasChildren,
|
|
31
|
+
depth,
|
|
32
|
+
renderChildren,
|
|
33
|
+
isDefaultExpanded,
|
|
34
|
+
data,
|
|
35
|
+
onExpand: providedOnExpand,
|
|
36
|
+
onCollapse: providedOnCollapse,
|
|
37
|
+
mainColumnForExpandCollapseLabel,
|
|
38
|
+
expandLabel,
|
|
39
|
+
collapseLabel,
|
|
40
|
+
itemId,
|
|
41
|
+
children,
|
|
42
|
+
isExpanded: isProvidedExpanded
|
|
43
|
+
}) {
|
|
44
|
+
const [isExpandedState, setIsExpandedState] = useState(isDefaultExpanded || false);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (isProvidedExpanded === undefined && isDefaultExpanded !== undefined && isExpandedState !== isDefaultExpanded) {
|
|
47
|
+
setIsExpandedState(isDefaultExpanded);
|
|
84
48
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
}, [isDefaultExpanded, isProvidedExpanded, isExpandedState]);
|
|
50
|
+
const onExpand = usePlatformLeafEventHandler({
|
|
51
|
+
fn: value => providedOnExpand && providedOnExpand(value),
|
|
52
|
+
action: 'expanded',
|
|
53
|
+
actionSubject: 'tableTree',
|
|
54
|
+
componentName: 'row',
|
|
55
|
+
packageName: "@atlaskit/table-tree",
|
|
56
|
+
packageVersion: "10.0.1"
|
|
57
|
+
});
|
|
58
|
+
const onCollapse = usePlatformLeafEventHandler({
|
|
59
|
+
fn: value => providedOnCollapse && providedOnCollapse(value),
|
|
60
|
+
action: 'collapsed',
|
|
61
|
+
actionSubject: 'tableTree',
|
|
62
|
+
componentName: 'row',
|
|
63
|
+
packageName: "@atlaskit/table-tree",
|
|
64
|
+
packageVersion: "10.0.1"
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* This ensures a user won't trigger a click event and expand the accordion
|
|
69
|
+
* when making a text selection.
|
|
70
|
+
*/
|
|
71
|
+
const onClickHandler = e => {
|
|
72
|
+
var _window$getSelection;
|
|
73
|
+
const selection = ((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString()) || '';
|
|
74
|
+
if ((selection === null || selection === void 0 ? void 0 : selection.length) === 0) {
|
|
75
|
+
onExpandToggle();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const onExpandStateChange = isExpanded => {
|
|
79
|
+
if (data) {
|
|
80
|
+
if (isExpanded && onExpand) {
|
|
81
|
+
onExpand(data);
|
|
82
|
+
} else if (!isExpanded && onCollapse) {
|
|
83
|
+
onCollapse(data);
|
|
92
84
|
}
|
|
93
85
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const {
|
|
107
|
-
hasChildren,
|
|
108
|
-
depth,
|
|
109
|
-
mainColumnForExpandCollapseLabel
|
|
110
|
-
} = props;
|
|
86
|
+
};
|
|
87
|
+
const onExpandToggle = () => {
|
|
88
|
+
if (isProvidedExpanded !== undefined) {
|
|
89
|
+
onExpandStateChange(!isProvidedExpanded);
|
|
90
|
+
} else {
|
|
91
|
+
setIsExpandedState(prevState => {
|
|
92
|
+
onExpandStateChange(!prevState);
|
|
93
|
+
return !prevState;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const renderCell = (cell, cellIndex) => {
|
|
111
98
|
const isFirstCell = cellIndex === 0;
|
|
112
99
|
const indentLevel = isFirstCell ? depth : 0;
|
|
113
100
|
let cellContent = cell.props.children || [];
|
|
114
|
-
const extendedLabel =
|
|
101
|
+
const extendedLabel = getExtendedLabel(cellContent, cellIndex, mainColumnForExpandCollapseLabel);
|
|
115
102
|
if (isFirstCell && hasChildren) {
|
|
116
103
|
cellContent = [jsx(Chevron, {
|
|
117
104
|
key: "chevron",
|
|
118
|
-
expandLabel:
|
|
119
|
-
collapseLabel:
|
|
105
|
+
expandLabel: expandLabel,
|
|
106
|
+
collapseLabel: collapseLabel,
|
|
120
107
|
extendedLabel: extendedLabel,
|
|
121
|
-
isExpanded:
|
|
122
|
-
onExpandToggle:
|
|
123
|
-
ariaControls:
|
|
124
|
-
rowId:
|
|
108
|
+
isExpanded: isProvidedExpanded !== undefined ? isProvidedExpanded : isExpandedState,
|
|
109
|
+
onExpandToggle: onExpandToggle,
|
|
110
|
+
ariaControls: (isProvidedExpanded !== undefined ? isProvidedExpanded : isExpandedState) && !!itemId ? toItemId(itemId) : undefined,
|
|
111
|
+
rowId: !!itemId ? itemId : ''
|
|
125
112
|
})].concat(cellContent);
|
|
126
113
|
}
|
|
114
|
+
// eslint-disable-next-line @repo/internal/react/no-clone-element
|
|
127
115
|
return /*#__PURE__*/React.cloneElement(cell, {
|
|
128
116
|
key: cellIndex,
|
|
129
117
|
columnIndex: cellIndex,
|
|
130
118
|
indentLevel
|
|
131
119
|
}, cellContent);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
} = this.props;
|
|
140
|
-
const isExpanded = this.isExpanded();
|
|
141
|
-
const ariaAttrs = {};
|
|
142
|
-
if (hasChildren) {
|
|
143
|
-
ariaAttrs['aria-expanded'] = isExpanded;
|
|
144
|
-
}
|
|
145
|
-
if (depth !== undefined) {
|
|
146
|
-
ariaAttrs['aria-level'] = depth;
|
|
147
|
-
}
|
|
148
|
-
return jsx(Fragment, null, jsx(TreeRowContainer, _extends({
|
|
149
|
-
css: hasChildren && shouldExpandOnClick ? treeRowClickableStyles : undefined,
|
|
150
|
-
onClick: hasChildren && shouldExpandOnClick ? this.onClickHandler : undefined
|
|
151
|
-
}, ariaAttrs), React.Children.map(this.props.children, (cell, index) => this.renderCell(cell, index))), hasChildren && isExpanded && renderChildren && renderChildren());
|
|
152
|
-
}
|
|
120
|
+
};
|
|
121
|
+
return jsx(Fragment, null, jsx(TreeRowContainer, {
|
|
122
|
+
css: hasChildren && shouldExpandOnClick ? treeRowClickableStyles : undefined,
|
|
123
|
+
onClick: hasChildren && shouldExpandOnClick ? onClickHandler : undefined,
|
|
124
|
+
"aria-expanded": hasChildren ? isExpandedState : undefined,
|
|
125
|
+
"aria-level": depth ? depth : undefined
|
|
126
|
+
}, React.Children.map(children, (cell, index) => renderCell(cell, index))), hasChildren && (isProvidedExpanded !== undefined ? isProvidedExpanded : isExpandedState) && renderChildren && renderChildren());
|
|
153
127
|
}
|
|
154
|
-
export { RowComponent as RowWithoutAnalytics };
|
|
155
|
-
const createAndFireEventOnAtlaskit = createAndFireEvent('atlaskit');
|
|
156
|
-
const Row = withAnalyticsContext({
|
|
157
|
-
componentName: 'row',
|
|
158
|
-
packageName,
|
|
159
|
-
packageVersion
|
|
160
|
-
})(withAnalyticsEvents({
|
|
161
|
-
onExpand: createAndFireEventOnAtlaskit({
|
|
162
|
-
action: 'expanded',
|
|
163
|
-
actionSubject: 'tableTree',
|
|
164
|
-
attributes: {
|
|
165
|
-
componentName: 'row',
|
|
166
|
-
packageName,
|
|
167
|
-
packageVersion
|
|
168
|
-
}
|
|
169
|
-
}),
|
|
170
|
-
onCollapse: createAndFireEventOnAtlaskit({
|
|
171
|
-
action: 'collapsed',
|
|
172
|
-
actionSubject: 'tableTree',
|
|
173
|
-
attributes: {
|
|
174
|
-
componentName: 'row',
|
|
175
|
-
packageName,
|
|
176
|
-
packageVersion
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
})(RowComponent));
|
|
180
128
|
|
|
181
129
|
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
182
130
|
export default Row;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import Items from './internal/items';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
function Rows({
|
|
4
|
+
items,
|
|
5
|
+
render,
|
|
6
|
+
loadingLabel = 'Loading'
|
|
7
|
+
}) {
|
|
8
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
9
|
+
role: "rowgroup"
|
|
10
|
+
}, /*#__PURE__*/React.createElement(Items, {
|
|
11
|
+
items: items,
|
|
12
|
+
loadingLabel: loadingLabel,
|
|
13
|
+
render: render
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
18
|
+
export default Rows;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
/* eslint-disable react/prop-types */
|
|
3
|
-
import React, {
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
4
3
|
import Cell from './cell';
|
|
5
4
|
import Header from './header';
|
|
6
5
|
import Headers from './headers';
|
|
7
6
|
import { TableTreeContext } from './internal/context';
|
|
8
7
|
import Row from './row';
|
|
9
8
|
import Rows from './rows';
|
|
10
|
-
class Content extends Object {}
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* This is hard-coded here because our actual <TableTree /> has no typings
|
|
@@ -18,91 +16,69 @@ class Content extends Object {}
|
|
|
18
16
|
* Defining it here for now lets us provide *something* without much headache.
|
|
19
17
|
*/
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
_defineProperty(this, "getColumnWidth", columnIndex => {
|
|
40
|
-
return this.state && this.state.columnWidths[columnIndex] || null;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
componentDidMount() {
|
|
44
|
-
const widths = this.props.columnWidths;
|
|
45
|
-
if (widths) {
|
|
46
|
-
this.setState({
|
|
47
|
-
columnWidths: widths
|
|
48
|
-
}); // eslint-disable-line
|
|
19
|
+
const emptyColumnWidths = [];
|
|
20
|
+
function TableTree({
|
|
21
|
+
children,
|
|
22
|
+
columns,
|
|
23
|
+
columnWidths: defaultColumnWidths = emptyColumnWidths,
|
|
24
|
+
headers,
|
|
25
|
+
shouldExpandOnClick,
|
|
26
|
+
items,
|
|
27
|
+
mainColumnForExpandCollapseLabel,
|
|
28
|
+
label,
|
|
29
|
+
referencedLabel
|
|
30
|
+
}) {
|
|
31
|
+
const [columnWidths, setColumnWidths] = useState(defaultColumnWidths);
|
|
32
|
+
const setColumnWidth = useCallback((columnIndex, width) => {
|
|
33
|
+
if (width === columnWidths[columnIndex]) {
|
|
34
|
+
return;
|
|
49
35
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
getColumnWidth: this.getColumnWidth
|
|
100
|
-
}
|
|
101
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
102
|
-
role: "treegrid",
|
|
103
|
-
"aria-readonly": true,
|
|
104
|
-
"aria-label": label,
|
|
105
|
-
"aria-labelledby": referencedLabel
|
|
106
|
-
}, heads, rows, this.props.children));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
36
|
+
setColumnWidths(columnWidths => {
|
|
37
|
+
const newColumnWidths = [...columnWidths];
|
|
38
|
+
newColumnWidths[columnIndex] = width;
|
|
39
|
+
return newColumnWidths;
|
|
40
|
+
});
|
|
41
|
+
}, [columnWidths]);
|
|
42
|
+
const getColumnWidth = useCallback(columnIndex => {
|
|
43
|
+
return columnWidths[columnIndex] || null;
|
|
44
|
+
}, [columnWidths]);
|
|
45
|
+
const contextValue = useMemo(() => ({
|
|
46
|
+
setColumnWidth,
|
|
47
|
+
getColumnWidth
|
|
48
|
+
}), [setColumnWidth, getColumnWidth]);
|
|
49
|
+
const heads = headers && /*#__PURE__*/React.createElement(Headers, null, headers.map((header, index) => /*#__PURE__*/React.createElement(Header, {
|
|
50
|
+
key: index,
|
|
51
|
+
columnIndex: index,
|
|
52
|
+
width: columnWidths[index]
|
|
53
|
+
}, header)));
|
|
54
|
+
return /*#__PURE__*/React.createElement(TableTreeContext.Provider, {
|
|
55
|
+
value: contextValue
|
|
56
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
role: "treegrid",
|
|
58
|
+
"aria-readonly": true,
|
|
59
|
+
"aria-label": label,
|
|
60
|
+
"aria-labelledby": referencedLabel
|
|
61
|
+
}, heads, columns && items && /*#__PURE__*/React.createElement(Rows, {
|
|
62
|
+
items: items,
|
|
63
|
+
render: ({
|
|
64
|
+
id,
|
|
65
|
+
children,
|
|
66
|
+
content
|
|
67
|
+
}) => /*#__PURE__*/React.createElement(Row, {
|
|
68
|
+
itemId: id,
|
|
69
|
+
items: children,
|
|
70
|
+
hasChildren: !!children && children.length > 0,
|
|
71
|
+
shouldExpandOnClick: shouldExpandOnClick,
|
|
72
|
+
mainColumnForExpandCollapseLabel: mainColumnForExpandCollapseLabel
|
|
73
|
+
}, columns.map((CellContent, index) => {
|
|
74
|
+
return /*#__PURE__*/React.createElement(Cell, {
|
|
75
|
+
key: `cell-${index}`,
|
|
76
|
+
columnIndex: index,
|
|
77
|
+
width: columnWidths[index]
|
|
78
|
+
}, /*#__PURE__*/React.createElement(CellContent, content));
|
|
79
|
+
}))
|
|
80
|
+
}), children));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
84
|
+
export default TableTree;
|
|
@@ -1,48 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
-
import _inherits from "@babel/runtime/helpers/inherits";
|
|
6
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
7
|
-
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
3
|
var _excluded = ["children", "singleLine", "indentLevel", "width", "className"];
|
|
9
|
-
|
|
10
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
11
|
-
import React, { Component } from 'react';
|
|
4
|
+
import React from 'react';
|
|
12
5
|
import CommonCell from './internal/common-cell';
|
|
13
6
|
import OverflowContainer from './internal/overflow-container';
|
|
14
7
|
import { indentBase } from './internal/styled';
|
|
15
8
|
import withColumnWidth from './internal/with-column-width';
|
|
16
|
-
var CellComponent =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
indent: indentLevel ? "calc(".concat(indentBase, " * ").concat(indentLevel, ")") : undefined,
|
|
35
|
-
width: width
|
|
36
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
37
|
-
,
|
|
38
|
-
className: className
|
|
39
|
-
}, props), /*#__PURE__*/React.createElement(OverflowContainer, {
|
|
40
|
-
isSingleLine: singleLine
|
|
41
|
-
}, children));
|
|
42
|
-
}
|
|
43
|
-
}]);
|
|
44
|
-
return CellComponent;
|
|
45
|
-
}(Component);
|
|
9
|
+
var CellComponent = function CellComponent(_ref) {
|
|
10
|
+
var children = _ref.children,
|
|
11
|
+
singleLine = _ref.singleLine,
|
|
12
|
+
indentLevel = _ref.indentLevel,
|
|
13
|
+
width = _ref.width,
|
|
14
|
+
className = _ref.className,
|
|
15
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
16
|
+
return /*#__PURE__*/React.createElement(CommonCell, _extends({
|
|
17
|
+
indent: indentLevel ? "calc(".concat(indentBase, " * ").concat(indentLevel, ")") : undefined,
|
|
18
|
+
width: width
|
|
19
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
20
|
+
,
|
|
21
|
+
className: className
|
|
22
|
+
// eslint-disable-next-line @repo/internal/react/no-unsafe-spread-props
|
|
23
|
+
}, props), /*#__PURE__*/React.createElement(OverflowContainer, {
|
|
24
|
+
isSingleLine: singleLine
|
|
25
|
+
}, children));
|
|
26
|
+
};
|
|
46
27
|
var Cell = withColumnWidth(CellComponent);
|
|
47
28
|
|
|
48
29
|
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|