@sb1/ffe-tables-react 9.0.0 → 10.0.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/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 +7 -11
- 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
- package/types/index.d.ts +0 -133
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.default = (function (columns, data, sortBy, descending) {
|
|
13
|
-
var sortedData = __spreadArray([], data, true);
|
|
14
|
-
var compare = function (data1, data2) {
|
|
15
|
-
if (!isNaN(data1[sortBy])) {
|
|
16
|
-
return data1[sortBy] - data2[sortBy];
|
|
17
|
-
}
|
|
18
|
-
if (!data1[sortBy]) {
|
|
19
|
-
return data2[sortBy] ? 1 : 0;
|
|
20
|
-
}
|
|
21
|
-
return data1[sortBy].localeCompare(data2[sortBy]);
|
|
22
|
-
};
|
|
23
|
-
var column = columns.find(function (col) { return col.key === sortBy; });
|
|
24
|
-
var customCompare = column && typeof column.compare === 'function' ? column.compare : null;
|
|
25
|
-
if (customCompare) {
|
|
26
|
-
compare = function (data1, data2) { return customCompare(data1[sortBy], data2[sortBy]); };
|
|
27
|
-
}
|
|
28
|
-
sortedData.sort(compare);
|
|
29
|
-
if (descending) {
|
|
30
|
-
sortedData.reverse();
|
|
31
|
-
}
|
|
32
|
-
return sortedData;
|
|
33
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var sort_data_1 = __importDefault(require("./sort-data"));
|
|
7
|
-
var columns = [
|
|
8
|
-
{ key: 'name', header: 'Name' },
|
|
9
|
-
{ key: 'age', header: 'Age' },
|
|
10
|
-
{ key: 'id', header: 'Employee-id' },
|
|
11
|
-
{
|
|
12
|
-
key: 'rand',
|
|
13
|
-
header: 'A random number with thousand separator needs a custom compare',
|
|
14
|
-
compare: function (a, b) { return a.replace(/\s/g, '') - b.replace(/\s/g, ''); },
|
|
15
|
-
},
|
|
16
|
-
];
|
|
17
|
-
var data = [
|
|
18
|
-
{ name: 'Zombie Mountain', age: 36, id: 2, rand: '69 873' },
|
|
19
|
-
{ name: 'Daenerys Targaryen', age: 16, id: 4, rand: '9 156' },
|
|
20
|
-
{ name: 'Ned Stark', age: 48, id: 3, rand: '3 863 914' },
|
|
21
|
-
{ name: 'Jon Snow', age: 20, id: 1, rand: '145 678' },
|
|
22
|
-
];
|
|
23
|
-
describe('sortData', function () {
|
|
24
|
-
it('should sort data in descending order', function () {
|
|
25
|
-
var ascendingTableData = (0, sort_data_1.default)(columns, data, 'age', true);
|
|
26
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
27
|
-
expect(ascendingTableData[i].id).toBeLessThan(ascendingTableData[i - 1].id);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
it('should sort data in ascending order', function () {
|
|
31
|
-
var ascendingTableData = (0, sort_data_1.default)(columns, data, 'age', false);
|
|
32
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
33
|
-
expect(ascendingTableData[i].id).toBeGreaterThan(ascendingTableData[i - 1].id);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
it('should sort data based on `sortBy` parameter', function () {
|
|
37
|
-
var tableData = (0, sort_data_1.default)(columns, data, 'age', true);
|
|
38
|
-
expect(tableData[0].age).toBe(48);
|
|
39
|
-
expect(tableData[1].age).toBe(36);
|
|
40
|
-
expect(tableData[2].age).toBe(20);
|
|
41
|
-
expect(tableData[3].age).toBe(16);
|
|
42
|
-
});
|
|
43
|
-
it('should sort data even though an attribute is not set', function () {
|
|
44
|
-
data[3] = { name: 'Jon Snow', id: 1, rand: '145 678' }; // no age key
|
|
45
|
-
var tableData = (0, sort_data_1.default)(columns, data, 'age', false);
|
|
46
|
-
expect(tableData[0].age).toBe(16);
|
|
47
|
-
expect(tableData[1].age).toBe(36);
|
|
48
|
-
expect(tableData[2].age).toBe(48);
|
|
49
|
-
expect(tableData[3].age).toBe(undefined);
|
|
50
|
-
});
|
|
51
|
-
it('should sort data with a custom compare function when provided', function () {
|
|
52
|
-
var tableData = (0, sort_data_1.default)(columns, data, 'rand', false);
|
|
53
|
-
expect(tableData[0].rand).toBe('9 156');
|
|
54
|
-
expect(tableData[1].rand).toBe('69 873');
|
|
55
|
-
expect(tableData[2].rand).toBe('145 678');
|
|
56
|
-
expect(tableData[3].rand).toBe('3 863 914');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var react_1 = __importDefault(require("react"));
|
|
7
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
8
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
9
|
-
var TableCell = function (props) {
|
|
10
|
-
var alignRight = props.alignRight, alignTop = props.alignTop, children = props.children, columnHeader = props.columnHeader, contentClasses = props.contentClasses, tdClasses = props.tdClasses;
|
|
11
|
-
var dataTh = '';
|
|
12
|
-
if (columnHeader) {
|
|
13
|
-
if (typeof columnHeader === 'string') {
|
|
14
|
-
dataTh = columnHeader;
|
|
15
|
-
}
|
|
16
|
-
else if (columnHeader.props && columnHeader.props.children) {
|
|
17
|
-
dataTh = react_1.default.Children.toArray(columnHeader.props.children)[0];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return (react_1.default.createElement("td", { className: (0, classnames_1.default)('ffe-table__cell', { 'ffe-table__cell--top': alignTop }, tdClasses), "data-th": dataTh },
|
|
21
|
-
react_1.default.createElement("span", { className: (0, classnames_1.default)('ffe-table__content', { 'ffe-table__content--text-right': alignRight }, contentClasses) }, children)));
|
|
22
|
-
};
|
|
23
|
-
TableCell.propTypes = {
|
|
24
|
-
alignRight: prop_types_1.default.bool,
|
|
25
|
-
alignTop: prop_types_1.default.bool,
|
|
26
|
-
children: prop_types_1.default.any,
|
|
27
|
-
columnHeader: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.node]),
|
|
28
|
-
contentClasses: prop_types_1.default.string,
|
|
29
|
-
tdClasses: prop_types_1.default.string,
|
|
30
|
-
};
|
|
31
|
-
exports.default = TableCell;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var react_1 = __importDefault(require("react"));
|
|
18
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
19
|
-
var TableCell_1 = __importDefault(require("./TableCell"));
|
|
20
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
21
|
-
var TableFooter = function (_a) {
|
|
22
|
-
var columns = _a.columns, footerRender = _a.footerRender, dataWindow = _a.dataWindow;
|
|
23
|
-
var footerContent = columns.map(function (column, index) {
|
|
24
|
-
if (column === null) {
|
|
25
|
-
return react_1.default.createElement("td", { key: index });
|
|
26
|
-
}
|
|
27
|
-
var className = (0, classnames_1.default)({ 'ffe-table--hide-sm': column.hideOnMobile }, { 'ffe-table--hide-md': column.hideOnSmallTablet }, { 'ffe-table--hide-lg': column.hideOnTablet }, { 'ffe-table--hide-xlg': column.hideOnDesktop });
|
|
28
|
-
var dataTh = '';
|
|
29
|
-
var columnHeader = column.header;
|
|
30
|
-
if (columnHeader) {
|
|
31
|
-
if (typeof columnHeader === 'string') {
|
|
32
|
-
dataTh = columnHeader;
|
|
33
|
-
}
|
|
34
|
-
else if (columnHeader.props && columnHeader.props.children) {
|
|
35
|
-
dataTh = react_1.default.Children.toArray(columnHeader.props.children)[0];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
var tdProps = {
|
|
39
|
-
className: (0, classnames_1.default)('ffe-table__cell', { 'ffe-table__cell--top': column.alignTop }, className),
|
|
40
|
-
'data-th': dataTh,
|
|
41
|
-
key: index,
|
|
42
|
-
};
|
|
43
|
-
var spanProps = {
|
|
44
|
-
className: (0, classnames_1.default)('ffe-table__content', {
|
|
45
|
-
'ffe-table__content--text-right': column.alignRight,
|
|
46
|
-
}),
|
|
47
|
-
};
|
|
48
|
-
if (typeof column.columnFooterRender === 'function') {
|
|
49
|
-
return column.columnFooterRender(column.footer, dataWindow, tdProps, spanProps, columns, index);
|
|
50
|
-
}
|
|
51
|
-
return (react_1.default.createElement(TableCell_1.default, { key: index, columnHeader: column.header, alignRight: column.alignRight, alignTop: column.alignTop, tdClasses: className }, column.footer));
|
|
52
|
-
});
|
|
53
|
-
var trProps = { className: 'ffe-table__row', children: footerContent };
|
|
54
|
-
var trDefault = react_1.default.createElement("tr", __assign({}, trProps));
|
|
55
|
-
var footerRendered = typeof footerRender === 'function'
|
|
56
|
-
? footerRender(trProps, columns)
|
|
57
|
-
: trDefault;
|
|
58
|
-
return react_1.default.createElement("tfoot", { className: "ffe-table__footer" }, footerRendered);
|
|
59
|
-
};
|
|
60
|
-
TableFooter.propTypes = {
|
|
61
|
-
columns: prop_types_1.default.arrayOf(prop_types_1.default.shape({
|
|
62
|
-
alignRight: prop_types_1.default.bool,
|
|
63
|
-
alignTop: prop_types_1.default.bool,
|
|
64
|
-
footer: prop_types_1.default.any,
|
|
65
|
-
header: prop_types_1.default.node.isRequired,
|
|
66
|
-
hideOnDesktop: prop_types_1.default.bool,
|
|
67
|
-
hideOnMobile: prop_types_1.default.bool,
|
|
68
|
-
hideOnSmallTablet: prop_types_1.default.bool,
|
|
69
|
-
hideOnTablet: prop_types_1.default.bool,
|
|
70
|
-
})),
|
|
71
|
-
footerRender: prop_types_1.default.func,
|
|
72
|
-
dataWindow: prop_types_1.default.array,
|
|
73
|
-
};
|
|
74
|
-
exports.default = TableFooter;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var react_1 = __importDefault(require("react"));
|
|
18
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
19
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
20
|
-
var TableHeaders = function (_a) {
|
|
21
|
-
var columns = _a.columns, headerRender = _a.headerRender, dataWindow = _a.dataWindow;
|
|
22
|
-
var headerContent = columns.map(function (column, index) {
|
|
23
|
-
if (column === null) {
|
|
24
|
-
return react_1.default.createElement("th", { key: index });
|
|
25
|
-
}
|
|
26
|
-
var thProps = {
|
|
27
|
-
key: index,
|
|
28
|
-
className: (0, classnames_1.default)('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 }),
|
|
29
|
-
'aria-sort': column.ariaSort,
|
|
30
|
-
scope: 'col',
|
|
31
|
-
};
|
|
32
|
-
var spanProps = {
|
|
33
|
-
className: (0, classnames_1.default)('ffe-table__content', {
|
|
34
|
-
'ffe-table__content--text-right': column.alignRight,
|
|
35
|
-
}),
|
|
36
|
-
};
|
|
37
|
-
var thContentDefault = react_1.default.createElement("span", __assign({}, spanProps), column.header);
|
|
38
|
-
if (typeof column.columnHeaderRender === 'function') {
|
|
39
|
-
return column.columnHeaderRender(column.header, dataWindow, spanProps, thProps, columns, index);
|
|
40
|
-
}
|
|
41
|
-
return (react_1.default.createElement("th", __assign({ key: thProps.key }, thProps), thContentDefault));
|
|
42
|
-
});
|
|
43
|
-
var trProps = { className: 'ffe-table__row', children: headerContent };
|
|
44
|
-
var trDefault = react_1.default.createElement("tr", __assign({}, trProps));
|
|
45
|
-
var headerRendered = typeof headerRender === 'function'
|
|
46
|
-
? headerRender(trProps, columns)
|
|
47
|
-
: trDefault;
|
|
48
|
-
return react_1.default.createElement("thead", { className: "ffe-table__head" }, headerRendered);
|
|
49
|
-
};
|
|
50
|
-
TableHeaders.propTypes = {
|
|
51
|
-
columns: prop_types_1.default.arrayOf(prop_types_1.default.shape({
|
|
52
|
-
alignRight: prop_types_1.default.bool,
|
|
53
|
-
header: prop_types_1.default.node.isRequired,
|
|
54
|
-
hideOnDesktop: prop_types_1.default.bool,
|
|
55
|
-
hideOnMobile: prop_types_1.default.bool,
|
|
56
|
-
hideOnSmallTablet: prop_types_1.default.bool,
|
|
57
|
-
hideOnTablet: prop_types_1.default.bool,
|
|
58
|
-
key: prop_types_1.default.string.isRequired,
|
|
59
|
-
})),
|
|
60
|
-
headerRender: prop_types_1.default.func,
|
|
61
|
-
dataWindow: prop_types_1.default.array,
|
|
62
|
-
};
|
|
63
|
-
exports.default = TableHeaders;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var react_1 = __importDefault(require("react"));
|
|
18
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
19
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
20
|
-
var TableCell_1 = __importDefault(require("./TableCell"));
|
|
21
|
-
var TableRow = function (props) {
|
|
22
|
-
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;
|
|
23
|
-
var expandableProps = expandable && {
|
|
24
|
-
'aria-expanded': expanded,
|
|
25
|
-
onClick: onClick,
|
|
26
|
-
onKeyDown: onKeyDown,
|
|
27
|
-
role: 'button',
|
|
28
|
-
tabIndex: '0',
|
|
29
|
-
};
|
|
30
|
-
var rowContent = columns.map(function (column, index) {
|
|
31
|
-
return (react_1.default.createElement(TableCell_1.default, { alignRight: column.alignRight, alignTop: column.alignTop, columnHeader: column.header, key: index, tdClasses: (0, classnames_1.default)({
|
|
32
|
-
'ffe-table__cell--collapsed': column.key === 'expandIcon',
|
|
33
|
-
}, { '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
|
|
34
|
-
? column.cellRender(cells[column.key], column, props, index)
|
|
35
|
-
: cells[column.key]));
|
|
36
|
-
});
|
|
37
|
-
var trprops = __assign(__assign({ className: (0, classnames_1.default)('ffe-table__row', trClasses) }, expandableProps), { onClick: onClick, children: rowContent });
|
|
38
|
-
if (typeof rowRender === 'function') {
|
|
39
|
-
return rowRender(trprops, props, rowIndex);
|
|
40
|
-
}
|
|
41
|
-
return react_1.default.createElement("tr", __assign({}, trprops), rowContent);
|
|
42
|
-
};
|
|
43
|
-
TableRow.propTypes = {
|
|
44
|
-
cells: prop_types_1.default.object.isRequired,
|
|
45
|
-
columns: prop_types_1.default.arrayOf(prop_types_1.default.shape({
|
|
46
|
-
alignRight: prop_types_1.default.bool,
|
|
47
|
-
alignTop: prop_types_1.default.bool,
|
|
48
|
-
header: prop_types_1.default.any,
|
|
49
|
-
hideOnDesktop: prop_types_1.default.bool,
|
|
50
|
-
hideOnMobile: prop_types_1.default.bool,
|
|
51
|
-
hideOnSmallTablet: prop_types_1.default.bool,
|
|
52
|
-
hideOnTablet: prop_types_1.default.bool,
|
|
53
|
-
key: prop_types_1.default.string,
|
|
54
|
-
cellRender: prop_types_1.default.func,
|
|
55
|
-
})).isRequired,
|
|
56
|
-
expandable: prop_types_1.default.bool,
|
|
57
|
-
expanded: prop_types_1.default.bool,
|
|
58
|
-
onClick: prop_types_1.default.func,
|
|
59
|
-
rowRender: prop_types_1.default.func,
|
|
60
|
-
headerRender: prop_types_1.default.func,
|
|
61
|
-
footerRender: prop_types_1.default.func,
|
|
62
|
-
onKeyDown: prop_types_1.default.func,
|
|
63
|
-
trClasses: prop_types_1.default.string,
|
|
64
|
-
rowIndex: prop_types_1.default.number,
|
|
65
|
-
};
|
|
66
|
-
exports.default = TableRow;
|
|
@@ -1,130 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
|
-
};
|
|
54
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
-
var ffe_icons_react_1 = require("@sb1/ffe-icons-react");
|
|
56
|
-
var classnames_1 = __importDefault(require("classnames"));
|
|
57
|
-
var prop_types_1 = __importDefault(require("prop-types"));
|
|
58
|
-
var react_1 = __importStar(require("react"));
|
|
59
|
-
var react_lifecycles_compat_1 = require("react-lifecycles-compat");
|
|
60
|
-
var shallow_equals_1 = __importDefault(require("shallow-equals"));
|
|
61
|
-
var TableRow_1 = __importDefault(require("./TableRow"));
|
|
62
|
-
var TableRowExpandable = /** @class */ (function (_super) {
|
|
63
|
-
__extends(TableRowExpandable, _super);
|
|
64
|
-
function TableRowExpandable(props) {
|
|
65
|
-
var _this = _super.call(this, props) || this;
|
|
66
|
-
_this.handleKeyPress = _this.handleKeyPress.bind(_this);
|
|
67
|
-
_this.toggleExpand = _this.toggleExpand.bind(_this);
|
|
68
|
-
_this.state = {
|
|
69
|
-
expanded: !!props.defaultExpanded,
|
|
70
|
-
sort: props.sort,
|
|
71
|
-
};
|
|
72
|
-
_this.rowRef = react_1.default.createRef();
|
|
73
|
-
return _this;
|
|
74
|
-
}
|
|
75
|
-
TableRowExpandable.prototype.componentDidMount = function () {
|
|
76
|
-
if (this.props.scrollToOnMount && this.rowRef.current) {
|
|
77
|
-
this.rowRef.current.scrollIntoView();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
TableRowExpandable.getDerivedStateFromProps = function (nextProps, prevState) {
|
|
81
|
-
if ((!nextProps.children && prevState.expanded) ||
|
|
82
|
-
!(0, shallow_equals_1.default)(nextProps.sort, prevState.sort)) {
|
|
83
|
-
return {
|
|
84
|
-
expanded: false,
|
|
85
|
-
sort: nextProps.sort,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
};
|
|
90
|
-
TableRowExpandable.prototype.toggleExpand = function () {
|
|
91
|
-
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
92
|
-
};
|
|
93
|
-
TableRowExpandable.prototype.handleKeyPress = function (event) {
|
|
94
|
-
if ((event.key === 'Enter' || event.key === ' ') &&
|
|
95
|
-
event.target.tagName === 'TR') {
|
|
96
|
-
this.setState(function (prevState) { return ({ expanded: !prevState.expanded }); });
|
|
97
|
-
event.preventDefault();
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
TableRowExpandable.prototype.render = function () {
|
|
101
|
-
var _a = this.props, cells = _a.cells, columns = _a.columns, children = _a.children, rowRender = _a.rowRender, rowIndex = _a.rowIndex;
|
|
102
|
-
var unexpandable = !children;
|
|
103
|
-
return (react_1.default.createElement("tbody", { ref: this.rowRef },
|
|
104
|
-
react_1.default.createElement(TableRow_1.default, { cells: __assign(__assign({}, cells), { expandIcon: unexpandable ? (' ') : (react_1.default.createElement(ffe_icons_react_1.Icon, { className: (0, classnames_1.default)('ffe-table__expand-icon', {
|
|
105
|
-
'ffe-table__expand-icon--expanded': this.state.expanded,
|
|
106
|
-
}), fileUrl: "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik00ODAtMzczLjUzOXEtNy4yMzEgMC0xMy40NjEtMi4zMDgtNi4yMzEtMi4zMDgtMTEuODQ2LTcuOTIzTDI3NC45MjQtNTYzLjUzOXEtOC4zMDgtOC4zMDctOC41LTIwLjg4NC0uMTkzLTEyLjU3NyA4LjUtMjEuMjY5IDguNjkyLTguNjkyIDIxLjA3Ni04LjY5MnQyMS4wNzYgOC42OTJMNDgwLTQ0Mi43NjhsMTYyLjkyNC0xNjIuOTI0cTguMzA3LTguMzA3IDIwLjg4NC04LjUgMTIuNTc2LS4xOTIgMjEuMjY4IDguNSA4LjY5MyA4LjY5MiA4LjY5MyAyMS4wNzcgMCAxMi4zODQtOC42OTMgMjEuMDc2TDUwNS4zMDctMzgzLjc3cS01LjYxNSA1LjYxNS0xMS44NDYgNy45MjMtNi4yMyAyLjMwOC0xMy40NjEgMi4zMDhaIi8+PC9zdmc+", size: "md" })) }), trClasses: (0, classnames_1.default)({ 'ffe-table__row-expandable': !unexpandable }, {
|
|
107
|
-
'ffe-table__row-expandable--expanded': this.state.expanded,
|
|
108
|
-
}), columns: columns, onClick: this.toggleExpand, onKeyDown: this.handleKeyPress, expandable: !unexpandable, expanded: this.state.expanded, rowRender: rowRender, rowIndex: rowIndex }),
|
|
109
|
-
react_1.default.createElement("tr", { role: "presentation", "aria-hidden": String(!this.state.expanded), className: (0, classnames_1.default)('ffe-table__row', 'ffe-table__row-expandable-content', {
|
|
110
|
-
'ffe-table__row-expandable-content--expanded': this.state.expanded,
|
|
111
|
-
}, { 'ffe-table__row--collapsed': !this.state.expanded }) },
|
|
112
|
-
react_1.default.createElement("td", { colSpan: columns.length, className: "ffe-table__cell-expandable-content" },
|
|
113
|
-
react_1.default.createElement("div", null, this.state.expanded && children)))));
|
|
114
|
-
};
|
|
115
|
-
return TableRowExpandable;
|
|
116
|
-
}(react_1.Component));
|
|
117
|
-
TableRowExpandable.propTypes = {
|
|
118
|
-
children: prop_types_1.default.node,
|
|
119
|
-
cells: prop_types_1.default.object.isRequired,
|
|
120
|
-
columns: prop_types_1.default.array.isRequired,
|
|
121
|
-
sort: prop_types_1.default.object,
|
|
122
|
-
rowRender: prop_types_1.default.func,
|
|
123
|
-
headerRender: prop_types_1.default.func,
|
|
124
|
-
footerRender: prop_types_1.default.func,
|
|
125
|
-
rowIndex: prop_types_1.default.number,
|
|
126
|
-
defaultExpanded: prop_types_1.default.bool,
|
|
127
|
-
scrollToOnMount: prop_types_1.default.bool,
|
|
128
|
-
};
|
|
129
|
-
(0, react_lifecycles_compat_1.polyfill)(TableRowExpandable);
|
|
130
|
-
exports.default = TableRowExpandable;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var react_1 = __importDefault(require("react"));
|
|
18
|
-
var TableRowExpandable_1 = __importDefault(require("./TableRowExpandable"));
|
|
19
|
-
var react_2 = require("@testing-library/react");
|
|
20
|
-
var props = {
|
|
21
|
-
cells: {
|
|
22
|
-
name: 'Ola Normann',
|
|
23
|
-
address: 'Gateveien 2',
|
|
24
|
-
age: 23,
|
|
25
|
-
phone: '912 34 567',
|
|
26
|
-
email: 'ola@normann.no',
|
|
27
|
-
},
|
|
28
|
-
columns: [
|
|
29
|
-
{ key: 'name', content: 'Navn' },
|
|
30
|
-
{ key: 'address', content: 'Adresse' },
|
|
31
|
-
{ key: 'age', content: 'Alder', alignRight: true },
|
|
32
|
-
{ key: 'phone', content: 'Telefon' },
|
|
33
|
-
{ key: 'email', content: 'E-post' },
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
describe('<TableRowExpandable>', function () {
|
|
37
|
-
it('should be collapsed by default', function () {
|
|
38
|
-
var container = (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
|
|
39
|
-
react_1.default.createElement("p", null, "The cake is a lie"))).container;
|
|
40
|
-
expect(container.querySelectorAll('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
41
|
-
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
42
|
-
expect(content.getAttribute('aria-hidden')).toBe('true');
|
|
43
|
-
expect(content.classList.contains('ffe-table__row--collapsed')).toBeTruthy();
|
|
44
|
-
});
|
|
45
|
-
it('should be expanded if provided true defaultExpanded', function () {
|
|
46
|
-
var container = (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { defaultExpanded: true }),
|
|
47
|
-
react_1.default.createElement("p", null, "The cake is a lie"))).container;
|
|
48
|
-
expect(container.querySelectorAll('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
49
|
-
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
50
|
-
expect(content.getAttribute('aria-hidden')).toBe('false');
|
|
51
|
-
expect(content.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
54
|
-
var scrollIntoViewMock = jest.fn();
|
|
55
|
-
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
56
|
-
(0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { scrollToOnMount: true }),
|
|
57
|
-
react_1.default.createElement("p", null, "The cake is a lie")));
|
|
58
|
-
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
59
|
-
});
|
|
60
|
-
it('should render expanded content', function () {
|
|
61
|
-
(0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
|
|
62
|
-
react_1.default.createElement("p", null, "The cake is a lie")));
|
|
63
|
-
var row = react_2.screen.getByRole('button');
|
|
64
|
-
react_2.fireEvent.click(row);
|
|
65
|
-
var expandedContent = react_2.screen.getByRole('presentation');
|
|
66
|
-
expect(expandedContent.textContent).toBe('The cake is a lie');
|
|
67
|
-
expect(expandedContent.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
68
|
-
expect(expandedContent.classList.contains('ffe-table__row--collapsed')).toBeFalsy();
|
|
69
|
-
});
|
|
70
|
-
});
|
package/types/index.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
export interface RowRenderTrProps extends React.ComponentProps<'tr'> {}
|
|
4
|
-
|
|
5
|
-
export interface TableRowProps {
|
|
6
|
-
cells: Data;
|
|
7
|
-
columns: Column[];
|
|
8
|
-
expandable?: boolean;
|
|
9
|
-
expanded?: boolean;
|
|
10
|
-
onClick?: (e: React.MouseEvent | undefined) => void;
|
|
11
|
-
rowRender?: (
|
|
12
|
-
trprops: RowRenderTrProps,
|
|
13
|
-
props: TableRowProps,
|
|
14
|
-
rowIndex: number,
|
|
15
|
-
) => JSX.Element;
|
|
16
|
-
headerRender?: (
|
|
17
|
-
trprops: HeaderRenderTrProps,
|
|
18
|
-
columns: Column[],
|
|
19
|
-
) => JSX.Element;
|
|
20
|
-
footerRender?: (
|
|
21
|
-
trprops: HeaderRenderTrProps,
|
|
22
|
-
columns: Column[],
|
|
23
|
-
) => JSX.Element;
|
|
24
|
-
onKeyDown?: (e: React.KeyboardEvent | undefined) => void;
|
|
25
|
-
trClasses?: string;
|
|
26
|
-
rowIndex?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SpanProps {
|
|
30
|
-
className?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ThProps {
|
|
34
|
-
className: string;
|
|
35
|
-
key: number;
|
|
36
|
-
'aria-sort': 'none' | 'ascending' | 'descending' | 'other';
|
|
37
|
-
scope: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface TdProps {
|
|
41
|
-
classNames: string;
|
|
42
|
-
'data-th': string;
|
|
43
|
-
key: number;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Column {
|
|
47
|
-
header: React.ReactNode | '';
|
|
48
|
-
key: string;
|
|
49
|
-
footer?: React.ReactNode;
|
|
50
|
-
alignRight?: boolean;
|
|
51
|
-
alignTop?: boolean;
|
|
52
|
-
hideOnDesktop?: boolean;
|
|
53
|
-
hideOnTablet?: boolean;
|
|
54
|
-
hideOnSmallTablet?: boolean;
|
|
55
|
-
hideOnMobile?: boolean;
|
|
56
|
-
compare?: (a: any, b: any) => number;
|
|
57
|
-
notSortable?: boolean;
|
|
58
|
-
cellRender?: (
|
|
59
|
-
value: any,
|
|
60
|
-
col: Column,
|
|
61
|
-
props: TableRowProps,
|
|
62
|
-
index: number,
|
|
63
|
-
) => JSX.Element;
|
|
64
|
-
columnHeaderRender?: (
|
|
65
|
-
value: React.ReactNode | '',
|
|
66
|
-
dataWindow: Data[],
|
|
67
|
-
spanProps: SpanProps,
|
|
68
|
-
thProps: ThProps,
|
|
69
|
-
columns: Column[],
|
|
70
|
-
index: number,
|
|
71
|
-
) => JSX.Element;
|
|
72
|
-
columnFooterRender?: (
|
|
73
|
-
value: any,
|
|
74
|
-
dataWindow: Data[],
|
|
75
|
-
tdProps: TdProps,
|
|
76
|
-
spanProps: SpanProps,
|
|
77
|
-
columns: Column[],
|
|
78
|
-
index: number,
|
|
79
|
-
) => JSX.Element;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface Data {
|
|
83
|
-
id?: string | number;
|
|
84
|
-
[propName: string]: any;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface HeaderRenderTrProps {
|
|
88
|
-
className: string;
|
|
89
|
-
children: any;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export type OnSortParam = {
|
|
93
|
-
sortBy: string;
|
|
94
|
-
descending: boolean;
|
|
95
|
-
tableData: Data[];
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export interface TableProps {
|
|
99
|
-
caption?: React.ReactNode;
|
|
100
|
-
srOnlyCaption?: boolean;
|
|
101
|
-
expandedContentMapper?: (data: Data) => JSX.Element | false;
|
|
102
|
-
sortable?: boolean;
|
|
103
|
-
sortBy?: string;
|
|
104
|
-
onSort?: (config: OnSortParam) => void;
|
|
105
|
-
descending?: boolean;
|
|
106
|
-
offset?: number;
|
|
107
|
-
limit?: number;
|
|
108
|
-
condensed?: boolean;
|
|
109
|
-
smallHeader?: boolean;
|
|
110
|
-
alignLeft?: boolean;
|
|
111
|
-
columnLayoutMobile?: boolean;
|
|
112
|
-
breakpoint?: 'sm' | 'none';
|
|
113
|
-
rowRender?: (
|
|
114
|
-
trprops: RowRenderTrProps,
|
|
115
|
-
props: TableRowProps,
|
|
116
|
-
rowIndex: number,
|
|
117
|
-
) => JSX.Element;
|
|
118
|
-
headerRender?: (
|
|
119
|
-
trprops: HeaderRenderTrProps,
|
|
120
|
-
columns: Column[],
|
|
121
|
-
) => JSX.Element;
|
|
122
|
-
footerRender?: (
|
|
123
|
-
trprops: HeaderRenderTrProps,
|
|
124
|
-
columns: Column[],
|
|
125
|
-
) => JSX.Element;
|
|
126
|
-
data?: Data[];
|
|
127
|
-
columns?: Column[];
|
|
128
|
-
className?: string;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
declare class Table extends React.Component<TableProps, any> {}
|
|
132
|
-
|
|
133
|
-
export default Table;
|