@sb1/ffe-tables-react 8.0.30 → 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,216 +1,182 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
34
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
35
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
36
|
-
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
37
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
38
|
-
var DefaultTable = /*#__PURE__*/function (_Component) {
|
|
39
|
-
function DefaultTable() {
|
|
40
|
-
_classCallCheck(this, DefaultTable);
|
|
41
|
-
return _callSuper(this, DefaultTable, arguments);
|
|
42
|
-
}
|
|
43
|
-
_inherits(DefaultTable, _Component);
|
|
44
|
-
return _createClass(DefaultTable, [{
|
|
45
|
-
key: "renderTableCaption",
|
|
46
|
-
value: function renderTableCaption() {
|
|
47
|
-
var _this$props = this.props,
|
|
48
|
-
caption = _this$props.caption,
|
|
49
|
-
srOnlyCaption = _this$props.srOnlyCaption;
|
|
50
|
-
if (!caption) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
if (srOnlyCaption) {
|
|
54
|
-
return /*#__PURE__*/_react.default.createElement("caption", {
|
|
55
|
-
className: "ffe-screenreader-only",
|
|
56
|
-
"aria-live": "polite"
|
|
57
|
-
}, caption);
|
|
58
|
-
}
|
|
59
|
-
return /*#__PURE__*/_react.default.createElement("caption", {
|
|
60
|
-
className: "ffe-table__caption"
|
|
61
|
-
}, caption);
|
|
62
|
-
}
|
|
63
|
-
}, {
|
|
64
|
-
key: "renderTableHeaders",
|
|
65
|
-
value: function renderTableHeaders() {
|
|
66
|
-
var _this$props2 = this.props,
|
|
67
|
-
_this$props2$columns = _this$props2.columns,
|
|
68
|
-
columns = _this$props2$columns === void 0 ? [] : _this$props2$columns,
|
|
69
|
-
headerRender = _this$props2.headerRender;
|
|
70
|
-
if (!columns.length) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
var renderColumns = _toConsumableArray(columns);
|
|
74
|
-
if (this.props.expandedContentMapper) {
|
|
75
|
-
renderColumns.push({
|
|
76
|
-
key: 'expandIcon',
|
|
77
|
-
header: /*#__PURE__*/_react.default.createElement("span", {
|
|
78
|
-
className: "ffe-screenreader-only"
|
|
79
|
-
}, "Valg for raden"),
|
|
80
|
-
alignRight: true
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return /*#__PURE__*/_react.default.createElement(_TableHeaders.default, {
|
|
84
|
-
columns: renderColumns,
|
|
85
|
-
headerRender: headerRender,
|
|
86
|
-
dataWindow: this.getData()
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "renderTableFooter",
|
|
91
|
-
value: function renderTableFooter() {
|
|
92
|
-
var _this$props3 = this.props,
|
|
93
|
-
columns = _this$props3.columns,
|
|
94
|
-
footerRender = _this$props3.footerRender;
|
|
95
|
-
if (!columns.some(function (column) {
|
|
96
|
-
return column.footer;
|
|
97
|
-
})) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
return /*#__PURE__*/_react.default.createElement(_TableFooter.default, {
|
|
101
|
-
columns: columns,
|
|
102
|
-
footerRender: footerRender,
|
|
103
|
-
dataWindow: this.getData()
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}, {
|
|
107
|
-
key: "getData",
|
|
108
|
-
value: function getData() {
|
|
109
|
-
var _this$props4 = this.props,
|
|
110
|
-
_this$props4$data = _this$props4.data,
|
|
111
|
-
data = _this$props4$data === void 0 ? [] : _this$props4$data,
|
|
112
|
-
_this$props4$offset = _this$props4.offset,
|
|
113
|
-
offset = _this$props4$offset === void 0 ? 0 : _this$props4$offset,
|
|
114
|
-
_this$props4$limit = _this$props4.limit,
|
|
115
|
-
limit = _this$props4$limit === void 0 ? 0 : _this$props4$limit;
|
|
116
|
-
if (!offset && !limit) {
|
|
117
|
-
return data;
|
|
118
|
-
}
|
|
119
|
-
return data.slice(offset, limit ? offset + limit : data.length);
|
|
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]; } };
|
|
120
33
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
cells: row,
|
|
145
|
-
columns: renderColumns,
|
|
146
|
-
sort: sort,
|
|
147
|
-
rowRender: rowRender,
|
|
148
|
-
rowIndex: index,
|
|
149
|
-
defaultExpanded: row.defaultExpanded,
|
|
150
|
-
scrollToOnMount: row.scrollToOnMount
|
|
151
|
-
};
|
|
152
|
-
return expandedContent ? /*#__PURE__*/_react.default.createElement(_TableRowExpandable.default, _extends({
|
|
153
|
-
key: key
|
|
154
|
-
}, rowProps), expandedContent) : /*#__PURE__*/_react.default.createElement("tbody", {
|
|
155
|
-
key: key
|
|
156
|
-
}, /*#__PURE__*/_react.default.createElement(_TableRow.default, rowProps));
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
return /*#__PURE__*/_react.default.createElement("tbody", null, data.map(function (row, index) {
|
|
160
|
-
var key = row.id || row.id === 0 ? row.id.toString() : index;
|
|
161
|
-
return /*#__PURE__*/_react.default.createElement(_TableRow.default, {
|
|
162
|
-
cells: row,
|
|
163
|
-
columns: columns,
|
|
164
|
-
key: key,
|
|
165
|
-
rowRender: rowRender,
|
|
166
|
-
rowIndex: index
|
|
167
|
-
});
|
|
168
|
-
}));
|
|
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
|
+
}
|
|
169
57
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}, {
|
|
188
|
-
'ffe-table--text-left': alignLeft
|
|
189
|
-
}, _defineProperty({}, "ffe-table--breakpoint-".concat(breakpoint), !!breakpoint), className)
|
|
190
|
-
}, this.renderTableCaption(), this.renderTableHeaders(), this.renderTableFooter(), this.renderTableBody());
|
|
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;
|
|
191
75
|
}
|
|
192
|
-
|
|
193
|
-
|
|
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));
|
|
194
160
|
DefaultTable.propTypes = {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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,
|
|
215
181
|
};
|
|
216
|
-
|
|
182
|
+
exports.default = DefaultTable;
|