@dbcdk/react-components 0.0.20 → 0.0.21

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 (40) hide show
  1. package/dist/components/button/Button.module.css +13 -6
  2. package/dist/components/chip/Chip.d.ts +3 -2
  3. package/dist/components/chip/Chip.js +2 -1
  4. package/dist/components/chip/Chip.module.css +107 -67
  5. package/dist/components/filter-field/FilterField.d.ts +2 -1
  6. package/dist/components/filter-field/FilterField.js +4 -9
  7. package/dist/components/filter-field/FilterField.module.css +203 -152
  8. package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.d.ts +2 -3
  9. package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.js +3 -5
  10. package/dist/components/filtering/chip-multi-toggle/ChipMultiToggle.module.css +13 -13
  11. package/dist/components/forms/input/Input.d.ts +1 -1
  12. package/dist/components/forms/input/Input.js +3 -9
  13. package/dist/components/forms/input/Input.module.css +106 -17
  14. package/dist/components/hyperlink/Hyperlink.module.css +14 -3
  15. package/dist/components/interval-select/IntervalSelect.js +2 -2
  16. package/dist/components/popover/Popover.module.css +4 -1
  17. package/dist/components/segmented-progress-bar/SegmentedProgressBar.d.ts +4 -2
  18. package/dist/components/segmented-progress-bar/SegmentedProgressBar.js +17 -19
  19. package/dist/components/segmented-progress-bar/SegmentedProgressBar.module.css +128 -20
  20. package/dist/components/sidebar/Sidebar.d.ts +2 -1
  21. package/dist/components/sidebar/Sidebar.js +2 -2
  22. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.d.ts +2 -3
  23. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.js +2 -4
  24. package/dist/components/sidebar/components/sidebar-container/SidebarContainer.module.css +2 -1
  25. package/dist/components/table/Table.d.ts +2 -7
  26. package/dist/components/table/Table.js +90 -47
  27. package/dist/components/table/Table.module.css +301 -72
  28. package/dist/components/table/TanstackTable.js +3 -27
  29. package/dist/components/table/table.utils.d.ts +1 -1
  30. package/dist/components/table/table.utils.js +2 -1
  31. package/dist/components/table/tanstackTable.utils.d.ts +9 -10
  32. package/dist/components/table/tanstackTable.utils.js +50 -30
  33. package/dist/hooks/useViewportFill.d.ts +6 -5
  34. package/dist/hooks/useViewportFill.js +43 -41
  35. package/dist/src/styles/styles.css +5 -2
  36. package/dist/styles/styles.css +5 -2
  37. package/dist/styles/themes/dbc/base.css +0 -3
  38. package/dist/styles/themes/dbc/dark.css +44 -12
  39. package/dist/styles/themes/dbc/light.css +33 -7
  40. package/package.json +1 -1
@@ -1,12 +1,11 @@
1
1
  'use client';
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { ArrowDown, ArrowUp } from 'lucide-react';
4
- import { useCallback, useMemo, useRef } from 'react';
5
- import { SeverityBgColor } from '../../constants/severity';
6
- import { useViewportFill } from '../../hooks/useViewportFill';
4
+ import { useCallback, useMemo } from 'react';
7
5
  import { Checkbox } from '../../components/forms/checkbox/Checkbox';
8
6
  import { Pagination } from '../../components/pagination/Pagination';
9
7
  import { SkeletonLoaderItem } from '../../components/skeleton-loader/skeleton-loader-item/SkeletonLoaderItem';
8
+ import { SeverityBgColor } from '../../constants/severity';
10
9
  import { TableEmptyState } from './components/empty-state/EmptyState';
11
10
  import styles from './Table.module.css';
12
11
  import { getAriaSort, getCellDisplayValue, getHeaderLabel, getNextSortDirection, getVisibleColumns, isModifierClick, shouldAllowWrap, shouldToggleOnKey, isActiveSort, } from './table.utils';
@@ -19,53 +18,81 @@ function buildDefaultGridTemplate(args) {
19
18
  parts.push('minmax(120px, 1fr)');
20
19
  return parts.join(' ');
21
20
  }
22
- export function Table({ data, columns, selectedRows, onRowSelect, selectionMode = 'single', onSortChange, onRowClick, sortById, sortDirection, dataKey, headerExtras, gridTemplateColumns, toolbar, striped, fillViewport = false, viewportBottomOffset = 0, viewportMin = 120, viewportIncludeMarginTop = false, take, skip, paginationPlacement = 'bottom', totalItemsCount, onPageChange, loading, variant = 'primary', size = 'md', getRowSeverity, showFirstLast = false, allRowsSelected, onSelectAllRows, viewMode, emptyConfig, ...rest }) {
21
+ export function Table({ data, columns, selectedRows, onRowSelect, selectionMode = 'single', onSortChange, onRowClick, sortById, sortDirection, dataKey, headerExtras, gridTemplateColumns, toolbar, striped, fillViewport = false, viewportBottomOffset, viewportMin, viewportIncludeMarginTop, take, skip, paginationPlacement = 'bottom', totalItemsCount, onPageChange, loading, variant = 'primary', size = 'md', getRowSeverity, showFirstLast = false, allRowsSelected, onSelectAllRows, viewMode, emptyConfig, ...rest }) {
22
+ void viewportBottomOffset;
23
+ void viewportMin;
24
+ void viewportIncludeMarginTop;
23
25
  const filteredColumns = useMemo(() => getVisibleColumns(columns), [columns]);
24
26
  const handlePageChange = useCallback((e) => onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange(e), [onPageChange]);
25
- const scrollRef = useRef(null);
26
- const { style: viewportStyle } = useViewportFill(scrollRef, {
27
- bottomOffset: viewportBottomOffset + (onPageChange ? 60 : 0),
28
- min: viewportMin,
29
- includeMarginTop: viewportIncludeMarginTop,
30
- });
31
27
  const hasSelection = Boolean(selectedRows && onRowSelect && dataKey);
32
28
  const template = useMemo(() => {
33
29
  return (gridTemplateColumns !== null && gridTemplateColumns !== void 0 ? gridTemplateColumns : buildDefaultGridTemplate({ hasSelection, colCount: filteredColumns.length }));
34
30
  }, [gridTemplateColumns, hasSelection, filteredColumns.length]);
35
31
  const gridStyle = useMemo(() => ({ ['--grid-template']: template }), [template]);
36
- const headerEl = (_jsxs("div", { className: `${styles.headerRow}`, style: gridStyle, role: "row", children: [hasSelection && (_jsx("div", { className: `${styles.headerCell} ${styles.selectionCell}`, role: "columnheader", children: selectionMode === 'multiple' ? (_jsx(Checkbox, { size: "sm", variant: "primary", checked: allRowsSelected, onChange: checked => onSelectAllRows === null || onSelectAllRows === void 0 ? void 0 : onSelectAllRows(checked) })) : null })), filteredColumns.map((column, index) => {
32
+ const headerEl = (_jsxs("div", { className: styles.headerRow, style: gridStyle, role: "row", children: [hasSelection && (_jsx("div", { className: `${styles.headerCell} ${styles.selectionCell}`, role: "columnheader", children: selectionMode === 'multiple' ? (_jsx(Checkbox, { size: "sm", variant: "primary", checked: allRowsSelected, onChange: checked => onSelectAllRows === null || onSelectAllRows === void 0 ? void 0 : onSelectAllRows(checked) })) : null })), filteredColumns.map((column, index) => {
37
33
  var _a;
38
34
  const active = isActiveSort(sortById, column.id);
39
35
  const ariaSort = getAriaSort(column.sortable, active, sortDirection !== null && sortDirection !== void 0 ? sortDirection : null);
36
+ const align = (_a = column.align) !== null && _a !== void 0 ? _a : 'left';
37
+ const extraContent = headerExtras === null || headerExtras === void 0 ? void 0 : headerExtras({ column, index });
40
38
  const toggleSort = () => {
41
39
  if (!onSortChange || !column.sortable)
42
40
  return;
43
41
  const nextDir = getNextSortDirection(column.sortable, active, sortDirection !== null && sortDirection !== void 0 ? sortDirection : null);
44
42
  onSortChange(column, nextDir);
45
43
  };
46
- return (_jsx("div", { className: styles.headerCell, role: "columnheader", "aria-sort": ariaSort, "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: _jsxs("div", { className: styles.thInner, children: [column.sortable ? (_jsxs("button", { type: "button", className: [
47
- styles.thButton,
48
- column.align === 'right' ? styles.thButtonRight : '',
49
- column.align === 'center' ? styles.thButtonCenter : '',
50
- ].join(' '), onClick: toggleSort, onKeyDown: e => {
51
- if (shouldToggleOnKey(e.key)) {
52
- e.preventDefault();
53
- toggleSort();
54
- }
55
- }, children: [_jsx("span", { className: [
56
- styles.thLabel,
57
- column.align === 'right' ? styles.thLabelRight : '',
58
- column.align === 'center' ? styles.thLabelCenter : '',
59
- ].join(' '), children: getHeaderLabel(column.header) }), _jsxs("span", { className: styles.sortIndicator, "aria-hidden": "true", children: [active && sortDirection === 'asc' && _jsx(ArrowUp, {}), active && sortDirection === 'desc' && (_jsx(ArrowDown, { className: styles.descending })), !active && (_jsx(ArrowDown, { className: `${styles.descending} ${styles.inActiveSort}` }))] })] })) : (_jsx("span", { className: [
60
- styles.thLabel,
61
- column.align === 'right' ? styles.thLabelRight : '',
62
- column.align === 'center' ? styles.thLabelCenter : '',
63
- ].join(' '), children: getHeaderLabel(column.header) })), headerExtras ? (_jsx("div", { className: styles.thExtras, children: headerExtras({ column, index }) })) : null] }) }, column.id));
44
+ const dividerClass = column.divider === 'left'
45
+ ? styles.dividerLeft
46
+ : column.divider === 'right'
47
+ ? styles.dividerRight
48
+ : '';
49
+ return (_jsxs("div", { className: [styles.headerCell, dividerClass].filter(Boolean).join(' '), role: "columnheader", "aria-sort": ariaSort, "data-align": align, "data-divider": column.divider, children: [_jsx("div", { className: [
50
+ styles.thInner,
51
+ align === 'right' ? styles.thInnerRight : '',
52
+ align === 'center' ? styles.thInnerCenter : '',
53
+ ]
54
+ .filter(Boolean)
55
+ .join(' '), children: _jsx("div", { className: [
56
+ styles.thMain,
57
+ align === 'right' ? styles.thMainRight : '',
58
+ align === 'center' ? styles.thMainCenter : '',
59
+ ]
60
+ .filter(Boolean)
61
+ .join(' '), children: column.sortable ? (_jsxs("button", { type: "button", className: [
62
+ styles.thButton,
63
+ align === 'right' ? styles.thButtonRight : '',
64
+ align === 'center' ? styles.thButtonCenter : '',
65
+ ]
66
+ .filter(Boolean)
67
+ .join(' '), onClick: toggleSort, onKeyDown: e => {
68
+ if (shouldToggleOnKey(e.key)) {
69
+ e.preventDefault();
70
+ toggleSort();
71
+ }
72
+ }, children: [_jsx("span", { className: [
73
+ styles.thLabel,
74
+ align === 'right' ? styles.thLabelRight : '',
75
+ align === 'center' ? styles.thLabelCenter : '',
76
+ ]
77
+ .filter(Boolean)
78
+ .join(' '), children: getHeaderLabel(column.header) }), _jsxs("span", { className: styles.sortIndicator, "aria-hidden": "true", children: [active && sortDirection === 'asc' && _jsx(ArrowUp, {}), active && sortDirection === 'desc' && (_jsx(ArrowDown, { className: styles.descending })), !active && (_jsx(ArrowDown, { className: `${styles.descending} ${styles.inActiveSort}` }))] })] })) : (_jsx("span", { className: [
79
+ styles.thLabel,
80
+ align === 'right' ? styles.thLabelRight : '',
81
+ align === 'center' ? styles.thLabelCenter : '',
82
+ ]
83
+ .filter(Boolean)
84
+ .join(' '), children: getHeaderLabel(column.header) })) }) }), extraContent != null ? (_jsx("div", { className: styles.thOverlayExtras, children: extraContent })) : null] }, column.id));
64
85
  })] }));
65
- const bodyEl = loading && !data.length ? (_jsx("div", { className: styles.body, role: "rowgroup", children: Array.from({ length: take !== null && take !== void 0 ? take : 5 }).map((_, rowIndex) => (_jsxs("div", { className: styles.row, style: gridStyle, role: "row", children: [hasSelection ? (_jsx("div", { className: `${styles.cell} ${styles.selectionCell}`, role: "cell" })) : null, filteredColumns.map(column => {
86
+ const loadingBodyEl = (_jsx("div", { className: styles.body, role: "rowgroup", children: Array.from({ length: take !== null && take !== void 0 ? take : 5 }).map((_, rowIndex) => (_jsxs("div", { className: styles.row, style: gridStyle, role: "row", children: [hasSelection ? (_jsx("div", { className: `${styles.cell} ${styles.selectionCell}`, role: "cell" })) : null, filteredColumns.map(column => {
66
87
  var _a;
67
- return (_jsx("div", { className: styles.cell, role: "cell", "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: _jsx(SkeletonLoaderItem, { height: 20, width: "100%" }) }, column.id));
68
- })] }, `loading-row-${rowIndex}`))) })) : (_jsx("div", { className: `${styles.body} ${striped ? styles.striped : ''}`, role: "rowgroup", children: data === null || data === void 0 ? void 0 : data.map(row => {
88
+ const dividerClass = column.divider === 'left'
89
+ ? styles.dividerLeft
90
+ : column.divider === 'right'
91
+ ? styles.dividerRight
92
+ : '';
93
+ return (_jsx("div", { className: [styles.cell, dividerClass].filter(Boolean).join(' '), role: "cell", "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', "data-divider": column.divider, children: _jsx("div", { className: styles.cellContent, children: _jsx("div", { className: styles.cellValueEllipsis, children: _jsx(SkeletonLoaderItem, { height: 20, width: "100%" }) }) }) }, column.id));
94
+ })] }, `loading-row-${rowIndex}`))) }));
95
+ const dataBodyEl = (_jsx("div", { className: `${styles.body} ${striped ? styles.striped : ''}`, role: "rowgroup", children: data.map(row => {
69
96
  const rowSeverity = getRowSeverity === null || getRowSeverity === void 0 ? void 0 : getRowSeverity(row);
70
97
  const rowId = row[dataKey];
71
98
  const isSelected = Boolean(selectedRows === null || selectedRows === void 0 ? void 0 : selectedRows.has(rowId));
@@ -74,7 +101,9 @@ export function Table({ data, columns, selectedRows, onRowSelect, selectionMode
74
101
  onRowClick ? styles.clickableRow : '',
75
102
  isSelected ? styles.selectedRow : '',
76
103
  rowSeverity ? styles.severity : '',
77
- ].join(' '), style: {
104
+ ]
105
+ .filter(Boolean)
106
+ .join(' '), style: {
78
107
  ...gridStyle,
79
108
  ['--row-severity-color']: rowSeverity
80
109
  ? SeverityBgColor[rowSeverity]
@@ -100,26 +129,40 @@ export function Table({ data, columns, selectedRows, onRowSelect, selectionMode
100
129
  onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(rowId, checked);
101
130
  } }) })), filteredColumns.map(column => {
102
131
  var _a;
132
+ const dividerClass = column.divider === 'left'
133
+ ? styles.dividerLeft
134
+ : column.divider === 'right'
135
+ ? styles.dividerRight
136
+ : '';
137
+ const allowWrap = shouldAllowWrap(column.allowWrap, isSelected, viewMode);
138
+ const cellValue = getCellDisplayValue(row, column);
103
139
  return (_jsx("div", { className: [
104
140
  styles.cell,
105
- shouldAllowWrap(column.allowWrap, isSelected, viewMode)
106
- ? styles.allowWrap
107
- : styles.nowrap,
108
- ].join(' '), role: "cell", "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', children: getCellDisplayValue(row, column) }, column.id));
141
+ allowWrap ? styles.allowWrap : styles.nowrap,
142
+ dividerClass,
143
+ ]
144
+ .filter(Boolean)
145
+ .join(' '), role: "cell", "data-align": (_a = column.align) !== null && _a !== void 0 ? _a : 'left', "data-divider": column.divider, children: _jsx("div", { className: styles.cellContent, children: allowWrap ? (cellValue) : (_jsx("div", { className: styles.cellValueEllipsis, children: cellValue })) }) }, column.id));
109
146
  })] }, `gridRow-${String(rowId)}`));
110
147
  }) }));
111
- const gridEl = (_jsxs(_Fragment, { children: [toolbar ? _jsx("div", { style: { marginBottom: 12 }, children: toolbar }) : null, _jsxs("div", { ...rest, className: `${styles.grid} ${styles[variant]} ${styles[size]} ${getRowSeverity ? styles.severityTable : ''}`, role: "table", "aria-rowcount": data.length, children: [_jsx("div", { className: styles.header, role: "rowgroup", children: headerEl }), bodyEl] }), !data.length && !loading && _jsx(TableEmptyState, { config: emptyConfig })] }));
148
+ const bodyContent = loading && !data.length ? loadingBodyEl : dataBodyEl;
149
+ const tableClassName = [
150
+ styles.tableRoot,
151
+ styles[variant],
152
+ styles[size],
153
+ getRowSeverity ? styles.severityTable : '',
154
+ ]
155
+ .filter(Boolean)
156
+ .join(' ');
157
+ const tableShell = (_jsxs("div", { ...rest, className: tableClassName, role: "table", "aria-rowcount": data.length, children: [_jsx("div", { className: styles.header, role: "rowgroup", children: headerEl }), _jsx("div", { className: styles.bodyScroll, children: !data.length && !loading ? (_jsx("div", { className: styles.emptyStateSlot, children: _jsx(TableEmptyState, { config: emptyConfig }) })) : (bodyContent) })] }));
158
+ const paginationEl = onPageChange && data.length > 0 ? (_jsx("div", { className: `${styles.paginationSlot} ${paginationPlacement === 'top' ? styles.paginationSlotTop : ''}`, children: _jsx(Pagination, { itemsCount: totalItemsCount, take: take, skip: skip, onPageChange: handlePageChange, showFirstLast: showFirstLast }) })) : null;
112
159
  if (fillViewport) {
113
- return (_jsxs("div", { style: {
114
- display: 'flex',
115
- flexDirection: 'column',
116
- gap: '20px',
117
- flexFlow: paginationPlacement === 'top' ? 'column-reverse' : 'column',
118
- position: 'relative',
119
- }, children: [_jsx("div", { ref: scrollRef, style: viewportStyle, className: styles.tableScroll, children: gridEl }), onPageChange && data.length > 0 && (_jsx(Pagination, { itemsCount: totalItemsCount, take: take, skip: skip, onPageChange: handlePageChange, showFirstLast: showFirstLast }))] }));
160
+ return (_jsxs("div", { className: styles.fillViewportRoot, style: {
161
+ flexDirection: paginationPlacement === 'top' ? 'column-reverse' : 'column',
162
+ }, children: [toolbar ? _jsx("div", { className: styles.toolbarSlot, children: toolbar }) : null, _jsx("div", { className: styles.tableViewport, children: tableShell }), paginationEl] }));
120
163
  }
121
164
  return (_jsxs("div", { className: "dbc-flex dbc-flex-column dbc-gap-md", style: {
122
165
  flexFlow: paginationPlacement === 'top' ? 'column-reverse' : 'column',
123
166
  position: 'relative',
124
- }, children: [gridEl, onPageChange && data.length > 0 && (_jsx(Pagination, { itemsCount: totalItemsCount, take: take, skip: skip, onPageChange: handlePageChange }))] }));
167
+ }, children: [toolbar ? _jsx("div", { className: styles.toolbarSlot, children: toolbar }) : null, tableShell, paginationEl] }));
125
168
  }