@dbcdk/react-components 0.0.135 → 0.0.137
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/components/forms/file-upload/FileUpload.cjs +13 -3
- package/dist/components/forms/file-upload/FileUpload.d.ts +4 -1
- package/dist/components/forms/file-upload/FileUpload.js +14 -4
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.cjs +12 -10
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +12 -10
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.module.css +18 -14
- package/dist/components/sidebar/components/sidebar-item-content/SidebarItemContent.module.css +12 -0
- package/dist/components/table/Table.cjs +3 -4
- package/dist/components/table/Table.d.ts +1 -1
- package/dist/components/table/Table.js +4 -5
- package/dist/components/table/Table.module.css +52 -21
- package/dist/components/table/Table.types.d.ts +9 -1
- package/dist/components/table/components/TableBody.cjs +2 -0
- package/dist/components/table/components/TableBody.d.ts +2 -1
- package/dist/components/table/components/TableBody.js +2 -0
- package/dist/components/table/components/TableHeader.cjs +1 -10
- package/dist/components/table/components/TableHeader.d.ts +1 -2
- package/dist/components/table/components/TableHeader.js +1 -10
- package/dist/components/table/components/TableRow.cjs +89 -68
- package/dist/components/table/components/TableRow.d.ts +2 -1
- package/dist/components/table/components/TableRow.js +89 -68
- package/dist/components/table/table.utils.cjs +0 -2
- package/dist/components/table/table.utils.d.ts +0 -1
- package/dist/components/table/table.utils.js +1 -2
- package/dist/components/table/tanstackTable.utils.cjs +2 -2
- package/dist/components/table/tanstackTable.utils.js +3 -3
- package/dist/hooks/useSorting.cjs +1 -0
- package/dist/hooks/useSorting.d.ts +6 -5
- package/dist/hooks/useSorting.js +1 -1
- package/dist/hooks/useTableData.cjs +29 -7
- package/dist/hooks/useTableData.d.ts +3 -1
- package/dist/hooks/useTableData.js +31 -9
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var lucideReact = require('lucide-react');
|
|
5
|
+
var react = require('react');
|
|
5
6
|
var Checkbox = require('../../../components/forms/checkbox/Checkbox');
|
|
6
7
|
var RadioButton = require('../../../components/forms/radio-buttons/RadioButton');
|
|
7
8
|
var Popover = require('../../../components/popover/Popover');
|
|
@@ -28,6 +29,7 @@ function TableRow({
|
|
|
28
29
|
viewMode,
|
|
29
30
|
getRowSeverity,
|
|
30
31
|
getContextMenuItems,
|
|
32
|
+
showContextMenuOnHover,
|
|
31
33
|
onRowClick,
|
|
32
34
|
onRowMouseEnter,
|
|
33
35
|
onRowSelect
|
|
@@ -41,6 +43,7 @@ function TableRow({
|
|
|
41
43
|
rowId,
|
|
42
44
|
open: () => onRowClick == null ? void 0 : onRowClick(row)
|
|
43
45
|
});
|
|
46
|
+
const hasContextMenu = Boolean(contextMenuItems == null ? void 0 : contextMenuItems.length);
|
|
44
47
|
const { handleRowClick, handleRowKeyDown } = useTableRowInteractions.useTableRowInteractions({
|
|
45
48
|
row,
|
|
46
49
|
rowId,
|
|
@@ -56,8 +59,10 @@ function TableRow({
|
|
|
56
59
|
styles__default.default.row,
|
|
57
60
|
onRowClick && styles__default.default.clickableRow,
|
|
58
61
|
isSelected && styles__default.default.selectedRow,
|
|
59
|
-
rowSeverity && styles__default.default.severity
|
|
62
|
+
rowSeverity && styles__default.default.severity,
|
|
63
|
+
hasContextMenu && showContextMenuOnHover && styles__default.default.contextMenuHoverOnly
|
|
60
64
|
),
|
|
65
|
+
"data-context-menu-visibility": hasContextMenu ? showContextMenuOnHover ? "hover" : "always" : void 0,
|
|
61
66
|
style: {
|
|
62
67
|
["--row-severity-color"]: rowSeverity ? `color-mix(in srgb, ${severity.SeverityBgColor[rowSeverity]} 65%, var(--table-component-row-bg))` : void 0
|
|
63
68
|
},
|
|
@@ -124,10 +129,11 @@ function TableRow({
|
|
|
124
129
|
}
|
|
125
130
|
) }) : null,
|
|
126
131
|
columns.map((column) => {
|
|
127
|
-
var _a2, _b, _c, _d;
|
|
132
|
+
var _a2, _b, _c, _d, _e;
|
|
128
133
|
const allowWrap = table_utils.shouldAllowWrap(column.allowWrap, isSelected, viewMode);
|
|
129
134
|
const allowOverflow = column.allowOverflow;
|
|
130
135
|
const cellValue = table_utils.getCellDisplayValue(row, column);
|
|
136
|
+
const isLastColumn = column.id === ((_a2 = columns[columns.length - 1]) == null ? void 0 : _a2.id);
|
|
131
137
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
132
138
|
"td",
|
|
133
139
|
{
|
|
@@ -135,96 +141,111 @@ function TableRow({
|
|
|
135
141
|
styles__default.default.cell,
|
|
136
142
|
allowOverflow && styles__default.default.allowOverflow,
|
|
137
143
|
allowWrap ? styles__default.default.allowWrap : styles__default.default.nowrap,
|
|
144
|
+
hasContextMenu && isLastColumn && styles__default.default.contextMenuAnchorCell,
|
|
138
145
|
column.divider === "left" && styles__default.default.dividerLeft,
|
|
139
146
|
column.divider === "right" && styles__default.default.dividerRight
|
|
140
147
|
),
|
|
141
|
-
"data-align": (
|
|
142
|
-
"data-vertical-align": (
|
|
148
|
+
"data-align": (_b = column.align) != null ? _b : "left",
|
|
149
|
+
"data-vertical-align": (_c = column.verticalAlign) != null ? _c : "top",
|
|
143
150
|
"data-divider": column.divider,
|
|
144
|
-
children: /* @__PURE__ */ jsxRuntime.
|
|
151
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
145
152
|
"div",
|
|
146
153
|
{
|
|
147
154
|
className: styles__default.default.cellContent,
|
|
148
|
-
"data-align": (
|
|
149
|
-
"data-vertical-align": (
|
|
150
|
-
children:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
"data-align": (_d = column.align) != null ? _d : "left",
|
|
156
|
+
"data-vertical-align": (_e = column.verticalAlign) != null ? _e : "top",
|
|
157
|
+
children: [
|
|
158
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
className: allowOverflow ? styles__default.default.cellValueNoEllipsis : styles__default.default.cellValueEllipsis,
|
|
162
|
+
children: cellValue
|
|
163
|
+
}
|
|
164
|
+
),
|
|
165
|
+
hasContextMenu && isLastColumn ? /* @__PURE__ */ jsxRuntime.jsx(RowContextMenu, { rowId, items: contextMenuItems }) : null
|
|
166
|
+
]
|
|
157
167
|
}
|
|
158
168
|
)
|
|
159
169
|
},
|
|
160
170
|
column.id
|
|
161
171
|
);
|
|
162
|
-
})
|
|
163
|
-
(contextMenuItems == null ? void 0 : contextMenuItems.length) ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: table_classes.cx(styles__default.default.cell, styles__default.default.contextMenuCell), "data-row-context-menu": "true", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
164
|
-
"div",
|
|
165
|
-
{
|
|
166
|
-
className: table_classes.cx(styles__default.default.cellContent, styles__default.default.contextMenuCellContent),
|
|
167
|
-
"data-align": "right",
|
|
168
|
-
"data-row-context-menu": "true",
|
|
169
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(RowContextMenu, { row, rowId, items: contextMenuItems })
|
|
170
|
-
}
|
|
171
|
-
) }) : null
|
|
172
|
+
})
|
|
172
173
|
]
|
|
173
174
|
}
|
|
174
175
|
);
|
|
175
176
|
}
|
|
176
177
|
function RowContextMenu({
|
|
177
|
-
row,
|
|
178
178
|
rowId,
|
|
179
179
|
items
|
|
180
180
|
}) {
|
|
181
|
+
const toggleRef = react.useRef(null);
|
|
181
182
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
182
|
-
|
|
183
|
+
"div",
|
|
183
184
|
{
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
className: styles__default.default.contextMenuTrigger,
|
|
194
|
-
"aria-label": `Flere handlinger for r\xE6kke ${String(rowId)}`,
|
|
195
|
-
"aria-haspopup": "menu",
|
|
196
|
-
"aria-expanded": isOpen ? true : false,
|
|
197
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreVertical, { size: 16 }),
|
|
198
|
-
"data-row-context-menu": "true",
|
|
199
|
-
onClick: (e) => {
|
|
200
|
-
e.stopPropagation();
|
|
201
|
-
toggle(e);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
),
|
|
205
|
-
children: (close) => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
206
|
-
Menu.Menu.Item,
|
|
185
|
+
className: styles__default.default.contextMenuOverlay,
|
|
186
|
+
"data-row-context-menu": "true",
|
|
187
|
+
onClick: (e) => {
|
|
188
|
+
var _a;
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
(_a = toggleRef.current) == null ? void 0 : _a.call(toggleRef, e);
|
|
191
|
+
},
|
|
192
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
193
|
+
Popover.Popover,
|
|
207
194
|
{
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
195
|
+
matchTriggerWidth: false,
|
|
196
|
+
minWidth: "180px",
|
|
197
|
+
trigger: (toggle, _icon, isOpen) => {
|
|
198
|
+
toggleRef.current = toggle;
|
|
199
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
200
|
+
Button.Button,
|
|
201
|
+
{
|
|
202
|
+
type: "button",
|
|
203
|
+
size: "sm",
|
|
204
|
+
variant: "inline",
|
|
205
|
+
shape: "round",
|
|
206
|
+
className: styles__default.default.contextMenuTrigger,
|
|
207
|
+
"aria-label": `Flere handlinger for r\xE6kke ${String(rowId)}`,
|
|
208
|
+
"aria-haspopup": "menu",
|
|
209
|
+
"aria-expanded": isOpen ? true : false,
|
|
210
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreVertical, { size: 16 }),
|
|
211
|
+
"data-row-context-menu": "true",
|
|
212
|
+
onClick: (e) => {
|
|
213
|
+
e.stopPropagation();
|
|
214
|
+
toggle(e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
},
|
|
219
|
+
children: (close) => /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu, { children: items.map(
|
|
220
|
+
(item, index) => item.type === "header" ? /* @__PURE__ */ jsxRuntime.jsx(Menu.Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
221
|
+
Menu.Menu.Item,
|
|
222
|
+
{
|
|
223
|
+
active: item.active,
|
|
224
|
+
selected: item.selected,
|
|
225
|
+
disabled: item.disabled,
|
|
226
|
+
variant: item.variant,
|
|
227
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
"data-row-context-menu": "true",
|
|
232
|
+
onClick: (e) => {
|
|
233
|
+
e.stopPropagation();
|
|
234
|
+
item.onClick();
|
|
235
|
+
close();
|
|
236
|
+
},
|
|
237
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: styles__default.default.contextMenuItemLabel, children: [
|
|
238
|
+
item.icon,
|
|
239
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles__default.default.contextMenuItemText, children: item.label })
|
|
240
|
+
] })
|
|
241
|
+
}
|
|
242
|
+
)
|
|
221
243
|
},
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
)) })
|
|
244
|
+
index
|
|
245
|
+
)
|
|
246
|
+
) })
|
|
247
|
+
}
|
|
248
|
+
)
|
|
228
249
|
}
|
|
229
250
|
);
|
|
230
251
|
}
|
|
@@ -16,9 +16,10 @@ type Props<T extends Record<string, any>> = {
|
|
|
16
16
|
rowId: string | number;
|
|
17
17
|
open: () => void;
|
|
18
18
|
}) => TableContextMenuItem[];
|
|
19
|
+
showContextMenuOnHover: boolean;
|
|
19
20
|
onRowClick?: (row: T) => void;
|
|
20
21
|
onRowMouseEnter?: (row: T) => void;
|
|
21
22
|
onRowSelect?: (rowId: number | string, isSelected: boolean) => void;
|
|
22
23
|
};
|
|
23
|
-
export declare function TableRow<T extends Record<string, any>>({ row, rowId, columns, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, getContextMenuItems, onRowClick, onRowMouseEnter, onRowSelect, }: Props<T>): React.ReactNode;
|
|
24
|
+
export declare function TableRow<T extends Record<string, any>>({ row, rowId, columns, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, getContextMenuItems, showContextMenuOnHover, onRowClick, onRowMouseEnter, onRowSelect, }: Props<T>): React.ReactNode;
|
|
24
25
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { MoreVertical } from 'lucide-react';
|
|
3
|
+
import { useRef } from 'react';
|
|
3
4
|
import { Checkbox } from '../../../components/forms/checkbox/Checkbox';
|
|
4
5
|
import { RadioButton } from '../../../components/forms/radio-buttons/RadioButton';
|
|
5
6
|
import { Popover } from '../../../components/popover/Popover';
|
|
@@ -22,6 +23,7 @@ function TableRow({
|
|
|
22
23
|
viewMode,
|
|
23
24
|
getRowSeverity,
|
|
24
25
|
getContextMenuItems,
|
|
26
|
+
showContextMenuOnHover,
|
|
25
27
|
onRowClick,
|
|
26
28
|
onRowMouseEnter,
|
|
27
29
|
onRowSelect
|
|
@@ -35,6 +37,7 @@ function TableRow({
|
|
|
35
37
|
rowId,
|
|
36
38
|
open: () => onRowClick == null ? void 0 : onRowClick(row)
|
|
37
39
|
});
|
|
40
|
+
const hasContextMenu = Boolean(contextMenuItems == null ? void 0 : contextMenuItems.length);
|
|
38
41
|
const { handleRowClick, handleRowKeyDown } = useTableRowInteractions({
|
|
39
42
|
row,
|
|
40
43
|
rowId,
|
|
@@ -50,8 +53,10 @@ function TableRow({
|
|
|
50
53
|
styles.row,
|
|
51
54
|
onRowClick && styles.clickableRow,
|
|
52
55
|
isSelected && styles.selectedRow,
|
|
53
|
-
rowSeverity && styles.severity
|
|
56
|
+
rowSeverity && styles.severity,
|
|
57
|
+
hasContextMenu && showContextMenuOnHover && styles.contextMenuHoverOnly
|
|
54
58
|
),
|
|
59
|
+
"data-context-menu-visibility": hasContextMenu ? showContextMenuOnHover ? "hover" : "always" : void 0,
|
|
55
60
|
style: {
|
|
56
61
|
["--row-severity-color"]: rowSeverity ? `color-mix(in srgb, ${SeverityBgColor[rowSeverity]} 65%, var(--table-component-row-bg))` : void 0
|
|
57
62
|
},
|
|
@@ -118,10 +123,11 @@ function TableRow({
|
|
|
118
123
|
}
|
|
119
124
|
) }) : null,
|
|
120
125
|
columns.map((column) => {
|
|
121
|
-
var _a2, _b, _c, _d;
|
|
126
|
+
var _a2, _b, _c, _d, _e;
|
|
122
127
|
const allowWrap = shouldAllowWrap(column.allowWrap, isSelected, viewMode);
|
|
123
128
|
const allowOverflow = column.allowOverflow;
|
|
124
129
|
const cellValue = getCellDisplayValue(row, column);
|
|
130
|
+
const isLastColumn = column.id === ((_a2 = columns[columns.length - 1]) == null ? void 0 : _a2.id);
|
|
125
131
|
return /* @__PURE__ */ jsx(
|
|
126
132
|
"td",
|
|
127
133
|
{
|
|
@@ -129,96 +135,111 @@ function TableRow({
|
|
|
129
135
|
styles.cell,
|
|
130
136
|
allowOverflow && styles.allowOverflow,
|
|
131
137
|
allowWrap ? styles.allowWrap : styles.nowrap,
|
|
138
|
+
hasContextMenu && isLastColumn && styles.contextMenuAnchorCell,
|
|
132
139
|
column.divider === "left" && styles.dividerLeft,
|
|
133
140
|
column.divider === "right" && styles.dividerRight
|
|
134
141
|
),
|
|
135
|
-
"data-align": (
|
|
136
|
-
"data-vertical-align": (
|
|
142
|
+
"data-align": (_b = column.align) != null ? _b : "left",
|
|
143
|
+
"data-vertical-align": (_c = column.verticalAlign) != null ? _c : "top",
|
|
137
144
|
"data-divider": column.divider,
|
|
138
|
-
children: /* @__PURE__ */
|
|
145
|
+
children: /* @__PURE__ */ jsxs(
|
|
139
146
|
"div",
|
|
140
147
|
{
|
|
141
148
|
className: styles.cellContent,
|
|
142
|
-
"data-align": (
|
|
143
|
-
"data-vertical-align": (
|
|
144
|
-
children:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
"data-align": (_d = column.align) != null ? _d : "left",
|
|
150
|
+
"data-vertical-align": (_e = column.verticalAlign) != null ? _e : "top",
|
|
151
|
+
children: [
|
|
152
|
+
/* @__PURE__ */ jsx(
|
|
153
|
+
"div",
|
|
154
|
+
{
|
|
155
|
+
className: allowOverflow ? styles.cellValueNoEllipsis : styles.cellValueEllipsis,
|
|
156
|
+
children: cellValue
|
|
157
|
+
}
|
|
158
|
+
),
|
|
159
|
+
hasContextMenu && isLastColumn ? /* @__PURE__ */ jsx(RowContextMenu, { rowId, items: contextMenuItems }) : null
|
|
160
|
+
]
|
|
151
161
|
}
|
|
152
162
|
)
|
|
153
163
|
},
|
|
154
164
|
column.id
|
|
155
165
|
);
|
|
156
|
-
})
|
|
157
|
-
(contextMenuItems == null ? void 0 : contextMenuItems.length) ? /* @__PURE__ */ jsx("td", { className: cx(styles.cell, styles.contextMenuCell), "data-row-context-menu": "true", children: /* @__PURE__ */ jsx(
|
|
158
|
-
"div",
|
|
159
|
-
{
|
|
160
|
-
className: cx(styles.cellContent, styles.contextMenuCellContent),
|
|
161
|
-
"data-align": "right",
|
|
162
|
-
"data-row-context-menu": "true",
|
|
163
|
-
children: /* @__PURE__ */ jsx(RowContextMenu, { row, rowId, items: contextMenuItems })
|
|
164
|
-
}
|
|
165
|
-
) }) : null
|
|
166
|
+
})
|
|
166
167
|
]
|
|
167
168
|
}
|
|
168
169
|
);
|
|
169
170
|
}
|
|
170
171
|
function RowContextMenu({
|
|
171
|
-
row,
|
|
172
172
|
rowId,
|
|
173
173
|
items
|
|
174
174
|
}) {
|
|
175
|
+
const toggleRef = useRef(null);
|
|
175
176
|
return /* @__PURE__ */ jsx(
|
|
176
|
-
|
|
177
|
+
"div",
|
|
177
178
|
{
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
className: styles.contextMenuTrigger,
|
|
188
|
-
"aria-label": `Flere handlinger for r\xE6kke ${String(rowId)}`,
|
|
189
|
-
"aria-haspopup": "menu",
|
|
190
|
-
"aria-expanded": isOpen ? true : false,
|
|
191
|
-
icon: /* @__PURE__ */ jsx(MoreVertical, { size: 16 }),
|
|
192
|
-
"data-row-context-menu": "true",
|
|
193
|
-
onClick: (e) => {
|
|
194
|
-
e.stopPropagation();
|
|
195
|
-
toggle(e);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
),
|
|
199
|
-
children: (close) => /* @__PURE__ */ jsx(Menu, { children: items.map((item, index) => /* @__PURE__ */ jsx(
|
|
200
|
-
Menu.Item,
|
|
179
|
+
className: styles.contextMenuOverlay,
|
|
180
|
+
"data-row-context-menu": "true",
|
|
181
|
+
onClick: (e) => {
|
|
182
|
+
var _a;
|
|
183
|
+
e.stopPropagation();
|
|
184
|
+
(_a = toggleRef.current) == null ? void 0 : _a.call(toggleRef, e);
|
|
185
|
+
},
|
|
186
|
+
children: /* @__PURE__ */ jsx(
|
|
187
|
+
Popover,
|
|
201
188
|
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
189
|
+
matchTriggerWidth: false,
|
|
190
|
+
minWidth: "180px",
|
|
191
|
+
trigger: (toggle, _icon, isOpen) => {
|
|
192
|
+
toggleRef.current = toggle;
|
|
193
|
+
return /* @__PURE__ */ jsx(
|
|
194
|
+
Button,
|
|
195
|
+
{
|
|
196
|
+
type: "button",
|
|
197
|
+
size: "sm",
|
|
198
|
+
variant: "inline",
|
|
199
|
+
shape: "round",
|
|
200
|
+
className: styles.contextMenuTrigger,
|
|
201
|
+
"aria-label": `Flere handlinger for r\xE6kke ${String(rowId)}`,
|
|
202
|
+
"aria-haspopup": "menu",
|
|
203
|
+
"aria-expanded": isOpen ? true : false,
|
|
204
|
+
icon: /* @__PURE__ */ jsx(MoreVertical, { size: 16 }),
|
|
205
|
+
"data-row-context-menu": "true",
|
|
206
|
+
onClick: (e) => {
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
toggle(e);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
},
|
|
213
|
+
children: (close) => /* @__PURE__ */ jsx(Menu, { children: items.map(
|
|
214
|
+
(item, index) => item.type === "header" ? /* @__PURE__ */ jsx(Menu.Header, { children: item.label }, index) : /* @__PURE__ */ jsx(
|
|
215
|
+
Menu.Item,
|
|
216
|
+
{
|
|
217
|
+
active: item.active,
|
|
218
|
+
selected: item.selected,
|
|
219
|
+
disabled: item.disabled,
|
|
220
|
+
variant: item.variant,
|
|
221
|
+
children: /* @__PURE__ */ jsx(
|
|
222
|
+
"button",
|
|
223
|
+
{
|
|
224
|
+
type: "button",
|
|
225
|
+
"data-row-context-menu": "true",
|
|
226
|
+
onClick: (e) => {
|
|
227
|
+
e.stopPropagation();
|
|
228
|
+
item.onClick();
|
|
229
|
+
close();
|
|
230
|
+
},
|
|
231
|
+
children: /* @__PURE__ */ jsxs("span", { className: styles.contextMenuItemLabel, children: [
|
|
232
|
+
item.icon,
|
|
233
|
+
/* @__PURE__ */ jsx("span", { className: styles.contextMenuItemText, children: item.label })
|
|
234
|
+
] })
|
|
235
|
+
}
|
|
236
|
+
)
|
|
215
237
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
)) })
|
|
238
|
+
index
|
|
239
|
+
)
|
|
240
|
+
) })
|
|
241
|
+
}
|
|
242
|
+
)
|
|
222
243
|
}
|
|
223
244
|
);
|
|
224
245
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const SELECTION_COLUMN_PX = 40;
|
|
4
|
-
const CONTEXT_MENU_COLUMN_PX = 44;
|
|
5
4
|
const DEFAULT_COLUMN_PX = 150;
|
|
6
5
|
function getVisibleColumns(columns) {
|
|
7
6
|
return columns.filter((column) => !column.hidden);
|
|
@@ -45,7 +44,6 @@ function getCellDisplayValue(row, column) {
|
|
|
45
44
|
return empty;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
exports.CONTEXT_MENU_COLUMN_PX = CONTEXT_MENU_COLUMN_PX;
|
|
49
47
|
exports.DEFAULT_COLUMN_PX = DEFAULT_COLUMN_PX;
|
|
50
48
|
exports.SELECTION_COLUMN_PX = SELECTION_COLUMN_PX;
|
|
51
49
|
exports.getAriaSort = getAriaSort;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { ColumnItem } from './Table.types';
|
|
3
3
|
export declare const SELECTION_COLUMN_PX: 40;
|
|
4
|
-
export declare const CONTEXT_MENU_COLUMN_PX: 44;
|
|
5
4
|
export declare const DEFAULT_COLUMN_PX: 150;
|
|
6
5
|
export type SortDirection = 'asc' | 'desc' | null;
|
|
7
6
|
export declare function getVisibleColumns<T>(columns: Array<ColumnItem<T>>): Array<ColumnItem<T>>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const SELECTION_COLUMN_PX = 40;
|
|
2
|
-
const CONTEXT_MENU_COLUMN_PX = 44;
|
|
3
2
|
const DEFAULT_COLUMN_PX = 150;
|
|
4
3
|
function getVisibleColumns(columns) {
|
|
5
4
|
return columns.filter((column) => !column.hidden);
|
|
@@ -43,4 +42,4 @@ function getCellDisplayValue(row, column) {
|
|
|
43
42
|
return empty;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
export {
|
|
45
|
+
export { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX, getAriaSort, getCellDisplayValue, getHeaderLabel, getNextSortDirection, getVisibleColumns, isActiveSort, isModifierClick, shouldAllowWrap, shouldToggleOnKey };
|
|
@@ -103,7 +103,7 @@ function buildDistributedColumnWidths(args) {
|
|
|
103
103
|
} = args;
|
|
104
104
|
const leaf = table.getVisibleLeafColumns();
|
|
105
105
|
const selectionWidth = hasSelection ? table_utils.SELECTION_COLUMN_PX : 0;
|
|
106
|
-
const contextMenuWidth = hasContextMenu ?
|
|
106
|
+
const contextMenuWidth = hasContextMenu ? 0 : 0;
|
|
107
107
|
const tracks = leaf.map((c) => {
|
|
108
108
|
var _a, _b, _c, _d;
|
|
109
109
|
const def = c.columnDef;
|
|
@@ -165,7 +165,7 @@ function buildDistributedColumnWidths(args) {
|
|
|
165
165
|
const totalWidth = selectionWidth + contextMenuWidth + Object.values(widths).reduce((sum, width) => sum + width, 0);
|
|
166
166
|
return {
|
|
167
167
|
selectionWidth: hasSelection ? table_utils.SELECTION_COLUMN_PX : void 0,
|
|
168
|
-
contextMenuWidth: hasContextMenu ?
|
|
168
|
+
contextMenuWidth: hasContextMenu ? 0 : void 0,
|
|
169
169
|
widths,
|
|
170
170
|
totalWidth,
|
|
171
171
|
availableWidth,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_COLUMN_PX,
|
|
1
|
+
import { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX } from './table.utils';
|
|
2
2
|
|
|
3
3
|
function getColumnId(def, index) {
|
|
4
4
|
const d = def;
|
|
@@ -101,7 +101,7 @@ function buildDistributedColumnWidths(args) {
|
|
|
101
101
|
} = args;
|
|
102
102
|
const leaf = table.getVisibleLeafColumns();
|
|
103
103
|
const selectionWidth = hasSelection ? SELECTION_COLUMN_PX : 0;
|
|
104
|
-
const contextMenuWidth = hasContextMenu ?
|
|
104
|
+
const contextMenuWidth = hasContextMenu ? 0 : 0;
|
|
105
105
|
const tracks = leaf.map((c) => {
|
|
106
106
|
var _a, _b, _c, _d;
|
|
107
107
|
const def = c.columnDef;
|
|
@@ -163,7 +163,7 @@ function buildDistributedColumnWidths(args) {
|
|
|
163
163
|
const totalWidth = selectionWidth + contextMenuWidth + Object.values(widths).reduce((sum, width) => sum + width, 0);
|
|
164
164
|
return {
|
|
165
165
|
selectionWidth: hasSelection ? SELECTION_COLUMN_PX : void 0,
|
|
166
|
-
contextMenuWidth: hasContextMenu ?
|
|
166
|
+
contextMenuWidth: hasContextMenu ? 0 : void 0,
|
|
167
167
|
widths,
|
|
168
168
|
totalWidth,
|
|
169
169
|
availableWidth,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export type SortDirection = 'asc' | 'desc' | null;
|
|
2
|
-
export type SortState<T> = {
|
|
3
|
-
sortBy:
|
|
2
|
+
export type SortState<T = unknown> = {
|
|
3
|
+
sortBy: string | null;
|
|
4
4
|
sortDirection: SortDirection;
|
|
5
5
|
};
|
|
6
|
-
export type SortEvent<T> = Partial<SortState<T>>;
|
|
7
|
-
export type ColumnComparators<T> = Partial<Record<
|
|
6
|
+
export type SortEvent<T = unknown> = Partial<SortState<T>>;
|
|
7
|
+
export type ColumnComparators<T> = Partial<Record<string, (a: T, b: T, direction: Exclude<SortDirection, null>) => number>>;
|
|
8
8
|
export interface UseSortingProps<T> {
|
|
9
9
|
data?: readonly T[];
|
|
10
10
|
/**
|
|
11
11
|
* Default/initial state. If you pass `state`, these are ignored.
|
|
12
12
|
*/
|
|
13
|
-
sortBy?:
|
|
13
|
+
sortBy?: string | null;
|
|
14
14
|
sortDirection?: SortDirection;
|
|
15
15
|
/**
|
|
16
16
|
* Controlled mode: if provided, hook will not keep its own state.
|
|
@@ -46,4 +46,5 @@ export interface UseSortingResult<T> {
|
|
|
46
46
|
setSort: (next: SortState<T>) => void;
|
|
47
47
|
clearSort: () => void;
|
|
48
48
|
}
|
|
49
|
+
export declare function defaultCompare(a: unknown, b: unknown, dir: 'asc' | 'desc', nulls: 'first' | 'last'): number;
|
|
49
50
|
export declare function useSorting<T extends Record<string, any>>({ data, sortBy, sortDirection, state, onStateChange, columnComparators, nulls, allowUnsort, resetOnDataChange, }: UseSortingProps<T>): UseSortingResult<T>;
|
package/dist/hooks/useSorting.js
CHANGED
|
@@ -12,28 +12,50 @@ function useTableData({
|
|
|
12
12
|
resetPageOnSortChange = true
|
|
13
13
|
}) {
|
|
14
14
|
var _a, _b, _c, _d, _e, _f;
|
|
15
|
+
const hasPagination = pagination != null;
|
|
16
|
+
const nullsMode = (_a = sorting == null ? void 0 : sorting.nulls) != null ? _a : "last";
|
|
17
|
+
const mergedComparators = react.useMemo(() => {
|
|
18
|
+
var _a2, _b2;
|
|
19
|
+
const derived = {};
|
|
20
|
+
for (const col of (_a2 = sorting == null ? void 0 : sorting.columns) != null ? _a2 : []) {
|
|
21
|
+
const colId = (_b2 = col.id) != null ? _b2 : col.accessorKey;
|
|
22
|
+
if (!colId) continue;
|
|
23
|
+
const accessorFn = col.accessorFn;
|
|
24
|
+
const accessorKey = col.accessorKey;
|
|
25
|
+
if (accessorFn) {
|
|
26
|
+
derived[colId] = (a, b, dir) => useSorting.defaultCompare(accessorFn(a, 0), accessorFn(b, 0), dir, nullsMode);
|
|
27
|
+
} else if (accessorKey) {
|
|
28
|
+
derived[colId] = (a, b, dir) => useSorting.defaultCompare(a[accessorKey], b[accessorKey], dir, nullsMode);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { ...derived, ...sorting == null ? void 0 : sorting.columnComparators };
|
|
32
|
+
}, [sorting == null ? void 0 : sorting.columns, sorting == null ? void 0 : sorting.columnComparators, nullsMode]);
|
|
15
33
|
const s = useSorting.useSorting({
|
|
16
34
|
data,
|
|
17
|
-
sortBy: (
|
|
18
|
-
sortDirection: (
|
|
35
|
+
sortBy: (_b = sorting == null ? void 0 : sorting.sortBy) != null ? _b : null,
|
|
36
|
+
sortDirection: (_c = sorting == null ? void 0 : sorting.direction) != null ? _c : null,
|
|
19
37
|
state: sorting == null ? void 0 : sorting.state,
|
|
20
38
|
onStateChange: sorting == null ? void 0 : sorting.onStateChange,
|
|
21
|
-
columnComparators:
|
|
22
|
-
nulls:
|
|
39
|
+
columnComparators: mergedComparators,
|
|
40
|
+
nulls: nullsMode,
|
|
23
41
|
allowUnsort: (_d = sorting == null ? void 0 : sorting.allowUnsort) != null ? _d : true
|
|
24
42
|
});
|
|
25
43
|
const p = usePagination.usePagination({
|
|
26
44
|
data: s.sortedData,
|
|
27
45
|
skip: (_e = pagination == null ? void 0 : pagination.skip) != null ? _e : 0,
|
|
28
|
-
take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f :
|
|
46
|
+
take: (_f = pagination == null ? void 0 : pagination.take) != null ? _f : Math.max(s.sortedData.length, 1),
|
|
29
47
|
state: pagination == null ? void 0 : pagination.state,
|
|
30
48
|
onStateChange: pagination == null ? void 0 : pagination.onStateChange
|
|
31
49
|
});
|
|
32
50
|
react.useEffect(() => {
|
|
51
|
+
if (!hasPagination) return;
|
|
33
52
|
if (!resetPageOnSortChange) return;
|
|
34
53
|
p.resetPage();
|
|
35
|
-
}, [resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
|
|
36
|
-
const rows = react.useMemo(
|
|
54
|
+
}, [hasPagination, resetPageOnSortChange, s.sortState.sortBy, s.sortState.sortDirection]);
|
|
55
|
+
const rows = react.useMemo(
|
|
56
|
+
() => hasPagination ? p.paginatedData : s.sortedData,
|
|
57
|
+
[hasPagination, p.paginatedData, s.sortedData]
|
|
58
|
+
);
|
|
37
59
|
return {
|
|
38
60
|
rows,
|
|
39
61
|
totalCount: s.sortedData.length,
|