@sb1/ffe-tables-react 8.0.31 → 8.0.33
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/es/DefaultTable/DefaultTable.js +144 -197
- package/es/DefaultTable/DefaultTable.spec.js +441 -0
- package/es/SortableTable/SortableTable.js +127 -187
- package/es/SortableTable/SortableTable.spec.js +68 -0
- package/es/SortableTable/sort-data.js +28 -29
- package/es/SortableTable/sort-data.spec.js +53 -0
- package/es/Table.js +101 -83
- package/es/TableParts/TableCell.js +19 -31
- package/es/TableParts/TableFooter.js +61 -72
- package/es/TableParts/TableHeaders.js +52 -59
- package/es/TableParts/TableRow.js +54 -74
- package/es/TableParts/TableRowExpandable.js +90 -128
- package/es/TableParts/TableRowExpandable.spec.js +99 -0
- package/es/index.js +1 -1
- package/lib/DefaultTable/DefaultTable.js +176 -210
- package/lib/DefaultTable/DefaultTable.spec.js +446 -0
- package/lib/SortableTable/SortableTable.js +160 -201
- package/lib/SortableTable/SortableTable.spec.js +73 -0
- package/lib/SortableTable/sort-data.js +30 -35
- package/lib/SortableTable/sort-data.spec.js +58 -0
- package/lib/Table.js +108 -92
- package/lib/TableParts/TableCell.js +26 -40
- package/lib/TableParts/TableFooter.js +69 -82
- package/lib/TableParts/TableHeaders.js +58 -67
- package/lib/TableParts/TableRow.js +62 -84
- package/lib/TableParts/TableRowExpandable.js +123 -142
- package/lib/TableParts/TableRowExpandable.spec.js +104 -0
- package/lib/index.js +6 -8
- package/package.json +7 -7
- package/es/index.d.js +0 -1
- package/lib/index.d.js +0 -6
|
@@ -1,81 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
7
12
|
import React from 'react';
|
|
8
13
|
import PropTypes from 'prop-types';
|
|
9
14
|
import classNames from 'classnames';
|
|
10
15
|
import TableCell from './TableCell';
|
|
11
|
-
var TableRow = function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
columnHeader: column.header,
|
|
33
|
-
key: index,
|
|
34
|
-
tdClasses: classNames({
|
|
35
|
-
'ffe-table__cell--collapsed': column.key === 'expandIcon'
|
|
36
|
-
}, {
|
|
37
|
-
'ffe-table--hide-sm': column.hideOnMobile
|
|
38
|
-
}, {
|
|
39
|
-
'ffe-table--hide-md': column.hideOnSmallTablet
|
|
40
|
-
}, {
|
|
41
|
-
'ffe-table--hide-lg': column.hideOnTablet
|
|
42
|
-
}, {
|
|
43
|
-
'ffe-table--hide-xlg': column.hideOnDesktop
|
|
44
|
-
})
|
|
45
|
-
}, column.cellRender ? column.cellRender(cells[column.key], column, props, index) : cells[column.key]);
|
|
46
|
-
});
|
|
47
|
-
var trprops = _objectSpread(_objectSpread({
|
|
48
|
-
className: classNames('ffe-table__row', trClasses)
|
|
49
|
-
}, expandableProps), {}, {
|
|
50
|
-
onClick: onClick,
|
|
51
|
-
children: rowContent
|
|
52
|
-
});
|
|
53
|
-
if (typeof rowRender === 'function') {
|
|
54
|
-
return rowRender(trprops, props, rowIndex);
|
|
55
|
-
}
|
|
56
|
-
return /*#__PURE__*/React.createElement("tr", trprops, rowContent);
|
|
16
|
+
var TableRow = function (props) {
|
|
17
|
+
var cells = props.cells, columns = props.columns, onClick = props.onClick, onKeyDown = props.onKeyDown, trClasses = props.trClasses, expandable = props.expandable, expanded = props.expanded, rowRender = props.rowRender, rowIndex = props.rowIndex;
|
|
18
|
+
var expandableProps = expandable && {
|
|
19
|
+
'aria-expanded': expanded,
|
|
20
|
+
onClick: onClick,
|
|
21
|
+
onKeyDown: onKeyDown,
|
|
22
|
+
role: 'button',
|
|
23
|
+
tabIndex: '0',
|
|
24
|
+
};
|
|
25
|
+
var rowContent = columns.map(function (column, index) {
|
|
26
|
+
return (React.createElement(TableCell, { alignRight: column.alignRight, alignTop: column.alignTop, columnHeader: column.header, key: index, tdClasses: classNames({
|
|
27
|
+
'ffe-table__cell--collapsed': column.key === 'expandIcon',
|
|
28
|
+
}, { 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop }) }, column.cellRender
|
|
29
|
+
? column.cellRender(cells[column.key], column, props, index)
|
|
30
|
+
: cells[column.key]));
|
|
31
|
+
});
|
|
32
|
+
var trprops = __assign(__assign({ className: classNames('ffe-table__row', trClasses) }, expandableProps), { onClick: onClick, children: rowContent });
|
|
33
|
+
if (typeof rowRender === 'function') {
|
|
34
|
+
return rowRender(trprops, props, rowIndex);
|
|
35
|
+
}
|
|
36
|
+
return React.createElement("tr", __assign({}, trprops), rowContent);
|
|
57
37
|
};
|
|
58
38
|
TableRow.propTypes = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
39
|
+
cells: PropTypes.object.isRequired,
|
|
40
|
+
columns: PropTypes.arrayOf(PropTypes.shape({
|
|
41
|
+
alignRight: PropTypes.bool,
|
|
42
|
+
alignTop: PropTypes.bool,
|
|
43
|
+
header: PropTypes.any,
|
|
44
|
+
hideOnDesktop: PropTypes.bool,
|
|
45
|
+
hideOnMobile: PropTypes.bool,
|
|
46
|
+
hideOnSmallTablet: PropTypes.bool,
|
|
47
|
+
hideOnTablet: PropTypes.bool,
|
|
48
|
+
key: PropTypes.string,
|
|
49
|
+
cellRender: PropTypes.func,
|
|
50
|
+
})).isRequired,
|
|
51
|
+
expandable: PropTypes.bool,
|
|
52
|
+
expanded: PropTypes.bool,
|
|
53
|
+
onClick: PropTypes.func,
|
|
54
|
+
rowRender: PropTypes.func,
|
|
55
|
+
headerRender: PropTypes.func,
|
|
56
|
+
footerRender: PropTypes.func,
|
|
57
|
+
onKeyDown: PropTypes.func,
|
|
58
|
+
trClasses: PropTypes.string,
|
|
59
|
+
rowIndex: PropTypes.number,
|
|
80
60
|
};
|
|
81
|
-
export default TableRow;
|
|
61
|
+
export default TableRow;
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
17
27
|
import { Icon } from '@sb1/ffe-icons-react';
|
|
18
28
|
import classNames from 'classnames';
|
|
19
29
|
import PropTypes from 'prop-types';
|
|
@@ -21,120 +31,72 @@ import React, { Component } from 'react';
|
|
|
21
31
|
import { polyfill } from 'react-lifecycles-compat';
|
|
22
32
|
import shallowEqual from 'shallow-equals';
|
|
23
33
|
import TableRow from './TableRow';
|
|
24
|
-
var TableRowExpandable =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
sort: props.sort
|
|
34
|
-
};
|
|
35
|
-
_this.rowRef = /*#__PURE__*/React.createRef();
|
|
36
|
-
return _this;
|
|
37
|
-
}
|
|
38
|
-
_inherits(TableRowExpandable, _Component);
|
|
39
|
-
return _createClass(TableRowExpandable, [{
|
|
40
|
-
key: "componentDidMount",
|
|
41
|
-
value: function componentDidMount() {
|
|
42
|
-
if (this.props.scrollToOnMount && this.rowRef.current) {
|
|
43
|
-
this.rowRef.current.scrollIntoView();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
|
-
key: "toggleExpand",
|
|
48
|
-
value: function toggleExpand() {
|
|
49
|
-
this.setState(function (prevState) {
|
|
50
|
-
return {
|
|
51
|
-
expanded: !prevState.expanded
|
|
34
|
+
var TableRowExpandable = /** @class */ (function (_super) {
|
|
35
|
+
__extends(TableRowExpandable, _super);
|
|
36
|
+
function TableRowExpandable(props) {
|
|
37
|
+
var _this = _super.call(this, props) || this;
|
|
38
|
+
_this.handleKeyPress = _this.handleKeyPress.bind(_this);
|
|
39
|
+
_this.toggleExpand = _this.toggleExpand.bind(_this);
|
|
40
|
+
_this.state = {
|
|
41
|
+
expanded: !!props.defaultExpanded,
|
|
42
|
+
sort: props.sort,
|
|
52
43
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}, {
|
|
56
|
-
key: "handleKeyPress",
|
|
57
|
-
value: function handleKeyPress(event) {
|
|
58
|
-
if ((event.key === 'Enter' || event.key === ' ') && event.target.tagName === 'TR') {
|
|
59
|
-
this.setState(function (prevState) {
|
|
60
|
-
return {
|
|
61
|
-
expanded: !prevState.expanded
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
event.preventDefault();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "render",
|
|
69
|
-
value: function render() {
|
|
70
|
-
var _this$props = this.props,
|
|
71
|
-
cells = _this$props.cells,
|
|
72
|
-
columns = _this$props.columns,
|
|
73
|
-
children = _this$props.children,
|
|
74
|
-
rowRender = _this$props.rowRender,
|
|
75
|
-
rowIndex = _this$props.rowIndex;
|
|
76
|
-
var unexpandable = !children;
|
|
77
|
-
return /*#__PURE__*/React.createElement("tbody", {
|
|
78
|
-
ref: this.rowRef
|
|
79
|
-
}, /*#__PURE__*/React.createElement(TableRow, {
|
|
80
|
-
cells: _objectSpread(_objectSpread({}, cells), {}, {
|
|
81
|
-
expandIcon: unexpandable ? ' ' : /*#__PURE__*/React.createElement(Icon, {
|
|
82
|
-
className: classNames('ffe-table__expand-icon', {
|
|
83
|
-
'ffe-table__expand-icon--expanded': this.state.expanded
|
|
84
|
-
}),
|
|
85
|
-
fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+",
|
|
86
|
-
size: "md"
|
|
87
|
-
})
|
|
88
|
-
}),
|
|
89
|
-
trClasses: classNames({
|
|
90
|
-
'ffe-table__row-expandable': !unexpandable
|
|
91
|
-
}, {
|
|
92
|
-
'ffe-table__row-expandable--expanded': this.state.expanded
|
|
93
|
-
}),
|
|
94
|
-
columns: columns,
|
|
95
|
-
onClick: this.toggleExpand,
|
|
96
|
-
onKeyDown: this.handleKeyPress,
|
|
97
|
-
expandable: !unexpandable,
|
|
98
|
-
expanded: this.state.expanded,
|
|
99
|
-
rowRender: rowRender,
|
|
100
|
-
rowIndex: rowIndex
|
|
101
|
-
}), /*#__PURE__*/React.createElement("tr", {
|
|
102
|
-
role: "presentation",
|
|
103
|
-
"aria-hidden": String(!this.state.expanded),
|
|
104
|
-
className: classNames('ffe-table__row', 'ffe-table__row-expandable-content', {
|
|
105
|
-
'ffe-table__row-expandable-content--expanded': this.state.expanded
|
|
106
|
-
}, {
|
|
107
|
-
'ffe-table__row--collapsed': !this.state.expanded
|
|
108
|
-
})
|
|
109
|
-
}, /*#__PURE__*/React.createElement("td", {
|
|
110
|
-
colSpan: columns.length,
|
|
111
|
-
className: "ffe-table__cell-expandable-content"
|
|
112
|
-
}, /*#__PURE__*/React.createElement("div", null, this.state.expanded && children))));
|
|
44
|
+
_this.rowRef = React.createRef();
|
|
45
|
+
return _this;
|
|
113
46
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
47
|
+
TableRowExpandable.prototype.componentDidMount = function () {
|
|
48
|
+
if (this.props.scrollToOnMount && this.rowRef.current) {
|
|
49
|
+
this.rowRef.current.scrollIntoView();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
TableRowExpandable.getDerivedStateFromProps = function (nextProps, prevState) {
|
|
53
|
+
if ((!nextProps.children && prevState.expanded) ||
|
|
54
|
+
!shallowEqual(nextProps.sort, prevState.sort)) {
|
|
55
|
+
return {
|
|
56
|
+
expanded: false,
|
|
57
|
+
sort: nextProps.sort,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
TableRowExpandable.prototype.toggleExpand = function () {
|
|
63
|
+
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
64
|
+
};
|
|
65
|
+
TableRowExpandable.prototype.handleKeyPress = function (event) {
|
|
66
|
+
if ((event.key === 'Enter' || event.key === ' ') &&
|
|
67
|
+
event.target.tagName === 'TR') {
|
|
68
|
+
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
TableRowExpandable.prototype.render = function () {
|
|
73
|
+
var _a = this.props, cells = _a.cells, columns = _a.columns, children = _a.children, rowRender = _a.rowRender, rowIndex = _a.rowIndex;
|
|
74
|
+
var unexpandable = !children;
|
|
75
|
+
return (React.createElement("tbody", { ref: this.rowRef },
|
|
76
|
+
React.createElement(TableRow, { cells: __assign(__assign({}, cells), { expandIcon: unexpandable ? (' ') : (React.createElement(Icon, { className: classNames('ffe-table__expand-icon', {
|
|
77
|
+
'ffe-table__expand-icon--expanded': this.state.expanded,
|
|
78
|
+
}), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" })) }), trClasses: classNames({ 'ffe-table__row-expandable': !unexpandable }, {
|
|
79
|
+
'ffe-table__row-expandable--expanded': this.state.expanded,
|
|
80
|
+
}), columns: columns, onClick: this.toggleExpand, onKeyDown: this.handleKeyPress, expandable: !unexpandable, expanded: this.state.expanded, rowRender: rowRender, rowIndex: rowIndex }),
|
|
81
|
+
React.createElement("tr", { role: "presentation", "aria-hidden": String(!this.state.expanded), className: classNames('ffe-table__row', 'ffe-table__row-expandable-content', {
|
|
82
|
+
'ffe-table__row-expandable-content--expanded': this.state.expanded,
|
|
83
|
+
}, { 'ffe-table__row--collapsed': !this.state.expanded }) },
|
|
84
|
+
React.createElement("td", { colSpan: columns.length, className: "ffe-table__cell-expandable-content" },
|
|
85
|
+
React.createElement("div", null, this.state.expanded && children)))));
|
|
86
|
+
};
|
|
87
|
+
return TableRowExpandable;
|
|
88
|
+
}(Component));
|
|
127
89
|
TableRowExpandable.propTypes = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
90
|
+
children: PropTypes.node,
|
|
91
|
+
cells: PropTypes.object.isRequired,
|
|
92
|
+
columns: PropTypes.array.isRequired,
|
|
93
|
+
sort: PropTypes.object,
|
|
94
|
+
rowRender: PropTypes.func,
|
|
95
|
+
headerRender: PropTypes.func,
|
|
96
|
+
footerRender: PropTypes.func,
|
|
97
|
+
rowIndex: PropTypes.number,
|
|
98
|
+
defaultExpanded: PropTypes.bool,
|
|
99
|
+
scrollToOnMount: PropTypes.bool,
|
|
138
100
|
};
|
|
139
101
|
polyfill(TableRowExpandable);
|
|
140
|
-
export default TableRowExpandable;
|
|
102
|
+
export default TableRowExpandable;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import TableRowExpandable from './TableRowExpandable';
|
|
14
|
+
var props = {
|
|
15
|
+
cells: {
|
|
16
|
+
name: 'Ola Normann',
|
|
17
|
+
address: 'Gateveien 2',
|
|
18
|
+
age: 23,
|
|
19
|
+
phone: '912 34 567',
|
|
20
|
+
email: 'ola@normann.no',
|
|
21
|
+
},
|
|
22
|
+
columns: [
|
|
23
|
+
{ key: 'name', content: 'Navn' },
|
|
24
|
+
{ key: 'address', content: 'Adresse' },
|
|
25
|
+
{ key: 'age', content: 'Alder', alignRight: true },
|
|
26
|
+
{ key: 'phone', content: 'Telefon' },
|
|
27
|
+
{ key: 'email', content: 'E-post' },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
var wrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props),
|
|
31
|
+
React.createElement("p", null, "The cake is a lie")));
|
|
32
|
+
var unexpandableWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props), false && React.createElement("div", null, "Ignorance is bliss, and we won't render this")));
|
|
33
|
+
var defaultExpandedWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props, { defaultExpanded: true }),
|
|
34
|
+
React.createElement("p", null, "The cake is a lie")));
|
|
35
|
+
describe('<TableRowExpandable>', function () {
|
|
36
|
+
it('should be collapsed by default', function () {
|
|
37
|
+
expect(wrapper.state().expanded).toBe(false);
|
|
38
|
+
expect(wrapper.find('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
39
|
+
expect(wrapper
|
|
40
|
+
.find('.ffe-table__row-expandable-content')
|
|
41
|
+
.prop('aria-hidden')).toBe('true');
|
|
42
|
+
expect(wrapper
|
|
43
|
+
.find('.ffe-table__row-expandable-content')
|
|
44
|
+
.hasClass('ffe-table__row--collapsed')).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
it('should be expanded if provided true defaultExpanded', function () {
|
|
47
|
+
expect(defaultExpandedWrapper.state().expanded).toBe(true);
|
|
48
|
+
expect(defaultExpandedWrapper.find('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
49
|
+
expect(defaultExpandedWrapper
|
|
50
|
+
.find('.ffe-table__row-expandable-content')
|
|
51
|
+
.prop('aria-hidden')).toBe('false');
|
|
52
|
+
expect(defaultExpandedWrapper
|
|
53
|
+
.find('.ffe-table__row-expandable-content')
|
|
54
|
+
.hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
57
|
+
var scrollIntoViewMock = jest.fn();
|
|
58
|
+
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
59
|
+
mount(React.createElement(TableRowExpandable, __assign({}, props, { scrollToOnMount: true }),
|
|
60
|
+
React.createElement("p", null, "The cake is a lie")));
|
|
61
|
+
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
62
|
+
});
|
|
63
|
+
it('should render expanded content', function () {
|
|
64
|
+
wrapper.setState({ expanded: true });
|
|
65
|
+
expect(wrapper.find('td').last().find('p').text()).toBe('The cake is a lie');
|
|
66
|
+
expect(wrapper
|
|
67
|
+
.find('tr')
|
|
68
|
+
.last()
|
|
69
|
+
.hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
70
|
+
expect(wrapper.find('tr').last().hasClass('ffe-table__row--collapsed')).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
it('should pass correct props to TableRow component', function () {
|
|
73
|
+
wrapper.setState({ expanded: true });
|
|
74
|
+
var tableRow = wrapper.find('TableRow').props();
|
|
75
|
+
expect(tableRow.expanded).toBe(true);
|
|
76
|
+
expect(tableRow.columns).toBe(props.columns);
|
|
77
|
+
expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
|
|
78
|
+
});
|
|
79
|
+
it('should pass an expand icon with correct classname to TableRow', function () {
|
|
80
|
+
wrapper.setState({ expanded: true });
|
|
81
|
+
var tableRow = wrapper.find('TableRow').props();
|
|
82
|
+
expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
|
|
83
|
+
expect(tableRow.expandable).toBe(true);
|
|
84
|
+
});
|
|
85
|
+
it('should not pass an expand icon to TableRows that are not expandable', function () {
|
|
86
|
+
var tableRow = unexpandableWrapper.find('TableRow').props();
|
|
87
|
+
expect(tableRow.cells.expandIcon).toBe(' ');
|
|
88
|
+
expect(tableRow.expandable).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
var renderedWrapper = render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
91
|
+
React.createElement("p", null, "a Festivus for the rest of us")));
|
|
92
|
+
it('should render a tbody with two tr', function () {
|
|
93
|
+
expect(renderedWrapper.children()).toHaveLength(2);
|
|
94
|
+
});
|
|
95
|
+
it('should set the correct aria attributes on tr', function () {
|
|
96
|
+
expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
|
|
97
|
+
expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
|
|
98
|
+
});
|
|
99
|
+
});
|
package/es/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import Table from './Table';
|
|
2
|
-
export default Table;
|
|
2
|
+
export default Table;
|