@sb1/ffe-tables-react 8.0.31 → 8.0.32
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,24 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
28
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
29
|
+
if (ar || !(i in from)) {
|
|
30
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
31
|
+
ar[i] = from[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
35
|
+
};
|
|
22
36
|
import React, { Component } from 'react';
|
|
23
37
|
import PropTypes from 'prop-types';
|
|
24
38
|
import classNames from 'classnames';
|
|
@@ -26,182 +40,115 @@ import TableHeaders from '../TableParts/TableHeaders';
|
|
|
26
40
|
import TableFooter from '../TableParts/TableFooter';
|
|
27
41
|
import TableRow from '../TableParts/TableRow';
|
|
28
42
|
import TableRowExpandable from '../TableParts/TableRowExpandable';
|
|
29
|
-
var DefaultTable =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
_inherits(DefaultTable, _Component);
|
|
35
|
-
return _createClass(DefaultTable, [{
|
|
36
|
-
key: "renderTableCaption",
|
|
37
|
-
value: function renderTableCaption() {
|
|
38
|
-
var _this$props = this.props,
|
|
39
|
-
caption = _this$props.caption,
|
|
40
|
-
srOnlyCaption = _this$props.srOnlyCaption;
|
|
41
|
-
if (!caption) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
if (srOnlyCaption) {
|
|
45
|
-
return /*#__PURE__*/React.createElement("caption", {
|
|
46
|
-
className: "ffe-screenreader-only",
|
|
47
|
-
"aria-live": "polite"
|
|
48
|
-
}, caption);
|
|
49
|
-
}
|
|
50
|
-
return /*#__PURE__*/React.createElement("caption", {
|
|
51
|
-
className: "ffe-table__caption"
|
|
52
|
-
}, caption);
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
key: "renderTableHeaders",
|
|
56
|
-
value: function renderTableHeaders() {
|
|
57
|
-
var _this$props2 = this.props,
|
|
58
|
-
_this$props2$columns = _this$props2.columns,
|
|
59
|
-
columns = _this$props2$columns === void 0 ? [] : _this$props2$columns,
|
|
60
|
-
headerRender = _this$props2.headerRender;
|
|
61
|
-
if (!columns.length) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
var renderColumns = _toConsumableArray(columns);
|
|
65
|
-
if (this.props.expandedContentMapper) {
|
|
66
|
-
renderColumns.push({
|
|
67
|
-
key: 'expandIcon',
|
|
68
|
-
header: /*#__PURE__*/React.createElement("span", {
|
|
69
|
-
className: "ffe-screenreader-only"
|
|
70
|
-
}, "Valg for raden"),
|
|
71
|
-
alignRight: true
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return /*#__PURE__*/React.createElement(TableHeaders, {
|
|
75
|
-
columns: renderColumns,
|
|
76
|
-
headerRender: headerRender,
|
|
77
|
-
dataWindow: this.getData()
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}, {
|
|
81
|
-
key: "renderTableFooter",
|
|
82
|
-
value: function renderTableFooter() {
|
|
83
|
-
var _this$props3 = this.props,
|
|
84
|
-
columns = _this$props3.columns,
|
|
85
|
-
footerRender = _this$props3.footerRender;
|
|
86
|
-
if (!columns.some(function (column) {
|
|
87
|
-
return column.footer;
|
|
88
|
-
})) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
return /*#__PURE__*/React.createElement(TableFooter, {
|
|
92
|
-
columns: columns,
|
|
93
|
-
footerRender: footerRender,
|
|
94
|
-
dataWindow: this.getData()
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}, {
|
|
98
|
-
key: "getData",
|
|
99
|
-
value: function getData() {
|
|
100
|
-
var _this$props4 = this.props,
|
|
101
|
-
_this$props4$data = _this$props4.data,
|
|
102
|
-
data = _this$props4$data === void 0 ? [] : _this$props4$data,
|
|
103
|
-
_this$props4$offset = _this$props4.offset,
|
|
104
|
-
offset = _this$props4$offset === void 0 ? 0 : _this$props4$offset,
|
|
105
|
-
_this$props4$limit = _this$props4.limit,
|
|
106
|
-
limit = _this$props4$limit === void 0 ? 0 : _this$props4$limit;
|
|
107
|
-
if (!offset && !limit) {
|
|
108
|
-
return data;
|
|
109
|
-
}
|
|
110
|
-
return data.slice(offset, limit ? offset + limit : data.length);
|
|
111
|
-
}
|
|
112
|
-
}, {
|
|
113
|
-
key: "renderTableBody",
|
|
114
|
-
value: function renderTableBody() {
|
|
115
|
-
var _this$props5 = this.props,
|
|
116
|
-
columns = _this$props5.columns,
|
|
117
|
-
expandedContentMapper = _this$props5.expandedContentMapper,
|
|
118
|
-
sort = _this$props5.sort,
|
|
119
|
-
rowRender = _this$props5.rowRender;
|
|
120
|
-
var data = this.getData();
|
|
121
|
-
if (!data.length) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
var renderColumns = _toConsumableArray(columns);
|
|
125
|
-
if (expandedContentMapper) {
|
|
126
|
-
renderColumns.push({
|
|
127
|
-
key: 'expandIcon',
|
|
128
|
-
header: '',
|
|
129
|
-
alignRight: true
|
|
130
|
-
});
|
|
131
|
-
return data.map(function (row, index) {
|
|
132
|
-
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
133
|
-
var expandedContent = expandedContentMapper(row);
|
|
134
|
-
var rowProps = {
|
|
135
|
-
cells: row,
|
|
136
|
-
columns: renderColumns,
|
|
137
|
-
sort: sort,
|
|
138
|
-
rowRender: rowRender,
|
|
139
|
-
rowIndex: index,
|
|
140
|
-
defaultExpanded: row.defaultExpanded,
|
|
141
|
-
scrollToOnMount: row.scrollToOnMount
|
|
142
|
-
};
|
|
143
|
-
return expandedContent ? /*#__PURE__*/React.createElement(TableRowExpandable, _extends({
|
|
144
|
-
key: key
|
|
145
|
-
}, rowProps), expandedContent) : /*#__PURE__*/React.createElement("tbody", {
|
|
146
|
-
key: key
|
|
147
|
-
}, /*#__PURE__*/React.createElement(TableRow, rowProps));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
return /*#__PURE__*/React.createElement("tbody", null, data.map(function (row, index) {
|
|
151
|
-
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
152
|
-
return /*#__PURE__*/React.createElement(TableRow, {
|
|
153
|
-
cells: row,
|
|
154
|
-
columns: columns,
|
|
155
|
-
key: key,
|
|
156
|
-
rowRender: rowRender,
|
|
157
|
-
rowIndex: index
|
|
158
|
-
});
|
|
159
|
-
}));
|
|
160
|
-
}
|
|
161
|
-
}, {
|
|
162
|
-
key: "render",
|
|
163
|
-
value: function render() {
|
|
164
|
-
var _this$props6 = this.props,
|
|
165
|
-
alignLeft = _this$props6.alignLeft,
|
|
166
|
-
condensed = _this$props6.condensed,
|
|
167
|
-
smallHeader = _this$props6.smallHeader,
|
|
168
|
-
columnLayoutMobile = _this$props6.columnLayoutMobile,
|
|
169
|
-
breakpoint = _this$props6.breakpoint,
|
|
170
|
-
className = _this$props6.className;
|
|
171
|
-
return /*#__PURE__*/React.createElement("table", {
|
|
172
|
-
className: classNames('ffe-table', {
|
|
173
|
-
'ffe-table--condensed': condensed
|
|
174
|
-
}, {
|
|
175
|
-
'ffe-table--small-header': smallHeader
|
|
176
|
-
}, {
|
|
177
|
-
'ffe-table--columns-sm': columnLayoutMobile
|
|
178
|
-
}, {
|
|
179
|
-
'ffe-table--text-left': alignLeft
|
|
180
|
-
}, _defineProperty({}, "ffe-table--breakpoint-".concat(breakpoint), !!breakpoint), className)
|
|
181
|
-
}, this.renderTableCaption(), this.renderTableHeaders(), this.renderTableFooter(), this.renderTableBody());
|
|
43
|
+
var DefaultTable = /** @class */ (function (_super) {
|
|
44
|
+
__extends(DefaultTable, _super);
|
|
45
|
+
function DefaultTable() {
|
|
46
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
182
47
|
}
|
|
183
|
-
|
|
184
|
-
|
|
48
|
+
DefaultTable.prototype.renderTableCaption = function () {
|
|
49
|
+
var _a = this.props, caption = _a.caption, srOnlyCaption = _a.srOnlyCaption;
|
|
50
|
+
if (!caption) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (srOnlyCaption) {
|
|
54
|
+
return (React.createElement("caption", { className: "ffe-screenreader-only", "aria-live": "polite" }, caption));
|
|
55
|
+
}
|
|
56
|
+
return React.createElement("caption", { className: "ffe-table__caption" }, caption);
|
|
57
|
+
};
|
|
58
|
+
DefaultTable.prototype.renderTableHeaders = function () {
|
|
59
|
+
var _a = this.props, _b = _a.columns, columns = _b === void 0 ? [] : _b, headerRender = _a.headerRender;
|
|
60
|
+
if (!columns.length) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
var renderColumns = __spreadArray([], columns, true);
|
|
64
|
+
if (this.props.expandedContentMapper) {
|
|
65
|
+
renderColumns.push({
|
|
66
|
+
key: 'expandIcon',
|
|
67
|
+
header: (React.createElement("span", { className: "ffe-screenreader-only" }, "Valg for raden")),
|
|
68
|
+
alignRight: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return (React.createElement(TableHeaders, { columns: renderColumns, headerRender: headerRender, dataWindow: this.getData() }));
|
|
72
|
+
};
|
|
73
|
+
DefaultTable.prototype.renderTableFooter = function () {
|
|
74
|
+
var _a = this.props, columns = _a.columns, footerRender = _a.footerRender;
|
|
75
|
+
if (!columns.some(function (column) { return column.footer; })) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return (React.createElement(TableFooter, { columns: columns, footerRender: footerRender, dataWindow: this.getData() }));
|
|
79
|
+
};
|
|
80
|
+
DefaultTable.prototype.getData = function () {
|
|
81
|
+
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;
|
|
82
|
+
if (!offset && !limit) {
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
return data.slice(offset, limit ? offset + limit : data.length);
|
|
86
|
+
};
|
|
87
|
+
DefaultTable.prototype.renderTableBody = function () {
|
|
88
|
+
var _a = this.props, columns = _a.columns, expandedContentMapper = _a.expandedContentMapper, sort = _a.sort, rowRender = _a.rowRender;
|
|
89
|
+
var data = this.getData();
|
|
90
|
+
if (!data.length) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
var renderColumns = __spreadArray([], columns, true);
|
|
94
|
+
if (expandedContentMapper) {
|
|
95
|
+
renderColumns.push({
|
|
96
|
+
key: 'expandIcon',
|
|
97
|
+
header: '',
|
|
98
|
+
alignRight: true,
|
|
99
|
+
});
|
|
100
|
+
return data.map(function (row, index) {
|
|
101
|
+
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
102
|
+
var expandedContent = expandedContentMapper(row);
|
|
103
|
+
var rowProps = {
|
|
104
|
+
cells: row,
|
|
105
|
+
columns: renderColumns,
|
|
106
|
+
sort: sort,
|
|
107
|
+
rowRender: rowRender,
|
|
108
|
+
rowIndex: index,
|
|
109
|
+
defaultExpanded: row.defaultExpanded,
|
|
110
|
+
scrollToOnMount: row.scrollToOnMount,
|
|
111
|
+
};
|
|
112
|
+
return expandedContent ? (React.createElement(TableRowExpandable, __assign({ key: key }, rowProps), expandedContent)) : (React.createElement("tbody", { key: key },
|
|
113
|
+
React.createElement(TableRow, __assign({}, rowProps))));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return (React.createElement("tbody", null, data.map(function (row, index) {
|
|
117
|
+
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
118
|
+
return (React.createElement(TableRow, { cells: row, columns: columns, key: key, rowRender: rowRender, rowIndex: index }));
|
|
119
|
+
})));
|
|
120
|
+
};
|
|
121
|
+
DefaultTable.prototype.render = function () {
|
|
122
|
+
var _a;
|
|
123
|
+
var _b = this.props, alignLeft = _b.alignLeft, condensed = _b.condensed, smallHeader = _b.smallHeader, columnLayoutMobile = _b.columnLayoutMobile, breakpoint = _b.breakpoint, className = _b.className;
|
|
124
|
+
return (React.createElement("table", { className: classNames('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) },
|
|
125
|
+
this.renderTableCaption(),
|
|
126
|
+
this.renderTableHeaders(),
|
|
127
|
+
this.renderTableFooter(),
|
|
128
|
+
this.renderTableBody()));
|
|
129
|
+
};
|
|
130
|
+
return DefaultTable;
|
|
131
|
+
}(Component));
|
|
185
132
|
DefaultTable.propTypes = {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
133
|
+
alignLeft: PropTypes.bool,
|
|
134
|
+
columnLayoutMobile: PropTypes.bool,
|
|
135
|
+
caption: PropTypes.node,
|
|
136
|
+
srOnlyCaption: PropTypes.bool,
|
|
137
|
+
expandedContentMapper: PropTypes.func,
|
|
138
|
+
condensed: PropTypes.bool,
|
|
139
|
+
smallHeader: PropTypes.bool,
|
|
140
|
+
sort: PropTypes.object,
|
|
141
|
+
offset: PropTypes.number,
|
|
142
|
+
limit: PropTypes.number,
|
|
143
|
+
breakpoint: PropTypes.oneOf(['sm', 'none']),
|
|
144
|
+
data: PropTypes.arrayOf(PropTypes.object),
|
|
145
|
+
columns: PropTypes.arrayOf(PropTypes.shape({
|
|
146
|
+
header: PropTypes.node.isRequired,
|
|
147
|
+
key: PropTypes.string.isRequired,
|
|
148
|
+
}).isRequired),
|
|
149
|
+
rowRender: PropTypes.func,
|
|
150
|
+
headerRender: PropTypes.func,
|
|
151
|
+
footerRender: PropTypes.func,
|
|
152
|
+
className: PropTypes.string,
|
|
206
153
|
};
|
|
207
|
-
export default DefaultTable;
|
|
154
|
+
export default DefaultTable;
|