@dbcdk/react-components 0.0.120 → 0.0.122

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 (44) hide show
  1. package/dist/components/card/Card.cjs +4 -7
  2. package/dist/components/card/Card.js +4 -7
  3. package/dist/components/card/Card.module.css +4 -9
  4. package/dist/components/code-block/CodeBlock.cjs +11 -1
  5. package/dist/components/code-block/CodeBlock.d.ts +1 -1
  6. package/dist/components/code-block/CodeBlock.js +12 -2
  7. package/dist/components/code-block/CodeBlock.module.css +12 -1
  8. package/dist/components/forms/file-upload/FileUpload.d.ts +2 -2
  9. package/dist/components/search-box/SearchBox.cjs +9 -4
  10. package/dist/components/search-box/SearchBox.js +9 -4
  11. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.cjs +3 -2
  12. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +4 -3
  13. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +5 -0
  14. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.cjs +1 -1
  15. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.js +1 -1
  16. package/dist/components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem.module.css +11 -7
  17. package/dist/components/table/Table.cjs +9 -4
  18. package/dist/components/table/Table.d.ts +1 -1
  19. package/dist/components/table/Table.js +10 -5
  20. package/dist/components/table/Table.module.css +25 -0
  21. package/dist/components/table/Table.types.d.ts +13 -0
  22. package/dist/components/table/TanstackTable.cjs +10 -1
  23. package/dist/components/table/TanstackTable.js +10 -1
  24. package/dist/components/table/components/TableBody.cjs +2 -0
  25. package/dist/components/table/components/TableBody.d.ts +7 -2
  26. package/dist/components/table/components/TableBody.js +2 -0
  27. package/dist/components/table/components/TableHeader.cjs +10 -1
  28. package/dist/components/table/components/TableHeader.d.ts +2 -1
  29. package/dist/components/table/components/TableHeader.js +10 -1
  30. package/dist/components/table/components/TableRow.cjs +75 -1
  31. package/dist/components/table/components/TableRow.d.ts +7 -2
  32. package/dist/components/table/components/TableRow.js +75 -1
  33. package/dist/components/table/hooks/useTableRowInteractions.cjs +2 -2
  34. package/dist/components/table/hooks/useTableRowInteractions.js +2 -2
  35. package/dist/components/table/table.utils.cjs +2 -0
  36. package/dist/components/table/table.utils.d.ts +1 -0
  37. package/dist/components/table/table.utils.js +2 -1
  38. package/dist/components/table/tanstackTable.utils.cjs +6 -4
  39. package/dist/components/table/tanstackTable.utils.d.ts +2 -0
  40. package/dist/components/table/tanstackTable.utils.js +7 -5
  41. package/package.json +1 -1
  42. package/dist/components/table/components/TableLoadingBody.cjs +0 -35
  43. package/dist/components/table/components/TableLoadingBody.d.ts +0 -9
  44. package/dist/components/table/components/TableLoadingBody.js +0 -29
@@ -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) {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const SELECTION_COLUMN_PX = 40;
4
+ const CONTEXT_MENU_COLUMN_PX = 44;
4
5
  const DEFAULT_COLUMN_PX = 150;
5
6
  function getVisibleColumns(columns) {
6
7
  return columns.filter((column) => !column.hidden);
@@ -44,6 +45,7 @@ function getCellDisplayValue(row, column) {
44
45
  return empty;
45
46
  }
46
47
 
48
+ exports.CONTEXT_MENU_COLUMN_PX = CONTEXT_MENU_COLUMN_PX;
47
49
  exports.DEFAULT_COLUMN_PX = DEFAULT_COLUMN_PX;
48
50
  exports.SELECTION_COLUMN_PX = SELECTION_COLUMN_PX;
49
51
  exports.getAriaSort = getAriaSort;
@@ -1,6 +1,7 @@
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;
4
5
  export declare const DEFAULT_COLUMN_PX: 150;
5
6
  export type SortDirection = 'asc' | 'desc' | null;
6
7
  export declare function getVisibleColumns<T>(columns: Array<ColumnItem<T>>): Array<ColumnItem<T>>;
@@ -1,4 +1,5 @@
1
1
  const SELECTION_COLUMN_PX = 40;
2
+ const CONTEXT_MENU_COLUMN_PX = 44;
2
3
  const DEFAULT_COLUMN_PX = 150;
3
4
  function getVisibleColumns(columns) {
4
5
  return columns.filter((column) => !column.hidden);
@@ -42,4 +43,4 @@ function getCellDisplayValue(row, column) {
42
43
  return empty;
43
44
  }
44
45
 
45
- export { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX, getAriaSort, getCellDisplayValue, getHeaderLabel, getNextSortDirection, getVisibleColumns, isActiveSort, isModifierClick, shouldAllowWrap, shouldToggleOnKey };
46
+ export { CONTEXT_MENU_COLUMN_PX, DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX, getAriaSort, getCellDisplayValue, getHeaderLabel, getNextSortDirection, getVisibleColumns, isActiveSort, isModifierClick, shouldAllowWrap, shouldToggleOnKey };
@@ -93,9 +93,10 @@ function toIntegerTrackWidths(tracks, targetWidth) {
93
93
  return Object.fromEntries(floored.map((track) => [track.id, track.width]));
94
94
  }
95
95
  function buildDistributedColumnWidths(args) {
96
- const { table, hasSelection, defaultMinPx, columnSizing, availableWidth } = args;
96
+ const { table, hasSelection, hasContextMenu, defaultMinPx, columnSizing, availableWidth } = args;
97
97
  const leaf = table.getVisibleLeafColumns();
98
98
  const selectionWidth = hasSelection ? table_utils.SELECTION_COLUMN_PX : 0;
99
+ const contextMenuWidth = hasContextMenu ? table_utils.CONTEXT_MENU_COLUMN_PX : 0;
99
100
  const tracks = leaf.map((c) => {
100
101
  var _a, _b, _c, _d;
101
102
  const def = c.columnDef;
@@ -123,7 +124,7 @@ function buildDistributedColumnWidths(args) {
123
124
  fixed: false
124
125
  };
125
126
  });
126
- const fixedWidth = selectionWidth + tracks.reduce((sum, track) => sum + track.width, 0);
127
+ const fixedWidth = selectionWidth + contextMenuWidth + tracks.reduce((sum, track) => sum + track.width, 0);
127
128
  let remaining = Math.max(0, availableWidth - fixedWidth);
128
129
  let active = tracks.filter(
129
130
  (track) => !track.fixed && (track.max == null || track.width < track.max)
@@ -148,18 +149,19 @@ function buildDistributedColumnWidths(args) {
148
149
  active = nextActive;
149
150
  }
150
151
  const floatTrackTotal = tracks.reduce((sum, track) => sum + track.width, 0);
151
- const maxTrackWidth = availableWidth - selectionWidth;
152
+ const maxTrackWidth = availableWidth - selectionWidth - contextMenuWidth;
152
153
  const targetTrackWidth = Math.min(
153
154
  floatTrackTotal <= maxTrackWidth ? Math.floor(floatTrackTotal) : Math.ceil(floatTrackTotal),
154
155
  maxTrackWidth
155
156
  );
156
157
  const widths = toIntegerTrackWidths(tracks, targetTrackWidth);
157
158
  const totalWidth = Math.min(
158
- selectionWidth + Object.values(widths).reduce((sum, width) => sum + width, 0),
159
+ selectionWidth + contextMenuWidth + Object.values(widths).reduce((sum, width) => sum + width, 0),
159
160
  availableWidth
160
161
  );
161
162
  return {
162
163
  selectionWidth: hasSelection ? table_utils.SELECTION_COLUMN_PX : void 0,
164
+ contextMenuWidth: hasContextMenu ? table_utils.CONTEXT_MENU_COLUMN_PX : void 0,
163
165
  widths,
164
166
  totalWidth
165
167
  };
@@ -14,11 +14,13 @@ export declare function getSortPropsFromSorting(sorting: SortingState): {
14
14
  export declare function buildDistributedColumnWidths(args: {
15
15
  table: any;
16
16
  hasSelection: boolean;
17
+ hasContextMenu: boolean;
17
18
  defaultMinPx: number;
18
19
  columnSizing: ColumnSizingState;
19
20
  availableWidth: number;
20
21
  }): {
21
22
  selectionWidth?: number;
23
+ contextMenuWidth?: number;
22
24
  widths: Record<string, number>;
23
25
  totalWidth: number;
24
26
  };
@@ -1,4 +1,4 @@
1
- import { DEFAULT_COLUMN_PX, SELECTION_COLUMN_PX } from './table.utils';
1
+ import { DEFAULT_COLUMN_PX, CONTEXT_MENU_COLUMN_PX, SELECTION_COLUMN_PX } from './table.utils';
2
2
 
3
3
  function getColumnId(def, index) {
4
4
  const d = def;
@@ -91,9 +91,10 @@ function toIntegerTrackWidths(tracks, targetWidth) {
91
91
  return Object.fromEntries(floored.map((track) => [track.id, track.width]));
92
92
  }
93
93
  function buildDistributedColumnWidths(args) {
94
- const { table, hasSelection, defaultMinPx, columnSizing, availableWidth } = args;
94
+ const { table, hasSelection, hasContextMenu, defaultMinPx, columnSizing, availableWidth } = args;
95
95
  const leaf = table.getVisibleLeafColumns();
96
96
  const selectionWidth = hasSelection ? SELECTION_COLUMN_PX : 0;
97
+ const contextMenuWidth = hasContextMenu ? CONTEXT_MENU_COLUMN_PX : 0;
97
98
  const tracks = leaf.map((c) => {
98
99
  var _a, _b, _c, _d;
99
100
  const def = c.columnDef;
@@ -121,7 +122,7 @@ function buildDistributedColumnWidths(args) {
121
122
  fixed: false
122
123
  };
123
124
  });
124
- const fixedWidth = selectionWidth + tracks.reduce((sum, track) => sum + track.width, 0);
125
+ const fixedWidth = selectionWidth + contextMenuWidth + tracks.reduce((sum, track) => sum + track.width, 0);
125
126
  let remaining = Math.max(0, availableWidth - fixedWidth);
126
127
  let active = tracks.filter(
127
128
  (track) => !track.fixed && (track.max == null || track.width < track.max)
@@ -146,18 +147,19 @@ function buildDistributedColumnWidths(args) {
146
147
  active = nextActive;
147
148
  }
148
149
  const floatTrackTotal = tracks.reduce((sum, track) => sum + track.width, 0);
149
- const maxTrackWidth = availableWidth - selectionWidth;
150
+ const maxTrackWidth = availableWidth - selectionWidth - contextMenuWidth;
150
151
  const targetTrackWidth = Math.min(
151
152
  floatTrackTotal <= maxTrackWidth ? Math.floor(floatTrackTotal) : Math.ceil(floatTrackTotal),
152
153
  maxTrackWidth
153
154
  );
154
155
  const widths = toIntegerTrackWidths(tracks, targetTrackWidth);
155
156
  const totalWidth = Math.min(
156
- selectionWidth + Object.values(widths).reduce((sum, width) => sum + width, 0),
157
+ selectionWidth + contextMenuWidth + Object.values(widths).reduce((sum, width) => sum + width, 0),
157
158
  availableWidth
158
159
  );
159
160
  return {
160
161
  selectionWidth: hasSelection ? SELECTION_COLUMN_PX : void 0,
162
+ contextMenuWidth: hasContextMenu ? CONTEXT_MENU_COLUMN_PX : void 0,
161
163
  widths,
162
164
  totalWidth
163
165
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.120",
3
+ "version": "0.0.122",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var SkeletonLoaderItem = require('../../../components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem');
5
- var table_classes = require('../table.classes');
6
- var styles = require('../Table.module.css');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- var styles__default = /*#__PURE__*/_interopDefault(styles);
11
-
12
- function TableLoadingBody({ rows, columns, hasSelection }) {
13
- return /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: styles__default.default.body, children: Array.from({ length: rows }).map((_, rowIndex) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: styles__default.default.row, children: [
14
- hasSelection ? /* @__PURE__ */ jsxRuntime.jsx("td", { className: table_classes.cx(styles__default.default.cell, styles__default.default.selectionCell), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.cellContent, children: /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoaderItem.SkeletonLoaderItem, { height: 20, width: 20 }) }) }) : null,
15
- columns.map((column) => {
16
- var _a;
17
- return /* @__PURE__ */ jsxRuntime.jsx(
18
- "td",
19
- {
20
- className: table_classes.cx(
21
- styles__default.default.cell,
22
- column.divider === "left" && styles__default.default.dividerLeft,
23
- column.divider === "right" && styles__default.default.dividerRight
24
- ),
25
- "data-align": (_a = column.align) != null ? _a : "left",
26
- "data-divider": column.divider,
27
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.cellContent, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.cellValueEllipsis, children: /* @__PURE__ */ jsxRuntime.jsx(SkeletonLoaderItem.SkeletonLoaderItem, { height: 20, width: "100%" }) }) })
28
- },
29
- column.id
30
- );
31
- })
32
- ] }, `loading-row-${rowIndex}`)) });
33
- }
34
-
35
- exports.TableLoadingBody = TableLoadingBody;
@@ -1,9 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { ColumnItem } from '../Table.types';
3
- type Props<T> = {
4
- rows: number;
5
- columns: ColumnItem<T>[];
6
- hasSelection: boolean;
7
- };
8
- export declare function TableLoadingBody<T>({ rows, columns, hasSelection }: Props<T>): ReactNode;
9
- export {};