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