@instructure/ui-table 9.7.2 → 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 +11 -0
- package/es/Table/Body/index.js +13 -5
- 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 +21 -18
- 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 +66 -2
- package/es/Table/index.js +10 -6
- package/es/index.js +2 -1
- package/lib/Table/Body/index.js +13 -5
- 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 +18 -17
- 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 +66 -2
- package/lib/Table/index.js +10 -6
- package/lib/index.js +8 -1
- package/package.json +17 -17
- package/src/Table/Body/index.tsx +14 -7
- 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 +21 -23
- 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 +95 -2
- package/src/Table/index.tsx +32 -28
- 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.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/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,10 +57,11 @@ 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,
|
@@ -68,15 +70,21 @@ let Body = exports.Body = (_dec = (0, _emotion.withStyle)(_styles.default, _them
|
|
68
70
|
if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
69
71
|
return (0, _safeCloneElement.safeCloneElement)(child, {
|
70
72
|
key: child.props.name,
|
71
|
-
|
73
|
+
// Sent down for compatibility with custom components
|
74
|
+
// TODO DEPRECATED, remove in v11
|
72
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
|
73
81
|
headers
|
74
82
|
});
|
75
83
|
}
|
76
84
|
return child;
|
77
85
|
}));
|
78
86
|
}
|
79
|
-
}, _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 = {
|
80
88
|
children: null
|
81
89
|
}, _Body)) || _class);
|
82
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
@@ -8,14 +8,12 @@ exports.default = exports.Row = void 0;
|
|
8
8
|
var _react = require("react");
|
9
9
|
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
10
10
|
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
11
|
-
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
12
11
|
var _View = require("@instructure/ui-view/lib/View");
|
13
12
|
var _emotion = require("@instructure/emotion");
|
14
13
|
var _styles = _interopRequireDefault(require("./styles"));
|
15
14
|
var _theme = _interopRequireDefault(require("./theme"));
|
16
|
-
var _Cell = require("../Cell");
|
17
|
-
var _RowHeader = require("../RowHeader");
|
18
15
|
var _props = require("./props");
|
16
|
+
var _TableContext = _interopRequireDefault(require("../TableContext"));
|
19
17
|
var _dec, _class, _Row;
|
20
18
|
/*
|
21
19
|
* The MIT License (MIT)
|
@@ -50,40 +48,43 @@ id: Table.Row
|
|
50
48
|
let Row = exports.Row = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_Row = class Row extends _react.Component {
|
51
49
|
componentDidMount() {
|
52
50
|
var _this$props$makeStyle, _this$props;
|
53
|
-
(_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
|
+
});
|
54
55
|
}
|
55
56
|
componentDidUpdate() {
|
56
57
|
var _this$props$makeStyle2, _this$props2;
|
57
|
-
(_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
|
+
});
|
58
62
|
}
|
59
63
|
render() {
|
60
64
|
const _this$props3 = this.props,
|
61
65
|
children = _this$props3.children,
|
62
|
-
styles = _this$props3.styles
|
63
|
-
|
64
|
-
|
66
|
+
styles = _this$props3.styles;
|
67
|
+
const isStacked = this.context.isStacked;
|
68
|
+
const headers = this.context.headers;
|
65
69
|
return (0, _emotion.jsx)(_View.View, Object.assign({}, _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Row.allowedProps), Row), {
|
66
70
|
as: isStacked ? 'div' : 'tr',
|
67
71
|
css: styles === null || styles === void 0 ? void 0 : styles.row,
|
68
72
|
role: isStacked ? 'row' : void 0
|
69
73
|
}), _react.Children.toArray(children).filter(Boolean).map((child, index) => {
|
70
|
-
if ((0,
|
74
|
+
if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
71
75
|
return (0, _safeCloneElement.safeCloneElement)(child, {
|
72
|
-
key:
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_Cell.Cell])) {
|
77
|
-
return (0, _safeCloneElement.safeCloneElement)(child, {
|
78
|
-
key: index,
|
76
|
+
key: child.props.name,
|
77
|
+
// Sent down for compatibility with custom components
|
78
|
+
// TODO DEPRECATED, remove in v11
|
79
79
|
isStacked,
|
80
|
+
// used by `Cell` to render its column title in `stacked` layout
|
80
81
|
header: headers && headers[index]
|
81
82
|
});
|
82
83
|
}
|
83
84
|
return child;
|
84
85
|
}));
|
85
86
|
}
|
86
|
-
}, _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 = {
|
87
88
|
children: null
|
88
89
|
}, _Row)) || _class);
|
89
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, _span, _Table$Row,
|
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
|
*
|
@@ -133,7 +133,7 @@ describe('<Table />', async () => {
|
|
133
133
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Table, {
|
134
134
|
caption: "Test table",
|
135
135
|
layout: "stacked"
|
136
|
-
}, /*#__PURE__*/_react.default.createElement(_index.Table.Head, null,
|
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
137
|
const table = _react2.screen.getByRole('table');
|
138
138
|
expect(table).toBeInTheDocument();
|
139
139
|
expect(table).toHaveTextContent('Foo');
|
@@ -227,4 +227,68 @@ describe('<Table />', async () => {
|
|
227
227
|
expect(header).toHaveAttribute('aria-sort', 'descending');
|
228
228
|
});
|
229
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
|
+
});
|
230
294
|
});
|
package/lib/Table/index.js
CHANGED
@@ -21,6 +21,7 @@ var _ColHeader = require("./ColHeader");
|
|
21
21
|
var _RowHeader = require("./RowHeader");
|
22
22
|
var _Cell = require("./Cell");
|
23
23
|
var _props = require("./props");
|
24
|
+
var _TableContext = _interopRequireDefault(require("./TableContext"));
|
24
25
|
var _dec, _class, _Table;
|
25
26
|
/*
|
26
27
|
* The MIT License (MIT)
|
@@ -95,7 +96,13 @@ let Table = exports.Table = (_dec = (0, _emotion.withStyle)(_styles.default, _th
|
|
95
96
|
styles = _this$props3.styles;
|
96
97
|
const isStacked = layout === 'stacked';
|
97
98
|
const headers = isStacked ? this.getHeaders() : void 0;
|
98
|
-
return (0, _emotion.jsx)(
|
99
|
+
return (0, _emotion.jsx)(_TableContext.default.Provider, {
|
100
|
+
value: {
|
101
|
+
isStacked: isStacked,
|
102
|
+
hover: hover,
|
103
|
+
headers: headers
|
104
|
+
}
|
105
|
+
}, (0, _emotion.jsx)(_View.View, Object.assign({}, _View.View.omitViewProps((0, _omitProps.omitProps)(this.props, Table.allowedProps), Table), {
|
99
106
|
as: isStacked ? 'div' : 'table',
|
100
107
|
margin: margin,
|
101
108
|
elementRef: this.handleRef,
|
@@ -105,14 +112,11 @@ let Table = exports.Table = (_dec = (0, _emotion.withStyle)(_styles.default, _th
|
|
105
112
|
}), !isStacked && (0, _emotion.jsx)("caption", null, (0, _emotion.jsx)(_ScreenReaderContent.ScreenReaderContent, null, caption)), _react.Children.map(children, child => {
|
106
113
|
if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
|
107
114
|
return (0, _safeCloneElement.safeCloneElement)(child, {
|
108
|
-
key: child.props.name
|
109
|
-
isStacked,
|
110
|
-
hover,
|
111
|
-
headers
|
115
|
+
key: child.props.name
|
112
116
|
});
|
113
117
|
}
|
114
118
|
return child;
|
115
|
-
}));
|
119
|
+
})));
|
116
120
|
}
|
117
121
|
}, _Table.displayName = "Table", _Table.componentId = 'Table', _Table.allowedProps = _props.allowedProps, _Table.propTypes = _props.propTypes, _Table.defaultProps = {
|
118
122
|
children: null,
|
package/lib/index.js
CHANGED
@@ -9,4 +9,11 @@ Object.defineProperty(exports, "Table", {
|
|
9
9
|
return _Table.Table;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
|
12
|
+
Object.defineProperty(exports, "TableContext", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _TableContext.TableContext;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _Table = require("./Table");
|
19
|
+
var _TableContext = require("./Table/TableContext");
|