@dbcdk/react-components 0.0.119 → 0.0.121

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.
Files changed (41) hide show
  1. package/dist/components/button/Button.module.css +2 -2
  2. package/dist/components/card/Card.cjs +4 -7
  3. package/dist/components/card/Card.js +4 -7
  4. package/dist/components/card/Card.module.css +4 -9
  5. package/dist/components/lightbox/Lightbox.cjs +94 -23
  6. package/dist/components/lightbox/Lightbox.d.ts +14 -1
  7. package/dist/components/lightbox/Lightbox.js +95 -24
  8. package/dist/components/lightbox/Lightbox.module.css +56 -3
  9. package/dist/components/search-box/SearchBox.cjs +9 -4
  10. package/dist/components/search-box/SearchBox.js +9 -4
  11. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +1 -1
  12. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +1 -1
  13. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +11 -7
  14. package/dist/components/table/Table.cjs +9 -4
  15. package/dist/components/table/Table.d.ts +1 -1
  16. package/dist/components/table/Table.js +10 -5
  17. package/dist/components/table/Table.module.css +25 -0
  18. package/dist/components/table/Table.types.d.ts +13 -0
  19. package/dist/components/table/TanstackTable.cjs +10 -1
  20. package/dist/components/table/TanstackTable.js +10 -1
  21. package/dist/components/table/components/TableBody.cjs +2 -0
  22. package/dist/components/table/components/TableBody.d.ts +7 -2
  23. package/dist/components/table/components/TableBody.js +2 -0
  24. package/dist/components/table/components/TableHeader.cjs +10 -1
  25. package/dist/components/table/components/TableHeader.d.ts +2 -1
  26. package/dist/components/table/components/TableHeader.js +10 -1
  27. package/dist/components/table/components/TableRow.cjs +75 -1
  28. package/dist/components/table/components/TableRow.d.ts +7 -2
  29. package/dist/components/table/components/TableRow.js +75 -1
  30. package/dist/components/table/hooks/useTableRowInteractions.cjs +2 -2
  31. package/dist/components/table/hooks/useTableRowInteractions.js +2 -2
  32. package/dist/components/table/table.utils.cjs +2 -0
  33. package/dist/components/table/table.utils.d.ts +1 -0
  34. package/dist/components/table/table.utils.js +2 -1
  35. package/dist/components/table/tanstackTable.utils.cjs +6 -4
  36. package/dist/components/table/tanstackTable.utils.d.ts +2 -0
  37. package/dist/components/table/tanstackTable.utils.js +7 -5
  38. package/package.json +1 -1
  39. package/dist/components/table/components/TableLoadingBody.cjs +0 -35
  40. package/dist/components/table/components/TableLoadingBody.d.ts +0 -9
  41. package/dist/components/table/components/TableLoadingBody.js +0 -29
@@ -4,11 +4,11 @@
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('react');
6
6
  var Pagination = require('../../components/pagination/Pagination');
7
+ var SkeletonLoader = require('../../components/skeleton-loader/SkeletonLoader');
7
8
  var useViewportFill = require('../../hooks/useViewportFill');
8
9
  var EmptyState = require('./components/empty-state/EmptyState');
9
10
  var TableBody = require('./components/TableBody');
10
11
  var TableHeader = require('./components/TableHeader');
11
- var TableLoadingBody = require('./components/TableLoadingBody');
12
12
  var table_classes = require('./table.classes');
13
13
  var styles = require('./Table.module.css');
14
14
  var table_utils = require('./table.utils');
@@ -51,6 +51,7 @@ function Table({
51
51
  pageSizeOptions,
52
52
  showHeader = true,
53
53
  getRowSeverity,
54
+ getContextMenuItems,
54
55
  onRowClick,
55
56
  onRowMouseEnter,
56
57
  onRowSelect,
@@ -64,6 +65,7 @@ function Table({
64
65
  const internalTableRootRef = react.useRef(null);
65
66
  const tableRootRefWrapper = react.useRef(tableRootRef);
66
67
  const hasSelection = Boolean(selectedRows && onRowSelect);
68
+ const hasContextMenu = Boolean(getContextMenuItems);
67
69
  const hasPagination = Boolean(onPageChange && (loading || data.length > 0));
68
70
  const paginationOffset = hasPagination ? 72 : 0;
69
71
  const { style: viewportFillStyle, maxHeight } = useViewportFill.useViewportFill(internalTableRootRef, {
@@ -86,7 +88,7 @@ function Table({
86
88
  },
87
89
  [onPageChange]
88
90
  );
89
- const bodyContent = loading && !data.length ? /* @__PURE__ */ jsxRuntime.jsx(TableLoadingBody.TableLoadingBody, { rows: take != null ? take : 5, columns: visibleColumns, hasSelection }) : /* @__PURE__ */ jsxRuntime.jsx(
91
+ const bodyContent = /* @__PURE__ */ jsxRuntime.jsx(
90
92
  TableBody.TableBody,
91
93
  {
92
94
  data,
@@ -99,6 +101,7 @@ function Table({
99
101
  selectionInputName,
100
102
  viewMode,
101
103
  getRowSeverity,
104
+ getContextMenuItems,
102
105
  onRowClick,
103
106
  onRowMouseEnter,
104
107
  onRowSelect
@@ -139,7 +142,7 @@ function Table({
139
142
  ref: setTableRootRef,
140
143
  className: styles__default.default.tableScroll,
141
144
  style: fillViewportActive ? viewportFillStyle : !containScrolling ? { overflow: "visible" } : void 0,
142
- children: !data.length && !loading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.emptyStateSlot, children: /* @__PURE__ */ jsxRuntime.jsx(EmptyState.TableEmptyState, { config: emptyConfig }) }) : /* @__PURE__ */ jsxRuntime.jsxs(
145
+ children: loading && !data.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.emptyStateSlot, children: /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoader.SkeletonLoader, { type: "table", rows: 5, columns: 3 }) }) : !data.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.emptyStateSlot, children: /* @__PURE__ */ jsxRuntime.jsx(EmptyState.TableEmptyState, { config: emptyConfig }) }) : /* @__PURE__ */ jsxRuntime.jsxs(
143
146
  "table",
144
147
  {
145
148
  className: styles__default.default.tableElement,
@@ -155,13 +158,15 @@ function Table({
155
158
  style: column.width != null ? { width: column.width } : void 0
156
159
  },
157
160
  column.id
158
- ))
161
+ )),
162
+ hasContextMenu ? /* @__PURE__ */ jsxRuntime.jsx("col", { style: { width: table_utils.CONTEXT_MENU_COLUMN_PX } }) : null
159
163
  ] }),
160
164
  showHeader && /* @__PURE__ */ jsxRuntime.jsx(
161
165
  TableHeader.TableHeader,
162
166
  {
163
167
  columns: visibleColumns,
164
168
  hasSelection,
169
+ hasContextMenu,
165
170
  selectionMode,
166
171
  allRowsSelected,
167
172
  onSelectAllRows,
@@ -1,4 +1,4 @@
1
1
  import type { JSX } from 'react';
2
2
  import type { TableProps } from './Table.types';
3
- export declare function Table<T extends Record<string, any>>({ data, dataKey, columns, selectedRows, selectionMode, allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant, size, viewMode, striped, fillViewport, fillViewportBottomOffset, containScrolling, stickyHeader, tableWidth, tableRootRef, measuringLayout, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement, showFirstLast, showGoToPage, showPageSize, pageSizeOptions, showHeader, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }: TableProps<T>): JSX.Element;
3
+ export declare function Table<T extends Record<string, any>>({ data, dataKey, columns, selectedRows, selectionMode, allRowsSelected, sortById, sortDirection, loading, emptyConfig, variant, size, viewMode, striped, fillViewport, fillViewportBottomOffset, containScrolling, stickyHeader, tableWidth, tableRootRef, measuringLayout, toolbar, headerExtras, take, skip, totalItemsCount, paginationPlacement, showFirstLast, showGoToPage, showPageSize, pageSizeOptions, showHeader, getRowSeverity, getContextMenuItems, onRowClick, onRowMouseEnter, onRowSelect, onSelectAllRows, onSortChange, onPageChange, ...rest }: TableProps<T>): JSX.Element;
4
4
  export type { ColumnItem } from './Table.types';
@@ -2,14 +2,14 @@
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useMemo, useId, useRef, useCallback } from 'react';
4
4
  import { Pagination } from '../../components/pagination/Pagination';
5
+ import { SkeletonLoader } from '../../components/skeleton-loader/SkeletonLoader';
5
6
  import { useViewportFill } from '../../hooks/useViewportFill';
6
7
  import { TableEmptyState } from './components/empty-state/EmptyState';
7
8
  import { TableBody } from './components/TableBody';
8
9
  import { TableHeader } from './components/TableHeader';
9
- import { TableLoadingBody } from './components/TableLoadingBody';
10
10
  import { cx } from './table.classes';
11
11
  import styles from './Table.module.css';
12
- import { getVisibleColumns, SELECTION_COLUMN_PX } from './table.utils';
12
+ import { getVisibleColumns, SELECTION_COLUMN_PX, CONTEXT_MENU_COLUMN_PX } from './table.utils';
13
13
 
14
14
  function Table({
15
15
  data,
@@ -45,6 +45,7 @@ function Table({
45
45
  pageSizeOptions,
46
46
  showHeader = true,
47
47
  getRowSeverity,
48
+ getContextMenuItems,
48
49
  onRowClick,
49
50
  onRowMouseEnter,
50
51
  onRowSelect,
@@ -58,6 +59,7 @@ function Table({
58
59
  const internalTableRootRef = useRef(null);
59
60
  const tableRootRefWrapper = useRef(tableRootRef);
60
61
  const hasSelection = Boolean(selectedRows && onRowSelect);
62
+ const hasContextMenu = Boolean(getContextMenuItems);
61
63
  const hasPagination = Boolean(onPageChange && (loading || data.length > 0));
62
64
  const paginationOffset = hasPagination ? 72 : 0;
63
65
  const { style: viewportFillStyle, maxHeight } = useViewportFill(internalTableRootRef, {
@@ -80,7 +82,7 @@ function Table({
80
82
  },
81
83
  [onPageChange]
82
84
  );
83
- const bodyContent = loading && !data.length ? /* @__PURE__ */ jsx(TableLoadingBody, { rows: take != null ? take : 5, columns: visibleColumns, hasSelection }) : /* @__PURE__ */ jsx(
85
+ const bodyContent = /* @__PURE__ */ jsx(
84
86
  TableBody,
85
87
  {
86
88
  data,
@@ -93,6 +95,7 @@ function Table({
93
95
  selectionInputName,
94
96
  viewMode,
95
97
  getRowSeverity,
98
+ getContextMenuItems,
96
99
  onRowClick,
97
100
  onRowMouseEnter,
98
101
  onRowSelect
@@ -133,7 +136,7 @@ function Table({
133
136
  ref: setTableRootRef,
134
137
  className: styles.tableScroll,
135
138
  style: fillViewportActive ? viewportFillStyle : !containScrolling ? { overflow: "visible" } : void 0,
136
- children: !data.length && !loading ? /* @__PURE__ */ jsx("div", { className: styles.emptyStateSlot, children: /* @__PURE__ */ jsx(TableEmptyState, { config: emptyConfig }) }) : /* @__PURE__ */ jsxs(
139
+ children: loading && !data.length ? /* @__PURE__ */ jsx("div", { className: styles.emptyStateSlot, children: /* @__PURE__ */ jsx(SkeletonLoader, { type: "table", rows: 5, columns: 3 }) }) : !data.length ? /* @__PURE__ */ jsx("div", { className: styles.emptyStateSlot, children: /* @__PURE__ */ jsx(TableEmptyState, { config: emptyConfig }) }) : /* @__PURE__ */ jsxs(
137
140
  "table",
138
141
  {
139
142
  className: styles.tableElement,
@@ -149,13 +152,15 @@ function Table({
149
152
  style: column.width != null ? { width: column.width } : void 0
150
153
  },
151
154
  column.id
152
- ))
155
+ )),
156
+ hasContextMenu ? /* @__PURE__ */ jsx("col", { style: { width: CONTEXT_MENU_COLUMN_PX } }) : null
153
157
  ] }),
154
158
  showHeader && /* @__PURE__ */ jsx(
155
159
  TableHeader,
156
160
  {
157
161
  columns: visibleColumns,
158
162
  hasSelection,
163
+ hasContextMenu,
159
164
  selectionMode,
160
165
  allRowsSelected,
161
166
  onSelectAllRows,
@@ -241,6 +241,14 @@
241
241
  line-height: 0;
242
242
  }
243
243
 
244
+ .headerCell.contextMenuCell,
245
+ .cell.contextMenuCell {
246
+ inline-size: 1%;
247
+ white-space: nowrap;
248
+ padding-inline: var(--spacing-2xs);
249
+ overflow: visible;
250
+ }
251
+
244
252
  .headerCell.selectionCell {
245
253
  padding-block: var(--spacing-xxs);
246
254
  vertical-align: middle;
@@ -251,6 +259,15 @@
251
259
  padding-block: var(--spacing-xxs);
252
260
  }
253
261
 
262
+ .headerCell.contextMenuHeaderCell {
263
+ padding-block: var(--spacing-xxs);
264
+ }
265
+
266
+ .cell.contextMenuCell {
267
+ vertical-align: top;
268
+ padding-block: var(--spacing-2xs);
269
+ }
270
+
254
271
  .selectionHitArea {
255
272
  display: inline-flex;
256
273
  align-items: flex-start;
@@ -475,6 +492,10 @@
475
492
  text-align: right;
476
493
  }
477
494
 
495
+ .contextMenuCellContent {
496
+ justify-content: flex-end;
497
+ }
498
+
478
499
  /* vertical alignment inside content wrapper */
479
500
  .cellContent[data-vertical-align='top'] {
480
501
  align-items: flex-start;
@@ -535,6 +556,10 @@
535
556
  text-overflow: clip;
536
557
  }
537
558
 
559
+ .contextMenuTrigger {
560
+ color: var(--color-fg-subtle);
561
+ }
562
+
538
563
  .severityTable {
539
564
  --row-rail-width: 2px;
540
565
  --row-rail-inset-block: 1px;
@@ -24,6 +24,14 @@ export type HeaderExtrasArgs<T> = {
24
24
  column: ColumnItem<T>;
25
25
  index: number;
26
26
  };
27
+ export type TableContextMenuItem = {
28
+ label: ReactNode;
29
+ onClick: () => void;
30
+ active?: boolean;
31
+ selected?: boolean;
32
+ disabled?: boolean;
33
+ variant?: 'default' | 'danger';
34
+ };
27
35
  export type StickyHeader = false | 'app-header' | number;
28
36
  export type TableVariant = 'primary' | 'embedded';
29
37
  export type SortDirection = 'asc' | 'desc' | null;
@@ -61,6 +69,11 @@ export type TableProps<T extends Record<string, any>> = Omit<HTMLAttributes<HTML
61
69
  pageSizeOptions?: number[];
62
70
  showHeader?: boolean;
63
71
  getRowSeverity?: (row: T) => Severity | undefined;
72
+ getContextMenuItems?: (args: {
73
+ row: T;
74
+ rowId: string | number;
75
+ open: () => void;
76
+ }) => TableContextMenuItem[];
64
77
  onRowClick?: (row: T) => void;
65
78
  onRowMouseEnter?: (row: T) => void;
66
79
  onRowSelect?: (rowId: number | string, isSelected: boolean) => void;
@@ -116,11 +116,20 @@ function TanstackTable(props) {
116
116
  return tanstackTable_utils.buildDistributedColumnWidths({
117
117
  table,
118
118
  hasSelection: Boolean(selectedRows && onRowSelect && dataKey),
119
+ hasContextMenu: Boolean(tableProps.getContextMenuItems),
119
120
  defaultMinPx: 80,
120
121
  columnSizing,
121
122
  availableWidth
122
123
  });
123
- }, [table, selectedRows, onRowSelect, dataKey, columnSizing, availableWidth]);
124
+ }, [
125
+ table,
126
+ selectedRows,
127
+ onRowSelect,
128
+ dataKey,
129
+ tableProps.getContextMenuItems,
130
+ columnSizing,
131
+ availableWidth
132
+ ]);
124
133
  const initialLayoutReady = availableWidth != null;
125
134
  const resolvedLayout = React__namespace.useMemo(() => {
126
135
  const next = {};
@@ -91,11 +91,20 @@ function TanstackTable(props) {
91
91
  return buildDistributedColumnWidths({
92
92
  table,
93
93
  hasSelection: Boolean(selectedRows && onRowSelect && dataKey),
94
+ hasContextMenu: Boolean(tableProps.getContextMenuItems),
94
95
  defaultMinPx: 80,
95
96
  columnSizing,
96
97
  availableWidth
97
98
  });
98
- }, [table, selectedRows, onRowSelect, dataKey, columnSizing, availableWidth]);
99
+ }, [
100
+ table,
101
+ selectedRows,
102
+ onRowSelect,
103
+ dataKey,
104
+ tableProps.getContextMenuItems,
105
+ columnSizing,
106
+ availableWidth
107
+ ]);
99
108
  const initialLayoutReady = availableWidth != null;
100
109
  const resolvedLayout = React.useMemo(() => {
101
110
  const next = {};
@@ -20,6 +20,7 @@ function TableBody({
20
20
  selectionInputName,
21
21
  viewMode,
22
22
  getRowSeverity,
23
+ getContextMenuItems,
23
24
  onRowClick,
24
25
  onRowMouseEnter,
25
26
  onRowSelect
@@ -38,6 +39,7 @@ function TableBody({
38
39
  selectionInputName,
39
40
  viewMode,
40
41
  getRowSeverity,
42
+ getContextMenuItems,
41
43
  onRowClick,
42
44
  onRowMouseEnter,
43
45
  onRowSelect
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { ViewMode } from '../../../hooks/useTableSettings';
3
- import type { ColumnItem } from '../Table.types';
3
+ import type { ColumnItem, TableContextMenuItem } from '../Table.types';
4
4
  type Props<T extends Record<string, any>> = {
5
5
  data: T[];
6
6
  dataKey: keyof T;
@@ -12,9 +12,14 @@ type Props<T extends Record<string, any>> = {
12
12
  selectionInputName: string;
13
13
  viewMode?: ViewMode;
14
14
  getRowSeverity?: (row: T) => any;
15
+ getContextMenuItems?: (args: {
16
+ row: T;
17
+ rowId: string | number;
18
+ open: () => void;
19
+ }) => TableContextMenuItem[];
15
20
  onRowClick?: (row: T) => void;
16
21
  onRowMouseEnter?: (row: T) => void;
17
22
  onRowSelect?: (rowId: number | string, isSelected: boolean) => void;
18
23
  };
19
- export declare function TableBody<T extends Record<string, any>>({ data, dataKey, columns, striped, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, }: Props<T>): ReactNode;
24
+ export declare function TableBody<T extends Record<string, any>>({ data, dataKey, columns, striped, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, getContextMenuItems, onRowClick, onRowMouseEnter, onRowSelect, }: Props<T>): ReactNode;
20
25
  export {};
@@ -14,6 +14,7 @@ function TableBody({
14
14
  selectionInputName,
15
15
  viewMode,
16
16
  getRowSeverity,
17
+ getContextMenuItems,
17
18
  onRowClick,
18
19
  onRowMouseEnter,
19
20
  onRowSelect
@@ -32,6 +33,7 @@ function TableBody({
32
33
  selectionInputName,
33
34
  viewMode,
34
35
  getRowSeverity,
36
+ getContextMenuItems,
35
37
  onRowClick,
36
38
  onRowMouseEnter,
37
39
  onRowSelect
@@ -12,6 +12,7 @@ var styles__default = /*#__PURE__*/_interopDefault(styles);
12
12
  function TableHeader({
13
13
  columns,
14
14
  hasSelection,
15
+ hasContextMenu,
15
16
  selectionMode,
16
17
  allRowsSelected,
17
18
  onSelectAllRows,
@@ -47,7 +48,15 @@ function TableHeader({
47
48
  extraContent: headerExtras == null ? void 0 : headerExtras({ column, index })
48
49
  },
49
50
  column.id
50
- ))
51
+ )),
52
+ hasContextMenu ? /* @__PURE__ */ jsxRuntime.jsx(
53
+ "th",
54
+ {
55
+ className: [styles__default.default.headerCell, styles__default.default.contextMenuCell, styles__default.default.contextMenuHeaderCell].filter(Boolean).join(" "),
56
+ scope: "col",
57
+ "aria-label": "R\xE6kkehandlinger"
58
+ }
59
+ ) : null
51
60
  ] })
52
61
  }
53
62
  );
@@ -3,6 +3,7 @@ import type { ColumnItem, HeaderExtrasArgs, SortDirection } from '../Table.types
3
3
  type Props<T> = {
4
4
  columns: ColumnItem<T>[];
5
5
  hasSelection: boolean;
6
+ hasContextMenu: boolean;
6
7
  selectionMode: 'single' | 'multiple';
7
8
  allRowsSelected?: boolean;
8
9
  onSelectAllRows?: (isSelected: boolean) => void;
@@ -12,5 +13,5 @@ type Props<T> = {
12
13
  headerExtras?: (args: HeaderExtrasArgs<T>) => ReactNode;
13
14
  stickyTop?: string;
14
15
  };
15
- export declare function TableHeader<T>({ columns, hasSelection, selectionMode, allRowsSelected, onSelectAllRows, sortById, sortDirection, onSortChange, headerExtras, stickyTop, }: Props<T>): React.ReactNode;
16
+ export declare function TableHeader<T>({ columns, hasSelection, hasContextMenu, selectionMode, allRowsSelected, onSelectAllRows, sortById, sortDirection, onSortChange, headerExtras, stickyTop, }: Props<T>): React.ReactNode;
16
17
  export {};
@@ -6,6 +6,7 @@ import styles from '../Table.module.css';
6
6
  function TableHeader({
7
7
  columns,
8
8
  hasSelection,
9
+ hasContextMenu,
9
10
  selectionMode,
10
11
  allRowsSelected,
11
12
  onSelectAllRows,
@@ -41,7 +42,15 @@ function TableHeader({
41
42
  extraContent: headerExtras == null ? void 0 : headerExtras({ column, index })
42
43
  },
43
44
  column.id
44
- ))
45
+ )),
46
+ hasContextMenu ? /* @__PURE__ */ jsx(
47
+ "th",
48
+ {
49
+ className: [styles.headerCell, styles.contextMenuCell, styles.contextMenuHeaderCell].filter(Boolean).join(" "),
50
+ scope: "col",
51
+ "aria-label": "R\xE6kkehandlinger"
52
+ }
53
+ ) : null
45
54
  ] })
46
55
  }
47
56
  );
@@ -1,9 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
+ var lucideReact = require('lucide-react');
4
5
  var Checkbox = require('../../../components/forms/checkbox/Checkbox');
5
6
  var RadioButton = require('../../../components/forms/radio-buttons/RadioButton');
7
+ var Popover = require('../../../components/popover/Popover');
6
8
  var severity = require('../../../constants/severity');
9
+ var Button = require('../../button/Button');
10
+ var Menu = require('../../menu/Menu');
7
11
  var useTableRowInteractions = require('../hooks/useTableRowInteractions');
8
12
  var table_classes = require('../table.classes');
9
13
  var styles = require('../Table.module.css');
@@ -23,6 +27,7 @@ function TableRow({
23
27
  selectionInputName,
24
28
  viewMode,
25
29
  getRowSeverity,
30
+ getContextMenuItems,
26
31
  onRowClick,
27
32
  onRowMouseEnter,
28
33
  onRowSelect
@@ -31,6 +36,11 @@ function TableRow({
31
36
  const isSelected = (_a = selectedRows == null ? void 0 : selectedRows.has(rowId)) != null ? _a : false;
32
37
  const rowSeverity = getRowSeverity == null ? void 0 : getRowSeverity(row);
33
38
  const canSelect = Boolean(selectedRows && onRowSelect);
39
+ const contextMenuItems = getContextMenuItems == null ? void 0 : getContextMenuItems({
40
+ row,
41
+ rowId,
42
+ open: () => onRowClick == null ? void 0 : onRowClick(row)
43
+ });
34
44
  const { handleRowClick, handleRowKeyDown } = useTableRowInteractions.useTableRowInteractions({
35
45
  row,
36
46
  rowId,
@@ -149,10 +159,74 @@ function TableRow({
149
159
  },
150
160
  column.id
151
161
  );
152
- })
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
153
172
  ]
154
173
  }
155
174
  );
156
175
  }
176
+ function RowContextMenu({
177
+ row,
178
+ rowId,
179
+ items
180
+ }) {
181
+ return /* @__PURE__ */ jsxRuntime.jsx(
182
+ Popover.Popover,
183
+ {
184
+ matchTriggerWidth: false,
185
+ minWidth: "180px",
186
+ trigger: (toggle, _icon, isOpen) => /* @__PURE__ */ jsxRuntime.jsx(
187
+ Button.Button,
188
+ {
189
+ type: "button",
190
+ size: "sm",
191
+ variant: "inline",
192
+ shape: "round",
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.MoreHorizontal, { 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,
207
+ {
208
+ active: item.active,
209
+ selected: item.selected,
210
+ disabled: item.disabled,
211
+ variant: item.variant,
212
+ children: /* @__PURE__ */ jsxRuntime.jsx(
213
+ "button",
214
+ {
215
+ type: "button",
216
+ "data-row-context-menu": "true",
217
+ onClick: (e) => {
218
+ e.stopPropagation();
219
+ item.onClick();
220
+ close();
221
+ },
222
+ children: item.label
223
+ }
224
+ )
225
+ },
226
+ index
227
+ )) })
228
+ }
229
+ );
230
+ }
157
231
 
158
232
  exports.TableRow = TableRow;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { ViewMode } from '../../../hooks/useTableSettings';
3
- import type { ColumnItem } from '../Table.types';
3
+ import type { ColumnItem, TableContextMenuItem } from '../Table.types';
4
4
  type Props<T extends Record<string, any>> = {
5
5
  row: T;
6
6
  rowId: string | number;
@@ -11,9 +11,14 @@ type Props<T extends Record<string, any>> = {
11
11
  selectionInputName: string;
12
12
  viewMode?: ViewMode;
13
13
  getRowSeverity?: (row: T) => any;
14
+ getContextMenuItems?: (args: {
15
+ row: T;
16
+ rowId: string | number;
17
+ open: () => void;
18
+ }) => TableContextMenuItem[];
14
19
  onRowClick?: (row: T) => void;
15
20
  onRowMouseEnter?: (row: T) => void;
16
21
  onRowSelect?: (rowId: number | string, isSelected: boolean) => void;
17
22
  };
18
- export declare function TableRow<T extends Record<string, any>>({ row, rowId, columns, selectedRows, hasSelection, selectionMode, selectionInputName, viewMode, getRowSeverity, onRowClick, onRowMouseEnter, onRowSelect, }: Props<T>): React.ReactNode;
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;
19
24
  export {};
@@ -1,7 +1,11 @@
1
1
  import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { MoreHorizontal } from 'lucide-react';
2
3
  import { Checkbox } from '../../../components/forms/checkbox/Checkbox';
3
4
  import { RadioButton } from '../../../components/forms/radio-buttons/RadioButton';
5
+ import { Popover } from '../../../components/popover/Popover';
4
6
  import { SeverityBgColor } from '../../../constants/severity';
7
+ import { Button } from '../../button/Button';
8
+ import { Menu } from '../../menu/Menu';
5
9
  import { useTableRowInteractions } from '../hooks/useTableRowInteractions';
6
10
  import { cx } from '../table.classes';
7
11
  import styles from '../Table.module.css';
@@ -17,6 +21,7 @@ function TableRow({
17
21
  selectionInputName,
18
22
  viewMode,
19
23
  getRowSeverity,
24
+ getContextMenuItems,
20
25
  onRowClick,
21
26
  onRowMouseEnter,
22
27
  onRowSelect
@@ -25,6 +30,11 @@ function TableRow({
25
30
  const isSelected = (_a = selectedRows == null ? void 0 : selectedRows.has(rowId)) != null ? _a : false;
26
31
  const rowSeverity = getRowSeverity == null ? void 0 : getRowSeverity(row);
27
32
  const canSelect = Boolean(selectedRows && onRowSelect);
33
+ const contextMenuItems = getContextMenuItems == null ? void 0 : getContextMenuItems({
34
+ row,
35
+ rowId,
36
+ open: () => onRowClick == null ? void 0 : onRowClick(row)
37
+ });
28
38
  const { handleRowClick, handleRowKeyDown } = useTableRowInteractions({
29
39
  row,
30
40
  rowId,
@@ -143,10 +153,74 @@ function TableRow({
143
153
  },
144
154
  column.id
145
155
  );
146
- })
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
147
166
  ]
148
167
  }
149
168
  );
150
169
  }
170
+ function RowContextMenu({
171
+ row,
172
+ rowId,
173
+ items
174
+ }) {
175
+ return /* @__PURE__ */ jsx(
176
+ Popover,
177
+ {
178
+ matchTriggerWidth: false,
179
+ minWidth: "180px",
180
+ trigger: (toggle, _icon, isOpen) => /* @__PURE__ */ jsx(
181
+ Button,
182
+ {
183
+ type: "button",
184
+ size: "sm",
185
+ variant: "inline",
186
+ shape: "round",
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(MoreHorizontal, { 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,
201
+ {
202
+ active: item.active,
203
+ selected: item.selected,
204
+ disabled: item.disabled,
205
+ variant: item.variant,
206
+ children: /* @__PURE__ */ jsx(
207
+ "button",
208
+ {
209
+ type: "button",
210
+ "data-row-context-menu": "true",
211
+ onClick: (e) => {
212
+ e.stopPropagation();
213
+ item.onClick();
214
+ close();
215
+ },
216
+ children: item.label
217
+ }
218
+ )
219
+ },
220
+ index
221
+ )) })
222
+ }
223
+ );
224
+ }
151
225
 
152
226
  export { TableRow };
@@ -13,9 +13,9 @@ function useTableRowInteractions({
13
13
  }) {
14
14
  const handleRowClick = react.useCallback(
15
15
  (e) => {
16
- var _a;
16
+ var _a, _b;
17
17
  const target = e.target;
18
- if ((_a = target == null ? void 0 : target.closest) == null ? void 0 : _a.call(target, '[data-selection-control="true"]')) {
18
+ if (((_a = target == null ? void 0 : target.closest) == null ? void 0 : _a.call(target, '[data-selection-control="true"]')) || ((_b = target == null ? void 0 : target.closest) == null ? void 0 : _b.call(target, '[data-row-context-menu="true"]'))) {
19
19
  return;
20
20
  }
21
21
  if (table_utils.isModifierClick(e) && canSelect) {
@@ -11,9 +11,9 @@ function useTableRowInteractions({
11
11
  }) {
12
12
  const handleRowClick = useCallback(
13
13
  (e) => {
14
- var _a;
14
+ var _a, _b;
15
15
  const target = e.target;
16
- if ((_a = target == null ? void 0 : target.closest) == null ? void 0 : _a.call(target, '[data-selection-control="true"]')) {
16
+ if (((_a = target == null ? void 0 : target.closest) == null ? void 0 : _a.call(target, '[data-selection-control="true"]')) || ((_b = target == null ? void 0 : target.closest) == null ? void 0 : _b.call(target, '[data-row-context-menu="true"]'))) {
17
17
  return;
18
18
  }
19
19
  if (isModifierClick(e) && canSelect) {