@sb1/ffe-tables-react 9.0.0 → 10.0.1
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/CellContent.js +28 -0
- package/es/Table.js +15 -84
- package/es/TableBody.js +28 -0
- package/es/TableCaption.js +28 -0
- package/es/TableContext.js +34 -0
- package/es/TableDataCell.js +30 -0
- package/es/TableFoot.js +28 -0
- package/es/TableHead.js +28 -0
- package/es/TableHeaderCell.js +51 -0
- package/es/TableRow.js +28 -0
- package/es/TableRowExpandable.js +62 -0
- package/es/index.js +9 -2
- package/es/texts.js +13 -0
- package/es/types.js +1 -0
- package/lib/CellContent.js +35 -0
- package/lib/Table.js +16 -84
- package/lib/TableBody.js +35 -0
- package/lib/TableCaption.js +34 -0
- package/lib/TableContext.js +61 -0
- package/lib/TableDataCell.js +36 -0
- package/lib/TableFoot.js +35 -0
- package/lib/TableHead.js +35 -0
- package/lib/TableHeaderCell.js +80 -0
- package/lib/TableRow.js +34 -0
- package/lib/TableRowExpandable.js +91 -0
- package/lib/index.js +19 -5
- package/lib/texts.js +16 -0
- package/lib/types.js +4 -0
- package/package.json +8 -12
- package/types/CellContent.d.ts +2 -0
- package/types/Table.d.ts +11 -0
- package/types/TableBody.d.ts +4 -0
- package/types/TableCaption.d.ts +4 -0
- package/types/TableContext.d.ts +15 -0
- package/types/TableDataCell.d.ts +4 -0
- package/types/TableFoot.d.ts +4 -0
- package/types/TableHead.d.ts +4 -0
- package/types/TableHeaderCell.d.ts +5 -0
- package/types/TableRow.d.ts +4 -0
- package/types/TableRowExpandable.d.ts +6 -0
- package/types/index.d.ts +9 -133
- package/types/texts.d.ts +14 -0
- package/types/types.d.ts +6 -0
- package/es/DefaultTable/DefaultTable.js +0 -154
- package/es/DefaultTable/DefaultTable.spec.js +0 -414
- package/es/SortableTable/SortableTable.js +0 -141
- package/es/SortableTable/SortableTable.spec.js +0 -62
- package/es/SortableTable/sort-data.js +0 -31
- package/es/SortableTable/sort-data.spec.js +0 -53
- package/es/TableParts/TableCell.js +0 -26
- package/es/TableParts/TableFooter.js +0 -69
- package/es/TableParts/TableHeaders.js +0 -58
- package/es/TableParts/TableRow.js +0 -61
- package/es/TableParts/TableRowExpandable.js +0 -102
- package/es/TableParts/TableRowExpandable.spec.js +0 -65
- package/lib/DefaultTable/DefaultTable.js +0 -182
- package/lib/DefaultTable/DefaultTable.spec.js +0 -419
- package/lib/SortableTable/SortableTable.js +0 -169
- package/lib/SortableTable/SortableTable.spec.js +0 -67
- package/lib/SortableTable/sort-data.js +0 -33
- package/lib/SortableTable/sort-data.spec.js +0 -58
- package/lib/TableParts/TableCell.js +0 -31
- package/lib/TableParts/TableFooter.js +0 -74
- package/lib/TableParts/TableHeaders.js +0 -63
- package/lib/TableParts/TableRow.js +0 -66
- package/lib/TableParts/TableRowExpandable.js +0 -130
- package/lib/TableParts/TableRowExpandable.spec.js +0 -70
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import sortData from './sort-data';
|
|
2
|
-
var columns = [
|
|
3
|
-
{ key: 'name', header: 'Name' },
|
|
4
|
-
{ key: 'age', header: 'Age' },
|
|
5
|
-
{ key: 'id', header: 'Employee-id' },
|
|
6
|
-
{
|
|
7
|
-
key: 'rand',
|
|
8
|
-
header: 'A random number with thousand separator needs a custom compare',
|
|
9
|
-
compare: function (a, b) { return a.replace(/\s/g, '') - b.replace(/\s/g, ''); },
|
|
10
|
-
},
|
|
11
|
-
];
|
|
12
|
-
var data = [
|
|
13
|
-
{ name: 'Zombie Mountain', age: 36, id: 2, rand: '69 873' },
|
|
14
|
-
{ name: 'Daenerys Targaryen', age: 16, id: 4, rand: '9 156' },
|
|
15
|
-
{ name: 'Ned Stark', age: 48, id: 3, rand: '3 863 914' },
|
|
16
|
-
{ name: 'Jon Snow', age: 20, id: 1, rand: '145 678' },
|
|
17
|
-
];
|
|
18
|
-
describe('sortData', function () {
|
|
19
|
-
it('should sort data in descending order', function () {
|
|
20
|
-
var ascendingTableData = sortData(columns, data, 'age', true);
|
|
21
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
22
|
-
expect(ascendingTableData[i].id).toBeLessThan(ascendingTableData[i - 1].id);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
it('should sort data in ascending order', function () {
|
|
26
|
-
var ascendingTableData = sortData(columns, data, 'age', false);
|
|
27
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
28
|
-
expect(ascendingTableData[i].id).toBeGreaterThan(ascendingTableData[i - 1].id);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
it('should sort data based on `sortBy` parameter', function () {
|
|
32
|
-
var tableData = sortData(columns, data, 'age', true);
|
|
33
|
-
expect(tableData[0].age).toBe(48);
|
|
34
|
-
expect(tableData[1].age).toBe(36);
|
|
35
|
-
expect(tableData[2].age).toBe(20);
|
|
36
|
-
expect(tableData[3].age).toBe(16);
|
|
37
|
-
});
|
|
38
|
-
it('should sort data even though an attribute is not set', function () {
|
|
39
|
-
data[3] = { name: 'Jon Snow', id: 1, rand: '145 678' }; // no age key
|
|
40
|
-
var tableData = sortData(columns, data, 'age', false);
|
|
41
|
-
expect(tableData[0].age).toBe(16);
|
|
42
|
-
expect(tableData[1].age).toBe(36);
|
|
43
|
-
expect(tableData[2].age).toBe(48);
|
|
44
|
-
expect(tableData[3].age).toBe(undefined);
|
|
45
|
-
});
|
|
46
|
-
it('should sort data with a custom compare function when provided', function () {
|
|
47
|
-
var tableData = sortData(columns, data, 'rand', false);
|
|
48
|
-
expect(tableData[0].rand).toBe('9 156');
|
|
49
|
-
expect(tableData[1].rand).toBe('69 873');
|
|
50
|
-
expect(tableData[2].rand).toBe('145 678');
|
|
51
|
-
expect(tableData[3].rand).toBe('3 863 914');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
var TableCell = function (props) {
|
|
5
|
-
var alignRight = props.alignRight, alignTop = props.alignTop, children = props.children, columnHeader = props.columnHeader, contentClasses = props.contentClasses, tdClasses = props.tdClasses;
|
|
6
|
-
var dataTh = '';
|
|
7
|
-
if (columnHeader) {
|
|
8
|
-
if (typeof columnHeader === 'string') {
|
|
9
|
-
dataTh = columnHeader;
|
|
10
|
-
}
|
|
11
|
-
else if (columnHeader.props && columnHeader.props.children) {
|
|
12
|
-
dataTh = React.Children.toArray(columnHeader.props.children)[0];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return (React.createElement("td", { className: classNames('ffe-table__cell', { 'ffe-table__cell--top': alignTop }, tdClasses), "data-th": dataTh },
|
|
16
|
-
React.createElement("span", { className: classNames('ffe-table__content', { 'ffe-table__content--text-right': alignRight }, contentClasses) }, children)));
|
|
17
|
-
};
|
|
18
|
-
TableCell.propTypes = {
|
|
19
|
-
alignRight: PropTypes.bool,
|
|
20
|
-
alignTop: PropTypes.bool,
|
|
21
|
-
children: PropTypes.any,
|
|
22
|
-
columnHeader: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
23
|
-
contentClasses: PropTypes.string,
|
|
24
|
-
tdClasses: PropTypes.string,
|
|
25
|
-
};
|
|
26
|
-
export default TableCell;
|
|
@@ -1,69 +0,0 @@
|
|
|
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 PropTypes from 'prop-types';
|
|
14
|
-
import TableCell from './TableCell';
|
|
15
|
-
import classNames from 'classnames';
|
|
16
|
-
var TableFooter = function (_a) {
|
|
17
|
-
var columns = _a.columns, footerRender = _a.footerRender, dataWindow = _a.dataWindow;
|
|
18
|
-
var footerContent = columns.map(function (column, index) {
|
|
19
|
-
if (column === null) {
|
|
20
|
-
return React.createElement("td", { key: index });
|
|
21
|
-
}
|
|
22
|
-
var className = classNames({ 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop });
|
|
23
|
-
var dataTh = '';
|
|
24
|
-
var columnHeader = column.header;
|
|
25
|
-
if (columnHeader) {
|
|
26
|
-
if (typeof columnHeader === 'string') {
|
|
27
|
-
dataTh = columnHeader;
|
|
28
|
-
}
|
|
29
|
-
else if (columnHeader.props && columnHeader.props.children) {
|
|
30
|
-
dataTh = React.Children.toArray(columnHeader.props.children)[0];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
var tdProps = {
|
|
34
|
-
className: classNames('ffe-table__cell', { 'ffe-table__cell--top': column.alignTop }, className),
|
|
35
|
-
'data-th': dataTh,
|
|
36
|
-
key: index,
|
|
37
|
-
};
|
|
38
|
-
var spanProps = {
|
|
39
|
-
className: classNames('ffe-table__content', {
|
|
40
|
-
'ffe-table__content--text-right': column.alignRight,
|
|
41
|
-
}),
|
|
42
|
-
};
|
|
43
|
-
if (typeof column.columnFooterRender === 'function') {
|
|
44
|
-
return column.columnFooterRender(column.footer, dataWindow, tdProps, spanProps, columns, index);
|
|
45
|
-
}
|
|
46
|
-
return (React.createElement(TableCell, { key: index, columnHeader: column.header, alignRight: column.alignRight, alignTop: column.alignTop, tdClasses: className }, column.footer));
|
|
47
|
-
});
|
|
48
|
-
var trProps = { className: 'ffe-table__row', children: footerContent };
|
|
49
|
-
var trDefault = React.createElement("tr", __assign({}, trProps));
|
|
50
|
-
var footerRendered = typeof footerRender === 'function'
|
|
51
|
-
? footerRender(trProps, columns)
|
|
52
|
-
: trDefault;
|
|
53
|
-
return React.createElement("tfoot", { className: "ffe-table__footer" }, footerRendered);
|
|
54
|
-
};
|
|
55
|
-
TableFooter.propTypes = {
|
|
56
|
-
columns: PropTypes.arrayOf(PropTypes.shape({
|
|
57
|
-
alignRight: PropTypes.bool,
|
|
58
|
-
alignTop: PropTypes.bool,
|
|
59
|
-
footer: PropTypes.any,
|
|
60
|
-
header: PropTypes.node.isRequired,
|
|
61
|
-
hideOnDesktop: PropTypes.bool,
|
|
62
|
-
hideOnMobile: PropTypes.bool,
|
|
63
|
-
hideOnSmallTablet: PropTypes.bool,
|
|
64
|
-
hideOnTablet: PropTypes.bool,
|
|
65
|
-
})),
|
|
66
|
-
footerRender: PropTypes.func,
|
|
67
|
-
dataWindow: PropTypes.array,
|
|
68
|
-
};
|
|
69
|
-
export default TableFooter;
|
|
@@ -1,58 +0,0 @@
|
|
|
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 PropTypes from 'prop-types';
|
|
14
|
-
import classNames from 'classnames';
|
|
15
|
-
var TableHeaders = function (_a) {
|
|
16
|
-
var columns = _a.columns, headerRender = _a.headerRender, dataWindow = _a.dataWindow;
|
|
17
|
-
var headerContent = columns.map(function (column, index) {
|
|
18
|
-
if (column === null) {
|
|
19
|
-
return React.createElement("th", { key: index });
|
|
20
|
-
}
|
|
21
|
-
var thProps = {
|
|
22
|
-
key: index,
|
|
23
|
-
className: classNames('ffe-table__heading', { 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop }),
|
|
24
|
-
'aria-sort': column.ariaSort,
|
|
25
|
-
scope: 'col',
|
|
26
|
-
};
|
|
27
|
-
var spanProps = {
|
|
28
|
-
className: classNames('ffe-table__content', {
|
|
29
|
-
'ffe-table__content--text-right': column.alignRight,
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
var thContentDefault = React.createElement("span", __assign({}, spanProps), column.header);
|
|
33
|
-
if (typeof column.columnHeaderRender === 'function') {
|
|
34
|
-
return column.columnHeaderRender(column.header, dataWindow, spanProps, thProps, columns, index);
|
|
35
|
-
}
|
|
36
|
-
return (React.createElement("th", __assign({ key: thProps.key }, thProps), thContentDefault));
|
|
37
|
-
});
|
|
38
|
-
var trProps = { className: 'ffe-table__row', children: headerContent };
|
|
39
|
-
var trDefault = React.createElement("tr", __assign({}, trProps));
|
|
40
|
-
var headerRendered = typeof headerRender === 'function'
|
|
41
|
-
? headerRender(trProps, columns)
|
|
42
|
-
: trDefault;
|
|
43
|
-
return React.createElement("thead", { className: "ffe-table__head" }, headerRendered);
|
|
44
|
-
};
|
|
45
|
-
TableHeaders.propTypes = {
|
|
46
|
-
columns: PropTypes.arrayOf(PropTypes.shape({
|
|
47
|
-
alignRight: PropTypes.bool,
|
|
48
|
-
header: PropTypes.node.isRequired,
|
|
49
|
-
hideOnDesktop: PropTypes.bool,
|
|
50
|
-
hideOnMobile: PropTypes.bool,
|
|
51
|
-
hideOnSmallTablet: PropTypes.bool,
|
|
52
|
-
hideOnTablet: PropTypes.bool,
|
|
53
|
-
key: PropTypes.string.isRequired,
|
|
54
|
-
})),
|
|
55
|
-
headerRender: PropTypes.func,
|
|
56
|
-
dataWindow: PropTypes.array,
|
|
57
|
-
};
|
|
58
|
-
export default TableHeaders;
|
|
@@ -1,61 +0,0 @@
|
|
|
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 PropTypes from 'prop-types';
|
|
14
|
-
import classNames from 'classnames';
|
|
15
|
-
import TableCell from './TableCell';
|
|
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);
|
|
37
|
-
};
|
|
38
|
-
TableRow.propTypes = {
|
|
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,
|
|
60
|
-
};
|
|
61
|
-
export default TableRow;
|
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
};
|
|
27
|
-
import { Icon } from '@sb1/ffe-icons-react';
|
|
28
|
-
import classNames from 'classnames';
|
|
29
|
-
import PropTypes from 'prop-types';
|
|
30
|
-
import React, { Component } from 'react';
|
|
31
|
-
import { polyfill } from 'react-lifecycles-compat';
|
|
32
|
-
import shallowEqual from 'shallow-equals';
|
|
33
|
-
import TableRow from './TableRow';
|
|
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,
|
|
43
|
-
};
|
|
44
|
-
_this.rowRef = React.createRef();
|
|
45
|
-
return _this;
|
|
46
|
-
}
|
|
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));
|
|
89
|
-
TableRowExpandable.propTypes = {
|
|
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,
|
|
100
|
-
};
|
|
101
|
-
polyfill(TableRowExpandable);
|
|
102
|
-
export default TableRowExpandable;
|
|
@@ -1,65 +0,0 @@
|
|
|
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
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
15
|
-
var props = {
|
|
16
|
-
cells: {
|
|
17
|
-
name: 'Ola Normann',
|
|
18
|
-
address: 'Gateveien 2',
|
|
19
|
-
age: 23,
|
|
20
|
-
phone: '912 34 567',
|
|
21
|
-
email: 'ola@normann.no',
|
|
22
|
-
},
|
|
23
|
-
columns: [
|
|
24
|
-
{ key: 'name', content: 'Navn' },
|
|
25
|
-
{ key: 'address', content: 'Adresse' },
|
|
26
|
-
{ key: 'age', content: 'Alder', alignRight: true },
|
|
27
|
-
{ key: 'phone', content: 'Telefon' },
|
|
28
|
-
{ key: 'email', content: 'E-post' },
|
|
29
|
-
],
|
|
30
|
-
};
|
|
31
|
-
describe('<TableRowExpandable>', function () {
|
|
32
|
-
it('should be collapsed by default', function () {
|
|
33
|
-
var container = render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
34
|
-
React.createElement("p", null, "The cake is a lie"))).container;
|
|
35
|
-
expect(container.querySelectorAll('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
36
|
-
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
37
|
-
expect(content.getAttribute('aria-hidden')).toBe('true');
|
|
38
|
-
expect(content.classList.contains('ffe-table__row--collapsed')).toBeTruthy();
|
|
39
|
-
});
|
|
40
|
-
it('should be expanded if provided true defaultExpanded', function () {
|
|
41
|
-
var container = render(React.createElement(TableRowExpandable, __assign({}, props, { defaultExpanded: true }),
|
|
42
|
-
React.createElement("p", null, "The cake is a lie"))).container;
|
|
43
|
-
expect(container.querySelectorAll('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
44
|
-
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
45
|
-
expect(content.getAttribute('aria-hidden')).toBe('false');
|
|
46
|
-
expect(content.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
47
|
-
});
|
|
48
|
-
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
49
|
-
var scrollIntoViewMock = jest.fn();
|
|
50
|
-
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
51
|
-
render(React.createElement(TableRowExpandable, __assign({}, props, { scrollToOnMount: true }),
|
|
52
|
-
React.createElement("p", null, "The cake is a lie")));
|
|
53
|
-
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
54
|
-
});
|
|
55
|
-
it('should render expanded content', function () {
|
|
56
|
-
render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
57
|
-
React.createElement("p", null, "The cake is a lie")));
|
|
58
|
-
var row = screen.getByRole('button');
|
|
59
|
-
fireEvent.click(row);
|
|
60
|
-
var expandedContent = screen.getByRole('presentation');
|
|
61
|
-
expect(expandedContent.textContent).toBe('The cake is a lie');
|
|
62
|
-
expect(expandedContent.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
63
|
-
expect(expandedContent.classList.contains('ffe-table__row--collapsed')).toBeFalsy();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
-
if (k2 === undefined) k2 = k;
|
|
30
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
-
}
|
|
34
|
-
Object.defineProperty(o, k2, desc);
|
|
35
|
-
}) : (function(o, m, k, k2) {
|
|
36
|
-
if (k2 === undefined) k2 = k;
|
|
37
|
-
o[k2] = m[k];
|
|
38
|
-
}));
|
|
39
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
-
}) : function(o, v) {
|
|
42
|
-
o["default"] = v;
|
|
43
|
-
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
-
if (mod && mod.__esModule) return mod;
|
|
46
|
-
var result = {};
|
|
47
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
-
__setModuleDefault(result, mod);
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
52
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
53
|
-
if (ar || !(i in from)) {
|
|
54
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
55
|
-
ar[i] = from[i];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
59
|
-
};
|
|
60
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
|
-
};
|
|
63
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
var react_1 = __importStar(require("react"));
|
|
65
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
66
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
67
|
-
var TableHeaders_1 = __importDefault(require("../TableParts/TableHeaders"));
|
|
68
|
-
var TableFooter_1 = __importDefault(require("../TableParts/TableFooter"));
|
|
69
|
-
var TableRow_1 = __importDefault(require("../TableParts/TableRow"));
|
|
70
|
-
var TableRowExpandable_1 = __importDefault(require("../TableParts/TableRowExpandable"));
|
|
71
|
-
var DefaultTable = /** @class */ (function (_super) {
|
|
72
|
-
__extends(DefaultTable, _super);
|
|
73
|
-
function DefaultTable() {
|
|
74
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
75
|
-
}
|
|
76
|
-
DefaultTable.prototype.renderTableCaption = function () {
|
|
77
|
-
var _a = this.props, caption = _a.caption, srOnlyCaption = _a.srOnlyCaption;
|
|
78
|
-
if (!caption) {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
if (srOnlyCaption) {
|
|
82
|
-
return (react_1.default.createElement("caption", { className: "ffe-screenreader-only", "aria-live": "polite" }, caption));
|
|
83
|
-
}
|
|
84
|
-
return react_1.default.createElement("caption", { className: "ffe-table__caption" }, caption);
|
|
85
|
-
};
|
|
86
|
-
DefaultTable.prototype.renderTableHeaders = function () {
|
|
87
|
-
var _a = this.props, _b = _a.columns, columns = _b === void 0 ? [] : _b, headerRender = _a.headerRender;
|
|
88
|
-
if (!columns.length) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
var renderColumns = __spreadArray([], columns, true);
|
|
92
|
-
if (this.props.expandedContentMapper) {
|
|
93
|
-
renderColumns.push({
|
|
94
|
-
key: 'expandIcon',
|
|
95
|
-
header: (react_1.default.createElement("span", { className: "ffe-screenreader-only" }, "Valg for raden")),
|
|
96
|
-
alignRight: true,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return (react_1.default.createElement(TableHeaders_1.default, { columns: renderColumns, headerRender: headerRender, dataWindow: this.getData() }));
|
|
100
|
-
};
|
|
101
|
-
DefaultTable.prototype.renderTableFooter = function () {
|
|
102
|
-
var _a = this.props, columns = _a.columns, footerRender = _a.footerRender;
|
|
103
|
-
if (!columns.some(function (column) { return column.footer; })) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
return (react_1.default.createElement(TableFooter_1.default, { columns: columns, footerRender: footerRender, dataWindow: this.getData() }));
|
|
107
|
-
};
|
|
108
|
-
DefaultTable.prototype.getData = function () {
|
|
109
|
-
var _a = this.props, _b = _a.data, data = _b === void 0 ? [] : _b, _c = _a.offset, offset = _c === void 0 ? 0 : _c, _d = _a.limit, limit = _d === void 0 ? 0 : _d;
|
|
110
|
-
if (!offset && !limit) {
|
|
111
|
-
return data;
|
|
112
|
-
}
|
|
113
|
-
return data.slice(offset, limit ? offset + limit : data.length);
|
|
114
|
-
};
|
|
115
|
-
DefaultTable.prototype.renderTableBody = function () {
|
|
116
|
-
var _a = this.props, columns = _a.columns, expandedContentMapper = _a.expandedContentMapper, sort = _a.sort, rowRender = _a.rowRender;
|
|
117
|
-
var data = this.getData();
|
|
118
|
-
if (!data.length) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
var renderColumns = __spreadArray([], columns, true);
|
|
122
|
-
if (expandedContentMapper) {
|
|
123
|
-
renderColumns.push({
|
|
124
|
-
key: 'expandIcon',
|
|
125
|
-
header: '',
|
|
126
|
-
alignRight: true,
|
|
127
|
-
});
|
|
128
|
-
return data.map(function (row, index) {
|
|
129
|
-
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
130
|
-
var expandedContent = expandedContentMapper(row);
|
|
131
|
-
var rowProps = {
|
|
132
|
-
cells: row,
|
|
133
|
-
columns: renderColumns,
|
|
134
|
-
sort: sort,
|
|
135
|
-
rowRender: rowRender,
|
|
136
|
-
rowIndex: index,
|
|
137
|
-
defaultExpanded: row.defaultExpanded,
|
|
138
|
-
scrollToOnMount: row.scrollToOnMount,
|
|
139
|
-
};
|
|
140
|
-
return expandedContent ? (react_1.default.createElement(TableRowExpandable_1.default, __assign({ key: key }, rowProps), expandedContent)) : (react_1.default.createElement("tbody", { key: key },
|
|
141
|
-
react_1.default.createElement(TableRow_1.default, __assign({}, rowProps))));
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return (react_1.default.createElement("tbody", null, data.map(function (row, index) {
|
|
145
|
-
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
146
|
-
return (react_1.default.createElement(TableRow_1.default, { cells: row, columns: columns, key: key, rowRender: rowRender, rowIndex: index }));
|
|
147
|
-
})));
|
|
148
|
-
};
|
|
149
|
-
DefaultTable.prototype.render = function () {
|
|
150
|
-
var _a;
|
|
151
|
-
var _b = this.props, alignLeft = _b.alignLeft, condensed = _b.condensed, smallHeader = _b.smallHeader, columnLayoutMobile = _b.columnLayoutMobile, breakpoint = _b.breakpoint, className = _b.className;
|
|
152
|
-
return (react_1.default.createElement("table", { className: (0, classnames_1.default)('ffe-table', { 'ffe-table--condensed': condensed }, { 'ffe-table--small-header': smallHeader }, { 'ffe-table--columns-sm': columnLayoutMobile }, { 'ffe-table--text-left': alignLeft }, (_a = {}, _a["ffe-table--breakpoint-".concat(breakpoint)] = !!breakpoint, _a), className) },
|
|
153
|
-
this.renderTableCaption(),
|
|
154
|
-
this.renderTableHeaders(),
|
|
155
|
-
this.renderTableFooter(),
|
|
156
|
-
this.renderTableBody()));
|
|
157
|
-
};
|
|
158
|
-
return DefaultTable;
|
|
159
|
-
}(react_1.Component));
|
|
160
|
-
DefaultTable.propTypes = {
|
|
161
|
-
alignLeft: prop_types_1.default.bool,
|
|
162
|
-
columnLayoutMobile: prop_types_1.default.bool,
|
|
163
|
-
caption: prop_types_1.default.node,
|
|
164
|
-
srOnlyCaption: prop_types_1.default.bool,
|
|
165
|
-
expandedContentMapper: prop_types_1.default.func,
|
|
166
|
-
condensed: prop_types_1.default.bool,
|
|
167
|
-
smallHeader: prop_types_1.default.bool,
|
|
168
|
-
sort: prop_types_1.default.object,
|
|
169
|
-
offset: prop_types_1.default.number,
|
|
170
|
-
limit: prop_types_1.default.number,
|
|
171
|
-
breakpoint: prop_types_1.default.oneOf(['sm', 'none']),
|
|
172
|
-
data: prop_types_1.default.arrayOf(prop_types_1.default.object),
|
|
173
|
-
columns: prop_types_1.default.arrayOf(prop_types_1.default.shape({
|
|
174
|
-
header: prop_types_1.default.node.isRequired,
|
|
175
|
-
key: prop_types_1.default.string.isRequired,
|
|
176
|
-
}).isRequired),
|
|
177
|
-
rowRender: prop_types_1.default.func,
|
|
178
|
-
headerRender: prop_types_1.default.func,
|
|
179
|
-
footerRender: prop_types_1.default.func,
|
|
180
|
-
className: prop_types_1.default.string,
|
|
181
|
-
};
|
|
182
|
-
exports.default = DefaultTable;
|