@instructure/ui-table 9.7.0 → 9.8.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 (97) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/es/Table/Body/index.js +24 -11
  3. package/es/Table/Body/props.js +2 -5
  4. package/es/Table/Body/styles.js +0 -2
  5. package/es/Table/Cell/index.js +3 -2
  6. package/es/Table/Cell/props.js +1 -2
  7. package/es/Table/ColHeader/props.js +2 -1
  8. package/es/Table/Head/index.js +40 -30
  9. package/es/Table/Head/props.js +1 -2
  10. package/es/Table/Head/styles.js +0 -2
  11. package/es/Table/Row/index.js +25 -12
  12. package/es/Table/Row/props.js +2 -5
  13. package/es/Table/Row/styles.js +4 -6
  14. package/es/Table/RowHeader/index.js +3 -2
  15. package/es/Table/RowHeader/props.js +1 -2
  16. package/es/Table/TableContext.js +34 -0
  17. package/es/Table/__new-tests__/Table.test.js +74 -1
  18. package/es/Table/index.js +25 -17
  19. package/es/index.js +2 -1
  20. package/lib/Table/Body/index.js +23 -10
  21. package/lib/Table/Body/props.js +2 -5
  22. package/lib/Table/Body/styles.js +0 -2
  23. package/lib/Table/Cell/index.js +3 -2
  24. package/lib/Table/Cell/props.js +1 -2
  25. package/lib/Table/ColHeader/props.js +2 -1
  26. package/lib/Table/Head/index.js +39 -30
  27. package/lib/Table/Head/props.js +1 -2
  28. package/lib/Table/Head/styles.js +0 -2
  29. package/lib/Table/Row/index.js +24 -11
  30. package/lib/Table/Row/props.js +2 -5
  31. package/lib/Table/Row/styles.js +4 -6
  32. package/lib/Table/RowHeader/index.js +3 -2
  33. package/lib/Table/RowHeader/props.js +1 -2
  34. package/lib/Table/TableContext.js +39 -0
  35. package/lib/Table/__new-tests__/Table.test.js +74 -1
  36. package/lib/Table/index.js +24 -16
  37. package/lib/index.js +8 -1
  38. package/package.json +17 -17
  39. package/src/Table/Body/index.tsx +23 -13
  40. package/src/Table/Body/props.ts +6 -18
  41. package/src/Table/Body/styles.ts +0 -2
  42. package/src/Table/Cell/index.tsx +6 -3
  43. package/src/Table/Cell/props.ts +7 -9
  44. package/src/Table/ColHeader/props.ts +9 -3
  45. package/src/Table/Head/index.tsx +40 -40
  46. package/src/Table/Head/props.ts +20 -10
  47. package/src/Table/Head/styles.ts +0 -2
  48. package/src/Table/README.md +1788 -546
  49. package/src/Table/Row/index.tsx +27 -11
  50. package/src/Table/Row/props.ts +7 -19
  51. package/src/Table/Row/styles.ts +5 -6
  52. package/src/Table/RowHeader/index.tsx +6 -4
  53. package/src/Table/RowHeader/props.ts +1 -3
  54. package/src/Table/TableContext.ts +54 -0
  55. package/src/Table/__new-tests__/Table.test.tsx +131 -2
  56. package/src/Table/index.tsx +42 -44
  57. package/src/Table/props.ts +8 -28
  58. package/src/index.ts +1 -0
  59. package/tsconfig.build.tsbuildinfo +1 -1
  60. package/types/Table/Body/index.d.ts +6 -13
  61. package/types/Table/Body/index.d.ts.map +1 -1
  62. package/types/Table/Body/props.d.ts +4 -5
  63. package/types/Table/Body/props.d.ts.map +1 -1
  64. package/types/Table/Body/styles.d.ts +0 -2
  65. package/types/Table/Body/styles.d.ts.map +1 -1
  66. package/types/Table/Cell/index.d.ts +4 -3
  67. package/types/Table/Cell/index.d.ts.map +1 -1
  68. package/types/Table/Cell/props.d.ts +6 -2
  69. package/types/Table/Cell/props.d.ts.map +1 -1
  70. package/types/Table/ColHeader/index.d.ts +2 -0
  71. package/types/Table/ColHeader/index.d.ts.map +1 -1
  72. package/types/Table/ColHeader/props.d.ts +7 -3
  73. package/types/Table/ColHeader/props.d.ts.map +1 -1
  74. package/types/Table/Head/index.d.ts +15 -5
  75. package/types/Table/Head/index.d.ts.map +1 -1
  76. package/types/Table/Head/props.d.ts +19 -4
  77. package/types/Table/Head/props.d.ts.map +1 -1
  78. package/types/Table/Head/styles.d.ts +0 -2
  79. package/types/Table/Head/styles.d.ts.map +1 -1
  80. package/types/Table/Row/index.d.ts +6 -13
  81. package/types/Table/Row/index.d.ts.map +1 -1
  82. package/types/Table/Row/props.d.ts +5 -6
  83. package/types/Table/Row/props.d.ts.map +1 -1
  84. package/types/Table/Row/styles.d.ts +5 -2
  85. package/types/Table/Row/styles.d.ts.map +1 -1
  86. package/types/Table/RowHeader/index.d.ts +4 -3
  87. package/types/Table/RowHeader/index.d.ts.map +1 -1
  88. package/types/Table/RowHeader/props.d.ts +0 -1
  89. package/types/Table/RowHeader/props.d.ts.map +1 -1
  90. package/types/Table/TableContext.d.ts +24 -0
  91. package/types/Table/TableContext.d.ts.map +1 -0
  92. package/types/Table/index.d.ts +1 -1
  93. package/types/Table/index.d.ts.map +1 -1
  94. package/types/Table/props.d.ts +10 -22
  95. package/types/Table/props.d.ts.map +1 -1
  96. package/types/index.d.ts +1 -0
  97. package/types/index.d.ts.map +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [9.8.0](https://github.com/instructure/instructure-ui/compare/v9.7.2...v9.8.0) (2024-10-16)
7
+
8
+
9
+ ### Features
10
+
11
+ * **ui-table:** expand table api ([8f03e48](https://github.com/instructure/instructure-ui/commit/8f03e48eb38d9608bed6f98984c66ab1679294aa))
12
+
13
+
14
+
15
+
16
+
17
+ ## [9.7.2](https://github.com/instructure/instructure-ui/compare/v9.7.0...v9.7.2) (2024-10-10)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **ui-table:** non standrd Row children props ([700e462](https://github.com/instructure/instructure-ui/commit/700e462cc8de0cfb68f0ed8a442dcd23961e4b77))
23
+
24
+
25
+
26
+
27
+
28
+ ## [9.7.1](https://github.com/instructure/instructure-ui/compare/v9.7.0...v9.7.1) (2024-10-10)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * **ui-table:** non standrd Row children props ([700e462](https://github.com/instructure/instructure-ui/commit/700e462cc8de0cfb68f0ed8a442dcd23961e4b77))
34
+
35
+
36
+
37
+
38
+
6
39
  # [9.7.0](https://github.com/instructure/instructure-ui/compare/v9.6.0...v9.7.0) (2024-09-23)
7
40
 
8
41
  **Note:** Version bump only for package @instructure/ui-table
@@ -24,13 +24,14 @@ var _dec, _class, _Body;
24
24
  */
25
25
 
26
26
  /** @jsx jsx */
27
- import { Component, Children } from 'react';
27
+ import { Component, Children, isValidElement } from 'react';
28
28
  import { safeCloneElement, omitProps } from '@instructure/ui-react-utils';
29
29
  import { View } from '@instructure/ui-view';
30
30
  import { withStyle, jsx } from '@instructure/emotion';
31
31
  import generateStyle from './styles';
32
32
  import generateComponentTheme from './theme';
33
33
  import { allowedProps, propTypes } from './props';
34
+ import TableContext from '../TableContext';
34
35
 
35
36
  /**
36
37
  ---
@@ -50,22 +51,34 @@ let Body = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
50
51
  render() {
51
52
  const _this$props3 = this.props,
52
53
  children = _this$props3.children,
53
- hover = _this$props3.hover,
54
- isStacked = _this$props3.isStacked,
55
- headers = _this$props3.headers,
56
54
  styles = _this$props3.styles;
55
+ const _this$context = this.context,
56
+ isStacked = _this$context.isStacked,
57
+ hover = _this$context.hover,
58
+ headers = _this$context.headers;
57
59
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, Body.allowedProps), Body), {
58
60
  as: isStacked ? 'div' : 'tbody',
59
61
  css: styles === null || styles === void 0 ? void 0 : styles.body,
60
62
  role: isStacked ? 'rowgroup' : void 0
61
- }), Children.map(children, child => safeCloneElement(child, {
62
- key: child.props.name,
63
- hover,
64
- isStacked,
65
- headers
66
- })));
63
+ }), Children.map(children, child => {
64
+ if ( /*#__PURE__*/isValidElement(child)) {
65
+ return safeCloneElement(child, {
66
+ key: child.props.name,
67
+ // Sent down for compatibility with custom components
68
+ // TODO DEPRECATED, remove in v11
69
+ hover,
70
+ // Sent down for compatibility with custom components
71
+ // TODO DEPRECATED, remove in v11
72
+ isStacked,
73
+ // Sent down for compatibility with custom components
74
+ // TODO DEPRECATED, remove in v11
75
+ headers
76
+ });
77
+ }
78
+ return child;
79
+ }));
67
80
  }
68
- }, _Body.displayName = "Body", _Body.componentId = 'Table.Body', _Body.allowedProps = allowedProps, _Body.propTypes = propTypes, _Body.defaultProps = {
81
+ }, _Body.displayName = "Body", _Body.componentId = 'Table.Body', _Body.contextType = TableContext, _Body.allowedProps = allowedProps, _Body.propTypes = propTypes, _Body.defaultProps = {
69
82
  children: null
70
83
  }, _Body)) || _class);
71
84
  export default Body;
@@ -24,10 +24,7 @@
24
24
 
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
- children: PropTypes.node,
28
- hover: PropTypes.bool,
29
- isStacked: PropTypes.bool,
30
- headers: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.node, PropTypes.func]))
27
+ children: PropTypes.node
31
28
  };
32
- const allowedProps = ['children', 'hover', 'isStacked', 'headers'];
29
+ const allowedProps = ['children'];
33
30
  export { propTypes, allowedProps };
@@ -28,8 +28,6 @@
28
28
  * ---
29
29
  * Generates the style object from the theme and provided additional information
30
30
  * @param {Object} componentTheme The theme variable object.
31
- * @param {Object} props the props of the component, the style is applied to
32
- * @param {Object} state the state of the component, the style is applied to
33
31
  * @return {Object} The final style object, which will be used in the component
34
32
  */
35
33
  const generateStyle = componentTheme => {
@@ -31,6 +31,7 @@ import { withStyle, jsx } from '@instructure/emotion';
31
31
  import generateStyle from './styles';
32
32
  import generateComponentTheme from './theme';
33
33
  import { allowedProps, propTypes } from './props';
34
+ import TableContext from '../TableContext';
34
35
 
35
36
  /**
36
37
  ---
@@ -51,15 +52,15 @@ let Cell = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
51
52
  const _this$props3 = this.props,
52
53
  children = _this$props3.children,
53
54
  styles = _this$props3.styles,
54
- isStacked = _this$props3.isStacked,
55
55
  header = _this$props3.header;
56
+ const isStacked = this.context.isStacked;
56
57
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, Cell.allowedProps), Cell), {
57
58
  as: isStacked ? 'div' : 'td',
58
59
  css: styles === null || styles === void 0 ? void 0 : styles.cell,
59
60
  role: isStacked ? 'cell' : void 0
60
61
  }), header && callRenderProp(header), header && ': ', callRenderProp(children));
61
62
  }
62
- }, _Cell.displayName = "Cell", _Cell.componentId = 'Table.Cell', _Cell.allowedProps = allowedProps, _Cell.propTypes = propTypes, _Cell.defaultProps = {
63
+ }, _Cell.displayName = "Cell", _Cell.componentId = 'Table.Cell', _Cell.contextType = TableContext, _Cell.allowedProps = allowedProps, _Cell.propTypes = propTypes, _Cell.defaultProps = {
63
64
  textAlign: 'start',
64
65
  children: null
65
66
  }, _Cell)) || _class);
@@ -25,9 +25,8 @@
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
27
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
28
- isStacked: PropTypes.bool,
29
28
  header: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
30
29
  textAlign: PropTypes.oneOf(['start', 'center', 'end'])
31
30
  };
32
- const allowedProps = ['children', 'isStacked', 'header', 'textAlign'];
31
+ const allowedProps = ['children', 'header', 'textAlign'];
33
32
  export { propTypes, allowedProps };
@@ -24,6 +24,7 @@
24
24
 
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
+ isStacked: PropTypes.bool,
27
28
  id: PropTypes.string.isRequired,
28
29
  stackedSortByLabel: PropTypes.string,
29
30
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
@@ -33,5 +34,5 @@ const propTypes = {
33
34
  onRequestSort: PropTypes.func,
34
35
  scope: PropTypes.oneOf(['row', 'col', 'rowgroup', 'colgroup', 'auto'])
35
36
  };
36
- const allowedProps = ['id', 'stackedSortByLabel', 'children', 'width', 'textAlign', 'sortDirection', 'onRequestSort', 'scope'];
37
+ const allowedProps = ['id', 'isStacked', 'stackedSortByLabel', 'children', 'width', 'textAlign', 'sortDirection', 'onRequestSort', 'scope'];
37
38
  export { propTypes, allowedProps };
@@ -26,7 +26,7 @@ var _dec, _class, _Head, _ScreenReaderContent;
26
26
 
27
27
  /** @jsx jsx */
28
28
  import { Component, Children } from 'react';
29
- import { omitProps, matchComponentTypes, callRenderProp } from '@instructure/ui-react-utils';
29
+ import { omitProps, callRenderProp } from '@instructure/ui-react-utils';
30
30
  import { SimpleSelect } from '@instructure/ui-simple-select';
31
31
  import { ScreenReaderContent } from '@instructure/ui-a11y-content';
32
32
  import { IconCheckLine } from '@instructure/ui-icons';
@@ -34,9 +34,8 @@ import { warn } from '@instructure/console';
34
34
  import { withStyle, jsx } from '@instructure/emotion';
35
35
  import generateStyle from './styles';
36
36
  import generateComponentTheme from './theme';
37
- import { Row } from '../Row';
38
- import { ColHeader } from '../ColHeader';
39
37
  import { allowedProps, propTypes } from './props';
38
+ import TableContext from '../TableContext';
40
39
 
41
40
  /**
42
41
  ---
@@ -45,15 +44,19 @@ id: Table.Head
45
44
  ---
46
45
  **/
47
46
  let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_Head = class Head extends Component {
47
+ /**
48
+ * Returns `true` if the first child's children have a `onRequestSort` prop
49
+ */
48
50
  get isSortable() {
49
51
  const _ref = Children.toArray(this.props.children),
50
52
  _ref2 = _slicedToArray(_ref, 1),
51
- row = _ref2[0];
53
+ firstRow = _ref2[0];
52
54
  let sortable = false;
53
- if (row) {
54
- Children.forEach(row.props.children, colHeader => {
55
- if (matchComponentTypes(colHeader, [ColHeader])) {
56
- if (colHeader.props.onRequestSort) sortable = true;
55
+ if (firstRow && firstRow.props && firstRow.props.children) {
56
+ Children.forEach(firstRow.props.children, grandchild => {
57
+ if (grandchild.props.onRequestSort) {
58
+ sortable = true;
59
+ return;
57
60
  }
58
61
  });
59
62
  }
@@ -70,38 +73,44 @@ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
70
73
  }
71
74
  (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
72
75
  }
76
+
77
+ /**
78
+ * This `Select` is used in `stacked` layout. It's populated by iterating
79
+ * through the first child's children (by default `ColHeader`) and reading
80
+ * there the `id`, `stackedSortByLabel`, `sortDirection`, `onRequestSort` props
81
+ */
73
82
  renderSelect() {
83
+ var _firstRow$props;
74
84
  const _this$props3 = this.props,
75
85
  children = _this$props3.children,
76
86
  renderSortLabel = _this$props3.renderSortLabel;
77
87
  const _ref3 = Children.toArray(children),
78
88
  _ref4 = _slicedToArray(_ref3, 1),
79
- row = _ref4[0];
80
- if (!matchComponentTypes(row, [Row])) {
89
+ firstRow = _ref4[0];
90
+ if (!(firstRow !== null && firstRow !== void 0 && (_firstRow$props = firstRow.props) !== null && _firstRow$props !== void 0 && _firstRow$props.children)) {
81
91
  return null;
82
92
  }
83
93
  const options = [];
84
94
  const clickHandlers = {};
85
95
  let selectedOption;
86
96
  let count = 0;
87
- Children.forEach(row.props.children, colHeader => {
97
+ Children.forEach(firstRow.props.children, grandchild => {
88
98
  count += 1;
89
- if (matchComponentTypes(colHeader, [ColHeader])) {
90
- const _colHeader$props = colHeader.props,
91
- id = _colHeader$props.id,
92
- stackedSortByLabel = _colHeader$props.stackedSortByLabel,
93
- sortDirection = _colHeader$props.sortDirection,
94
- onRequestSort = _colHeader$props.onRequestSort;
99
+ if (!grandchild.props) return;
100
+ const _grandchild$props = grandchild.props,
101
+ id = _grandchild$props.id,
102
+ stackedSortByLabel = _grandchild$props.stackedSortByLabel,
103
+ sortDirection = _grandchild$props.sortDirection,
104
+ onRequestSort = _grandchild$props.onRequestSort;
105
+ if (id && onRequestSort) {
95
106
  const label = stackedSortByLabel || id;
96
- if (onRequestSort) {
97
- options.push({
98
- id,
99
- label
100
- });
101
- clickHandlers[id] = onRequestSort;
102
- if (sortDirection !== 'none') {
103
- selectedOption = id;
104
- }
107
+ options.push({
108
+ id,
109
+ label
110
+ });
111
+ clickHandlers[id] = onRequestSort;
112
+ if (sortDirection !== 'none') {
113
+ selectedOption = id;
105
114
  }
106
115
  }
107
116
  });
@@ -146,13 +155,14 @@ let Head = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class
146
155
  render() {
147
156
  const _this$props4 = this.props,
148
157
  children = _this$props4.children,
149
- isStacked = _this$props4.isStacked,
150
158
  styles = _this$props4.styles;
151
- return isStacked ? this.renderSelect() : jsx("thead", Object.assign({}, omitProps(this.props, Head.allowedProps), {
159
+ return this.context.isStacked ? this.renderSelect() :
160
+ // TODO remove 'hover' exclude in v11, its passed down for compatibility with custom components
161
+ jsx("thead", Object.assign({}, omitProps(this.props, Head.allowedProps, ['hover']), {
152
162
  css: styles === null || styles === void 0 ? void 0 : styles.head
153
- }), Children.map(children, child => matchComponentTypes(child, [Row]) ? child : null));
163
+ }), children);
154
164
  }
155
- }, _Head.displayName = "Head", _Head.componentId = 'Table.Head', _Head.allowedProps = allowedProps, _Head.propTypes = propTypes, _Head.defaultProps = {
165
+ }, _Head.displayName = "Head", _Head.componentId = 'Table.Head', _Head.contextType = TableContext, _Head.allowedProps = allowedProps, _Head.propTypes = propTypes, _Head.defaultProps = {
156
166
  children: null
157
167
  }, _Head)) || _class);
158
168
  export default Head;
@@ -25,8 +25,7 @@
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
27
  children: PropTypes.node,
28
- isStacked: PropTypes.bool,
29
28
  renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
30
29
  };
31
- const allowedProps = ['children', 'isStacked', 'renderSortLabel'];
30
+ const allowedProps = ['children', 'renderSortLabel'];
32
31
  export { propTypes, allowedProps };
@@ -28,8 +28,6 @@
28
28
  * ---
29
29
  * Generates the style object from the theme and provided additional information
30
30
  * @param {Object} componentTheme The theme variable object.
31
- * @param {Object} props the props of the component, the style is applied to
32
- * @param {Object} state the state of the component, the style is applied to
33
31
  * @return {Object} The final style object, which will be used in the component
34
32
  */
35
33
  const generateStyle = componentTheme => {
@@ -24,13 +24,14 @@ var _dec, _class, _Row;
24
24
  */
25
25
 
26
26
  /** @jsx jsx */
27
- import { Component, Children } from 'react';
27
+ import { Component, Children, isValidElement } from 'react';
28
28
  import { omitProps, safeCloneElement } from '@instructure/ui-react-utils';
29
29
  import { View } from '@instructure/ui-view';
30
30
  import { withStyle, jsx } from '@instructure/emotion';
31
31
  import generateStyle from './styles';
32
32
  import generateComponentTheme from './theme';
33
33
  import { allowedProps, propTypes } from './props';
34
+ import TableContext from '../TableContext';
34
35
 
35
36
  /**
36
37
  ---
@@ -41,31 +42,43 @@ id: Table.Row
41
42
  let Row = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = (_Row = class Row extends Component {
42
43
  componentDidMount() {
43
44
  var _this$props$makeStyle, _this$props;
44
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
45
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, {
46
+ isStacked: this.context.isStacked,
47
+ hover: this.context.hover
48
+ });
45
49
  }
46
50
  componentDidUpdate() {
47
51
  var _this$props$makeStyle2, _this$props2;
48
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
52
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, {
53
+ isStacked: this.context.isStacked,
54
+ hover: this.context.hover
55
+ });
49
56
  }
50
57
  render() {
51
58
  const _this$props3 = this.props,
52
59
  children = _this$props3.children,
53
- styles = _this$props3.styles,
54
- isStacked = _this$props3.isStacked,
55
- headers = _this$props3.headers;
60
+ styles = _this$props3.styles;
61
+ const isStacked = this.context.isStacked;
62
+ const headers = this.context.headers;
56
63
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, Row.allowedProps), Row), {
57
64
  as: isStacked ? 'div' : 'tr',
58
65
  css: styles === null || styles === void 0 ? void 0 : styles.row,
59
66
  role: isStacked ? 'row' : void 0
60
67
  }), Children.toArray(children).filter(Boolean).map((child, index) => {
61
- return safeCloneElement(child, {
62
- key: child.props.name,
63
- isStacked,
64
- header: headers && headers[index]
65
- });
68
+ if ( /*#__PURE__*/isValidElement(child)) {
69
+ return safeCloneElement(child, {
70
+ key: child.props.name,
71
+ // Sent down for compatibility with custom components
72
+ // TODO DEPRECATED, remove in v11
73
+ isStacked,
74
+ // used by `Cell` to render its column title in `stacked` layout
75
+ header: headers && headers[index]
76
+ });
77
+ }
78
+ return child;
66
79
  }));
67
80
  }
68
- }, _Row.displayName = "Row", _Row.componentId = 'Table.Row', _Row.allowedProps = allowedProps, _Row.propTypes = propTypes, _Row.defaultProps = {
81
+ }, _Row.displayName = "Row", _Row.componentId = 'Table.Row', _Row.contextType = TableContext, _Row.allowedProps = allowedProps, _Row.propTypes = propTypes, _Row.defaultProps = {
69
82
  children: null
70
83
  }, _Row)) || _class);
71
84
  export default Row;
@@ -24,10 +24,7 @@
24
24
 
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
- children: PropTypes.node,
28
- hover: PropTypes.bool,
29
- isStacked: PropTypes.bool,
30
- headers: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.node, PropTypes.func]))
27
+ children: PropTypes.node
31
28
  };
32
- const allowedProps = ['children', 'hover', 'isStacked', 'headers'];
29
+ const allowedProps = ['children'];
33
30
  export { propTypes, allowedProps };
@@ -29,12 +29,10 @@
29
29
  * Generates the style object from the theme and provided additional information
30
30
  * @param {Object} componentTheme The theme variable object.
31
31
  * @param {Object} props the props of the component, the style is applied to
32
- * @param {Object} state the state of the component, the style is applied to
32
+ * @param {Object} extraArgs the state of the component, the style is applied to
33
33
  * @return {Object} The final style object, which will be used in the component
34
34
  */
35
- const generateStyle = (componentTheme, props) => {
36
- const hover = props.hover,
37
- isStacked = props.isStacked;
35
+ const generateStyle = (componentTheme, _props, extraArgs) => {
38
36
  return {
39
37
  row: {
40
38
  label: 'row',
@@ -47,7 +45,7 @@ const generateStyle = (componentTheme, props) => {
47
45
  borderBottomStyle: 'solid',
48
46
  borderBottomWidth: '0.0625rem',
49
47
  borderBottomColor: componentTheme.borderColor,
50
- ...(hover && {
48
+ ...(extraArgs.hover && {
51
49
  borderLeft: '0.1875rem solid transparent',
52
50
  borderRight: '0.1875rem solid transparent',
53
51
  '&:hover': {
@@ -55,7 +53,7 @@ const generateStyle = (componentTheme, props) => {
55
53
  borderRightColor: componentTheme.hoverBorderColor
56
54
  }
57
55
  }),
58
- ...(isStacked && {
56
+ ...(extraArgs.isStacked && {
59
57
  padding: componentTheme.padding
60
58
  })
61
59
  }
@@ -31,6 +31,7 @@ import { withStyle, jsx } from '@instructure/emotion';
31
31
  import generateStyle from './styles';
32
32
  import generateComponentTheme from './theme';
33
33
  import { allowedProps, propTypes } from './props';
34
+ import TableContext from '../TableContext';
34
35
 
35
36
  /**
36
37
  ---
@@ -50,8 +51,8 @@ let RowHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
50
51
  render() {
51
52
  const _this$props3 = this.props,
52
53
  children = _this$props3.children,
53
- isStacked = _this$props3.isStacked,
54
54
  styles = _this$props3.styles;
55
+ const isStacked = this.context.isStacked;
55
56
  return jsx(View, Object.assign({}, View.omitViewProps(omitProps(this.props, RowHeader.allowedProps), RowHeader), {
56
57
  as: isStacked ? 'div' : 'th',
57
58
  css: styles === null || styles === void 0 ? void 0 : styles.rowHeader,
@@ -59,7 +60,7 @@ let RowHeader = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_
59
60
  role: isStacked ? 'rowheader' : void 0
60
61
  }), callRenderProp(children));
61
62
  }
62
- }, _RowHeader.displayName = "RowHeader", _RowHeader.componentId = 'Table.RowHeader', _RowHeader.allowedProps = allowedProps, _RowHeader.propTypes = propTypes, _RowHeader.defaultProps = {
63
+ }, _RowHeader.displayName = "RowHeader", _RowHeader.componentId = 'Table.RowHeader', _RowHeader.contextType = TableContext, _RowHeader.allowedProps = allowedProps, _RowHeader.propTypes = propTypes, _RowHeader.defaultProps = {
63
64
  textAlign: 'start',
64
65
  children: null
65
66
  }, _RowHeader)) || _class);
@@ -25,8 +25,7 @@
25
25
  import PropTypes from 'prop-types';
26
26
  const propTypes = {
27
27
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
28
- isStacked: PropTypes.bool,
29
28
  textAlign: PropTypes.oneOf(['start', 'center', 'end'])
30
29
  };
31
- const allowedProps = ['children', 'isStacked', 'textAlign'];
30
+ const allowedProps = ['children', 'textAlign'];
32
31
  export { propTypes, allowedProps };
@@ -0,0 +1,34 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { createContext } from 'react';
26
+ /**
27
+ * React context created by the `Table` component to hold its data
28
+ */
29
+ const TableContext = /*#__PURE__*/createContext({
30
+ isStacked: false,
31
+ hover: false
32
+ });
33
+ export default TableContext;
34
+ export { TableContext };
@@ -1,4 +1,4 @@
1
- var _Table$Head, _Table$Body, _Table, _Table2, _Table3, _Table$Body2;
1
+ var _Table$Head, _Table$Body, _Table, _Table2, _Table3, _span, _span2, _Table$Row, _span3, _span4, _Table$Row2, _Table$Body2, _Table$RowHeader, _Table$Cell, _Table$Head2, _Table$Row3, _Table$ColHeader, _Table$RowHeader2, _Table$Cell2;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -127,6 +127,15 @@ describe('<Table />', async () => {
127
127
  expect(stackedTable).toBeInTheDocument();
128
128
  expect(stackedTable).not.toHaveTextContent('Foo');
129
129
  });
130
+ it('does not crash for invalid children', async () => {
131
+ render( /*#__PURE__*/React.createElement(Table, {
132
+ caption: "Test table",
133
+ layout: "stacked"
134
+ }, "test1", _span || (_span = /*#__PURE__*/React.createElement("span", null, "test")), /*#__PURE__*/React.createElement(Table.Head, null, _span2 || (_span2 = /*#__PURE__*/React.createElement("span", null, "test")), "test2", _Table$Row || (_Table$Row = /*#__PURE__*/React.createElement(Table.Row, null, "test3", /*#__PURE__*/React.createElement("span", null, "test"), /*#__PURE__*/React.createElement(Table.Cell, null, "Foo"))), "test4", _span3 || (_span3 = /*#__PURE__*/React.createElement("span", null, "test"))), "test5", /*#__PURE__*/React.createElement(Table.Body, null, "test", _span4 || (_span4 = /*#__PURE__*/React.createElement("span", null, "test")), _Table$Row2 || (_Table$Row2 = /*#__PURE__*/React.createElement(Table.Row, null, "test", /*#__PURE__*/React.createElement("span", null, "test"), /*#__PURE__*/React.createElement(Table.Cell, null, "Foo"), "test", /*#__PURE__*/React.createElement("span", null, "test"))))));
135
+ const table = screen.getByRole('table');
136
+ expect(table).toBeInTheDocument();
137
+ expect(table).toHaveTextContent('Foo');
138
+ });
130
139
  describe('when table is sortable', async () => {
131
140
  const renderSortableTable = (props, handlers = {}, layout = 'auto') => render( /*#__PURE__*/React.createElement(Table, {
132
141
  caption: "Sortable table",
@@ -216,4 +225,68 @@ describe('<Table />', async () => {
216
225
  expect(header).toHaveAttribute('aria-sort', 'descending');
217
226
  });
218
227
  });
228
+ describe('when using custom components', () => {
229
+ it('should render wrapper HOCs', () => {
230
+ var _CustomTableCell2;
231
+ class CustomTableCell extends React.Component {
232
+ render() {
233
+ return /*#__PURE__*/React.createElement(Table.Cell, this.props, this.props.children);
234
+ }
235
+ }
236
+ CustomTableCell.displayName = "CustomTableCell";
237
+ class CustomTableRow extends React.Component {
238
+ render() {
239
+ return /*#__PURE__*/React.createElement(Table.Row, this.props, _Table$RowHeader || (_Table$RowHeader = /*#__PURE__*/React.createElement(Table.RowHeader, null, "1")), _Table$Cell || (_Table$Cell = /*#__PURE__*/React.createElement(Table.Cell, null, "The Shawshank Redemption")), _CustomTableCell2 || (_CustomTableCell2 = /*#__PURE__*/React.createElement(CustomTableCell, null, "9.3")));
240
+ }
241
+ }
242
+ CustomTableRow.displayName = "CustomTableRow";
243
+ const table = render( /*#__PURE__*/React.createElement(Table, {
244
+ caption: "Test custom table"
245
+ }, _Table$Head2 || (_Table$Head2 = /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.ColHeader, {
246
+ id: "foo"
247
+ }, "ColHeader"), /*#__PURE__*/React.createElement(Table.ColHeader, {
248
+ id: "bar"
249
+ }, "Bar-header"), /*#__PURE__*/React.createElement(Table.ColHeader, {
250
+ id: "baz"
251
+ }, "Bar-header")))), /*#__PURE__*/React.createElement(Table.Body, null, /*#__PURE__*/React.createElement(CustomTableRow, null), _Table$Row3 || (_Table$Row3 = /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.RowHeader, null, "RowHeader"), /*#__PURE__*/React.createElement(Table.Cell, null, "Cell"), /*#__PURE__*/React.createElement(Table.Cell, null, "Cell2"))))));
252
+ const stackedTable = screen.getByRole('table');
253
+ expect(stackedTable).toBeInTheDocument();
254
+ const container = table.container;
255
+ expect(container).toBeInTheDocument();
256
+ expect(container).toHaveTextContent('The Shawshank Redemption');
257
+ expect(container).toHaveTextContent('9.3');
258
+ });
259
+ it('should render fully custom components', () => {
260
+ class CustomTableCell extends React.Component {
261
+ render() {
262
+ return /*#__PURE__*/React.createElement("td", null, this.props.children);
263
+ }
264
+ }
265
+ CustomTableCell.displayName = "CustomTableCell";
266
+ class CustomTableRow extends React.Component {
267
+ render() {
268
+ return /*#__PURE__*/React.createElement("tr", null, this.props.children);
269
+ }
270
+ }
271
+ CustomTableRow.displayName = "CustomTableRow";
272
+ const table = render( /*#__PURE__*/React.createElement(Table, {
273
+ caption: "Test custom table"
274
+ }, /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(CustomTableRow, null, /*#__PURE__*/React.createElement(CustomTableCell, {
275
+ id: "foo"
276
+ }, "ColHeader"), /*#__PURE__*/React.createElement(CustomTableCell, {
277
+ id: "bar"
278
+ }, "Bar-header"), _Table$ColHeader || (_Table$ColHeader = /*#__PURE__*/React.createElement(Table.ColHeader, {
279
+ id: "baz"
280
+ }, "Bar-header")))), /*#__PURE__*/React.createElement(Table.Body, null, /*#__PURE__*/React.createElement(CustomTableRow, null, _Table$RowHeader2 || (_Table$RowHeader2 = /*#__PURE__*/React.createElement(Table.RowHeader, null, "RowHeader2")), /*#__PURE__*/React.createElement(CustomTableCell, null, "Cell"), _Table$Cell2 || (_Table$Cell2 = /*#__PURE__*/React.createElement(Table.Cell, null, "Cell2"))))));
281
+ const stackedTable = screen.getByRole('table');
282
+ expect(stackedTable).toBeInTheDocument();
283
+ const container = table.container;
284
+ expect(container).toBeInTheDocument();
285
+ expect(container).toHaveTextContent('ColHeader');
286
+ expect(container).toHaveTextContent('Bar-header');
287
+ expect(container).toHaveTextContent('RowHeader2');
288
+ expect(container).toHaveTextContent('Cell');
289
+ expect(container).toHaveTextContent('Cell2');
290
+ });
291
+ });
219
292
  });