@entur/table 4.9.14-beta.0 → 4.9.14-beta.10

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