@atlaskit/table-tree 9.4.2 → 9.6.0

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 (33) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/components/internal/chevron.js +8 -3
  3. package/dist/cjs/components/internal/with-column-width.js +23 -49
  4. package/dist/cjs/components/row.js +19 -3
  5. package/dist/cjs/components/table-tree.js +25 -21
  6. package/dist/cjs/version.json +1 -1
  7. package/dist/es2019/components/internal/chevron.js +6 -3
  8. package/dist/es2019/components/internal/with-column-width.js +27 -29
  9. package/dist/es2019/components/row.js +19 -3
  10. package/dist/es2019/components/table-tree.js +35 -30
  11. package/dist/es2019/version.json +1 -1
  12. package/dist/esm/components/internal/chevron.js +8 -3
  13. package/dist/esm/components/internal/with-column-width.js +24 -51
  14. package/dist/esm/components/row.js +19 -3
  15. package/dist/esm/components/table-tree.js +23 -20
  16. package/dist/esm/version.json +1 -1
  17. package/dist/types/components/cell.d.ts +6 -59
  18. package/dist/types/components/header.d.ts +1 -58
  19. package/dist/types/components/internal/chevron.d.ts +2 -0
  20. package/dist/types/components/internal/with-column-width.d.ts +2 -60
  21. package/dist/types/components/row.d.ts +1 -0
  22. package/dist/types/components/table-tree.d.ts +15 -15
  23. package/dist/types-ts4.5/components/cell.d.ts +6 -59
  24. package/dist/types-ts4.5/components/header.d.ts +1 -58
  25. package/dist/types-ts4.5/components/internal/chevron.d.ts +2 -0
  26. package/dist/types-ts4.5/components/internal/with-column-width.d.ts +2 -60
  27. package/dist/types-ts4.5/components/row.d.ts +1 -0
  28. package/dist/types-ts4.5/components/table-tree.d.ts +15 -15
  29. package/extract-react-types/table-tree-row.tsx +9 -0
  30. package/extract-react-types/table-tree.tsx +7 -0
  31. package/package.json +7 -8
  32. package/report.api.md +9 -268
  33. package/tmp/api-report-tmp.d.ts +109 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/table-tree
2
2
 
3
+ ## 9.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`60b048eae5d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/60b048eae5d) - Replaced legacy context with useContext for handling column widths
8
+
9
+ ## 9.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`6e5546981a3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6e5546981a3) - Accessibility: Fix the chevron button label.
14
+ Add a new prop `mainColumnForExpandCollapseLabel` that allows you to show a chevron label with row contents instead of a row index.
15
+
3
16
  ## 9.4.2
4
17
 
5
18
  ### Patch Changes
@@ -47,20 +47,25 @@ var Chevron = /*#__PURE__*/function (_Component) {
47
47
  isExpanded = _this$props.isExpanded,
48
48
  ariaControls = _this$props.ariaControls,
49
49
  collapseLabel = _this$props.collapseLabel,
50
- expandLabel = _this$props.expandLabel;
50
+ expandLabel = _this$props.expandLabel,
51
+ rowId = _this$props.rowId,
52
+ extendedLabel = _this$props.extendedLabel;
51
53
  var iconProps = {
52
54
  size: 'medium',
53
55
  primaryColor: _styled.iconColor
54
56
  };
57
+ var getLabel = function getLabel(defaultLabel) {
58
+ return extendedLabel ? "".concat(defaultLabel, " ").concat(extendedLabel, " row") : "".concat(defaultLabel, " row ").concat(rowId);
59
+ };
55
60
  return /*#__PURE__*/_react.default.createElement(_styled.ChevronContainer, null, /*#__PURE__*/_react.default.createElement(_button.default, {
56
61
  spacing: "none",
57
62
  appearance: "subtle",
58
63
  "aria-controls": ariaControls,
59
64
  onClick: this.handleClick
60
65
  }, /*#__PURE__*/_react.default.createElement(_styled.ChevronIconContainer, null, isExpanded ? /*#__PURE__*/_react.default.createElement(_chevronDown.default, (0, _extends2.default)({
61
- label: collapseLabel
66
+ label: getLabel(collapseLabel)
62
67
  }, iconProps)) : /*#__PURE__*/_react.default.createElement(_chevronRight.default, (0, _extends2.default)({
63
- label: expandLabel
68
+ label: getLabel(expandLabel)
64
69
  }, iconProps)))));
65
70
  }
66
71
  }]);
@@ -8,60 +8,34 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = withColumnWidth;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
15
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
11
  var _react = _interopRequireWildcard(require("react"));
18
- var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _tableTree = require("../table-tree");
19
13
  var _excluded = ["width", "columnIndex"];
20
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
23
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /* eslint-disable react/prop-types */
24
16
  function withColumnWidth(Cell) {
25
- var _class;
26
- return _class = /*#__PURE__*/function (_Component) {
27
- (0, _inherits2.default)(CellWithColumnWidth, _Component);
28
- var _super = _createSuper(CellWithColumnWidth);
29
- function CellWithColumnWidth() {
30
- (0, _classCallCheck2.default)(this, CellWithColumnWidth);
31
- return _super.apply(this, arguments);
32
- }
33
- (0, _createClass2.default)(CellWithColumnWidth, [{
34
- key: "UNSAFE_componentWillMount",
35
- value: function UNSAFE_componentWillMount() {
36
- this.setColumnWidth(this.props.width);
37
- }
38
- }, {
39
- key: "setColumnWidth",
40
- value: function setColumnWidth(width) {
41
- if (width !== undefined) {
42
- this.context.tableTree.setColumnWidth(this.props.columnIndex, width);
43
- }
17
+ return function (props) {
18
+ var _useContext = (0, _react.useContext)(_tableTree.TableTreeContext),
19
+ setColumnWidth = _useContext.setColumnWidth,
20
+ getColumnWidth = _useContext.getColumnWidth;
21
+ var width = props.width,
22
+ columnIndex = props.columnIndex,
23
+ other = (0, _objectWithoutProperties2.default)(props, _excluded);
24
+ (0, _react.useEffect)(function () {
25
+ if (width !== undefined && columnIndex !== undefined) {
26
+ setColumnWidth(columnIndex, width);
44
27
  }
45
- }, {
46
- key: "UNSAFE_componentWillReceiveProps",
47
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
48
- this.setColumnWidth(nextProps.width);
28
+ }, [width, columnIndex, setColumnWidth]);
29
+ var columnWidth;
30
+ if (width !== null && width !== undefined) {
31
+ columnWidth = width;
32
+ } else {
33
+ if (columnIndex !== undefined) {
34
+ columnWidth = getColumnWidth(columnIndex);
49
35
  }
50
- }, {
51
- key: "render",
52
- value: function render() {
53
- var _this$props = this.props,
54
- width = _this$props.width,
55
- columnIndex = _this$props.columnIndex,
56
- other = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
57
- var columnWidth = width !== null && width !== undefined ? width : this.context.tableTree.getColumnWidth(columnIndex);
58
- return /*#__PURE__*/_react.default.createElement(Cell, (0, _extends2.default)({
59
- width: columnWidth
60
- }, other));
61
- }
62
- }]);
63
- return CellWithColumnWidth;
64
- }(_react.Component), (0, _defineProperty2.default)(_class, "contextTypes", {
65
- tableTree: _propTypes.default.object.isRequired
66
- }), _class;
36
+ }
37
+ return /*#__PURE__*/_react.default.createElement(Cell, (0, _extends2.default)({
38
+ width: columnWidth
39
+ }, other));
40
+ };
67
41
  }
@@ -28,7 +28,7 @@ var treeRowClickableStyles = (0, _react2.css)({
28
28
  cursor: 'pointer'
29
29
  });
30
30
  var packageName = "@atlaskit/table-tree";
31
- var packageVersion = "9.4.2";
31
+ var packageVersion = "9.6.0";
32
32
  var Row = /*#__PURE__*/function (_Component) {
33
33
  (0, _inherits2.default)(Row, _Component);
34
34
  var _super = _createSuper(Row);
@@ -64,6 +64,18 @@ var Row = /*#__PURE__*/function (_Component) {
64
64
  _this.onExpandStateChange(!_this.state.isExpanded);
65
65
  }
66
66
  });
67
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getExtendedLabel", function (cellContent, cellIndex, mainColumnForExpandCollapseLabel) {
68
+ /**
69
+ * First condition - when we pass data via `items` property in `<TableTree />`
70
+ * Second condition - when we pass data via `<Rows />` as children in `<TableTree />`.
71
+ */
72
+ if (cellContent.hasOwnProperty('props')) {
73
+ return cellContent === null || cellContent === void 0 ? void 0 : cellContent.props[mainColumnForExpandCollapseLabel === null || mainColumnForExpandCollapseLabel === void 0 ? void 0 : mainColumnForExpandCollapseLabel.toLowerCase()];
74
+ } else if (cellIndex === mainColumnForExpandCollapseLabel) {
75
+ return cellContent;
76
+ }
77
+ return undefined;
78
+ });
67
79
  return _this;
68
80
  }
69
81
  (0, _createClass2.default)(Row, [{
@@ -102,18 +114,22 @@ var Row = /*#__PURE__*/function (_Component) {
102
114
  var props = this.props;
103
115
  var isExpanded = this.isExpanded();
104
116
  var hasChildren = props.hasChildren,
105
- depth = props.depth;
117
+ depth = props.depth,
118
+ mainColumnForExpandCollapseLabel = props.mainColumnForExpandCollapseLabel;
106
119
  var isFirstCell = cellIndex === 0;
107
120
  var indentLevel = isFirstCell ? depth : 0;
108
121
  var cellContent = cell.props.children || [];
122
+ var extendedLabel = this.getExtendedLabel(cellContent, cellIndex, mainColumnForExpandCollapseLabel);
109
123
  if (isFirstCell && hasChildren) {
110
124
  cellContent = [(0, _react2.jsx)(_chevron.default, {
111
125
  key: "chevron",
112
126
  expandLabel: props.expandLabel,
113
127
  collapseLabel: props.collapseLabel,
128
+ extendedLabel: extendedLabel,
114
129
  isExpanded: isExpanded,
115
130
  onExpandToggle: this.onExpandToggle,
116
- ariaControls: (0, _toItemId.default)(props.itemId)
131
+ ariaControls: (0, _toItemId.default)(props.itemId),
132
+ rowId: props.itemId
117
133
  })].concat(cellContent);
118
134
  }
119
135
  return /*#__PURE__*/_react.default.cloneElement(cell, {
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
8
+ exports.default = exports.TableTreeContext = void 0;
9
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
11
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -14,7 +14,6 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
14
14
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
15
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
16
  var _react = _interopRequireWildcard(require("react"));
17
- var _propTypes = _interopRequireDefault(require("prop-types"));
18
17
  var _cell = _interopRequireDefault(require("./cell"));
19
18
  var _header = _interopRequireDefault(require("./header"));
20
19
  var _headers = _interopRequireDefault(require("./headers"));
@@ -24,6 +23,18 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
24
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
24
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
26
25
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /* eslint-disable react/prop-types */
26
+ /**
27
+ *
28
+ * Context provider which maintains the column widths and access methods for use in descendent table cells
29
+ * Enables composed table-tree implementations to e.g. set width on header cells only
30
+ */
31
+ var TableTreeContext = /*#__PURE__*/(0, _react.createContext)({
32
+ setColumnWidth: function setColumnWidth() {},
33
+ getColumnWidth: function getColumnWidth() {
34
+ return null;
35
+ }
36
+ });
37
+ exports.TableTreeContext = TableTreeContext;
27
38
  var TableTree = /*#__PURE__*/function (_Component) {
28
39
  (0, _inherits2.default)(TableTree, _Component);
29
40
  var _super = _createSuper(TableTree);
@@ -62,17 +73,6 @@ var TableTree = /*#__PURE__*/function (_Component) {
62
73
  }); // eslint-disable-line
63
74
  }
64
75
  }
65
- }, {
66
- key: "getChildContext",
67
- value: function getChildContext() {
68
- return {
69
- tableTree: {
70
- columnWidths: this.state.columnWidths,
71
- setColumnWidth: this.setColumnWidth,
72
- getColumnWidth: this.getColumnWidth
73
- }
74
- };
75
- }
76
76
  }, {
77
77
  key: "render",
78
78
  value: function render() {
@@ -82,7 +82,8 @@ var TableTree = /*#__PURE__*/function (_Component) {
82
82
  headers = _this$props.headers,
83
83
  columns = _this$props.columns,
84
84
  _this$props$columnWid = _this$props.columnWidths,
85
- columnWidths = _this$props$columnWid === void 0 ? [] : _this$props$columnWid;
85
+ columnWidths = _this$props$columnWid === void 0 ? [] : _this$props$columnWid,
86
+ mainColumnForExpandCollapseLabel = _this$props.mainColumnForExpandCollapseLabel;
86
87
  var heads = headers && /*#__PURE__*/_react.default.createElement(_headers.default, null, headers.map(function (header, index) {
87
88
  return (
88
89
  /*#__PURE__*/
@@ -107,7 +108,8 @@ var TableTree = /*#__PURE__*/function (_Component) {
107
108
  itemId: id,
108
109
  items: children,
109
110
  hasChildren: hasChildren,
110
- shouldExpandOnClick: shouldExpandOnClick
111
+ shouldExpandOnClick: shouldExpandOnClick,
112
+ mainColumnForExpandCollapseLabel: mainColumnForExpandCollapseLabel
111
113
  }, columns.map(function (CellContent, index) {
112
114
  return /*#__PURE__*/_react.default.createElement(_cell.default
113
115
  // eslint-disable-next-line react/no-array-index-key
@@ -120,15 +122,17 @@ var TableTree = /*#__PURE__*/function (_Component) {
120
122
  }
121
123
  });
122
124
  }
123
- return /*#__PURE__*/_react.default.createElement("div", {
125
+ return /*#__PURE__*/_react.default.createElement(TableTreeContext.Provider, {
126
+ value: {
127
+ setColumnWidth: this.setColumnWidth,
128
+ getColumnWidth: this.getColumnWidth
129
+ }
130
+ }, /*#__PURE__*/_react.default.createElement("div", {
124
131
  role: "treegrid",
125
132
  "aria-readonly": true
126
- }, heads, rows, this.props.children);
133
+ }, heads, rows, this.props.children));
127
134
  }
128
135
  }]);
129
136
  return TableTree;
130
137
  }(_react.Component);
131
- exports.default = TableTree;
132
- (0, _defineProperty2.default)(TableTree, "childContextTypes", {
133
- tableTree: _propTypes.default.object.isRequired
134
- });
138
+ exports.default = TableTree;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/table-tree",
3
- "version": "9.4.2",
3
+ "version": "9.6.0",
4
4
  "sideEffects": false
5
5
  }
@@ -21,21 +21,24 @@ export default class Chevron extends Component {
21
21
  isExpanded,
22
22
  ariaControls,
23
23
  collapseLabel,
24
- expandLabel
24
+ expandLabel,
25
+ rowId,
26
+ extendedLabel
25
27
  } = this.props;
26
28
  const iconProps = {
27
29
  size: 'medium',
28
30
  primaryColor: iconColor
29
31
  };
32
+ const getLabel = defaultLabel => extendedLabel ? `${defaultLabel} ${extendedLabel} row` : `${defaultLabel} row ${rowId}`;
30
33
  return /*#__PURE__*/React.createElement(ChevronContainer, null, /*#__PURE__*/React.createElement(Button, {
31
34
  spacing: "none",
32
35
  appearance: "subtle",
33
36
  "aria-controls": ariaControls,
34
37
  onClick: this.handleClick
35
38
  }, /*#__PURE__*/React.createElement(ChevronIconContainer, null, isExpanded ? /*#__PURE__*/React.createElement(ChevronDownIcon, _extends({
36
- label: collapseLabel
39
+ label: getLabel(collapseLabel)
37
40
  }, iconProps)) : /*#__PURE__*/React.createElement(ChevronRightIcon, _extends({
38
- label: expandLabel
41
+ label: getLabel(expandLabel)
39
42
  }, iconProps)))));
40
43
  }
41
44
  }
@@ -1,34 +1,32 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- /* eslint-disable react/prop-types */
4
- import React, { Component } from 'react';
5
- import PropTypes from 'prop-types';
2
+ import React, { useContext, useEffect } from 'react';
3
+ import { TableTreeContext } from '../table-tree';
6
4
  export default function withColumnWidth(Cell) {
7
- var _class;
8
- return _class = class CellWithColumnWidth extends Component {
9
- UNSAFE_componentWillMount() {
10
- this.setColumnWidth(this.props.width);
11
- }
12
- setColumnWidth(width) {
13
- if (width !== undefined) {
14
- this.context.tableTree.setColumnWidth(this.props.columnIndex, width);
5
+ return props => {
6
+ const {
7
+ setColumnWidth,
8
+ getColumnWidth
9
+ } = useContext(TableTreeContext);
10
+ const {
11
+ width,
12
+ columnIndex,
13
+ ...other
14
+ } = props;
15
+ useEffect(() => {
16
+ if (width !== undefined && columnIndex !== undefined) {
17
+ setColumnWidth(columnIndex, width);
18
+ }
19
+ }, [width, columnIndex, setColumnWidth]);
20
+ let columnWidth;
21
+ if (width !== null && width !== undefined) {
22
+ columnWidth = width;
23
+ } else {
24
+ if (columnIndex !== undefined) {
25
+ columnWidth = getColumnWidth(columnIndex);
15
26
  }
16
27
  }
17
- UNSAFE_componentWillReceiveProps(nextProps) {
18
- this.setColumnWidth(nextProps.width);
19
- }
20
- render() {
21
- const {
22
- width,
23
- columnIndex,
24
- ...other
25
- } = this.props;
26
- const columnWidth = width !== null && width !== undefined ? width : this.context.tableTree.getColumnWidth(columnIndex);
27
- return /*#__PURE__*/React.createElement(Cell, _extends({
28
- width: columnWidth
29
- }, other));
30
- }
31
- }, _defineProperty(_class, "contextTypes", {
32
- tableTree: PropTypes.object.isRequired
33
- }), _class;
28
+ return /*#__PURE__*/React.createElement(Cell, _extends({
29
+ width: columnWidth
30
+ }, other));
31
+ };
34
32
  }
@@ -12,7 +12,7 @@ const treeRowClickableStyles = css({
12
12
  cursor: 'pointer'
13
13
  });
14
14
  const packageName = "@atlaskit/table-tree";
15
- const packageVersion = "9.4.2";
15
+ const packageVersion = "9.6.0";
16
16
  class Row extends Component {
17
17
  constructor(...args) {
18
18
  super(...args);
@@ -43,6 +43,18 @@ class Row extends Component {
43
43
  this.onExpandStateChange(!this.state.isExpanded);
44
44
  }
45
45
  });
46
+ _defineProperty(this, "getExtendedLabel", (cellContent, cellIndex, mainColumnForExpandCollapseLabel) => {
47
+ /**
48
+ * First condition - when we pass data via `items` property in `<TableTree />`
49
+ * Second condition - when we pass data via `<Rows />` as children in `<TableTree />`.
50
+ */
51
+ if (cellContent.hasOwnProperty('props')) {
52
+ return cellContent === null || cellContent === void 0 ? void 0 : cellContent.props[mainColumnForExpandCollapseLabel === null || mainColumnForExpandCollapseLabel === void 0 ? void 0 : mainColumnForExpandCollapseLabel.toLowerCase()];
53
+ } else if (cellIndex === mainColumnForExpandCollapseLabel) {
54
+ return cellContent;
55
+ }
56
+ return undefined;
57
+ });
46
58
  }
47
59
  componentDidUpdate(prevProps) {
48
60
  const {
@@ -78,19 +90,23 @@ class Row extends Component {
78
90
  const isExpanded = this.isExpanded();
79
91
  const {
80
92
  hasChildren,
81
- depth
93
+ depth,
94
+ mainColumnForExpandCollapseLabel
82
95
  } = props;
83
96
  const isFirstCell = cellIndex === 0;
84
97
  const indentLevel = isFirstCell ? depth : 0;
85
98
  let cellContent = cell.props.children || [];
99
+ const extendedLabel = this.getExtendedLabel(cellContent, cellIndex, mainColumnForExpandCollapseLabel);
86
100
  if (isFirstCell && hasChildren) {
87
101
  cellContent = [jsx(Chevron, {
88
102
  key: "chevron",
89
103
  expandLabel: props.expandLabel,
90
104
  collapseLabel: props.collapseLabel,
105
+ extendedLabel: extendedLabel,
91
106
  isExpanded: isExpanded,
92
107
  onExpandToggle: this.onExpandToggle,
93
- ariaControls: toItemId(props.itemId)
108
+ ariaControls: toItemId(props.itemId),
109
+ rowId: props.itemId
94
110
  })].concat(cellContent);
95
111
  }
96
112
  return /*#__PURE__*/React.cloneElement(cell, {
@@ -1,12 +1,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  /* eslint-disable react/prop-types */
3
- import React, { Component } from 'react';
4
- import PropTypes from 'prop-types';
3
+ import React, { Component, createContext } from 'react';
5
4
  import Cell from './cell';
6
5
  import Header from './header';
7
6
  import Headers from './headers';
8
7
  import Row from './row';
9
8
  import Rows from './rows';
9
+ /**
10
+ *
11
+ * Context provider which maintains the column widths and access methods for use in descendent table cells
12
+ * Enables composed table-tree implementations to e.g. set width on header cells only
13
+ */
14
+ export const TableTreeContext = /*#__PURE__*/createContext({
15
+ setColumnWidth: () => {},
16
+ getColumnWidth: () => null
17
+ });
10
18
  export default class TableTree extends Component {
11
19
  constructor(...args) {
12
20
  super(...args);
@@ -38,22 +46,14 @@ export default class TableTree extends Component {
38
46
  }
39
47
  }
40
48
 
41
- getChildContext() {
42
- return {
43
- tableTree: {
44
- columnWidths: this.state.columnWidths,
45
- setColumnWidth: this.setColumnWidth,
46
- getColumnWidth: this.getColumnWidth
47
- }
48
- };
49
- }
50
49
  render() {
51
50
  const {
52
51
  items,
53
52
  shouldExpandOnClick,
54
53
  headers,
55
54
  columns,
56
- columnWidths = []
55
+ columnWidths = [],
56
+ mainColumnForExpandCollapseLabel
57
57
  } = this.props;
58
58
  const heads = headers && /*#__PURE__*/React.createElement(Headers, null, headers.map((header, index) =>
59
59
  /*#__PURE__*/
@@ -72,26 +72,31 @@ export default class TableTree extends Component {
72
72
  children,
73
73
  hasChildren,
74
74
  content
75
- }) => /*#__PURE__*/React.createElement(Row, {
76
- itemId: id,
77
- items: children,
78
- hasChildren: hasChildren,
79
- shouldExpandOnClick: shouldExpandOnClick
80
- }, columns.map((CellContent, index) => /*#__PURE__*/React.createElement(Cell
81
- // eslint-disable-next-line react/no-array-index-key
82
- , {
83
- key: index,
84
- columnIndex: index,
85
- width: columnWidths[index]
86
- }, /*#__PURE__*/React.createElement(CellContent, content))))
75
+ }) => {
76
+ return /*#__PURE__*/React.createElement(Row, {
77
+ itemId: id,
78
+ items: children,
79
+ hasChildren: hasChildren,
80
+ shouldExpandOnClick: shouldExpandOnClick,
81
+ mainColumnForExpandCollapseLabel: mainColumnForExpandCollapseLabel
82
+ }, columns.map((CellContent, index) => /*#__PURE__*/React.createElement(Cell
83
+ // eslint-disable-next-line react/no-array-index-key
84
+ , {
85
+ key: index,
86
+ columnIndex: index,
87
+ width: columnWidths[index]
88
+ }, /*#__PURE__*/React.createElement(CellContent, content))));
89
+ }
87
90
  });
88
91
  }
89
- return /*#__PURE__*/React.createElement("div", {
92
+ return /*#__PURE__*/React.createElement(TableTreeContext.Provider, {
93
+ value: {
94
+ setColumnWidth: this.setColumnWidth,
95
+ getColumnWidth: this.getColumnWidth
96
+ }
97
+ }, /*#__PURE__*/React.createElement("div", {
90
98
  role: "treegrid",
91
99
  "aria-readonly": true
92
- }, heads, rows, this.props.children);
100
+ }, heads, rows, this.props.children));
93
101
  }
94
- }
95
- _defineProperty(TableTree, "childContextTypes", {
96
- tableTree: PropTypes.object.isRequired
97
- });
102
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/table-tree",
3
- "version": "9.4.2",
3
+ "version": "9.6.0",
4
4
  "sideEffects": false
5
5
  }
@@ -39,20 +39,25 @@ var Chevron = /*#__PURE__*/function (_Component) {
39
39
  isExpanded = _this$props.isExpanded,
40
40
  ariaControls = _this$props.ariaControls,
41
41
  collapseLabel = _this$props.collapseLabel,
42
- expandLabel = _this$props.expandLabel;
42
+ expandLabel = _this$props.expandLabel,
43
+ rowId = _this$props.rowId,
44
+ extendedLabel = _this$props.extendedLabel;
43
45
  var iconProps = {
44
46
  size: 'medium',
45
47
  primaryColor: iconColor
46
48
  };
49
+ var getLabel = function getLabel(defaultLabel) {
50
+ return extendedLabel ? "".concat(defaultLabel, " ").concat(extendedLabel, " row") : "".concat(defaultLabel, " row ").concat(rowId);
51
+ };
47
52
  return /*#__PURE__*/React.createElement(ChevronContainer, null, /*#__PURE__*/React.createElement(Button, {
48
53
  spacing: "none",
49
54
  appearance: "subtle",
50
55
  "aria-controls": ariaControls,
51
56
  onClick: this.handleClick
52
57
  }, /*#__PURE__*/React.createElement(ChevronIconContainer, null, isExpanded ? /*#__PURE__*/React.createElement(ChevronDownIcon, _extends({
53
- label: collapseLabel
58
+ label: getLabel(collapseLabel)
54
59
  }, iconProps)) : /*#__PURE__*/React.createElement(ChevronRightIcon, _extends({
55
- label: expandLabel
60
+ label: getLabel(expandLabel)
56
61
  }, iconProps)))));
57
62
  }
58
63
  }]);