@dbcdk/react-components 0.0.12 → 0.0.13
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/accordion/Accordion.d.ts +2 -2
- package/dist/components/accordion/Accordion.js +34 -41
- package/dist/components/accordion/Accordion.module.css +13 -72
- package/dist/components/accordion/components/AccordionRow.d.ts +10 -0
- package/dist/components/accordion/components/AccordionRow.js +51 -0
- package/dist/components/accordion/components/AccordionRow.module.css +82 -0
- package/dist/components/breadcrumbs/Breadcrumbs.module.css +0 -1
- package/dist/components/button/Button.module.css +7 -7
- package/dist/components/card/Card.d.ts +9 -18
- package/dist/components/card/Card.js +34 -23
- package/dist/components/card/Card.module.css +22 -87
- package/dist/components/card/components/CardMeta.d.ts +15 -0
- package/dist/components/card/components/CardMeta.js +20 -0
- package/dist/components/card/components/CardMeta.module.css +51 -0
- package/dist/components/card-container/CardContainer.js +1 -1
- package/dist/components/card-container/CardContainer.module.css +3 -1
- package/dist/components/chip/Chip.module.css +7 -2
- package/dist/components/datetime-picker/DateTimePicker.d.ts +33 -8
- package/dist/components/datetime-picker/DateTimePicker.js +119 -78
- package/dist/components/datetime-picker/DateTimePicker.module.css +2 -0
- package/dist/components/datetime-picker/dateTimeHelpers.d.ts +15 -3
- package/dist/components/datetime-picker/dateTimeHelpers.js +137 -23
- package/dist/components/filter-field/FilterField.module.css +5 -5
- package/dist/components/forms/form-select/FormSelect.d.ts +35 -0
- package/dist/components/forms/form-select/FormSelect.js +86 -0
- package/dist/components/forms/form-select/FormSelect.module.css +236 -0
- package/dist/components/forms/input/Input.d.ts +0 -3
- package/dist/components/forms/input/Input.js +0 -3
- package/dist/components/forms/input/Input.module.css +7 -7
- package/dist/components/forms/radio-buttons/RadioButtons.module.css +1 -0
- package/dist/components/forms/select/Select.js +55 -16
- package/dist/components/interval-select/IntervalSelect.d.ts +9 -2
- package/dist/components/interval-select/IntervalSelect.js +21 -6
- package/dist/components/menu/Menu.d.ts +11 -14
- package/dist/components/menu/Menu.js +18 -33
- package/dist/components/menu/Menu.module.css +2 -2
- package/dist/components/overlay/modal/Modal.module.css +2 -1
- package/dist/components/overlay/modal/provider/ModalProvider.js +1 -3
- package/dist/components/overlay/side-panel/SidePanel.js +1 -1
- package/dist/components/overlay/side-panel/SidePanel.module.css +1 -1
- package/dist/components/page-layout/PageLayout.d.ts +16 -4
- package/dist/components/page-layout/PageLayout.js +57 -28
- package/dist/components/page-layout/PageLayout.module.css +153 -33
- package/dist/components/popover/Popover.d.ts +17 -4
- package/dist/components/popover/Popover.js +147 -65
- package/dist/components/popover/Popover.module.css +5 -0
- package/dist/components/split-pane/SplitPane.d.ts +10 -24
- package/dist/components/split-pane/SplitPane.js +83 -54
- package/dist/components/split-pane/SplitPane.module.css +11 -6
- package/dist/components/split-pane/provider/SplitPaneContext.js +5 -11
- package/dist/components/sticky-footer-layout/StickyFooterLayout.d.ts +3 -8
- package/dist/components/sticky-footer-layout/StickyFooterLayout.js +57 -20
- package/dist/components/table/Table.d.ts +3 -8
- package/dist/components/table/Table.js +37 -76
- package/dist/components/table/Table.module.css +45 -42
- package/dist/components/table/{tanstack.d.ts → TanstackTable.d.ts} +5 -12
- package/dist/components/table/TanstackTable.js +84 -0
- package/dist/components/table/components/column-resizer/ColumnResizer.js +1 -1
- package/dist/components/table/components/column-resizer/ColumnResizer.module.css +17 -7
- package/dist/components/table/table.utils.d.ts +17 -0
- package/dist/components/table/table.utils.js +61 -0
- package/dist/components/table/tanstackTable.utils.d.ts +22 -0
- package/dist/components/table/tanstackTable.utils.js +104 -0
- package/dist/components/tabs/Tabs.d.ts +35 -12
- package/dist/components/tabs/Tabs.js +114 -26
- package/dist/components/tabs/Tabs.module.css +158 -71
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/src/styles/styles.css +0 -1
- package/dist/styles/styles.css +0 -1
- package/dist/styles/themes/dbc/base.css +136 -0
- package/dist/styles/themes/dbc/dark.css +39 -202
- package/dist/styles/themes/dbc/light.css +17 -174
- package/package.json +4 -4
- package/dist/components/table/tanstack.js +0 -214
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useReactTable, getCoreRowModel, getSortedRowModel, getFilteredRowModel, } from '@tanstack/react-table';
|
|
4
|
-
import * as React from 'react';
|
|
5
|
-
import { Table } from './Table';
|
|
6
|
-
import ColumnResizer from './components/column-resizer/ColumnResizer';
|
|
7
|
-
function getColumnId(def, index) {
|
|
8
|
-
const d = def;
|
|
9
|
-
if (d.id != null && String(d.id).length)
|
|
10
|
-
return String(d.id);
|
|
11
|
-
if (d.accessorKey != null && String(d.accessorKey).length)
|
|
12
|
-
return String(d.accessorKey);
|
|
13
|
-
return `col_${index}`;
|
|
14
|
-
}
|
|
15
|
-
function buildDefaultVisibleIdsFromDefs(defs) {
|
|
16
|
-
const ids = [];
|
|
17
|
-
defs.forEach((def, idx) => {
|
|
18
|
-
var _a;
|
|
19
|
-
const id = getColumnId(def, idx);
|
|
20
|
-
const hiddenByMeta = Boolean((_a = def.meta) === null || _a === void 0 ? void 0 : _a.hidden);
|
|
21
|
-
if (!hiddenByMeta)
|
|
22
|
-
ids.push(id);
|
|
23
|
-
});
|
|
24
|
-
return ids;
|
|
25
|
-
}
|
|
26
|
-
function mapDefsToColumnItems(defs, columnVisibility) {
|
|
27
|
-
return defs.map((def, index) => {
|
|
28
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
29
|
-
const id = getColumnId(def, index);
|
|
30
|
-
const accessorKey = def.accessorKey;
|
|
31
|
-
const accessorFn = def.accessorFn;
|
|
32
|
-
const cell = def.cell;
|
|
33
|
-
let render;
|
|
34
|
-
if (typeof cell === 'function') {
|
|
35
|
-
render = (row) => cell({
|
|
36
|
-
row: { original: row },
|
|
37
|
-
getValue: () => accessorKey != null
|
|
38
|
-
? row[accessorKey]
|
|
39
|
-
: accessorFn
|
|
40
|
-
? accessorFn(row)
|
|
41
|
-
: undefined,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else if (accessorFn) {
|
|
45
|
-
render = (row) => accessorFn(row);
|
|
46
|
-
}
|
|
47
|
-
else if (accessorKey != null) {
|
|
48
|
-
render = (row) => row[accessorKey];
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
render = () => null;
|
|
52
|
-
}
|
|
53
|
-
const isVisible = (_a = columnVisibility[id]) !== null && _a !== void 0 ? _a : true;
|
|
54
|
-
return {
|
|
55
|
-
id,
|
|
56
|
-
header: def.header,
|
|
57
|
-
accessor: accessorKey,
|
|
58
|
-
sortable: (_b = def.enableSorting) !== null && _b !== void 0 ? _b : !!accessorKey,
|
|
59
|
-
render,
|
|
60
|
-
hidden: !isVisible,
|
|
61
|
-
align: (_d = (_c = def.meta) === null || _c === void 0 ? void 0 : _c.align) !== null && _d !== void 0 ? _d : undefined,
|
|
62
|
-
verticalAlign: (_f = (_e = def.meta) === null || _e === void 0 ? void 0 : _e.verticalAlign) !== null && _f !== void 0 ? _f : undefined,
|
|
63
|
-
fitContent: (_h = (_g = def.meta) === null || _g === void 0 ? void 0 : _g.fitContent) !== null && _h !== void 0 ? _h : false,
|
|
64
|
-
emptyPlaceholder: (_k = (_j = def.meta) === null || _j === void 0 ? void 0 : _j.emptyPlaceholder) !== null && _k !== void 0 ? _k : '-',
|
|
65
|
-
allowWrap: (_m = (_l = def.meta) === null || _l === void 0 ? void 0 : _l.allowWrap) !== null && _m !== void 0 ? _m : false,
|
|
66
|
-
fillWidth: (_p = (_o = def.meta) === null || _o === void 0 ? void 0 : _o.fillWidth) !== null && _p !== void 0 ? _p : false,
|
|
67
|
-
severity: (_r = (_q = def.meta) === null || _q === void 0 ? void 0 : _q.severity) !== null && _r !== void 0 ? _r : undefined,
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
export function TanstackTable(props) {
|
|
72
|
-
var _a, _b;
|
|
73
|
-
const { data, dataKey, columns, filterable = [], onSortingChange, initialSortBy, initialSortDirection, visibleColumnIds, ...tableProps } = props;
|
|
74
|
-
const [sorting, setSorting] = React.useState([]);
|
|
75
|
-
const [columnFilters, setColumnFilters] = React.useState([]);
|
|
76
|
-
const [columnSizing, setColumnSizing] = React.useState({});
|
|
77
|
-
// IDs in the same order as defs
|
|
78
|
-
const allColumnIds = React.useMemo(() => columns.map((def, i) => getColumnId(def, i)), [columns]);
|
|
79
|
-
// Defaults derived from ColumnDef meta.hidden
|
|
80
|
-
const defaultVisibleIds = React.useMemo(() => buildDefaultVisibleIdsFromDefs(columns), [columns]);
|
|
81
|
-
// Treat [] as "unset" and fall back to defaults
|
|
82
|
-
const effectiveVisibleIds = React.useMemo(() => {
|
|
83
|
-
if (visibleColumnIds && visibleColumnIds.length > 0)
|
|
84
|
-
return visibleColumnIds;
|
|
85
|
-
return defaultVisibleIds;
|
|
86
|
-
}, [visibleColumnIds, defaultVisibleIds]);
|
|
87
|
-
// TanStack visibility state
|
|
88
|
-
const [columnVisibility, setColumnVisibility] = React.useState(() => {
|
|
89
|
-
const visible = new Set(effectiveVisibleIds);
|
|
90
|
-
const next = {};
|
|
91
|
-
for (const id of allColumnIds)
|
|
92
|
-
next[id] = visible.has(id);
|
|
93
|
-
return next;
|
|
94
|
-
});
|
|
95
|
-
const table = useReactTable({
|
|
96
|
-
data,
|
|
97
|
-
columns: columns,
|
|
98
|
-
state: { sorting, columnFilters, columnSizing, columnVisibility },
|
|
99
|
-
onSortingChange: setSorting,
|
|
100
|
-
onColumnFiltersChange: setColumnFilters,
|
|
101
|
-
onColumnSizingChange: setColumnSizing,
|
|
102
|
-
onColumnVisibilityChange: setColumnVisibility,
|
|
103
|
-
getCoreRowModel: getCoreRowModel(),
|
|
104
|
-
getSortedRowModel: getSortedRowModel(),
|
|
105
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
106
|
-
enableColumnResizing: true,
|
|
107
|
-
columnResizeMode: 'onChange',
|
|
108
|
-
initialState: {},
|
|
109
|
-
defaultColumn: {
|
|
110
|
-
enableResizing: true,
|
|
111
|
-
minSize: 80,
|
|
112
|
-
size: 180,
|
|
113
|
-
maxSize: 800,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
// Apply external "visibleColumnIds" -> TanStack column visibility using toggleVisibility,
|
|
117
|
-
// as requested (no selector UI here).
|
|
118
|
-
React.useEffect(() => {
|
|
119
|
-
const desired = new Set(effectiveVisibleIds);
|
|
120
|
-
for (const id of allColumnIds) {
|
|
121
|
-
const col = table.getColumn(id);
|
|
122
|
-
if (!col)
|
|
123
|
-
continue;
|
|
124
|
-
const shouldBeVisible = desired.has(id);
|
|
125
|
-
if (col.getIsVisible() !== shouldBeVisible) {
|
|
126
|
-
col.toggleVisibility(shouldBeVisible);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, [table, allColumnIds, effectiveVisibleIds]);
|
|
130
|
-
React.useEffect(() => {
|
|
131
|
-
if (initialSortDirection !== 'asc' && initialSortDirection !== 'desc')
|
|
132
|
-
return table.setSorting([]);
|
|
133
|
-
table.setSorting(() => initialSortBy && initialSortDirection
|
|
134
|
-
? [{ id: initialSortBy, desc: initialSortDirection === 'desc' }]
|
|
135
|
-
: []);
|
|
136
|
-
}, [initialSortBy, initialSortDirection, table]);
|
|
137
|
-
const columnItems = React.useMemo(() => mapDefsToColumnItems(columns, columnVisibility), [columns, columnVisibility]);
|
|
138
|
-
const visibleData = table.getRowModel().rows.map(r => r.original);
|
|
139
|
-
const s = (_a = table.getState().sorting) === null || _a === void 0 ? void 0 : _a[0];
|
|
140
|
-
const sortById = (_b = s === null || s === void 0 ? void 0 : s.id) !== null && _b !== void 0 ? _b : undefined;
|
|
141
|
-
const sortDirection = s ? (s.desc ? 'desc' : 'asc') : null;
|
|
142
|
-
const gridTemplateColumns = React.useMemo(() => {
|
|
143
|
-
return columnItems
|
|
144
|
-
.filter(ci => !ci.hidden)
|
|
145
|
-
.map(ci => {
|
|
146
|
-
var _a;
|
|
147
|
-
const col = table.getColumn(ci.id);
|
|
148
|
-
const w = (_a = col === null || col === void 0 ? void 0 : col.getSize) === null || _a === void 0 ? void 0 : _a.call(col);
|
|
149
|
-
if (ci.fillWidth)
|
|
150
|
-
return '1fr';
|
|
151
|
-
if (ci.fitContent)
|
|
152
|
-
return '1%';
|
|
153
|
-
return `${w !== null && w !== void 0 ? w : 180}px`;
|
|
154
|
-
})
|
|
155
|
-
.join(' ');
|
|
156
|
-
}, [columnItems, table]);
|
|
157
|
-
const columnStyles = React.useMemo(() => {
|
|
158
|
-
const styles = {};
|
|
159
|
-
for (const c of table.getAllLeafColumns()) {
|
|
160
|
-
const id = c.id;
|
|
161
|
-
const ci = columnItems.find(x => x.id === id);
|
|
162
|
-
if (ci === null || ci === void 0 ? void 0 : ci.fillWidth) {
|
|
163
|
-
styles[id] = { width: 'auto', minWidth: 0 };
|
|
164
|
-
}
|
|
165
|
-
else if (ci === null || ci === void 0 ? void 0 : ci.fitContent) {
|
|
166
|
-
styles[id] = { width: '1%', whiteSpace: 'nowrap' };
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const w = c.getSize();
|
|
170
|
-
styles[id] = { width: w, minWidth: w, maxWidth: w };
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return styles;
|
|
174
|
-
}, [table, columnItems]);
|
|
175
|
-
const headerExtras = React.useCallback(({ index }) => {
|
|
176
|
-
var _a, _b, _c, _d;
|
|
177
|
-
const headerGroups = table.getHeaderGroups();
|
|
178
|
-
const leafHeaders = headerGroups.length > 0 ? headerGroups[headerGroups.length - 1].headers : [];
|
|
179
|
-
const header = leafHeaders[index];
|
|
180
|
-
if (!header)
|
|
181
|
-
return null;
|
|
182
|
-
const canResize = (_c = (_b = (_a = header.column).getCanResize) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false;
|
|
183
|
-
const handler = (_d = header.getResizeHandler) === null || _d === void 0 ? void 0 : _d.call(header);
|
|
184
|
-
if (!canResize || !handler)
|
|
185
|
-
return null;
|
|
186
|
-
return _jsx(ColumnResizer, { id: header.column.id, handler: handler });
|
|
187
|
-
}, [table]);
|
|
188
|
-
const headerBelowRow = React.useMemo(() => {
|
|
189
|
-
if (!(filterable === null || filterable === void 0 ? void 0 : filterable.length))
|
|
190
|
-
return null;
|
|
191
|
-
return (_jsx("div", { style: { display: 'grid', gridTemplateColumns, gap: 8 }, children: columnItems
|
|
192
|
-
.filter(ci => !ci.hidden)
|
|
193
|
-
.map(ci => {
|
|
194
|
-
var _a;
|
|
195
|
-
const id = ci.id;
|
|
196
|
-
const isFilterable = filterable.includes(id);
|
|
197
|
-
if (!isFilterable)
|
|
198
|
-
return _jsx("div", {}, id);
|
|
199
|
-
const col = table.getColumn(id);
|
|
200
|
-
const value = (_a = col === null || col === void 0 ? void 0 : col.getFilterValue()) !== null && _a !== void 0 ? _a : '';
|
|
201
|
-
return (_jsx("input", { value: value, placeholder: `Filter ${String(ci.header)}`, onChange: e => col === null || col === void 0 ? void 0 : col.setFilterValue(e.target.value), style: { width: '100%', padding: '4px 6px' } }, id));
|
|
202
|
-
}) }));
|
|
203
|
-
}, [columnItems, filterable, table, gridTemplateColumns]);
|
|
204
|
-
return (_jsx(Table, { ...tableProps, dataKey: dataKey, data: visibleData, columns: columnItems, sortById: sortById, sortDirection: sortDirection, onSortChange: (col, dir) => {
|
|
205
|
-
var _a;
|
|
206
|
-
if (dir == null) {
|
|
207
|
-
table.setSorting([]);
|
|
208
|
-
onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(null, null);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
table.setSorting([{ id: col.id, desc: dir === 'desc' }]);
|
|
212
|
-
onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange((_a = col.id) !== null && _a !== void 0 ? _a : null, dir);
|
|
213
|
-
}, headerExtras: headerExtras, columnStyles: columnStyles, headerBelowRow: headerBelowRow }));
|
|
214
|
-
}
|