@instructure/ui-table 10.2.1-snapshot-3 → 10.2.1-snapshot-11
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 +1 -1
- package/es/Table/Body/index.js +24 -11
- package/es/Table/Body/props.js +2 -5
- package/es/Table/Body/styles.js +0 -2
- package/es/Table/Cell/index.js +3 -2
- package/es/Table/Cell/props.js +1 -2
- package/es/Table/ColHeader/styles.js +0 -1
- package/es/Table/Head/index.js +40 -30
- package/es/Table/Head/props.js +1 -3
- package/es/Table/Head/styles.js +0 -2
- package/es/Table/Row/index.js +25 -12
- package/es/Table/Row/props.js +2 -5
- package/es/Table/Row/styles.js +4 -6
- package/es/Table/RowHeader/index.js +3 -2
- package/es/Table/RowHeader/props.js +1 -2
- package/es/Table/TableContext.js +34 -0
- package/es/Table/__new-tests__/Table.test.js +74 -1
- package/es/Table/index.js +25 -17
- package/es/index.js +2 -1
- package/lib/Table/Body/index.js +23 -10
- package/lib/Table/Body/props.js +2 -5
- package/lib/Table/Body/styles.js +0 -2
- package/lib/Table/Cell/index.js +3 -2
- package/lib/Table/Cell/props.js +1 -2
- package/lib/Table/ColHeader/styles.js +0 -1
- package/lib/Table/Head/index.js +39 -30
- package/lib/Table/Head/props.js +1 -3
- package/lib/Table/Head/styles.js +0 -2
- package/lib/Table/Row/index.js +24 -11
- package/lib/Table/Row/props.js +2 -5
- package/lib/Table/Row/styles.js +4 -6
- package/lib/Table/RowHeader/index.js +3 -2
- package/lib/Table/RowHeader/props.js +1 -2
- package/lib/Table/TableContext.js +39 -0
- package/lib/Table/__new-tests__/Table.test.js +74 -1
- package/lib/Table/index.js +24 -16
- package/lib/index.js +8 -1
- package/package.json +17 -17
- package/src/Table/Body/index.tsx +23 -13
- package/src/Table/Body/props.ts +6 -18
- package/src/Table/Body/styles.ts +0 -2
- package/src/Table/Cell/index.tsx +6 -3
- package/src/Table/Cell/props.ts +7 -9
- package/src/Table/ColHeader/props.ts +7 -4
- package/src/Table/ColHeader/styles.ts +0 -1
- package/src/Table/Head/index.tsx +40 -40
- package/src/Table/Head/props.ts +20 -13
- package/src/Table/Head/styles.ts +0 -2
- package/src/Table/README.md +299 -2
- package/src/Table/Row/index.tsx +27 -11
- package/src/Table/Row/props.ts +7 -19
- package/src/Table/Row/styles.ts +5 -6
- package/src/Table/RowHeader/index.tsx +6 -4
- package/src/Table/RowHeader/props.ts +1 -3
- package/src/Table/TableContext.ts +54 -0
- package/src/Table/__new-tests__/Table.test.tsx +131 -2
- package/src/Table/index.tsx +42 -44
- package/src/Table/props.ts +8 -28
- package/src/index.ts +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Table/Body/index.d.ts +6 -13
- package/types/Table/Body/index.d.ts.map +1 -1
- package/types/Table/Body/props.d.ts +4 -5
- package/types/Table/Body/props.d.ts.map +1 -1
- package/types/Table/Body/styles.d.ts +0 -2
- package/types/Table/Body/styles.d.ts.map +1 -1
- package/types/Table/Cell/index.d.ts +4 -3
- package/types/Table/Cell/index.d.ts.map +1 -1
- package/types/Table/Cell/props.d.ts +6 -2
- package/types/Table/Cell/props.d.ts.map +1 -1
- package/types/Table/ColHeader/props.d.ts +6 -3
- package/types/Table/ColHeader/props.d.ts.map +1 -1
- package/types/Table/ColHeader/styles.d.ts +0 -1
- package/types/Table/ColHeader/styles.d.ts.map +1 -1
- package/types/Table/Head/index.d.ts +15 -7
- package/types/Table/Head/index.d.ts.map +1 -1
- package/types/Table/Head/props.d.ts +19 -5
- package/types/Table/Head/props.d.ts.map +1 -1
- package/types/Table/Head/styles.d.ts +0 -2
- package/types/Table/Head/styles.d.ts.map +1 -1
- package/types/Table/Row/index.d.ts +6 -13
- package/types/Table/Row/index.d.ts.map +1 -1
- package/types/Table/Row/props.d.ts +5 -6
- package/types/Table/Row/props.d.ts.map +1 -1
- package/types/Table/Row/styles.d.ts +5 -2
- package/types/Table/Row/styles.d.ts.map +1 -1
- package/types/Table/RowHeader/index.d.ts +4 -3
- package/types/Table/RowHeader/index.d.ts.map +1 -1
- package/types/Table/RowHeader/props.d.ts +0 -1
- package/types/Table/RowHeader/props.d.ts.map +1 -1
- package/types/Table/TableContext.d.ts +24 -0
- package/types/Table/TableContext.d.ts.map +1 -0
- package/types/Table/index.d.ts +1 -1
- package/types/Table/index.d.ts.map +1 -1
- package/types/Table/props.d.ts +10 -22
- package/types/Table/props.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@
|
|
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
|
-
## [10.2.1-snapshot-
|
6
|
+
## [10.2.1-snapshot-11](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1-snapshot-11) (2024-08-30)
|
7
7
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-table
|
9
9
|
|
package/es/Table/Body/index.js
CHANGED
@@ -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 =>
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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;
|
package/es/Table/Body/props.js
CHANGED
@@ -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'
|
29
|
+
const allowedProps = ['children'];
|
33
30
|
export { propTypes, allowedProps };
|
package/es/Table/Body/styles.js
CHANGED
@@ -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 => {
|
package/es/Table/Cell/index.js
CHANGED
@@ -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);
|
package/es/Table/Cell/props.js
CHANGED
@@ -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', '
|
31
|
+
const allowedProps = ['children', 'header', 'textAlign'];
|
33
32
|
export { propTypes, allowedProps };
|
@@ -29,7 +29,6 @@
|
|
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
|
33
32
|
* @return {Object} The final style object, which will be used in the component
|
34
33
|
*/
|
35
34
|
const generateStyle = (componentTheme, props) => {
|
package/es/Table/Head/index.js
CHANGED
@@ -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,
|
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
|
-
|
53
|
+
firstRow = _ref2[0];
|
52
54
|
let sortable = false;
|
53
|
-
if (
|
54
|
-
Children.forEach(
|
55
|
-
if (
|
56
|
-
|
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
|
-
|
80
|
-
if (!
|
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(
|
97
|
+
Children.forEach(firstRow.props.children, grandchild => {
|
88
98
|
count += 1;
|
89
|
-
if (
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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() :
|
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
|
-
}),
|
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;
|
package/es/Table/Head/props.js
CHANGED
@@ -25,9 +25,7 @@
|
|
25
25
|
import PropTypes from 'prop-types';
|
26
26
|
const propTypes = {
|
27
27
|
children: PropTypes.node,
|
28
|
-
hover: PropTypes.bool,
|
29
|
-
isStacked: PropTypes.bool,
|
30
28
|
renderSortLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
31
29
|
};
|
32
|
-
const allowedProps = ['children', '
|
30
|
+
const allowedProps = ['children', 'renderSortLabel'];
|
33
31
|
export { propTypes, allowedProps };
|
package/es/Table/Head/styles.js
CHANGED
@@ -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 => {
|
package/es/Table/Row/index.js
CHANGED
@@ -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
|
-
|
55
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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;
|
package/es/Table/Row/props.js
CHANGED
@@ -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'
|
29
|
+
const allowedProps = ['children'];
|
33
30
|
export { propTypes, allowedProps };
|
package/es/Table/Row/styles.js
CHANGED
@@ -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}
|
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,
|
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', '
|
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
|
*
|
@@ -130,6 +130,15 @@ describe('<Table />', async () => {
|
|
130
130
|
expect(stackedTable).toBeInTheDocument();
|
131
131
|
expect(stackedTable).not.toHaveTextContent('Foo');
|
132
132
|
});
|
133
|
+
it('does not crash for invalid children', async () => {
|
134
|
+
render( /*#__PURE__*/React.createElement(Table, {
|
135
|
+
caption: "Test table",
|
136
|
+
layout: "stacked"
|
137
|
+
}, "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"))))));
|
138
|
+
const table = screen.getByRole('table');
|
139
|
+
expect(table).toBeInTheDocument();
|
140
|
+
expect(table).toHaveTextContent('Foo');
|
141
|
+
});
|
133
142
|
|
134
143
|
// see https://github.com/vitest-dev/eslint-plugin-vitest/issues/511
|
135
144
|
// eslint-disable-next-line vitest/valid-describe-callback
|
@@ -222,4 +231,68 @@ describe('<Table />', async () => {
|
|
222
231
|
expect(header).toHaveAttribute('aria-sort', 'descending');
|
223
232
|
});
|
224
233
|
});
|
234
|
+
describe('when using custom components', () => {
|
235
|
+
it('should render wrapper HOCs', () => {
|
236
|
+
var _CustomTableCell2;
|
237
|
+
class CustomTableCell extends React.Component {
|
238
|
+
render() {
|
239
|
+
return /*#__PURE__*/React.createElement(Table.Cell, this.props, this.props.children);
|
240
|
+
}
|
241
|
+
}
|
242
|
+
CustomTableCell.displayName = "CustomTableCell";
|
243
|
+
class CustomTableRow extends React.Component {
|
244
|
+
render() {
|
245
|
+
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")));
|
246
|
+
}
|
247
|
+
}
|
248
|
+
CustomTableRow.displayName = "CustomTableRow";
|
249
|
+
const table = render( /*#__PURE__*/React.createElement(Table, {
|
250
|
+
caption: "Test custom table"
|
251
|
+
}, _Table$Head2 || (_Table$Head2 = /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(Table.Row, null, /*#__PURE__*/React.createElement(Table.ColHeader, {
|
252
|
+
id: "foo"
|
253
|
+
}, "ColHeader"), /*#__PURE__*/React.createElement(Table.ColHeader, {
|
254
|
+
id: "bar"
|
255
|
+
}, "Bar-header"), /*#__PURE__*/React.createElement(Table.ColHeader, {
|
256
|
+
id: "baz"
|
257
|
+
}, "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"))))));
|
258
|
+
const stackedTable = screen.getByRole('table');
|
259
|
+
expect(stackedTable).toBeInTheDocument();
|
260
|
+
const container = table.container;
|
261
|
+
expect(container).toBeInTheDocument();
|
262
|
+
expect(container).toHaveTextContent('The Shawshank Redemption');
|
263
|
+
expect(container).toHaveTextContent('9.3');
|
264
|
+
});
|
265
|
+
it('should render fully custom components', () => {
|
266
|
+
class CustomTableCell extends React.Component {
|
267
|
+
render() {
|
268
|
+
return /*#__PURE__*/React.createElement("td", null, this.props.children);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
CustomTableCell.displayName = "CustomTableCell";
|
272
|
+
class CustomTableRow extends React.Component {
|
273
|
+
render() {
|
274
|
+
return /*#__PURE__*/React.createElement("tr", null, this.props.children);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
CustomTableRow.displayName = "CustomTableRow";
|
278
|
+
const table = render( /*#__PURE__*/React.createElement(Table, {
|
279
|
+
caption: "Test custom table"
|
280
|
+
}, /*#__PURE__*/React.createElement(Table.Head, null, /*#__PURE__*/React.createElement(CustomTableRow, null, /*#__PURE__*/React.createElement(CustomTableCell, {
|
281
|
+
id: "foo"
|
282
|
+
}, "ColHeader"), /*#__PURE__*/React.createElement(CustomTableCell, {
|
283
|
+
id: "bar"
|
284
|
+
}, "Bar-header"), _Table$ColHeader || (_Table$ColHeader = /*#__PURE__*/React.createElement(Table.ColHeader, {
|
285
|
+
id: "baz"
|
286
|
+
}, "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"))))));
|
287
|
+
const stackedTable = screen.getByRole('table');
|
288
|
+
expect(stackedTable).toBeInTheDocument();
|
289
|
+
const container = table.container;
|
290
|
+
expect(container).toBeInTheDocument();
|
291
|
+
expect(container).toHaveTextContent('ColHeader');
|
292
|
+
expect(container).toHaveTextContent('Bar-header');
|
293
|
+
expect(container).toHaveTextContent('RowHeader2');
|
294
|
+
expect(container).toHaveTextContent('Cell');
|
295
|
+
expect(container).toHaveTextContent('Cell2');
|
296
|
+
});
|
297
|
+
});
|
225
298
|
});
|