@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/components/cell.js +19 -41
  3. package/dist/cjs/components/header.js +25 -38
  4. package/dist/cjs/components/headers.js +31 -40
  5. package/dist/cjs/components/internal/chevron.js +32 -59
  6. package/dist/cjs/components/internal/item.js +38 -52
  7. package/dist/cjs/components/internal/items.js +32 -84
  8. package/dist/cjs/components/internal/loader-item.js +35 -67
  9. package/dist/cjs/components/internal/with-column-width.js +3 -5
  10. package/dist/cjs/components/row.js +121 -178
  11. package/dist/cjs/components/rows.js +17 -37
  12. package/dist/cjs/components/table-tree.js +76 -120
  13. package/dist/es2019/components/cell.js +18 -22
  14. package/dist/es2019/components/header.js +18 -21
  15. package/dist/es2019/components/headers.js +22 -19
  16. package/dist/es2019/components/internal/chevron.js +25 -35
  17. package/dist/es2019/components/internal/item.js +32 -36
  18. package/dist/es2019/components/internal/items.js +24 -60
  19. package/dist/es2019/components/internal/loader-item.js +29 -46
  20. package/dist/es2019/components/internal/with-column-width.js +2 -4
  21. package/dist/es2019/components/row.js +95 -147
  22. package/dist/es2019/components/rows.js +17 -17
  23. package/dist/es2019/components/table-tree.js +66 -90
  24. package/dist/esm/components/cell.js +19 -38
  25. package/dist/esm/components/header.js +19 -36
  26. package/dist/esm/components/headers.js +26 -40
  27. package/dist/esm/components/internal/chevron.js +29 -57
  28. package/dist/esm/components/internal/item.js +33 -53
  29. package/dist/esm/components/internal/items.js +32 -86
  30. package/dist/esm/components/internal/loader-item.js +33 -68
  31. package/dist/esm/components/internal/with-column-width.js +2 -4
  32. package/dist/esm/components/row.js +116 -179
  33. package/dist/esm/components/rows.js +17 -35
  34. package/dist/esm/components/table-tree.js +75 -121
  35. package/dist/types/components/header.d.ts +12 -1
  36. package/dist/types/components/headers.d.ts +13 -3
  37. package/dist/types/components/internal/chevron.d.ts +15 -13
  38. package/dist/types/components/internal/item.d.ts +24 -12
  39. package/dist/types/components/internal/items.d.ts +12 -23
  40. package/dist/types/components/internal/loader-item.d.ts +7 -16
  41. package/dist/types/components/row.d.ts +11 -39
  42. package/dist/types/components/rows.d.ts +15 -10
  43. package/dist/types/components/table-tree.d.ts +10 -20
  44. package/dist/types-ts4.5/components/header.d.ts +12 -1
  45. package/dist/types-ts4.5/components/headers.d.ts +13 -3
  46. package/dist/types-ts4.5/components/internal/chevron.d.ts +15 -13
  47. package/dist/types-ts4.5/components/internal/item.d.ts +24 -12
  48. package/dist/types-ts4.5/components/internal/items.d.ts +12 -23
  49. package/dist/types-ts4.5/components/internal/loader-item.d.ts +7 -16
  50. package/dist/types-ts4.5/components/row.d.ts +11 -39
  51. package/dist/types-ts4.5/components/rows.d.ts +15 -10
  52. package/dist/types-ts4.5/components/table-tree.d.ts +10 -20
  53. 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, { Component } from '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
- export default class LoaderItem extends Component {
8
- constructor(...args) {
9
- super(...args);
10
- _defineProperty(this, "state", {
11
- phase: 'loading'
12
- });
13
- }
14
- static getDerivedStateFromProps(nextProps, prevState) {
15
- if (nextProps.isCompleting && prevState.phase === 'loading') {
16
- return {
17
- phase: 'complete'
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
- return null;
21
- }
22
- componentDidUpdate(prevProps, prevState) {
23
- if (prevState.phase === 'loading' && this.state.phase === 'complete') {
24
- if (this.props.onComplete) {
25
- this.props.onComplete();
26
- }
27
- }
28
- }
29
- render() {
30
- const {
31
- depth,
32
- loadingLabel
33
- } = this.props;
34
- const {
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
- if (columnIndex !== undefined) {
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
- /* eslint-disable @repo/internal/react/no-clone-element */
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 { createAndFireEvent, withAnalyticsContext, withAnalyticsEvents } from '@atlaskit/analytics-next';
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 packageName = "@atlaskit/table-tree";
20
- const packageVersion = "9.12.2";
21
-
22
- /**
23
- * This is hard-coded here because our actual <TableTree /> has no typings
24
- * for its props.
25
- *
26
- * Adding types for real *might* break things so will need a little care.
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
- componentDidUpdate(prevProps) {
75
- const {
76
- isDefaultExpanded,
77
- isExpanded
78
- } = this.props;
79
- if (isExpanded === undefined && isDefaultExpanded !== undefined && prevProps.isDefaultExpanded !== isDefaultExpanded && this.state.isExpanded !== isDefaultExpanded) {
80
- // eslint-disable-next-line react/no-did-update-set-state
81
- this.setState({
82
- isExpanded: isDefaultExpanded
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
- onExpandStateChange(isExpanded) {
87
- if (this.props.data) {
88
- if (isExpanded && this.props.onExpand) {
89
- this.props.onExpand(this.props.data);
90
- } else if (!isExpanded && this.props.onCollapse) {
91
- this.props.onCollapse(this.props.data);
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
- isExpanded() {
96
- const {
97
- isExpanded
98
- } = this.props;
99
- return isExpanded !== undefined ? isExpanded : this.state.isExpanded;
100
- }
101
- renderCell(cell, cellIndex) {
102
- const {
103
- props
104
- } = this;
105
- const isExpanded = this.isExpanded();
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 = this.getExtendedLabel(cellContent, cellIndex, mainColumnForExpandCollapseLabel);
101
+ const extendedLabel = getExtendedLabel(cellContent, cellIndex, mainColumnForExpandCollapseLabel);
115
102
  if (isFirstCell && hasChildren) {
116
103
  cellContent = [jsx(Chevron, {
117
104
  key: "chevron",
118
- expandLabel: props.expandLabel,
119
- collapseLabel: props.collapseLabel,
105
+ expandLabel: expandLabel,
106
+ collapseLabel: collapseLabel,
120
107
  extendedLabel: extendedLabel,
121
- isExpanded: isExpanded,
122
- onExpandToggle: this.onExpandToggle,
123
- ariaControls: isExpanded ? toItemId(props.itemId) : undefined,
124
- rowId: props.itemId
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
- render() {
134
- const {
135
- shouldExpandOnClick,
136
- hasChildren,
137
- depth,
138
- renderChildren
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, { Component } from 'react';
1
+ import React from 'react';
2
2
  import Items from './internal/items';
3
- export default class Rows extends Component {
4
- render() {
5
- const {
6
- items,
7
- render,
8
- loadingLabel = 'Loading'
9
- } = this.props;
10
- return /*#__PURE__*/React.createElement("div", {
11
- role: "rowgroup"
12
- }, /*#__PURE__*/React.createElement(Items, {
13
- items: items,
14
- loadingLabel: loadingLabel,
15
- render: render
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, { Component } from '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
- export default class TableTree extends Component {
22
- constructor(...args) {
23
- super(...args);
24
- _defineProperty(this, "state", {
25
- columnWidths: []
26
- });
27
- _defineProperty(this, "setColumnWidth", (columnIndex, width) => {
28
- const {
29
- columnWidths
30
- } = this.state;
31
- if (width === columnWidths[columnIndex]) {
32
- return;
33
- }
34
- columnWidths[columnIndex] = width;
35
- this.setState({
36
- columnWidths
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
- render() {
52
- const {
53
- items,
54
- label,
55
- referencedLabel,
56
- shouldExpandOnClick,
57
- headers,
58
- columns,
59
- columnWidths = [],
60
- mainColumnForExpandCollapseLabel
61
- } = this.props;
62
- const heads = headers && /*#__PURE__*/React.createElement(Headers, null, headers.map((header, index) =>
63
- /*#__PURE__*/
64
- // eslint-disable-next-line react/no-array-index-key
65
- React.createElement(Header, {
66
- key: index,
67
- columnIndex: index,
68
- width: columnWidths[index]
69
- }, header)));
70
- let rows = null;
71
- if (columns && items) {
72
- rows = /*#__PURE__*/React.createElement(Rows, {
73
- items: items,
74
- render: ({
75
- id,
76
- children,
77
- hasChildren,
78
- content
79
- }) => {
80
- return /*#__PURE__*/React.createElement(Row, {
81
- itemId: id,
82
- items: children,
83
- hasChildren: hasChildren,
84
- shouldExpandOnClick: shouldExpandOnClick,
85
- mainColumnForExpandCollapseLabel: mainColumnForExpandCollapseLabel
86
- }, columns.map((CellContent, index) => /*#__PURE__*/React.createElement(Cell
87
- // eslint-disable-next-line react/no-array-index-key
88
- , {
89
- key: index,
90
- columnIndex: index,
91
- width: columnWidths[index]
92
- }, /*#__PURE__*/React.createElement(CellContent, content))));
93
- }
94
- });
95
- }
96
- return /*#__PURE__*/React.createElement(TableTreeContext.Provider, {
97
- value: {
98
- setColumnWidth: this.setColumnWidth,
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
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
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 = /*#__PURE__*/function (_Component) {
17
- _inherits(CellComponent, _Component);
18
- var _super = _createSuper(CellComponent);
19
- function CellComponent() {
20
- _classCallCheck(this, CellComponent);
21
- return _super.apply(this, arguments);
22
- }
23
- _createClass(CellComponent, [{
24
- key: "render",
25
- value: function render() {
26
- var _this$props = this.props,
27
- children = _this$props.children,
28
- singleLine = _this$props.singleLine,
29
- indentLevel = _this$props.indentLevel,
30
- width = _this$props.width,
31
- className = _this$props.className,
32
- props = _objectWithoutProperties(_this$props, _excluded);
33
- return /*#__PURE__*/React.createElement(CommonCell, _extends({
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