@entur/table 4.9.13 → 4.9.14-beta.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/dist/index.d.ts +226 -13
- package/dist/styles.css +100 -118
- package/dist/table.cjs.js +801 -0
- package/dist/table.cjs.js.map +1 -0
- package/dist/table.esm.js +743 -436
- package/dist/table.esm.js.map +1 -1
- package/package.json +37 -19
- package/dist/DataCell.d.ts +0 -20
- package/dist/EditableCell.d.ts +0 -24
- package/dist/ExpandRowButton.d.ts +0 -7
- package/dist/ExpandableRow.d.ts +0 -12
- package/dist/HeaderCell.d.ts +0 -24
- package/dist/Table.d.ts +0 -21
- package/dist/TableBody.d.ts +0 -9
- package/dist/TableFooter.d.ts +0 -6
- package/dist/TableHead.d.ts +0 -8
- package/dist/TableRow.d.ts +0 -21
- package/dist/index.js +0 -8
- package/dist/table.cjs.development.js +0 -509
- package/dist/table.cjs.development.js.map +0 -1
- package/dist/table.cjs.production.min.js +0 -2
- package/dist/table.cjs.production.min.js.map +0 -1
- package/dist/useSortableTable.d.ts +0 -41
- package/dist/useTableKeyboardNavigation.d.ts +0 -14
package/dist/table.esm.js
CHANGED
|
@@ -1,428 +1,745 @@
|
|
|
1
|
-
import { useRandomId, mergeRefs, warnAboutMissingStyles } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { VisuallyHidden } from
|
|
5
|
-
import { BulletBadge } from
|
|
6
|
-
import { UnsortedIcon, UpArrowIcon, DownArrowIcon } from
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
15
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
16
|
-
var t = arguments[e];
|
|
17
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
18
|
-
}
|
|
19
|
-
return n;
|
|
20
|
-
}, _extends.apply(null, arguments);
|
|
21
|
-
}
|
|
22
|
-
function _objectDestructuringEmpty(t) {
|
|
23
|
-
if (null == t) throw new TypeError("Cannot destructure " + t);
|
|
1
|
+
import { useRandomId, mergeRefs, warnAboutMissingStyles } from "@entur/utils";
|
|
2
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { useRef, useEffect, useState, useMemo } from "react";
|
|
4
|
+
import { VisuallyHidden } from "@entur/a11y";
|
|
5
|
+
import { BulletBadge } from "@entur/layout";
|
|
6
|
+
import { UnsortedIcon, UpArrowIcon, DownArrowIcon } from "@entur/icons";
|
|
7
|
+
import { VariantProvider } from "@entur/form";
|
|
8
|
+
import { Tooltip } from "@entur/tooltip";
|
|
9
|
+
import { BaseExpand } from "@entur/expand";
|
|
10
|
+
import { IconButton } from "@entur/button";
|
|
11
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
12
|
+
function getDefaultExportFromCjs(x) {
|
|
13
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
var classnames = { exports: {} };
|
|
16
|
+
/*!
|
|
17
|
+
Copyright (c) 2018 Jed Watson.
|
|
18
|
+
Licensed under the MIT License (MIT), see
|
|
19
|
+
http://jedwatson.github.io/classnames
|
|
20
|
+
*/
|
|
21
|
+
var hasRequiredClassnames;
|
|
22
|
+
function requireClassnames() {
|
|
23
|
+
if (hasRequiredClassnames) return classnames.exports;
|
|
24
|
+
hasRequiredClassnames = 1;
|
|
25
|
+
(function(module) {
|
|
26
|
+
(function() {
|
|
27
|
+
var hasOwn = {}.hasOwnProperty;
|
|
28
|
+
function classNames2() {
|
|
29
|
+
var classes = "";
|
|
30
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
31
|
+
var arg = arguments[i];
|
|
32
|
+
if (arg) {
|
|
33
|
+
classes = appendClass(classes, parseValue(arg));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return classes;
|
|
37
|
+
}
|
|
38
|
+
function parseValue(arg) {
|
|
39
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
40
|
+
return arg;
|
|
41
|
+
}
|
|
42
|
+
if (typeof arg !== "object") {
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(arg)) {
|
|
46
|
+
return classNames2.apply(null, arg);
|
|
47
|
+
}
|
|
48
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
49
|
+
return arg.toString();
|
|
50
|
+
}
|
|
51
|
+
var classes = "";
|
|
52
|
+
for (var key in arg) {
|
|
53
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
54
|
+
classes = appendClass(classes, key);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return classes;
|
|
58
|
+
}
|
|
59
|
+
function appendClass(value, newClass) {
|
|
60
|
+
if (!newClass) {
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
if (value) {
|
|
64
|
+
return value + " " + newClass;
|
|
65
|
+
}
|
|
66
|
+
return value + newClass;
|
|
67
|
+
}
|
|
68
|
+
if (module.exports) {
|
|
69
|
+
classNames2.default = classNames2;
|
|
70
|
+
module.exports = classNames2;
|
|
71
|
+
} else {
|
|
72
|
+
window.classNames = classNames2;
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
75
|
+
})(classnames);
|
|
76
|
+
return classnames.exports;
|
|
33
77
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
fixed =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
var classnamesExports = requireClassnames();
|
|
79
|
+
const classNames = /* @__PURE__ */ getDefaultExportFromCjs(classnamesExports);
|
|
80
|
+
const Table = React.forwardRef(
|
|
81
|
+
({
|
|
82
|
+
className,
|
|
83
|
+
fixed = false,
|
|
84
|
+
spacing = "default",
|
|
85
|
+
sortable = false,
|
|
86
|
+
changeSortDescription = "Tabelloverskrifter med knapper kan trykkes på for å endre sortering,",
|
|
87
|
+
stickyHeader = false,
|
|
88
|
+
...rest
|
|
89
|
+
}, ref) => {
|
|
90
|
+
const sortableHeaderId = useRandomId("sortable-header");
|
|
91
|
+
const tableRef = useRef(null);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (stickyHeader) {
|
|
94
|
+
const tableElement = tableRef.current;
|
|
95
|
+
const observerElement = document.createElement("div");
|
|
96
|
+
observerElement.classList.add("sticky-observer");
|
|
97
|
+
tableElement?.parentNode?.insertBefore(observerElement, tableElement);
|
|
98
|
+
const observer = new IntersectionObserver(
|
|
99
|
+
(entries) => {
|
|
100
|
+
tableElement?.classList.toggle(
|
|
101
|
+
"eds-table--sticky-header--active",
|
|
102
|
+
!entries[0].isIntersecting
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
{ threshold: [0, 1] }
|
|
106
|
+
);
|
|
107
|
+
observer.observe(observerElement);
|
|
108
|
+
return () => {
|
|
109
|
+
observer.unobserve(observerElement);
|
|
110
|
+
observerElement.remove();
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}, [stickyHeader]);
|
|
114
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
115
|
+
/* @__PURE__ */ jsx(
|
|
116
|
+
"table",
|
|
117
|
+
{
|
|
118
|
+
className: classNames(
|
|
119
|
+
"eds-table",
|
|
120
|
+
{ "eds-table--fixed": fixed },
|
|
121
|
+
{ "eds-table--middle": spacing === "middle" },
|
|
122
|
+
{ "eds-table--small": spacing === "small" },
|
|
123
|
+
{ "eds-table--sortable": sortable },
|
|
124
|
+
{ "eds-table--sticky-header": stickyHeader },
|
|
125
|
+
className
|
|
126
|
+
),
|
|
127
|
+
ref: mergeRefs(ref, tableRef),
|
|
128
|
+
"aria-describedby": sortable ? sortableHeaderId : void 0,
|
|
129
|
+
...rest
|
|
130
|
+
}
|
|
131
|
+
),
|
|
132
|
+
sortable && /* @__PURE__ */ jsx(VisuallyHidden, { id: sortableHeaderId, children: changeSortDescription })
|
|
133
|
+
] });
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
const TableHead = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
137
|
+
"thead",
|
|
138
|
+
{
|
|
139
|
+
className: classNames("eds-table__head", className),
|
|
140
|
+
ref,
|
|
141
|
+
...props
|
|
142
|
+
}
|
|
143
|
+
));
|
|
144
|
+
const TableBody = React.forwardRef(({ className, ...rest }, ref) => /* @__PURE__ */ jsx(
|
|
145
|
+
"tbody",
|
|
146
|
+
{
|
|
147
|
+
className: classNames("eds-table__body", className),
|
|
148
|
+
ref,
|
|
149
|
+
...rest
|
|
150
|
+
}
|
|
151
|
+
));
|
|
152
|
+
const TableFooter = React.forwardRef(({ ...props }, ref) => /* @__PURE__ */ jsx("tfoot", { ref, ...props }));
|
|
153
|
+
const TableRow = React.forwardRef(
|
|
154
|
+
({ className, hover = false, active = false, error = false, ...rest }, ref) => /* @__PURE__ */ jsx(
|
|
155
|
+
"tr",
|
|
156
|
+
{
|
|
157
|
+
className: classNames("eds-table__row", className, {
|
|
158
|
+
"eds-table__row--hover": hover,
|
|
159
|
+
"eds-table__row--active": active,
|
|
160
|
+
"eds-table__row--error": error
|
|
161
|
+
}),
|
|
162
|
+
ref,
|
|
163
|
+
...rest
|
|
73
164
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
className: classNames('eds-table', {
|
|
77
|
-
'eds-table--fixed': fixed
|
|
78
|
-
}, {
|
|
79
|
-
'eds-table--middle': spacing === 'middle'
|
|
80
|
-
}, {
|
|
81
|
-
'eds-table--small': spacing === 'small'
|
|
82
|
-
}, {
|
|
83
|
-
'eds-table--sortable': sortable
|
|
84
|
-
}, {
|
|
85
|
-
'eds-table--sticky-header': stickyHeader
|
|
86
|
-
}, className),
|
|
87
|
-
ref: mergeRefs(ref, tableRef),
|
|
88
|
-
"aria-describedby": sortable ? sortableHeaderId : undefined
|
|
89
|
-
}, rest)), sortable && React.createElement(VisuallyHidden, {
|
|
90
|
-
id: sortableHeaderId
|
|
91
|
-
}, changeSortDescription));
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
var _excluded$7 = ["className"];
|
|
95
|
-
var TableHead = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
96
|
-
var className = _ref.className,
|
|
97
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
98
|
-
return React.createElement("thead", _extends({
|
|
99
|
-
className: classNames('eds-table__head', className),
|
|
100
|
-
ref: ref
|
|
101
|
-
}, props));
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
var _excluded$6 = ["className"];
|
|
105
|
-
var TableBody = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
106
|
-
var className = _ref.className,
|
|
107
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
108
|
-
return React.createElement("tbody", _extends({
|
|
109
|
-
className: classNames('eds-table__body', className),
|
|
110
|
-
ref: ref
|
|
111
|
-
}, rest));
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
var TableFooter = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
115
|
-
var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
116
|
-
return React.createElement("tfoot", _extends({
|
|
117
|
-
ref: ref
|
|
118
|
-
}, props));
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
var _excluded$5 = ["className", "hover", "active", "error"];
|
|
122
|
-
var TableRow = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
123
|
-
var className = _ref.className,
|
|
124
|
-
_ref$hover = _ref.hover,
|
|
125
|
-
hover = _ref$hover === void 0 ? false : _ref$hover,
|
|
126
|
-
_ref$active = _ref.active,
|
|
127
|
-
active = _ref$active === void 0 ? false : _ref$active,
|
|
128
|
-
_ref$error = _ref.error,
|
|
129
|
-
error = _ref$error === void 0 ? false : _ref$error,
|
|
130
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
131
|
-
return React.createElement("tr", _extends({
|
|
132
|
-
className: classNames('eds-table__row', className, {
|
|
133
|
-
'eds-table__row--hover': hover,
|
|
134
|
-
'eds-table__row--active': active,
|
|
135
|
-
'eds-table__row--error': error
|
|
136
|
-
}),
|
|
137
|
-
ref: ref
|
|
138
|
-
}, rest));
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
var _excluded$4 = ["className", "padding", "status", "variant", "children"];
|
|
165
|
+
)
|
|
166
|
+
);
|
|
142
167
|
function mapStatusToVariant(status) {
|
|
143
168
|
switch (status) {
|
|
144
|
-
case
|
|
145
|
-
return
|
|
146
|
-
case
|
|
147
|
-
return
|
|
148
|
-
case
|
|
149
|
-
return
|
|
169
|
+
case "positive":
|
|
170
|
+
return "success";
|
|
171
|
+
case "negative":
|
|
172
|
+
return "negative";
|
|
173
|
+
case "neutral":
|
|
174
|
+
return "neutral";
|
|
150
175
|
default:
|
|
151
|
-
return
|
|
176
|
+
return "neutral";
|
|
152
177
|
}
|
|
153
178
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var DISMISS_SORT_INFO_TIME = 3000;
|
|
236
|
-
if (sortConfig.order == 'ascending') {
|
|
179
|
+
const DataCell = React.forwardRef(
|
|
180
|
+
({ className, padding = "default", status, variant, children, ...rest }, ref) => {
|
|
181
|
+
if (!variant && status) {
|
|
182
|
+
variant = mapStatusToVariant(status);
|
|
183
|
+
}
|
|
184
|
+
return /* @__PURE__ */ jsx(
|
|
185
|
+
"td",
|
|
186
|
+
{
|
|
187
|
+
ref,
|
|
188
|
+
className: classNames("eds-table__data-cell", className, {
|
|
189
|
+
"eds-table__data-cell--padding-checkbox": padding === "checkbox",
|
|
190
|
+
"eds-table__data-cell--padding-radio": padding === "radio",
|
|
191
|
+
"eds-table__data-cell--padding-overflow-menu": padding === "overflow-menu"
|
|
192
|
+
}),
|
|
193
|
+
...rest,
|
|
194
|
+
children: variant ? /* @__PURE__ */ jsx(BulletBadge, { variant, children }) : children
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
const HeaderCell = React.forwardRef(
|
|
200
|
+
({
|
|
201
|
+
className,
|
|
202
|
+
children,
|
|
203
|
+
name,
|
|
204
|
+
sortable = false,
|
|
205
|
+
sortConfig,
|
|
206
|
+
padding = "default",
|
|
207
|
+
sortableButtonProps,
|
|
208
|
+
sortedAscendingAriaLabel = ", sortert stigende",
|
|
209
|
+
sortedDescendingAriaLabel = ", sortert synkende",
|
|
210
|
+
...rest
|
|
211
|
+
}, ref) => {
|
|
212
|
+
const [isCurrentlySorted, setIsCurrentlySorted] = React.useState(false);
|
|
213
|
+
React.useEffect(() => {
|
|
214
|
+
sortConfig && name && setIsCurrentlySorted(sortConfig && name === sortConfig.key);
|
|
215
|
+
}, [sortConfig, name]);
|
|
216
|
+
const ariaSort = isCurrentlySorted ? sortConfig && sortConfig.order : void 0;
|
|
217
|
+
return /* @__PURE__ */ jsx(
|
|
218
|
+
"th",
|
|
219
|
+
{
|
|
220
|
+
className: classNames("eds-table__header-cell", className, {
|
|
221
|
+
"eds-table__header-cell--sortable": sortable,
|
|
222
|
+
"eds-table__header-cell--padding-radio": padding === "radio",
|
|
223
|
+
"eds-table__header-cell--padding-checkbox": padding === "checkbox",
|
|
224
|
+
"eds-table__header-cell--padding-overflow-menu": padding === "overflow-menu"
|
|
225
|
+
}),
|
|
226
|
+
"aria-sort": ariaSort,
|
|
227
|
+
ref,
|
|
228
|
+
...rest,
|
|
229
|
+
children: sortable && sortConfig && sortableButtonProps ? /* @__PURE__ */ jsx(
|
|
230
|
+
SortableHeaderCellButton,
|
|
231
|
+
{
|
|
232
|
+
sortableButtonProps,
|
|
233
|
+
sortConfig,
|
|
234
|
+
isCurrentlySorted,
|
|
235
|
+
ariaSort,
|
|
236
|
+
sortedAscendingAriaLabel,
|
|
237
|
+
sortedDescendingAriaLabel,
|
|
238
|
+
children
|
|
239
|
+
}
|
|
240
|
+
) : children
|
|
241
|
+
}
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
const SortableHeaderCellButton = ({
|
|
246
|
+
sortConfig,
|
|
247
|
+
sortableButtonProps,
|
|
248
|
+
isCurrentlySorted,
|
|
249
|
+
children,
|
|
250
|
+
ariaSort,
|
|
251
|
+
sortedAscendingAriaLabel,
|
|
252
|
+
sortedDescendingAriaLabel
|
|
253
|
+
}) => {
|
|
254
|
+
const [sortedAriaInfo, setSortedAriaInfo] = useState("");
|
|
255
|
+
const { className, ...rest } = sortableButtonProps;
|
|
256
|
+
const isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
const DISMISS_SORT_INFO_TIME = 3e3;
|
|
259
|
+
if (sortConfig.order == "ascending") {
|
|
237
260
|
setSortedAriaInfo(sortedAscendingAriaLabel);
|
|
238
|
-
} else if (sortConfig.order ==
|
|
261
|
+
} else if (sortConfig.order == "descending") {
|
|
239
262
|
setSortedAriaInfo(sortedDescendingAriaLabel);
|
|
240
263
|
}
|
|
241
|
-
|
|
242
|
-
setSortedAriaInfo(
|
|
243
|
-
if (isFirefox) setSortedAriaInfo(
|
|
264
|
+
const dismissAriaTimer = setTimeout(() => {
|
|
265
|
+
setSortedAriaInfo("");
|
|
266
|
+
if (isFirefox) setSortedAriaInfo(", sort " + sortConfig.order);
|
|
244
267
|
}, DISMISS_SORT_INFO_TIME);
|
|
245
|
-
return
|
|
246
|
-
return clearTimeout(dismissAriaTimer);
|
|
247
|
-
};
|
|
268
|
+
return () => clearTimeout(dismissAriaTimer);
|
|
248
269
|
}, [sortConfig.order]);
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
270
|
+
return /* @__PURE__ */ jsxs(
|
|
271
|
+
"button",
|
|
272
|
+
{
|
|
273
|
+
className: classNames("eds-table__header-cell-button", className),
|
|
274
|
+
type: "button",
|
|
275
|
+
"aria-sort": ariaSort,
|
|
276
|
+
...rest,
|
|
277
|
+
children: [
|
|
278
|
+
children,
|
|
279
|
+
(!isCurrentlySorted || sortConfig.order === "none") && /* @__PURE__ */ jsx(
|
|
280
|
+
UnsortedIcon,
|
|
281
|
+
{
|
|
282
|
+
size: "1em",
|
|
283
|
+
className: "eds-table__header-cell-button-icon",
|
|
284
|
+
"aria-hidden": "true"
|
|
285
|
+
}
|
|
286
|
+
),
|
|
287
|
+
isCurrentlySorted && sortConfig.order === "ascending" && /* @__PURE__ */ jsx(
|
|
288
|
+
UpArrowIcon,
|
|
289
|
+
{
|
|
290
|
+
size: "1em",
|
|
291
|
+
className: "eds-table__header-cell-button-icon",
|
|
292
|
+
"aria-hidden": "true"
|
|
293
|
+
}
|
|
294
|
+
),
|
|
295
|
+
isCurrentlySorted && sortConfig.order === "descending" && /* @__PURE__ */ jsx(
|
|
296
|
+
DownArrowIcon,
|
|
297
|
+
{
|
|
298
|
+
size: "1em",
|
|
299
|
+
className: "eds-table__header-cell-button-icon",
|
|
300
|
+
"aria-hidden": "true"
|
|
301
|
+
}
|
|
302
|
+
),
|
|
303
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: isCurrentlySorted && sortedAriaInfo })
|
|
304
|
+
]
|
|
305
|
+
}
|
|
306
|
+
);
|
|
266
307
|
};
|
|
267
|
-
|
|
268
|
-
var
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
308
|
+
var lodash_get;
|
|
309
|
+
var hasRequiredLodash_get;
|
|
310
|
+
function requireLodash_get() {
|
|
311
|
+
if (hasRequiredLodash_get) return lodash_get;
|
|
312
|
+
hasRequiredLodash_get = 1;
|
|
313
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
314
|
+
var HASH_UNDEFINED = "__lodash_hash_undefined__";
|
|
315
|
+
var funcTag = "[object Function]", genTag = "[object GeneratorFunction]", symbolTag = "[object Symbol]";
|
|
316
|
+
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, reIsPlainProp = /^\w*$/, reLeadingDot = /^\./, rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
|
317
|
+
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
318
|
+
var reEscapeChar = /\\(\\)?/g;
|
|
319
|
+
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
320
|
+
var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
321
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
322
|
+
var root = freeGlobal || freeSelf || Function("return this")();
|
|
323
|
+
function getValue(object, key) {
|
|
324
|
+
return object == null ? void 0 : object[key];
|
|
325
|
+
}
|
|
326
|
+
function isHostObject(value) {
|
|
327
|
+
var result = false;
|
|
328
|
+
if (value != null && typeof value.toString != "function") {
|
|
329
|
+
try {
|
|
330
|
+
result = !!(value + "");
|
|
331
|
+
} catch (e) {
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
var arrayProto = Array.prototype, funcProto = Function.prototype, objectProto = Object.prototype;
|
|
337
|
+
var coreJsData = root["__core-js_shared__"];
|
|
338
|
+
var maskSrcKey = function() {
|
|
339
|
+
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
|
|
340
|
+
return uid ? "Symbol(src)_1." + uid : "";
|
|
341
|
+
}();
|
|
342
|
+
var funcToString = funcProto.toString;
|
|
343
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
344
|
+
var objectToString = objectProto.toString;
|
|
345
|
+
var reIsNative = RegExp(
|
|
346
|
+
"^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
|
|
347
|
+
);
|
|
348
|
+
var Symbol = root.Symbol, splice = arrayProto.splice;
|
|
349
|
+
var Map = getNative(root, "Map"), nativeCreate = getNative(Object, "create");
|
|
350
|
+
var symbolProto = Symbol ? Symbol.prototype : void 0, symbolToString = symbolProto ? symbolProto.toString : void 0;
|
|
351
|
+
function Hash(entries) {
|
|
352
|
+
var index = -1, length = entries ? entries.length : 0;
|
|
353
|
+
this.clear();
|
|
354
|
+
while (++index < length) {
|
|
355
|
+
var entry = entries[index];
|
|
356
|
+
this.set(entry[0], entry[1]);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
function hashClear() {
|
|
360
|
+
this.__data__ = nativeCreate ? nativeCreate(null) : {};
|
|
361
|
+
}
|
|
362
|
+
function hashDelete(key) {
|
|
363
|
+
return this.has(key) && delete this.__data__[key];
|
|
364
|
+
}
|
|
365
|
+
function hashGet(key) {
|
|
366
|
+
var data = this.__data__;
|
|
367
|
+
if (nativeCreate) {
|
|
368
|
+
var result = data[key];
|
|
369
|
+
return result === HASH_UNDEFINED ? void 0 : result;
|
|
370
|
+
}
|
|
371
|
+
return hasOwnProperty.call(data, key) ? data[key] : void 0;
|
|
372
|
+
}
|
|
373
|
+
function hashHas(key) {
|
|
374
|
+
var data = this.__data__;
|
|
375
|
+
return nativeCreate ? data[key] !== void 0 : hasOwnProperty.call(data, key);
|
|
376
|
+
}
|
|
377
|
+
function hashSet(key, value) {
|
|
378
|
+
var data = this.__data__;
|
|
379
|
+
data[key] = nativeCreate && value === void 0 ? HASH_UNDEFINED : value;
|
|
380
|
+
return this;
|
|
381
|
+
}
|
|
382
|
+
Hash.prototype.clear = hashClear;
|
|
383
|
+
Hash.prototype["delete"] = hashDelete;
|
|
384
|
+
Hash.prototype.get = hashGet;
|
|
385
|
+
Hash.prototype.has = hashHas;
|
|
386
|
+
Hash.prototype.set = hashSet;
|
|
387
|
+
function ListCache(entries) {
|
|
388
|
+
var index = -1, length = entries ? entries.length : 0;
|
|
389
|
+
this.clear();
|
|
390
|
+
while (++index < length) {
|
|
391
|
+
var entry = entries[index];
|
|
392
|
+
this.set(entry[0], entry[1]);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
function listCacheClear() {
|
|
396
|
+
this.__data__ = [];
|
|
397
|
+
}
|
|
398
|
+
function listCacheDelete(key) {
|
|
399
|
+
var data = this.__data__, index = assocIndexOf(data, key);
|
|
400
|
+
if (index < 0) {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
var lastIndex = data.length - 1;
|
|
404
|
+
if (index == lastIndex) {
|
|
405
|
+
data.pop();
|
|
406
|
+
} else {
|
|
407
|
+
splice.call(data, index, 1);
|
|
408
|
+
}
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
function listCacheGet(key) {
|
|
412
|
+
var data = this.__data__, index = assocIndexOf(data, key);
|
|
413
|
+
return index < 0 ? void 0 : data[index][1];
|
|
414
|
+
}
|
|
415
|
+
function listCacheHas(key) {
|
|
416
|
+
return assocIndexOf(this.__data__, key) > -1;
|
|
417
|
+
}
|
|
418
|
+
function listCacheSet(key, value) {
|
|
419
|
+
var data = this.__data__, index = assocIndexOf(data, key);
|
|
420
|
+
if (index < 0) {
|
|
421
|
+
data.push([key, value]);
|
|
422
|
+
} else {
|
|
423
|
+
data[index][1] = value;
|
|
424
|
+
}
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
ListCache.prototype.clear = listCacheClear;
|
|
428
|
+
ListCache.prototype["delete"] = listCacheDelete;
|
|
429
|
+
ListCache.prototype.get = listCacheGet;
|
|
430
|
+
ListCache.prototype.has = listCacheHas;
|
|
431
|
+
ListCache.prototype.set = listCacheSet;
|
|
432
|
+
function MapCache(entries) {
|
|
433
|
+
var index = -1, length = entries ? entries.length : 0;
|
|
434
|
+
this.clear();
|
|
435
|
+
while (++index < length) {
|
|
436
|
+
var entry = entries[index];
|
|
437
|
+
this.set(entry[0], entry[1]);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function mapCacheClear() {
|
|
441
|
+
this.__data__ = {
|
|
442
|
+
"hash": new Hash(),
|
|
443
|
+
"map": new (Map || ListCache)(),
|
|
444
|
+
"string": new Hash()
|
|
275
445
|
};
|
|
276
446
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
447
|
+
function mapCacheDelete(key) {
|
|
448
|
+
return getMapData(this, key)["delete"](key);
|
|
449
|
+
}
|
|
450
|
+
function mapCacheGet(key) {
|
|
451
|
+
return getMapData(this, key).get(key);
|
|
452
|
+
}
|
|
453
|
+
function mapCacheHas(key) {
|
|
454
|
+
return getMapData(this, key).has(key);
|
|
455
|
+
}
|
|
456
|
+
function mapCacheSet(key, value) {
|
|
457
|
+
getMapData(this, key).set(key, value);
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
MapCache.prototype.clear = mapCacheClear;
|
|
461
|
+
MapCache.prototype["delete"] = mapCacheDelete;
|
|
462
|
+
MapCache.prototype.get = mapCacheGet;
|
|
463
|
+
MapCache.prototype.has = mapCacheHas;
|
|
464
|
+
MapCache.prototype.set = mapCacheSet;
|
|
465
|
+
function assocIndexOf(array, key) {
|
|
466
|
+
var length = array.length;
|
|
467
|
+
while (length--) {
|
|
468
|
+
if (eq(array[length][0], key)) {
|
|
469
|
+
return length;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return -1;
|
|
473
|
+
}
|
|
474
|
+
function baseGet(object, path) {
|
|
475
|
+
path = isKey(path, object) ? [path] : castPath(path);
|
|
476
|
+
var index = 0, length = path.length;
|
|
477
|
+
while (object != null && index < length) {
|
|
478
|
+
object = object[toKey(path[index++])];
|
|
479
|
+
}
|
|
480
|
+
return index && index == length ? object : void 0;
|
|
481
|
+
}
|
|
482
|
+
function baseIsNative(value) {
|
|
483
|
+
if (!isObject(value) || isMasked(value)) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
var pattern = isFunction(value) || isHostObject(value) ? reIsNative : reIsHostCtor;
|
|
487
|
+
return pattern.test(toSource(value));
|
|
488
|
+
}
|
|
489
|
+
function baseToString(value) {
|
|
490
|
+
if (typeof value == "string") {
|
|
491
|
+
return value;
|
|
492
|
+
}
|
|
493
|
+
if (isSymbol(value)) {
|
|
494
|
+
return symbolToString ? symbolToString.call(value) : "";
|
|
495
|
+
}
|
|
496
|
+
var result = value + "";
|
|
497
|
+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
|
|
498
|
+
}
|
|
499
|
+
function castPath(value) {
|
|
500
|
+
return isArray(value) ? value : stringToPath(value);
|
|
501
|
+
}
|
|
502
|
+
function getMapData(map, key) {
|
|
503
|
+
var data = map.__data__;
|
|
504
|
+
return isKeyable(key) ? data[typeof key == "string" ? "string" : "hash"] : data.map;
|
|
505
|
+
}
|
|
506
|
+
function getNative(object, key) {
|
|
507
|
+
var value = getValue(object, key);
|
|
508
|
+
return baseIsNative(value) ? value : void 0;
|
|
509
|
+
}
|
|
510
|
+
function isKey(value, object) {
|
|
511
|
+
if (isArray(value)) {
|
|
512
|
+
return false;
|
|
513
|
+
}
|
|
514
|
+
var type = typeof value;
|
|
515
|
+
if (type == "number" || type == "symbol" || type == "boolean" || value == null || isSymbol(value)) {
|
|
516
|
+
return true;
|
|
517
|
+
}
|
|
518
|
+
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
|
|
519
|
+
}
|
|
520
|
+
function isKeyable(value) {
|
|
521
|
+
var type = typeof value;
|
|
522
|
+
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value !== "__proto__" : value === null;
|
|
523
|
+
}
|
|
524
|
+
function isMasked(func) {
|
|
525
|
+
return !!maskSrcKey && maskSrcKey in func;
|
|
526
|
+
}
|
|
527
|
+
var stringToPath = memoize(function(string) {
|
|
528
|
+
string = toString(string);
|
|
529
|
+
var result = [];
|
|
530
|
+
if (reLeadingDot.test(string)) {
|
|
531
|
+
result.push("");
|
|
532
|
+
}
|
|
533
|
+
string.replace(rePropName, function(match, number, quote, string2) {
|
|
534
|
+
result.push(quote ? string2.replace(reEscapeChar, "$1") : number || match);
|
|
293
535
|
});
|
|
536
|
+
return result;
|
|
537
|
+
});
|
|
538
|
+
function toKey(value) {
|
|
539
|
+
if (typeof value == "string" || isSymbol(value)) {
|
|
540
|
+
return value;
|
|
541
|
+
}
|
|
542
|
+
var result = value + "";
|
|
543
|
+
return result == "0" && 1 / value == -Infinity ? "-0" : result;
|
|
544
|
+
}
|
|
545
|
+
function toSource(func) {
|
|
546
|
+
if (func != null) {
|
|
547
|
+
try {
|
|
548
|
+
return funcToString.call(func);
|
|
549
|
+
} catch (e) {
|
|
550
|
+
}
|
|
551
|
+
try {
|
|
552
|
+
return func + "";
|
|
553
|
+
} catch (e) {
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return "";
|
|
557
|
+
}
|
|
558
|
+
function memoize(func, resolver) {
|
|
559
|
+
if (typeof func != "function" || resolver && typeof resolver != "function") {
|
|
560
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
561
|
+
}
|
|
562
|
+
var memoized = function() {
|
|
563
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache = memoized.cache;
|
|
564
|
+
if (cache.has(key)) {
|
|
565
|
+
return cache.get(key);
|
|
566
|
+
}
|
|
567
|
+
var result = func.apply(this, args);
|
|
568
|
+
memoized.cache = cache.set(key, result);
|
|
569
|
+
return result;
|
|
570
|
+
};
|
|
571
|
+
memoized.cache = new (memoize.Cache || MapCache)();
|
|
572
|
+
return memoized;
|
|
573
|
+
}
|
|
574
|
+
memoize.Cache = MapCache;
|
|
575
|
+
function eq(value, other) {
|
|
576
|
+
return value === other || value !== value && other !== other;
|
|
577
|
+
}
|
|
578
|
+
var isArray = Array.isArray;
|
|
579
|
+
function isFunction(value) {
|
|
580
|
+
var tag = isObject(value) ? objectToString.call(value) : "";
|
|
581
|
+
return tag == funcTag || tag == genTag;
|
|
582
|
+
}
|
|
583
|
+
function isObject(value) {
|
|
584
|
+
var type = typeof value;
|
|
585
|
+
return !!value && (type == "object" || type == "function");
|
|
586
|
+
}
|
|
587
|
+
function isObjectLike(value) {
|
|
588
|
+
return !!value && typeof value == "object";
|
|
589
|
+
}
|
|
590
|
+
function isSymbol(value) {
|
|
591
|
+
return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
|
|
592
|
+
}
|
|
593
|
+
function toString(value) {
|
|
594
|
+
return value == null ? "" : baseToString(value);
|
|
595
|
+
}
|
|
596
|
+
function get2(object, path, defaultValue) {
|
|
597
|
+
var result = object == null ? void 0 : baseGet(object, path);
|
|
598
|
+
return result === void 0 ? defaultValue : result;
|
|
599
|
+
}
|
|
600
|
+
lodash_get = get2;
|
|
601
|
+
return lodash_get;
|
|
602
|
+
}
|
|
603
|
+
var lodash_getExports = requireLodash_get();
|
|
604
|
+
const get = /* @__PURE__ */ getDefaultExportFromCjs(lodash_getExports);
|
|
605
|
+
function useSortableData(tableData, externalSortConfig = { key: "", order: "none" }) {
|
|
606
|
+
const [sortConfig, setSortConfig] = useState(externalSortConfig);
|
|
607
|
+
const onSortRequested = (key) => {
|
|
608
|
+
const sortingNewColumn = key !== sortConfig.key;
|
|
609
|
+
if (sortingNewColumn || sortConfig.order === "none")
|
|
610
|
+
return setSortConfig({ key, order: "ascending" });
|
|
611
|
+
if (sortConfig.order === "ascending")
|
|
612
|
+
return setSortConfig({ key, order: "descending" });
|
|
613
|
+
if (sortConfig.order === "descending")
|
|
614
|
+
return setSortConfig({ key, order: "none" });
|
|
294
615
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var stringComparator = new Intl.Collator(['no', 'en'], {
|
|
616
|
+
const tableSortedAscending = useMemo(
|
|
617
|
+
() => [...tableData].sort((a, b) => {
|
|
618
|
+
const valueOfA = get(a, sortConfig.key, a)?.toString() ?? "";
|
|
619
|
+
const valueOfB = get(b, sortConfig.key, b)?.toString() ?? "";
|
|
620
|
+
const stringComparator = new Intl.Collator(["no", "en"], {
|
|
301
621
|
numeric: true,
|
|
302
|
-
sensitivity:
|
|
622
|
+
sensitivity: "base"
|
|
303
623
|
});
|
|
304
624
|
return stringComparator.compare(valueOfA, valueOfB);
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
|
|
625
|
+
}),
|
|
626
|
+
[tableData, sortConfig.key]
|
|
627
|
+
);
|
|
628
|
+
const sortedData = useMemo(() => {
|
|
308
629
|
switch (sortConfig.order) {
|
|
309
|
-
case
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
default:
|
|
322
|
-
{
|
|
323
|
-
return tableData;
|
|
324
|
-
}
|
|
630
|
+
case "ascending": {
|
|
631
|
+
return tableSortedAscending;
|
|
632
|
+
}
|
|
633
|
+
case "descending": {
|
|
634
|
+
return [...tableSortedAscending].reverse();
|
|
635
|
+
}
|
|
636
|
+
case "none": {
|
|
637
|
+
return tableData;
|
|
638
|
+
}
|
|
639
|
+
default: {
|
|
640
|
+
return tableData;
|
|
641
|
+
}
|
|
325
642
|
}
|
|
326
643
|
}, [sortConfig.order, tableData, tableSortedAscending]);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return
|
|
334
|
-
name
|
|
335
|
-
sortable
|
|
336
|
-
sortConfig
|
|
337
|
-
sortableButtonProps:
|
|
338
|
-
onClick:
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
var getSortableTableProps = function getSortableTableProps(_temp) {
|
|
345
|
-
var _ref2 = _temp === void 0 ? {} : _temp,
|
|
346
|
-
_ref2$sortable = _ref2.sortable,
|
|
347
|
-
sortable = _ref2$sortable === void 0 ? true : _ref2$sortable,
|
|
348
|
-
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
349
|
-
return _extends({
|
|
350
|
-
sortable: sortable,
|
|
351
|
-
sortConfig: sortConfig
|
|
352
|
-
}, props);
|
|
644
|
+
const getSortableHeaderProps = ({
|
|
645
|
+
name,
|
|
646
|
+
sortable = true,
|
|
647
|
+
buttonProps,
|
|
648
|
+
...props
|
|
649
|
+
}) => {
|
|
650
|
+
return {
|
|
651
|
+
name,
|
|
652
|
+
sortable,
|
|
653
|
+
sortConfig,
|
|
654
|
+
sortableButtonProps: {
|
|
655
|
+
onClick: () => onSortRequested(name),
|
|
656
|
+
...buttonProps
|
|
657
|
+
},
|
|
658
|
+
...props
|
|
659
|
+
};
|
|
353
660
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
661
|
+
const getSortableTableProps = ({
|
|
662
|
+
sortable = true,
|
|
663
|
+
...props
|
|
664
|
+
} = {}) => {
|
|
665
|
+
return {
|
|
666
|
+
sortable,
|
|
667
|
+
sortConfig,
|
|
668
|
+
...props
|
|
669
|
+
};
|
|
358
670
|
};
|
|
671
|
+
return { sortedData, getSortableHeaderProps, getSortableTableProps };
|
|
359
672
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
673
|
+
const EditableCell = ({
|
|
674
|
+
children,
|
|
675
|
+
className,
|
|
676
|
+
feedback,
|
|
677
|
+
variant,
|
|
678
|
+
outlined = false,
|
|
679
|
+
...rest
|
|
680
|
+
}) => {
|
|
681
|
+
return /* @__PURE__ */ jsx(VariantProvider, { variant, children: /* @__PURE__ */ jsx(
|
|
682
|
+
DataCell,
|
|
683
|
+
{
|
|
684
|
+
className: classNames(
|
|
685
|
+
"eds-editable-cell",
|
|
686
|
+
{
|
|
687
|
+
"eds-editable-cell--outlined": outlined
|
|
688
|
+
},
|
|
689
|
+
className
|
|
690
|
+
),
|
|
691
|
+
...rest,
|
|
692
|
+
children: /* @__PURE__ */ jsx(
|
|
693
|
+
Tooltip,
|
|
694
|
+
{
|
|
695
|
+
disableHoverListener: !feedback,
|
|
696
|
+
disableFocusListener: !feedback,
|
|
697
|
+
placement: "bottom",
|
|
698
|
+
content: feedback || void 0,
|
|
699
|
+
variant: feedback ? "negative" : void 0,
|
|
700
|
+
children
|
|
701
|
+
}
|
|
702
|
+
)
|
|
703
|
+
}
|
|
704
|
+
) });
|
|
383
705
|
};
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return React.createElement("tr", null, React.createElement("td", {
|
|
391
|
-
colSpan: colSpan
|
|
392
|
-
}, React.createElement(BaseExpand, {
|
|
393
|
-
open: open
|
|
394
|
-
}, children)));
|
|
706
|
+
const ExpandableRow = ({
|
|
707
|
+
open = false,
|
|
708
|
+
children,
|
|
709
|
+
colSpan
|
|
710
|
+
}) => {
|
|
711
|
+
return /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan, children: /* @__PURE__ */ jsx(BaseExpand, { open, children }) }) });
|
|
395
712
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
713
|
+
const ExpandRowButton = ({
|
|
714
|
+
open,
|
|
715
|
+
onClick,
|
|
716
|
+
...rest
|
|
717
|
+
}) => {
|
|
718
|
+
return /* @__PURE__ */ jsx(
|
|
719
|
+
IconButton,
|
|
720
|
+
{
|
|
721
|
+
className: classNames("eds-expand-row-button", {
|
|
722
|
+
"eds-expand-row-button--open": open
|
|
723
|
+
}),
|
|
724
|
+
onClick,
|
|
725
|
+
"aria-label": open ? "Lukk tabellrad" : "Utvid tabellrad",
|
|
726
|
+
type: "button",
|
|
727
|
+
...rest,
|
|
728
|
+
children: /* @__PURE__ */ jsx(DownArrowIcon, { "aria-hidden": true, className: "eds-expand-row-button__icon" })
|
|
729
|
+
}
|
|
730
|
+
);
|
|
413
731
|
};
|
|
414
|
-
|
|
415
732
|
function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
416
|
-
|
|
733
|
+
const keyPress = event.key;
|
|
417
734
|
switch (keyPress) {
|
|
418
|
-
case
|
|
735
|
+
case "ArrowUp":
|
|
419
736
|
event.preventDefault();
|
|
420
737
|
if (allowWrap) {
|
|
421
738
|
return currentRow === 0 ? maxRow - 1 : currentRow - 1;
|
|
422
739
|
} else {
|
|
423
740
|
return currentRow > 0 ? currentRow - 1 : 0;
|
|
424
741
|
}
|
|
425
|
-
case
|
|
742
|
+
case "ArrowDown":
|
|
426
743
|
event.preventDefault();
|
|
427
744
|
if (allowWrap) {
|
|
428
745
|
return currentRow === maxRow - 1 ? 0 : currentRow + 1;
|
|
@@ -433,62 +750,52 @@ function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
|
433
750
|
return currentRow;
|
|
434
751
|
}
|
|
435
752
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
var _useState = useState(numberOfRows),
|
|
445
|
-
currentRow = _useState[0],
|
|
446
|
-
setCurrentRow = _useState[1];
|
|
447
|
-
var _useState2 = useState(0),
|
|
448
|
-
maxRow = _useState2[0],
|
|
449
|
-
setMaxRow = _useState2[1];
|
|
450
|
-
var tableBodyRef = useRef(null);
|
|
451
|
-
var tableHasFocus = tableBodyRef == null || (_tableBodyRef$current = tableBodyRef.current) == null ? void 0 : _tableBodyRef$current.contains(document.activeElement);
|
|
452
|
-
useEffect(function () {
|
|
453
|
-
var _tableBodyRef$current2;
|
|
454
|
-
tableBodyRef && tableBodyRef.current && tableHasFocus && ((_tableBodyRef$current2 = tableBodyRef.current.childNodes[currentRow].childNodes[0].parentElement) == null ? void 0 : _tableBodyRef$current2.focus());
|
|
753
|
+
const useTableKeyboardNavigation = (numberOfRows = 0, allowWrap = true) => {
|
|
754
|
+
const [currentRow, setCurrentRow] = useState(numberOfRows);
|
|
755
|
+
const [maxRow, setMaxRow] = useState(0);
|
|
756
|
+
const tableBodyRef = useRef(null);
|
|
757
|
+
const tableHasFocus = tableBodyRef?.current?.contains(document.activeElement);
|
|
758
|
+
useEffect(() => {
|
|
759
|
+
tableBodyRef && tableBodyRef.current && tableHasFocus && tableBodyRef.current.childNodes[currentRow].childNodes[0].parentElement?.focus();
|
|
455
760
|
}, [currentRow, tableHasFocus]);
|
|
456
|
-
function getTableBodyNavigationProps() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
ref: tableBodyRef
|
|
462
|
-
}, rest);
|
|
761
|
+
function getTableBodyNavigationProps(...rest) {
|
|
762
|
+
return {
|
|
763
|
+
ref: tableBodyRef,
|
|
764
|
+
...rest
|
|
765
|
+
};
|
|
463
766
|
}
|
|
464
|
-
|
|
465
|
-
function getTableRowNavigationProps(row) {
|
|
767
|
+
const tableRowRef = useRef(null);
|
|
768
|
+
function getTableRowNavigationProps(row, ...rest) {
|
|
466
769
|
if (row >= maxRow) {
|
|
467
770
|
setMaxRow(row + 1);
|
|
468
771
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
return _extends({
|
|
474
|
-
tabIndex: tabIndex,
|
|
772
|
+
const tabIndex = currentRow ? 0 : -1;
|
|
773
|
+
return {
|
|
774
|
+
tabIndex,
|
|
475
775
|
ref: tableRowRef,
|
|
476
|
-
onClick:
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
onKeyDown: function onKeyDown(e) {
|
|
480
|
-
var newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);
|
|
776
|
+
onClick: () => setCurrentRow(row),
|
|
777
|
+
onKeyDown: (e) => {
|
|
778
|
+
const newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);
|
|
481
779
|
setCurrentRow(newCell);
|
|
482
|
-
}
|
|
483
|
-
|
|
780
|
+
},
|
|
781
|
+
...rest
|
|
782
|
+
};
|
|
484
783
|
}
|
|
485
|
-
return {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
784
|
+
return { getTableRowNavigationProps, getTableBodyNavigationProps };
|
|
785
|
+
};
|
|
786
|
+
warnAboutMissingStyles("table");
|
|
787
|
+
export {
|
|
788
|
+
DataCell,
|
|
789
|
+
EditableCell,
|
|
790
|
+
ExpandRowButton,
|
|
791
|
+
ExpandableRow,
|
|
792
|
+
HeaderCell,
|
|
793
|
+
Table,
|
|
794
|
+
TableBody,
|
|
795
|
+
TableFooter,
|
|
796
|
+
TableHead,
|
|
797
|
+
TableRow,
|
|
798
|
+
useSortableData,
|
|
799
|
+
useTableKeyboardNavigation
|
|
489
800
|
};
|
|
490
|
-
|
|
491
|
-
warnAboutMissingStyles('table');
|
|
492
|
-
|
|
493
|
-
export { DataCell, EditableCell, ExpandRowButton, ExpandableRow, HeaderCell, Table, TableBody, TableFooter, TableHead, TableRow, useSortableData, useTableKeyboardNavigation };
|
|
494
801
|
//# sourceMappingURL=table.esm.js.map
|