@dbcdk/react-components 0.0.10 → 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.
Files changed (106) hide show
  1. package/dist/components/accordion/Accordion.d.ts +2 -2
  2. package/dist/components/accordion/Accordion.js +34 -41
  3. package/dist/components/accordion/Accordion.module.css +13 -72
  4. package/dist/components/accordion/components/AccordionRow.d.ts +10 -0
  5. package/dist/components/accordion/components/AccordionRow.js +51 -0
  6. package/dist/components/accordion/components/AccordionRow.module.css +82 -0
  7. package/dist/components/breadcrumbs/Breadcrumbs.module.css +0 -1
  8. package/dist/components/button/Button.module.css +7 -7
  9. package/dist/components/card/Card.d.ts +15 -6
  10. package/dist/components/card/Card.js +39 -13
  11. package/dist/components/card/Card.module.css +22 -28
  12. package/dist/components/card/components/CardMeta.d.ts +15 -0
  13. package/dist/components/card/components/CardMeta.js +20 -0
  14. package/dist/components/card/components/CardMeta.module.css +51 -0
  15. package/dist/components/card-container/CardContainer.js +1 -1
  16. package/dist/components/card-container/CardContainer.module.css +3 -1
  17. package/dist/components/chip/Chip.module.css +7 -2
  18. package/dist/components/circle/Circle.d.ts +2 -1
  19. package/dist/components/circle/Circle.js +2 -2
  20. package/dist/components/circle/Circle.module.css +6 -2
  21. package/dist/components/code-block/CodeBlock.js +1 -1
  22. package/dist/components/code-block/CodeBlock.module.css +30 -17
  23. package/dist/components/copy-button/CopyButton.d.ts +1 -0
  24. package/dist/components/copy-button/CopyButton.js +10 -2
  25. package/dist/components/datetime-picker/DateTimePicker.d.ts +33 -8
  26. package/dist/components/datetime-picker/DateTimePicker.js +119 -78
  27. package/dist/components/datetime-picker/DateTimePicker.module.css +2 -0
  28. package/dist/components/datetime-picker/dateTimeHelpers.d.ts +15 -3
  29. package/dist/components/datetime-picker/dateTimeHelpers.js +137 -23
  30. package/dist/components/filter-field/FilterField.js +16 -11
  31. package/dist/components/filter-field/FilterField.module.css +137 -16
  32. package/dist/components/forms/checkbox/Checkbox.d.ts +2 -2
  33. package/dist/components/forms/checkbox-group/CheckboxGroup.js +1 -1
  34. package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +1 -1
  35. package/dist/components/forms/form-select/FormSelect.d.ts +35 -0
  36. package/dist/components/forms/form-select/FormSelect.js +86 -0
  37. package/dist/components/forms/form-select/FormSelect.module.css +236 -0
  38. package/dist/components/forms/input/Input.d.ts +0 -3
  39. package/dist/components/forms/input/Input.js +1 -4
  40. package/dist/components/forms/input/Input.module.css +8 -7
  41. package/dist/components/forms/input-container/InputContainer.module.css +1 -1
  42. package/dist/components/forms/radio-buttons/RadioButtons.module.css +1 -0
  43. package/dist/components/forms/select/Select.js +55 -16
  44. package/dist/components/hyperlink/Hyperlink.d.ts +19 -7
  45. package/dist/components/hyperlink/Hyperlink.js +35 -11
  46. package/dist/components/hyperlink/Hyperlink.module.css +50 -2
  47. package/dist/components/interval-select/IntervalSelect.d.ts +9 -2
  48. package/dist/components/interval-select/IntervalSelect.js +21 -6
  49. package/dist/components/menu/Menu.d.ts +29 -0
  50. package/dist/components/menu/Menu.js +61 -16
  51. package/dist/components/menu/Menu.module.css +73 -5
  52. package/dist/components/overlay/modal/Modal.module.css +4 -3
  53. package/dist/components/overlay/modal/provider/ModalProvider.js +1 -3
  54. package/dist/components/overlay/side-panel/SidePanel.js +18 -1
  55. package/dist/components/overlay/side-panel/SidePanel.module.css +1 -3
  56. package/dist/components/overlay/tooltip/useTooltipTrigger.js +4 -2
  57. package/dist/components/page-layout/PageLayout.d.ts +16 -4
  58. package/dist/components/page-layout/PageLayout.js +57 -28
  59. package/dist/components/page-layout/PageLayout.module.css +153 -33
  60. package/dist/components/popover/Popover.d.ts +17 -4
  61. package/dist/components/popover/Popover.js +147 -65
  62. package/dist/components/popover/Popover.module.css +5 -0
  63. package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +22 -18
  64. package/dist/components/sidebar/providers/SidebarProvider.d.ts +4 -1
  65. package/dist/components/sidebar/providers/SidebarProvider.js +66 -18
  66. package/dist/components/split-button/SplitButton.d.ts +1 -1
  67. package/dist/components/split-button/SplitButton.js +3 -1
  68. package/dist/components/split-button/SplitButton.module.css +4 -4
  69. package/dist/components/split-pane/SplitPane.d.ts +10 -24
  70. package/dist/components/split-pane/SplitPane.js +83 -54
  71. package/dist/components/split-pane/SplitPane.module.css +11 -6
  72. package/dist/components/split-pane/provider/SplitPaneContext.js +5 -11
  73. package/dist/components/state-page/StatePage.module.css +1 -1
  74. package/dist/components/sticky-footer-layout/StickyFooterLayout.d.ts +3 -8
  75. package/dist/components/sticky-footer-layout/StickyFooterLayout.js +57 -20
  76. package/dist/components/table/Table.d.ts +8 -8
  77. package/dist/components/table/Table.js +37 -79
  78. package/dist/components/table/Table.module.css +62 -46
  79. package/dist/components/table/{tanstack.d.ts → TanstackTable.d.ts} +7 -3
  80. package/dist/components/table/TanstackTable.js +84 -0
  81. package/dist/components/table/components/column-resizer/ColumnResizer.js +1 -1
  82. package/dist/components/table/components/column-resizer/ColumnResizer.module.css +17 -7
  83. package/dist/components/table/components/table-settings/TableSettings.d.ts +13 -3
  84. package/dist/components/table/components/table-settings/TableSettings.js +55 -4
  85. package/dist/components/table/table.utils.d.ts +17 -0
  86. package/dist/components/table/table.utils.js +61 -0
  87. package/dist/components/table/tanstackTable.utils.d.ts +22 -0
  88. package/dist/components/table/tanstackTable.utils.js +104 -0
  89. package/dist/components/tabs/Tabs.d.ts +35 -12
  90. package/dist/components/tabs/Tabs.js +114 -26
  91. package/dist/components/tabs/Tabs.module.css +158 -71
  92. package/dist/hooks/useTableSettings.d.ts +23 -4
  93. package/dist/hooks/useTableSettings.js +64 -17
  94. package/dist/index.d.ts +1 -1
  95. package/dist/index.js +1 -1
  96. package/dist/src/styles/styles.css +38 -23
  97. package/dist/styles/animation.d.ts +5 -0
  98. package/dist/styles/animation.js +5 -0
  99. package/dist/styles/styles.css +38 -23
  100. package/dist/styles/themes/dbc/base.css +136 -0
  101. package/dist/styles/themes/dbc/dark.css +39 -202
  102. package/dist/styles/themes/dbc/light.css +17 -174
  103. package/dist/utils/localStorage.utils.d.ts +19 -0
  104. package/dist/utils/localStorage.utils.js +78 -0
  105. package/package.json +4 -4
  106. package/dist/components/table/tanstack.js +0 -162
@@ -1,13 +1,13 @@
1
1
  html[data-theme='light'] {
2
2
  /* ==========================================================================
3
- * PRIMITIVES (DBC)
3
+ * PRIMITIVES (THEME-DEPENDENT)
4
4
  * ======================================================================= */
5
5
 
6
6
  /* Brand blues */
7
7
  --dbc-blue-500: #0c3ee3;
8
8
  --dbc-blue-600: #0932b6;
9
9
  --dbc-blue-400: #3b6ff5;
10
- --dbc-blue-300: #7ea5ff; /* used for focus ring */
10
+ --dbc-blue-300: #7ea5ff;
11
11
  --dbc-blue-100: #e8edfd;
12
12
  --dbc-blue-150: #dce5fc;
13
13
 
@@ -47,15 +47,14 @@ html[data-theme='light'] {
47
47
  --dbc-info-300: #38bdf8;
48
48
 
49
49
  /* ==========================================================================
50
- * SEMANTIC COLORS (HUE-AGNOSTIC – COMPONENTS USE THESE)
50
+ * SEMANTIC COLORS (THEME-DEPENDENT)
51
51
  * ======================================================================= */
52
52
 
53
- /* === Brand & accents === */
54
53
  --color-brand: var(--dbc-blue-500);
55
54
  --color-brand-hover: var(--dbc-blue-600);
56
- --color-brand-strong: var(--dbc-blue-600); /* same as hover for this theme */
55
+ --color-brand-strong: var(--dbc-blue-600);
57
56
 
58
- /* === Backgrounds & surfaces === */
57
+ /* Backgrounds & surfaces */
59
58
  --color-bg-page: #ffffff;
60
59
  --color-bg-surface: #ffffff;
61
60
  --color-bg-surface-subtle: rgba(0, 0, 0, 0.02);
@@ -73,23 +72,14 @@ html[data-theme='light'] {
73
72
  --color-bg-selected-hover: var(--dbc-blue-150);
74
73
 
75
74
  --color-neutral: var(--dbc-neutral-200);
76
- --color-neutral-fg: #000000;
77
- --color-neutral-strong: var(--dbc-neutral-600);
78
- --color-neutral-strong-fg: #ffffff;
79
- /* === Borders === */
80
75
 
76
+ /* Borders */
81
77
  --color-border-subtle: rgba(0, 0, 0, 0.12);
82
78
  --color-border-default: rgba(0, 0, 0, 0.12);
83
79
  --color-border-strong: rgba(0, 0, 0, 0.24);
84
80
  --color-border-selected: var(--color-brand);
85
81
 
86
- /* Border widths */
87
- --border-width-thin: 1px;
88
- --border-width-medium: 2px;
89
- --border-width-thick: 4px;
90
-
91
- /* === Text / foreground === */
92
-
82
+ /* Text */
93
83
  --color-fg-default: var(--dbc-neutral-900);
94
84
  --color-fg-muted: var(--dbc-neutral-700);
95
85
  --color-fg-subtle: var(--dbc-neutral-600);
@@ -97,14 +87,11 @@ html[data-theme='light'] {
97
87
  --color-fg-on-strong: #ffffff;
98
88
  --color-fg-on-brand: #ffffff;
99
89
 
100
- /* === Links === */
101
-
90
+ /* Links */
102
91
  --color-link: var(--dbc-blue-500);
103
92
  --color-link-hover: var(--dbc-blue-600);
104
- --color-link-visited: #5b3ee3;
105
-
106
- /* === Status / severity === */
107
93
 
94
+ /* Status */
108
95
  --color-status-success: var(--dbc-green-500);
109
96
  --color-status-success-bg: var(--dbc-green-100);
110
97
  --color-status-success-border: var(--dbc-green-300);
@@ -125,19 +112,17 @@ html[data-theme='light'] {
125
112
  --color-status-info-border: var(--dbc-info-300);
126
113
  --color-status-info-fg: var(--dbc-info-700);
127
114
 
128
- /* === Disabled === */
129
-
115
+ /* Disabled */
130
116
  --color-disabled-bg: var(--dbc-neutral-100);
131
117
  --color-disabled-fg: #9ca3af;
132
118
  --color-disabled-border: var(--dbc-neutral-200);
133
119
 
134
- /* === Focus === */
135
-
120
+ /* Focus */
136
121
  --color-focus-ring: var(--dbc-blue-300);
137
122
  --focus-ring: 0 0 0 3px rgba(12, 62, 227, 0.25);
138
123
 
139
124
  /* ==========================================================================
140
- * OPTIONAL COMPONENT-LEVEL TOKENS
125
+ * COMPONENT-LEVEL TOKENS (THEME-DEPENDENT COLORS)
141
126
  * ======================================================================= */
142
127
 
143
128
  /* Cards */
@@ -147,8 +132,6 @@ html[data-theme='light'] {
147
132
 
148
133
  --card-fg-default: var(--color-fg-default);
149
134
  --card-fg-on-strong: var(--color-fg-on-strong);
150
- --card-fg-on-accent-1: var(--color-fg-on-accent-1);
151
- --card-fg-on-accent-2: var(--color-fg-on-accent-2);
152
135
 
153
136
  /* Buttons */
154
137
  --button-bg-primary: var(--color-brand);
@@ -156,10 +139,10 @@ html[data-theme='light'] {
156
139
  --button-fg-primary: var(--color-fg-on-brand);
157
140
 
158
141
  /* ==========================================================================
159
- * NON-COLOR SYSTEM TOKENS
142
+ * THEME-SPECIFIC NON-COLOR TOKENS (VISUAL EFFECTS)
160
143
  * ======================================================================= */
161
144
 
162
- /* Opacities (light) */
145
+ /* Opacities */
163
146
  --opac-bg-light: rgba(0, 0, 0, 0.025);
164
147
  --opac-bg-default: rgba(0, 0, 0, 0.05);
165
148
  --opac-bg-dark: rgba(0, 0, 0, 0.1);
@@ -168,135 +151,13 @@ html[data-theme='light'] {
168
151
  --opac-bg-default-invert: rgba(255, 255, 255, 0.05);
169
152
  --opac-bg-dark-invert: rgba(255, 255, 255, 0.1);
170
153
 
171
- /* ===== Spacing & Layout ===== */
172
- --spacing-2xs: 2px;
173
- --spacing-xxs: 4px;
174
- --spacing-xs: 8px;
175
- --spacing-sm: 12px;
176
- --spacing-md: 16px;
177
- --spacing-lg: 24px;
178
- --spacing-xl: 32px;
179
- --spacing-2xl: 48px;
180
- --spacing-3xl: 64px;
181
- --spacing-4xl: 96px;
182
-
183
- --gutter-sm: 12px;
184
- --gutter-md: 16px;
185
- --gutter-lg: 24px;
186
-
187
- /* Breakpoints & Containers */
188
- --bp-xs: 480px;
189
- --bp-sm: 640px;
190
- --bp-md: 768px;
191
- --bp-lg: 1024px;
192
- --bp-xl: 1280px;
193
-
194
- --container-xs: 480px;
195
- --container-sm: 640px;
196
- --container-md: 768px;
197
- --container-lg: 1024px;
198
- --container-xl: 1280px;
199
-
200
- /* ===== Sizing ===== */
201
- --icon-size-sm: 16px;
202
- --icon-size-md: 20px;
203
- --icon-size-lg: 24px;
204
-
205
- --component-size-xxs: 12px;
206
- --component-size-xs: 20px;
207
- --component-size-sm: 30px;
208
- --component-size-md: 36px;
209
- --component-size-lg: 44px;
210
- --component-size-xl: 435px;
211
- --sidebar-width: 180px;
212
-
213
- /* Control paddings */
214
- --control-padding-x: 12px;
215
- --control-padding-y: 8px;
216
-
217
- /* Border Radius */
218
- --border-radius-none: 0;
219
- --border-radius-default: 0.25rem;
220
- --border-radius-rounded: 2rem;
221
- --border-radius-round: 50%;
222
- --border-radius-sm: 0.125rem;
223
- --border-radius-md: 0.375rem;
224
- --border-radius-lg: 0.5rem;
225
- --border-radius-xl: 0.75rem;
226
-
227
- /* Density */
228
- --density-compact: -2px;
229
- --density-comfortable: 0px;
230
- --density-spacious: 4px;
231
-
232
- /* Typography */
233
- --text-max-width: 65ch;
234
- --font-family:
235
- Roboto, Inter, ui-sans-serif, system-ui, 'Segoe UI', 'Helvetica Neue', Arial,
236
- 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
237
-
238
- --font-family-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
239
-
240
- --font-size-xs: 12px;
241
- --font-size-sm: 14px;
242
- --font-size-md: 16px;
243
- --font-size-lg: 18px;
244
- --font-size-xl: 24px;
245
- --font-size-2xl: 30px;
246
-
247
- --font-size-fluid-sm: clamp(14px, 1.2vw, 16px);
248
- --font-size-fluid-lg: clamp(18px, 1.6vw, 22px);
249
-
250
- --font-weight-default: 400;
251
- --font-weight-medium: 500;
252
- --font-weight-semibold: 600;
253
- --font-weight-bold: 700;
254
- --font-weight-extrabold: 800;
255
-
256
- --line-height-tight: 1.25;
257
- --line-height-normal: 1.5;
258
- --line-height-relaxed: 1.75;
259
-
260
- --letter-spacing-tight: -0.01em;
261
- --letter-spacing-normal: 0;
262
- --letter-spacing-wide: 0.02em;
263
-
264
- --nav-link-transform: none;
265
- --breadcrumb-transform: none;
266
- --tab-label-transform: none;
267
-
268
- /* Motion */
269
- --transition-fast: 150ms;
270
- --transition-normal: 250ms;
271
- --transition-slow: 400ms;
272
-
273
- --ease-standard: cubic-bezier(0.2, 0, 0.2, 1);
274
- --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
275
- --ease-decelerate: cubic-bezier(0, 0, 0.2, 1);
276
- --ease-accelerate: cubic-bezier(0.4, 0, 1, 1);
277
-
278
- /* Elevation & Overlay */
154
+ /* Shadows */
279
155
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
280
156
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
281
157
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.08);
282
158
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
283
159
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.1);
284
160
 
285
- --overlay-scrim: rgba(0, 0, 0, 0.5);
286
- --backdrop-blur: 8px;
287
-
288
- /* Layers */
289
- --z-base: 0;
290
- --z-backdrop: 1245;
291
- --z-dropdown: 1000;
292
- --z-sticky: 1100;
293
- --z-banner: 1150;
294
- --z-modal: 1200;
295
- --z-drawer: 1250;
296
- --z-popover: 1300;
297
- --z-tooltip: 1400;
298
- --z-toast: 1500;
299
-
300
161
  /* Data viz */
301
162
  --viz-cat-1: #2563eb;
302
163
  --viz-cat-2: #16a34a;
@@ -309,30 +170,12 @@ html[data-theme='light'] {
309
170
  --viz-seq-mid: #60a5fa;
310
171
  --viz-seq-end: #1d4ed8;
311
172
 
312
- /* Skeletons & loaders */
173
+ /* Skeletons */
313
174
  --skeleton-base: #e5e7eb;
314
175
  --skeleton-pulse: #f3f4f6;
315
- --spinner-size: 16px;
316
- --spinner-stroke: 2px;
317
-
318
- /* Logical spacing */
319
- --space-inline-sm: 8px;
320
- }
321
-
322
- /* Reduced motion */
323
- @media (prefers-reduced-motion: reduce) {
324
- :root {
325
- --transition-fast: 1ms;
326
- --transition-normal: 1ms;
327
- --transition-slow: 1ms;
328
- }
329
- * {
330
- animation: none !important;
331
- transition-duration: 1ms !important;
332
- }
333
176
  }
334
177
 
335
- /* High-contrast variant */
178
+ /* High-contrast variant (theme override) */
336
179
  :root[data-contrast='high'] {
337
180
  --color-border-subtle: #4b5563;
338
181
  --color-border-default: #374151;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Safely read from localStorage.
3
+ * - Returns undefined if not in browser
4
+ * - Returns parsed JSON if value is JSON
5
+ * - Returns plain string if not JSON
6
+ * - Never throws
7
+ */
8
+ export declare function readLocalStorage<T = unknown>(key: string): T | string | undefined;
9
+ /**
10
+ * Safely write to localStorage.
11
+ * - Automatically JSON.stringifies objects/arrays
12
+ * - Stores plain strings as-is
13
+ * - Never throws
14
+ */
15
+ export declare function writeLocalStorage(key: string, value: unknown): void;
16
+ /**
17
+ * Remove key safely
18
+ */
19
+ export declare function removeLocalStorage(key: string): void;
@@ -0,0 +1,78 @@
1
+ function isBrowser() {
2
+ return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
3
+ }
4
+ /**
5
+ * Safely read from localStorage.
6
+ * - Returns undefined if not in browser
7
+ * - Returns parsed JSON if value is JSON
8
+ * - Returns plain string if not JSON
9
+ * - Never throws
10
+ */
11
+ export function readLocalStorage(key) {
12
+ if (!isBrowser())
13
+ return undefined;
14
+ try {
15
+ const raw = window.localStorage.getItem(key);
16
+ if (raw == null)
17
+ return undefined;
18
+ // Try parse once
19
+ try {
20
+ const parsed = JSON.parse(raw);
21
+ // Handle double-stringified JSON
22
+ if (typeof parsed === 'string') {
23
+ try {
24
+ return JSON.parse(parsed);
25
+ }
26
+ catch {
27
+ return parsed;
28
+ }
29
+ }
30
+ return parsed;
31
+ }
32
+ catch {
33
+ // Not JSON — return as plain string
34
+ return raw;
35
+ }
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ }
41
+ /**
42
+ * Safely write to localStorage.
43
+ * - Automatically JSON.stringifies objects/arrays
44
+ * - Stores plain strings as-is
45
+ * - Never throws
46
+ */
47
+ export function writeLocalStorage(key, value) {
48
+ if (!isBrowser())
49
+ return;
50
+ try {
51
+ if (value === undefined) {
52
+ window.localStorage.removeItem(key);
53
+ return;
54
+ }
55
+ if (typeof value === 'string') {
56
+ window.localStorage.setItem(key, value);
57
+ }
58
+ else {
59
+ window.localStorage.setItem(key, JSON.stringify(value));
60
+ }
61
+ }
62
+ catch {
63
+ // ignore quota errors etc.
64
+ }
65
+ }
66
+ /**
67
+ * Remove key safely
68
+ */
69
+ export function removeLocalStorage(key) {
70
+ if (!isBrowser())
71
+ return;
72
+ try {
73
+ window.localStorage.removeItem(key);
74
+ }
75
+ catch {
76
+ // ignore
77
+ }
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbcdk/react-components",
3
- "version": "0.0.10",
3
+ "version": "0.0.13",
4
4
  "description": "Reusable React components for DBC projects",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -63,9 +63,9 @@
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@tanstack/react-table": "^8.21.3",
66
- "lucide-react": "^0.543.0",
67
- "react": "^19.2.0 || ^19.0.0",
68
- "react-dom": "^19.2.0 || ^19.0.0"
66
+ "lucide-react": ">=0.543.0 <1",
67
+ "react": "^19.0.0",
68
+ "react-dom": "^19.0.0"
69
69
  },
70
70
  "peerDependenciesMeta": {
71
71
  "@tanstack/react-table": {
@@ -1,162 +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 ColumnResizer from './components/column-resizer/ColumnResizer';
6
- import { Table } from './Table';
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 mapDefsToColumnItems(defs) {
16
- return defs.map((def, index) => {
17
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
18
- const id = getColumnId(def, index);
19
- const accessorKey = def.accessorKey;
20
- const accessorFn = def.accessorFn;
21
- const cell = def.cell;
22
- let render;
23
- if (typeof cell === 'function') {
24
- render = (row) => cell({
25
- row: { original: row },
26
- getValue: () => accessorKey != null
27
- ? row[accessorKey]
28
- : accessorFn
29
- ? accessorFn(row)
30
- : undefined,
31
- });
32
- }
33
- else if (accessorFn) {
34
- render = (row) => accessorFn(row);
35
- }
36
- else if (accessorKey != null) {
37
- render = (row) => row[accessorKey];
38
- }
39
- else {
40
- render = () => null;
41
- }
42
- return {
43
- id,
44
- header: def.header,
45
- accessor: accessorKey,
46
- sortable: (_a = def.enableSorting) !== null && _a !== void 0 ? _a : !!accessorKey,
47
- render,
48
- hidden: (_c = (_b = def.meta) === null || _b === void 0 ? void 0 : _b.hidden) !== null && _c !== void 0 ? _c : false,
49
- align: (_e = (_d = def.meta) === null || _d === void 0 ? void 0 : _d.align) !== null && _e !== void 0 ? _e : undefined,
50
- verticalAlign: (_g = (_f = def.meta) === null || _f === void 0 ? void 0 : _f.verticalAlign) !== null && _g !== void 0 ? _g : undefined,
51
- fitContent: (_j = (_h = def.meta) === null || _h === void 0 ? void 0 : _h.fitContent) !== null && _j !== void 0 ? _j : false,
52
- emptyPlaceholder: (_l = (_k = def.meta) === null || _k === void 0 ? void 0 : _k.emptyPlaceholder) !== null && _l !== void 0 ? _l : '-',
53
- allowWrap: (_o = (_m = def.meta) === null || _m === void 0 ? void 0 : _m.allowWrap) !== null && _o !== void 0 ? _o : false,
54
- fillWidth: (_q = (_p = def.meta) === null || _p === void 0 ? void 0 : _p.fillWidth) !== null && _q !== void 0 ? _q : false,
55
- severity: (_s = (_r = def.meta) === null || _r === void 0 ? void 0 : _r.severity) !== null && _s !== void 0 ? _s : undefined,
56
- };
57
- });
58
- }
59
- export function TanstackTable(props) {
60
- var _a, _b;
61
- const { data, dataKey, columns, filterable = [], onSortingChange, ...tableProps } = props;
62
- const [sorting, setSorting] = React.useState([]);
63
- const [columnFilters, setColumnFilters] = React.useState([]);
64
- const [columnSizing, setColumnSizing] = React.useState({});
65
- const table = useReactTable({
66
- data,
67
- columns: columns,
68
- state: { sorting, columnFilters, columnSizing },
69
- onSortingChange: setSorting,
70
- onColumnFiltersChange: setColumnFilters,
71
- onColumnSizingChange: setColumnSizing,
72
- getCoreRowModel: getCoreRowModel(),
73
- getSortedRowModel: getSortedRowModel(),
74
- getFilteredRowModel: getFilteredRowModel(),
75
- enableColumnResizing: true,
76
- columnResizeMode: 'onChange',
77
- defaultColumn: {
78
- enableResizing: true,
79
- minSize: 80,
80
- size: 180,
81
- maxSize: 800,
82
- },
83
- });
84
- const columnItems = React.useMemo(() => mapDefsToColumnItems(columns), [columns]);
85
- const visibleData = table.getRowModel().rows.map(r => r.original);
86
- const s = (_a = table.getState().sorting) === null || _a === void 0 ? void 0 : _a[0];
87
- const sortById = (_b = s === null || s === void 0 ? void 0 : s.id) !== null && _b !== void 0 ? _b : undefined;
88
- const sortDirection = s ? (s.desc ? 'desc' : 'asc') : null;
89
- const gridTemplateColumns = React.useMemo(() => {
90
- return columnItems
91
- .filter(ci => !ci.hidden)
92
- .map(ci => {
93
- var _a;
94
- const col = table.getColumn(ci.id);
95
- const w = (_a = col === null || col === void 0 ? void 0 : col.getSize) === null || _a === void 0 ? void 0 : _a.call(col);
96
- if (ci.fillWidth)
97
- return '1fr';
98
- if (ci.fitContent)
99
- return '1%';
100
- return `${w !== null && w !== void 0 ? w : 180}px`;
101
- })
102
- .join(' ');
103
- }, [columnItems, table]);
104
- const columnStyles = React.useMemo(() => {
105
- const styles = {};
106
- for (const c of table.getAllLeafColumns()) {
107
- const id = c.id;
108
- const ci = columnItems.find(x => x.id === id);
109
- if (ci === null || ci === void 0 ? void 0 : ci.fillWidth) {
110
- styles[id] = { width: 'auto', minWidth: 0 };
111
- }
112
- else if (ci === null || ci === void 0 ? void 0 : ci.fitContent) {
113
- styles[id] = { width: '1%', whiteSpace: 'nowrap' };
114
- }
115
- else {
116
- const w = c.getSize();
117
- styles[id] = { width: w, minWidth: w, maxWidth: w };
118
- }
119
- }
120
- return styles;
121
- }, [table, columnItems]);
122
- const headerExtras = React.useCallback(({ index }) => {
123
- var _a, _b, _c, _d;
124
- const headerGroups = table.getHeaderGroups();
125
- const leafHeaders = headerGroups.length > 0 ? headerGroups[headerGroups.length - 1].headers : [];
126
- const header = leafHeaders[index];
127
- if (!header)
128
- return null;
129
- const canResize = (_c = (_b = (_a = header.column).getCanResize) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false;
130
- const handler = (_d = header.getResizeHandler) === null || _d === void 0 ? void 0 : _d.call(header);
131
- if (!canResize || !handler)
132
- return null;
133
- return _jsx(ColumnResizer, { id: header.column.id, handler: handler });
134
- }, [table]);
135
- const headerBelowRow = React.useMemo(() => {
136
- if (!(filterable === null || filterable === void 0 ? void 0 : filterable.length))
137
- return null;
138
- return (_jsx("div", { style: { display: 'grid', gridTemplateColumns, gap: 8 }, children: columnItems
139
- .filter(ci => !ci.hidden)
140
- .map(ci => {
141
- var _a;
142
- const id = ci.id;
143
- const isFilterable = filterable.includes(id);
144
- if (!isFilterable)
145
- return _jsx("div", {}, id);
146
- const col = table.getColumn(id);
147
- const value = (_a = col === null || col === void 0 ? void 0 : col.getFilterValue()) !== null && _a !== void 0 ? _a : '';
148
- 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));
149
- }) }));
150
- }, [columnItems, filterable, table, gridTemplateColumns]);
151
- return (_jsx(Table, { ...tableProps, dataKey: dataKey, data: visibleData, columns: columnItems, sortById: sortById, sortDirection: sortDirection, onSortChange: (col, dir) => {
152
- var _a, _b, _c;
153
- const id = String(col.id);
154
- if (!id)
155
- return;
156
- if (!dir)
157
- table.setSorting([]);
158
- else
159
- table.setSorting([{ id, desc: dir === 'desc' }]);
160
- onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange((_c = (_b = (_a = table.getState().sorting) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : null, dir);
161
- }, headerExtras: headerExtras, columnStyles: columnStyles, headerBelowRow: headerBelowRow }));
162
- }