@entur/table 4.9.14-beta.9 → 4.9.14
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 +437 -0
- package/dist/table.cjs.js.map +1 -0
- package/dist/table.esm.js +382 -439
- package/dist/table.esm.js.map +1 -1
- package/package.json +29 -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,381 @@
|
|
|
1
|
-
import { useRandomId, mergeRefs, warnAboutMissingStyles } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 classNames from "classnames";
|
|
5
|
+
import { VisuallyHidden } from "@entur/a11y";
|
|
6
|
+
import { BulletBadge } from "@entur/layout";
|
|
7
|
+
import { UnsortedIcon, UpArrowIcon, DownArrowIcon } from "@entur/icons";
|
|
8
|
+
import get from "lodash.get";
|
|
9
|
+
import { VariantProvider } from "@entur/form";
|
|
10
|
+
import { Tooltip } from "@entur/tooltip";
|
|
11
|
+
import { BaseExpand } from "@entur/expand";
|
|
12
|
+
import { IconButton } from "@entur/button";
|
|
13
|
+
const Table = React.forwardRef(
|
|
14
|
+
({
|
|
15
|
+
className,
|
|
16
|
+
fixed = false,
|
|
17
|
+
spacing = "default",
|
|
18
|
+
sortable = false,
|
|
19
|
+
changeSortDescription = "Tabelloverskrifter med knapper kan trykkes på for å endre sortering,",
|
|
20
|
+
stickyHeader = false,
|
|
21
|
+
...rest
|
|
22
|
+
}, ref) => {
|
|
23
|
+
const sortableHeaderId = useRandomId("sortable-header");
|
|
24
|
+
const tableRef = useRef(null);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (stickyHeader) {
|
|
27
|
+
const tableElement = tableRef.current;
|
|
28
|
+
const observerElement = document.createElement("div");
|
|
29
|
+
observerElement.classList.add("sticky-observer");
|
|
30
|
+
tableElement?.parentNode?.insertBefore(observerElement, tableElement);
|
|
31
|
+
const observer = new IntersectionObserver(
|
|
32
|
+
(entries) => {
|
|
33
|
+
tableElement?.classList.toggle(
|
|
34
|
+
"eds-table--sticky-header--active",
|
|
35
|
+
!entries[0].isIntersecting
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
{ threshold: [0, 1] }
|
|
39
|
+
);
|
|
40
|
+
observer.observe(observerElement);
|
|
41
|
+
return () => {
|
|
42
|
+
observer.unobserve(observerElement);
|
|
43
|
+
observerElement.remove();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}, [stickyHeader]);
|
|
47
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
"table",
|
|
50
|
+
{
|
|
51
|
+
className: classNames(
|
|
52
|
+
"eds-table",
|
|
53
|
+
{ "eds-table--fixed": fixed },
|
|
54
|
+
{ "eds-table--middle": spacing === "middle" },
|
|
55
|
+
{ "eds-table--small": spacing === "small" },
|
|
56
|
+
{ "eds-table--sortable": sortable },
|
|
57
|
+
{ "eds-table--sticky-header": stickyHeader },
|
|
58
|
+
className
|
|
59
|
+
),
|
|
60
|
+
ref: mergeRefs(ref, tableRef),
|
|
61
|
+
"aria-describedby": sortable ? sortableHeaderId : void 0,
|
|
62
|
+
...rest
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
sortable && /* @__PURE__ */ jsx(VisuallyHidden, { id: sortableHeaderId, children: changeSortDescription })
|
|
66
|
+
] });
|
|
31
67
|
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
observerElement.classList.add('sticky-observer');
|
|
62
|
-
tableElement == null || (_tableElement$parentN = tableElement.parentNode) == null || _tableElement$parentN.insertBefore(observerElement, tableElement);
|
|
63
|
-
var observer = new IntersectionObserver(function (entries) {
|
|
64
|
-
tableElement == null || tableElement.classList.toggle('eds-table--sticky-header--active', !entries[0].isIntersecting);
|
|
65
|
-
}, {
|
|
66
|
-
threshold: [0, 1]
|
|
67
|
-
});
|
|
68
|
-
observer.observe(observerElement);
|
|
69
|
-
return function () {
|
|
70
|
-
observer.unobserve(observerElement);
|
|
71
|
-
observerElement.remove();
|
|
72
|
-
};
|
|
68
|
+
);
|
|
69
|
+
const TableHead = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
|
|
70
|
+
"thead",
|
|
71
|
+
{
|
|
72
|
+
className: classNames("eds-table__head", className),
|
|
73
|
+
ref,
|
|
74
|
+
...props
|
|
75
|
+
}
|
|
76
|
+
));
|
|
77
|
+
const TableBody = React.forwardRef(({ className, ...rest }, ref) => /* @__PURE__ */ jsx(
|
|
78
|
+
"tbody",
|
|
79
|
+
{
|
|
80
|
+
className: classNames("eds-table__body", className),
|
|
81
|
+
ref,
|
|
82
|
+
...rest
|
|
83
|
+
}
|
|
84
|
+
));
|
|
85
|
+
const TableFooter = React.forwardRef(({ ...props }, ref) => /* @__PURE__ */ jsx("tfoot", { ref, ...props }));
|
|
86
|
+
const TableRow = React.forwardRef(
|
|
87
|
+
({ className, hover = false, active = false, error = false, ...rest }, ref) => /* @__PURE__ */ jsx(
|
|
88
|
+
"tr",
|
|
89
|
+
{
|
|
90
|
+
className: classNames("eds-table__row", className, {
|
|
91
|
+
"eds-table__row--hover": hover,
|
|
92
|
+
"eds-table__row--active": active,
|
|
93
|
+
"eds-table__row--error": error
|
|
94
|
+
}),
|
|
95
|
+
ref,
|
|
96
|
+
...rest
|
|
73
97
|
}
|
|
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"];
|
|
98
|
+
)
|
|
99
|
+
);
|
|
142
100
|
function mapStatusToVariant(status) {
|
|
143
101
|
switch (status) {
|
|
144
|
-
case
|
|
145
|
-
return
|
|
146
|
-
case
|
|
147
|
-
return
|
|
148
|
-
case
|
|
149
|
-
return
|
|
102
|
+
case "positive":
|
|
103
|
+
return "success";
|
|
104
|
+
case "negative":
|
|
105
|
+
return "negative";
|
|
106
|
+
case "neutral":
|
|
107
|
+
return "neutral";
|
|
150
108
|
default:
|
|
151
|
-
return
|
|
109
|
+
return "neutral";
|
|
152
110
|
}
|
|
153
111
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
112
|
+
const DataCell = React.forwardRef(
|
|
113
|
+
({ className, padding = "default", status, variant, children, ...rest }, ref) => {
|
|
114
|
+
if (!variant && status) {
|
|
115
|
+
variant = mapStatusToVariant(status);
|
|
116
|
+
}
|
|
117
|
+
return /* @__PURE__ */ jsx(
|
|
118
|
+
"td",
|
|
119
|
+
{
|
|
120
|
+
ref,
|
|
121
|
+
className: classNames("eds-table__data-cell", className, {
|
|
122
|
+
"eds-table__data-cell--padding-checkbox": padding === "checkbox",
|
|
123
|
+
"eds-table__data-cell--padding-radio": padding === "radio",
|
|
124
|
+
"eds-table__data-cell--padding-overflow-menu": padding === "overflow-menu"
|
|
125
|
+
}),
|
|
126
|
+
...rest,
|
|
127
|
+
children: variant ? /* @__PURE__ */ jsx(BulletBadge, { variant, children }) : children
|
|
128
|
+
}
|
|
129
|
+
);
|
|
165
130
|
}
|
|
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
|
-
var _useState = useState(''),
|
|
229
|
-
sortedAriaInfo = _useState[0],
|
|
230
|
-
setSortedAriaInfo = _useState[1];
|
|
231
|
-
var className = sortableButtonProps.className,
|
|
232
|
-
rest = _objectWithoutPropertiesLoose(sortableButtonProps, _excluded2$1);
|
|
233
|
-
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
234
|
-
useEffect(function () {
|
|
235
|
-
var DISMISS_SORT_INFO_TIME = 3000;
|
|
236
|
-
if (sortConfig.order == 'ascending') {
|
|
131
|
+
);
|
|
132
|
+
const HeaderCell = React.forwardRef(
|
|
133
|
+
({
|
|
134
|
+
className,
|
|
135
|
+
children,
|
|
136
|
+
name,
|
|
137
|
+
sortable = false,
|
|
138
|
+
sortConfig,
|
|
139
|
+
padding = "default",
|
|
140
|
+
sortableButtonProps,
|
|
141
|
+
sortedAscendingAriaLabel = ", sortert stigende",
|
|
142
|
+
sortedDescendingAriaLabel = ", sortert synkende",
|
|
143
|
+
...rest
|
|
144
|
+
}, ref) => {
|
|
145
|
+
const [isCurrentlySorted, setIsCurrentlySorted] = React.useState(false);
|
|
146
|
+
React.useEffect(() => {
|
|
147
|
+
sortConfig && name && setIsCurrentlySorted(sortConfig && name === sortConfig.key);
|
|
148
|
+
}, [sortConfig, name]);
|
|
149
|
+
const ariaSort = isCurrentlySorted ? sortConfig && sortConfig.order : void 0;
|
|
150
|
+
return /* @__PURE__ */ jsx(
|
|
151
|
+
"th",
|
|
152
|
+
{
|
|
153
|
+
className: classNames("eds-table__header-cell", className, {
|
|
154
|
+
"eds-table__header-cell--sortable": sortable,
|
|
155
|
+
"eds-table__header-cell--padding-radio": padding === "radio",
|
|
156
|
+
"eds-table__header-cell--padding-checkbox": padding === "checkbox",
|
|
157
|
+
"eds-table__header-cell--padding-overflow-menu": padding === "overflow-menu"
|
|
158
|
+
}),
|
|
159
|
+
"aria-sort": ariaSort,
|
|
160
|
+
ref,
|
|
161
|
+
...rest,
|
|
162
|
+
children: sortable && sortConfig && sortableButtonProps ? /* @__PURE__ */ jsx(
|
|
163
|
+
SortableHeaderCellButton,
|
|
164
|
+
{
|
|
165
|
+
sortableButtonProps,
|
|
166
|
+
sortConfig,
|
|
167
|
+
isCurrentlySorted,
|
|
168
|
+
ariaSort,
|
|
169
|
+
sortedAscendingAriaLabel,
|
|
170
|
+
sortedDescendingAriaLabel,
|
|
171
|
+
children
|
|
172
|
+
}
|
|
173
|
+
) : children
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
const SortableHeaderCellButton = ({
|
|
179
|
+
sortConfig,
|
|
180
|
+
sortableButtonProps,
|
|
181
|
+
isCurrentlySorted,
|
|
182
|
+
children,
|
|
183
|
+
ariaSort,
|
|
184
|
+
sortedAscendingAriaLabel,
|
|
185
|
+
sortedDescendingAriaLabel
|
|
186
|
+
}) => {
|
|
187
|
+
const [sortedAriaInfo, setSortedAriaInfo] = useState("");
|
|
188
|
+
const { className, ...rest } = sortableButtonProps;
|
|
189
|
+
const isFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const DISMISS_SORT_INFO_TIME = 3e3;
|
|
192
|
+
if (sortConfig.order == "ascending") {
|
|
237
193
|
setSortedAriaInfo(sortedAscendingAriaLabel);
|
|
238
|
-
} else if (sortConfig.order ==
|
|
194
|
+
} else if (sortConfig.order == "descending") {
|
|
239
195
|
setSortedAriaInfo(sortedDescendingAriaLabel);
|
|
240
196
|
}
|
|
241
|
-
|
|
242
|
-
setSortedAriaInfo(
|
|
243
|
-
if (isFirefox) setSortedAriaInfo(
|
|
197
|
+
const dismissAriaTimer = setTimeout(() => {
|
|
198
|
+
setSortedAriaInfo("");
|
|
199
|
+
if (isFirefox) setSortedAriaInfo(", sort " + sortConfig.order);
|
|
244
200
|
}, DISMISS_SORT_INFO_TIME);
|
|
245
|
-
return
|
|
246
|
-
return clearTimeout(dismissAriaTimer);
|
|
247
|
-
};
|
|
201
|
+
return () => clearTimeout(dismissAriaTimer);
|
|
248
202
|
}, [sortConfig.order]);
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
203
|
+
return /* @__PURE__ */ jsxs(
|
|
204
|
+
"button",
|
|
205
|
+
{
|
|
206
|
+
className: classNames("eds-table__header-cell-button", className),
|
|
207
|
+
type: "button",
|
|
208
|
+
"aria-sort": ariaSort,
|
|
209
|
+
...rest,
|
|
210
|
+
children: [
|
|
211
|
+
children,
|
|
212
|
+
(!isCurrentlySorted || sortConfig.order === "none") && /* @__PURE__ */ jsx(
|
|
213
|
+
UnsortedIcon,
|
|
214
|
+
{
|
|
215
|
+
size: "1em",
|
|
216
|
+
className: "eds-table__header-cell-button-icon",
|
|
217
|
+
"aria-hidden": "true"
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
isCurrentlySorted && sortConfig.order === "ascending" && /* @__PURE__ */ jsx(
|
|
221
|
+
UpArrowIcon,
|
|
222
|
+
{
|
|
223
|
+
size: "1em",
|
|
224
|
+
className: "eds-table__header-cell-button-icon",
|
|
225
|
+
"aria-hidden": "true"
|
|
226
|
+
}
|
|
227
|
+
),
|
|
228
|
+
isCurrentlySorted && sortConfig.order === "descending" && /* @__PURE__ */ jsx(
|
|
229
|
+
DownArrowIcon,
|
|
230
|
+
{
|
|
231
|
+
size: "1em",
|
|
232
|
+
className: "eds-table__header-cell-button-icon",
|
|
233
|
+
"aria-hidden": "true"
|
|
234
|
+
}
|
|
235
|
+
),
|
|
236
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { children: isCurrentlySorted && sortedAriaInfo })
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
);
|
|
266
240
|
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
order:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
var _useState = useState(externalSortConfig),
|
|
278
|
-
sortConfig = _useState[0],
|
|
279
|
-
setSortConfig = _useState[1];
|
|
280
|
-
var onSortRequested = function onSortRequested(key) {
|
|
281
|
-
var sortingNewColumn = key !== sortConfig.key;
|
|
282
|
-
if (sortingNewColumn || sortConfig.order === 'none') return setSortConfig({
|
|
283
|
-
key: key,
|
|
284
|
-
order: 'ascending'
|
|
285
|
-
});
|
|
286
|
-
if (sortConfig.order === 'ascending') return setSortConfig({
|
|
287
|
-
key: key,
|
|
288
|
-
order: 'descending'
|
|
289
|
-
});
|
|
290
|
-
if (sortConfig.order === 'descending') return setSortConfig({
|
|
291
|
-
key: key,
|
|
292
|
-
order: 'none'
|
|
293
|
-
});
|
|
241
|
+
function useSortableData(tableData, externalSortConfig = { key: "", order: "none" }) {
|
|
242
|
+
const [sortConfig, setSortConfig] = useState(externalSortConfig);
|
|
243
|
+
const onSortRequested = (key) => {
|
|
244
|
+
const sortingNewColumn = key !== sortConfig.key;
|
|
245
|
+
if (sortingNewColumn || sortConfig.order === "none")
|
|
246
|
+
return setSortConfig({ key, order: "ascending" });
|
|
247
|
+
if (sortConfig.order === "ascending")
|
|
248
|
+
return setSortConfig({ key, order: "descending" });
|
|
249
|
+
if (sortConfig.order === "descending")
|
|
250
|
+
return setSortConfig({ key, order: "none" });
|
|
294
251
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var stringComparator = new Intl.Collator(['no', 'en'], {
|
|
252
|
+
const tableSortedAscending = useMemo(
|
|
253
|
+
() => [...tableData].sort((a, b) => {
|
|
254
|
+
const valueOfA = get(a, sortConfig.key, a)?.toString() ?? "";
|
|
255
|
+
const valueOfB = get(b, sortConfig.key, b)?.toString() ?? "";
|
|
256
|
+
const stringComparator = new Intl.Collator(["no", "en"], {
|
|
301
257
|
numeric: true,
|
|
302
|
-
sensitivity:
|
|
258
|
+
sensitivity: "base"
|
|
303
259
|
});
|
|
304
260
|
return stringComparator.compare(valueOfA, valueOfB);
|
|
305
|
-
})
|
|
306
|
-
|
|
307
|
-
|
|
261
|
+
}),
|
|
262
|
+
[tableData, sortConfig.key]
|
|
263
|
+
);
|
|
264
|
+
const sortedData = useMemo(() => {
|
|
308
265
|
switch (sortConfig.order) {
|
|
309
|
-
case
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
default:
|
|
322
|
-
{
|
|
323
|
-
return tableData;
|
|
324
|
-
}
|
|
266
|
+
case "ascending": {
|
|
267
|
+
return tableSortedAscending;
|
|
268
|
+
}
|
|
269
|
+
case "descending": {
|
|
270
|
+
return [...tableSortedAscending].reverse();
|
|
271
|
+
}
|
|
272
|
+
case "none": {
|
|
273
|
+
return tableData;
|
|
274
|
+
}
|
|
275
|
+
default: {
|
|
276
|
+
return tableData;
|
|
277
|
+
}
|
|
325
278
|
}
|
|
326
279
|
}, [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);
|
|
280
|
+
const getSortableHeaderProps = ({
|
|
281
|
+
name,
|
|
282
|
+
sortable = true,
|
|
283
|
+
buttonProps,
|
|
284
|
+
...props
|
|
285
|
+
}) => {
|
|
286
|
+
return {
|
|
287
|
+
name,
|
|
288
|
+
sortable,
|
|
289
|
+
sortConfig,
|
|
290
|
+
sortableButtonProps: {
|
|
291
|
+
onClick: () => onSortRequested(name),
|
|
292
|
+
...buttonProps
|
|
293
|
+
},
|
|
294
|
+
...props
|
|
295
|
+
};
|
|
353
296
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
297
|
+
const getSortableTableProps = ({
|
|
298
|
+
sortable = true,
|
|
299
|
+
...props
|
|
300
|
+
} = {}) => {
|
|
301
|
+
return {
|
|
302
|
+
sortable,
|
|
303
|
+
sortConfig,
|
|
304
|
+
...props
|
|
305
|
+
};
|
|
358
306
|
};
|
|
307
|
+
return { sortedData, getSortableHeaderProps, getSortableTableProps };
|
|
359
308
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
309
|
+
const EditableCell = ({
|
|
310
|
+
children,
|
|
311
|
+
className,
|
|
312
|
+
feedback,
|
|
313
|
+
variant,
|
|
314
|
+
outlined = false,
|
|
315
|
+
...rest
|
|
316
|
+
}) => {
|
|
317
|
+
return /* @__PURE__ */ jsx(VariantProvider, { variant, children: /* @__PURE__ */ jsx(
|
|
318
|
+
DataCell,
|
|
319
|
+
{
|
|
320
|
+
className: classNames(
|
|
321
|
+
"eds-editable-cell",
|
|
322
|
+
{
|
|
323
|
+
"eds-editable-cell--outlined": outlined
|
|
324
|
+
},
|
|
325
|
+
className
|
|
326
|
+
),
|
|
327
|
+
...rest,
|
|
328
|
+
children: /* @__PURE__ */ jsx(
|
|
329
|
+
Tooltip,
|
|
330
|
+
{
|
|
331
|
+
disableHoverListener: !feedback,
|
|
332
|
+
disableFocusListener: !feedback,
|
|
333
|
+
placement: "bottom",
|
|
334
|
+
content: feedback || void 0,
|
|
335
|
+
variant: feedback ? "negative" : void 0,
|
|
336
|
+
children
|
|
337
|
+
}
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
) });
|
|
383
341
|
};
|
|
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)));
|
|
342
|
+
const ExpandableRow = ({
|
|
343
|
+
open = false,
|
|
344
|
+
children,
|
|
345
|
+
colSpan
|
|
346
|
+
}) => {
|
|
347
|
+
return /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", { colSpan, children: /* @__PURE__ */ jsx(BaseExpand, { open, children }) }) });
|
|
395
348
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
349
|
+
const ExpandRowButton = ({
|
|
350
|
+
open,
|
|
351
|
+
onClick,
|
|
352
|
+
...rest
|
|
353
|
+
}) => {
|
|
354
|
+
return /* @__PURE__ */ jsx(
|
|
355
|
+
IconButton,
|
|
356
|
+
{
|
|
357
|
+
className: classNames("eds-expand-row-button", {
|
|
358
|
+
"eds-expand-row-button--open": open
|
|
359
|
+
}),
|
|
360
|
+
onClick,
|
|
361
|
+
"aria-label": open ? "Lukk tabellrad" : "Utvid tabellrad",
|
|
362
|
+
type: "button",
|
|
363
|
+
...rest,
|
|
364
|
+
children: /* @__PURE__ */ jsx(DownArrowIcon, { "aria-hidden": true, className: "eds-expand-row-button__icon" })
|
|
365
|
+
}
|
|
366
|
+
);
|
|
413
367
|
};
|
|
414
|
-
|
|
415
368
|
function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
416
|
-
|
|
369
|
+
const keyPress = event.key;
|
|
417
370
|
switch (keyPress) {
|
|
418
|
-
case
|
|
371
|
+
case "ArrowUp":
|
|
419
372
|
event.preventDefault();
|
|
420
373
|
if (allowWrap) {
|
|
421
374
|
return currentRow === 0 ? maxRow - 1 : currentRow - 1;
|
|
422
375
|
} else {
|
|
423
376
|
return currentRow > 0 ? currentRow - 1 : 0;
|
|
424
377
|
}
|
|
425
|
-
case
|
|
378
|
+
case "ArrowDown":
|
|
426
379
|
event.preventDefault();
|
|
427
380
|
if (allowWrap) {
|
|
428
381
|
return currentRow === maxRow - 1 ? 0 : currentRow + 1;
|
|
@@ -433,62 +386,52 @@ function onTableKeypress(event, currentRow, maxRow, allowWrap) {
|
|
|
433
386
|
return currentRow;
|
|
434
387
|
}
|
|
435
388
|
}
|
|
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());
|
|
389
|
+
const useTableKeyboardNavigation = (numberOfRows = 0, allowWrap = true) => {
|
|
390
|
+
const [currentRow, setCurrentRow] = useState(numberOfRows);
|
|
391
|
+
const [maxRow, setMaxRow] = useState(0);
|
|
392
|
+
const tableBodyRef = useRef(null);
|
|
393
|
+
const tableHasFocus = tableBodyRef?.current?.contains(document.activeElement);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
tableBodyRef && tableBodyRef.current && tableHasFocus && tableBodyRef.current.childNodes[currentRow].childNodes[0].parentElement?.focus();
|
|
455
396
|
}, [currentRow, tableHasFocus]);
|
|
456
|
-
function getTableBodyNavigationProps() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
ref: tableBodyRef
|
|
462
|
-
}, rest);
|
|
397
|
+
function getTableBodyNavigationProps(...rest) {
|
|
398
|
+
return {
|
|
399
|
+
ref: tableBodyRef,
|
|
400
|
+
...rest
|
|
401
|
+
};
|
|
463
402
|
}
|
|
464
|
-
|
|
465
|
-
function getTableRowNavigationProps(row) {
|
|
403
|
+
const tableRowRef = useRef(null);
|
|
404
|
+
function getTableRowNavigationProps(row, ...rest) {
|
|
466
405
|
if (row >= maxRow) {
|
|
467
406
|
setMaxRow(row + 1);
|
|
468
407
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
return _extends({
|
|
474
|
-
tabIndex: tabIndex,
|
|
408
|
+
const tabIndex = currentRow ? 0 : -1;
|
|
409
|
+
return {
|
|
410
|
+
tabIndex,
|
|
475
411
|
ref: tableRowRef,
|
|
476
|
-
onClick:
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
onKeyDown: function onKeyDown(e) {
|
|
480
|
-
var newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);
|
|
412
|
+
onClick: () => setCurrentRow(row),
|
|
413
|
+
onKeyDown: (e) => {
|
|
414
|
+
const newCell = onTableKeypress(e, currentRow, numberOfRows, allowWrap);
|
|
481
415
|
setCurrentRow(newCell);
|
|
482
|
-
}
|
|
483
|
-
|
|
416
|
+
},
|
|
417
|
+
...rest
|
|
418
|
+
};
|
|
484
419
|
}
|
|
485
|
-
return {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
420
|
+
return { getTableRowNavigationProps, getTableBodyNavigationProps };
|
|
421
|
+
};
|
|
422
|
+
warnAboutMissingStyles("table");
|
|
423
|
+
export {
|
|
424
|
+
DataCell,
|
|
425
|
+
EditableCell,
|
|
426
|
+
ExpandRowButton,
|
|
427
|
+
ExpandableRow,
|
|
428
|
+
HeaderCell,
|
|
429
|
+
Table,
|
|
430
|
+
TableBody,
|
|
431
|
+
TableFooter,
|
|
432
|
+
TableHead,
|
|
433
|
+
TableRow,
|
|
434
|
+
useSortableData,
|
|
435
|
+
useTableKeyboardNavigation
|
|
489
436
|
};
|
|
490
|
-
|
|
491
|
-
warnAboutMissingStyles('table');
|
|
492
|
-
|
|
493
|
-
export { DataCell, EditableCell, ExpandRowButton, ExpandableRow, HeaderCell, Table, TableBody, TableFooter, TableHead, TableRow, useSortableData, useTableKeyboardNavigation };
|
|
494
437
|
//# sourceMappingURL=table.esm.js.map
|