@dbcdk/react-components 0.0.10 → 0.0.12
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/card/Card.d.ts +21 -3
- package/dist/components/card/Card.js +17 -2
- package/dist/components/card/Card.module.css +59 -0
- package/dist/components/circle/Circle.d.ts +2 -1
- package/dist/components/circle/Circle.js +2 -2
- package/dist/components/circle/Circle.module.css +6 -2
- package/dist/components/code-block/CodeBlock.js +1 -1
- package/dist/components/code-block/CodeBlock.module.css +30 -17
- package/dist/components/copy-button/CopyButton.d.ts +1 -0
- package/dist/components/copy-button/CopyButton.js +10 -2
- package/dist/components/filter-field/FilterField.js +16 -11
- package/dist/components/filter-field/FilterField.module.css +133 -12
- package/dist/components/forms/checkbox/Checkbox.d.ts +2 -2
- package/dist/components/forms/checkbox-group/CheckboxGroup.js +1 -1
- package/dist/components/forms/checkbox-group/CheckboxGroup.module.css +1 -1
- package/dist/components/forms/input/Input.js +1 -1
- package/dist/components/forms/input/Input.module.css +1 -0
- package/dist/components/forms/input-container/InputContainer.module.css +1 -1
- package/dist/components/hyperlink/Hyperlink.d.ts +19 -7
- package/dist/components/hyperlink/Hyperlink.js +35 -11
- package/dist/components/hyperlink/Hyperlink.module.css +50 -2
- package/dist/components/menu/Menu.d.ts +32 -0
- package/dist/components/menu/Menu.js +73 -13
- package/dist/components/menu/Menu.module.css +72 -4
- package/dist/components/overlay/modal/Modal.module.css +2 -2
- package/dist/components/overlay/side-panel/SidePanel.js +17 -0
- package/dist/components/overlay/side-panel/SidePanel.module.css +0 -2
- package/dist/components/overlay/tooltip/useTooltipTrigger.js +4 -2
- package/dist/components/popover/Popover.js +1 -1
- package/dist/components/sidebar/components/expandable-sidebar-item/ExpandableSidebarItem.js +22 -18
- package/dist/components/sidebar/providers/SidebarProvider.d.ts +4 -1
- package/dist/components/sidebar/providers/SidebarProvider.js +66 -18
- package/dist/components/split-button/SplitButton.d.ts +1 -1
- package/dist/components/split-button/SplitButton.js +3 -1
- package/dist/components/split-button/SplitButton.module.css +4 -4
- package/dist/components/state-page/StatePage.module.css +1 -1
- package/dist/components/table/Table.d.ts +9 -4
- package/dist/components/table/Table.js +3 -6
- package/dist/components/table/Table.module.css +18 -5
- package/dist/components/table/components/table-settings/TableSettings.d.ts +13 -3
- package/dist/components/table/components/table-settings/TableSettings.js +55 -4
- package/dist/components/table/tanstack.d.ts +12 -1
- package/dist/components/table/tanstack.js +75 -23
- package/dist/hooks/useTableSettings.d.ts +23 -4
- package/dist/hooks/useTableSettings.js +64 -17
- package/dist/src/styles/styles.css +38 -22
- package/dist/styles/animation.d.ts +5 -0
- package/dist/styles/animation.js +5 -0
- package/dist/styles/styles.css +38 -22
- package/dist/utils/localStorage.utils.d.ts +19 -0
- package/dist/utils/localStorage.utils.js +78 -0
- package/package.json +1 -1
|
@@ -1,7 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ColumnDef } from '@tanstack/react-table';
|
|
2
|
+
export type ViewMode = 'compact' | 'wrapped';
|
|
3
|
+
export type TableSettingsState = {
|
|
3
4
|
viewMode: ViewMode;
|
|
4
|
-
|
|
5
|
+
visibleColumnIds: string[];
|
|
6
|
+
};
|
|
7
|
+
export type TableSettingsStorage = {
|
|
8
|
+
get: (key: string) => TableSettingsState | undefined;
|
|
9
|
+
set: (key: string, next: TableSettingsState) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare const localStorageTableSettingsStorage: TableSettingsStorage;
|
|
12
|
+
interface UseTableSettingsOptions {
|
|
13
|
+
storageKey: string;
|
|
14
|
+
tableColumns?: ColumnDef<any>[];
|
|
15
|
+
defaultViewMode?: ViewMode;
|
|
16
|
+
defaultVisibleColumnIds?: string[];
|
|
17
|
+
storage?: TableSettingsStorage;
|
|
5
18
|
}
|
|
6
|
-
export declare function useTableSettings(storageKey
|
|
19
|
+
export declare function useTableSettings({ storageKey, tableColumns, defaultViewMode, defaultVisibleColumnIds, storage, }: UseTableSettingsOptions): {
|
|
20
|
+
viewMode: ViewMode;
|
|
21
|
+
toggleViewMode: () => void;
|
|
22
|
+
setViewMode: (mode: ViewMode) => void;
|
|
23
|
+
visibleColumnIds: string[];
|
|
24
|
+
setVisibleColumnIds: (ids: string[]) => void;
|
|
25
|
+
};
|
|
7
26
|
export {};
|
|
@@ -1,24 +1,71 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { readLocalStorage, writeLocalStorage } from '../utils/localStorage.utils';
|
|
4
|
+
function getDefaultVisibleIds(tableColumns) {
|
|
5
|
+
var _a;
|
|
6
|
+
return ((_a = tableColumns === null || tableColumns === void 0 ? void 0 : tableColumns.filter(c => { var _a; return !((_a = c.meta) === null || _a === void 0 ? void 0 : _a.hidden); }).map(c => c.id).filter(Boolean)) !== null && _a !== void 0 ? _a : []);
|
|
7
|
+
}
|
|
8
|
+
function mergeDefaults(stored, defaults) {
|
|
9
|
+
const viewMode = (stored === null || stored === void 0 ? void 0 : stored.viewMode) === 'compact' || (stored === null || stored === void 0 ? void 0 : stored.viewMode) === 'wrapped'
|
|
10
|
+
? stored.viewMode
|
|
11
|
+
: defaults.viewMode;
|
|
12
|
+
const visibleColumnIds = Array.isArray(stored === null || stored === void 0 ? void 0 : stored.visibleColumnIds) && stored.visibleColumnIds.length > 0
|
|
13
|
+
? stored.visibleColumnIds
|
|
14
|
+
: defaults.visibleColumnIds;
|
|
15
|
+
return { viewMode, visibleColumnIds };
|
|
16
|
+
}
|
|
17
|
+
export const localStorageTableSettingsStorage = {
|
|
18
|
+
get: key => {
|
|
19
|
+
const v = readLocalStorage(key);
|
|
20
|
+
return v && typeof v === 'object' ? v : undefined;
|
|
21
|
+
},
|
|
22
|
+
set: (key, next) => {
|
|
23
|
+
writeLocalStorage(key, next);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export function useTableSettings({ storageKey, tableColumns, defaultViewMode = 'compact', defaultVisibleColumnIds, storage = localStorageTableSettingsStorage, }) {
|
|
27
|
+
const defaults = useMemo(() => {
|
|
28
|
+
return {
|
|
29
|
+
viewMode: defaultViewMode,
|
|
30
|
+
visibleColumnIds: defaultVisibleColumnIds !== null && defaultVisibleColumnIds !== void 0 ? defaultVisibleColumnIds : getDefaultVisibleIds(tableColumns),
|
|
31
|
+
};
|
|
32
|
+
}, [defaultViewMode, defaultVisibleColumnIds, tableColumns]);
|
|
33
|
+
const [state, setState] = useState(defaults);
|
|
5
34
|
useEffect(() => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
const stored = storage.get(storageKey);
|
|
36
|
+
const next = mergeDefaults(stored, defaults);
|
|
37
|
+
setState(next);
|
|
38
|
+
}, [storageKey, storage, defaults]);
|
|
39
|
+
const persist = useCallback((next) => storage.set(storageKey, next), [storage, storageKey]);
|
|
40
|
+
const setViewMode = useCallback((mode) => {
|
|
41
|
+
setState(prev => {
|
|
42
|
+
if (prev.viewMode === mode)
|
|
43
|
+
return prev;
|
|
44
|
+
const next = { ...prev, viewMode: mode };
|
|
45
|
+
persist(next);
|
|
46
|
+
return next;
|
|
47
|
+
});
|
|
48
|
+
}, [persist]);
|
|
13
49
|
const toggleViewMode = useCallback(() => {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
50
|
+
setState(prev => {
|
|
51
|
+
const nextMode = prev.viewMode === 'wrapped' ? 'compact' : 'wrapped';
|
|
52
|
+
const next = { ...prev, viewMode: nextMode };
|
|
53
|
+
persist(next);
|
|
54
|
+
return next;
|
|
55
|
+
});
|
|
56
|
+
}, [persist]);
|
|
57
|
+
const setVisibleColumnIds = useCallback((ids) => {
|
|
58
|
+
setState(prev => {
|
|
59
|
+
const next = { ...prev, visibleColumnIds: ids };
|
|
60
|
+
persist(next);
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
}, [persist]);
|
|
20
64
|
return {
|
|
21
|
-
viewMode,
|
|
65
|
+
viewMode: state.viewMode,
|
|
22
66
|
toggleViewMode,
|
|
67
|
+
setViewMode,
|
|
68
|
+
visibleColumnIds: state.visibleColumnIds,
|
|
69
|
+
setVisibleColumnIds,
|
|
23
70
|
};
|
|
24
71
|
}
|
|
@@ -61,34 +61,50 @@ body.dbc-app {
|
|
|
61
61
|
|
|
62
62
|
.dbc-table {
|
|
63
63
|
--card-label-width: 260px;
|
|
64
|
+
|
|
64
65
|
border-collapse: collapse;
|
|
65
66
|
font-size: var(--font-size-sm);
|
|
66
67
|
line-height: var(--line-height-normal);
|
|
67
|
-
|
|
68
|
-
tr + tr td {
|
|
69
|
-
padding-block: var(--spacing-xxs);
|
|
70
|
-
}
|
|
68
|
+
}
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
padding-right: var(--spacing-lg);
|
|
77
|
-
vertical-align: top;
|
|
78
|
-
text-align: left;
|
|
79
|
-
}
|
|
70
|
+
.dbc-table tr + tr th,
|
|
71
|
+
.dbc-table tr + tr td {
|
|
72
|
+
padding-block: var(--spacing-xxs);
|
|
73
|
+
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
/* LABELS (th) → match .metaLabel */
|
|
76
|
+
.dbc-table th {
|
|
77
|
+
white-space: nowrap;
|
|
78
|
+
text-align: left;
|
|
79
|
+
vertical-align: top;
|
|
80
|
+
max-width: var(--card-label-width);
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
text-overflow: ellipsis;
|
|
83
|
+
font-size: var(--font-size-xs);
|
|
84
|
+
color: var(--color-fg-subtle);
|
|
85
|
+
letter-spacing: var(--letter-spacing-wide);
|
|
86
|
+
text-transform: uppercase;
|
|
87
|
+
font-weight: var(--font-weight-default);
|
|
88
|
+
padding-right: var(--spacing-lg);
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
/* VALUES (td) → match .metaValue */
|
|
92
|
+
.dbc-table td {
|
|
93
|
+
vertical-align: top;
|
|
94
|
+
min-width: 0;
|
|
95
|
+
|
|
96
|
+
margin: 0; /* harmless on td, keeps parity with metaValue */
|
|
97
|
+
font-size: var(--font-size-sm);
|
|
98
|
+
color: var(--color-fg-default);
|
|
99
|
+
font-weight: var(--font-weight-medium);
|
|
100
|
+
|
|
101
|
+
word-break: break-word;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Optional: baseline alignment closer to metaRow */
|
|
105
|
+
.dbc-table th,
|
|
106
|
+
.dbc-table td {
|
|
107
|
+
vertical-align: baseline;
|
|
92
108
|
}
|
|
93
109
|
|
|
94
110
|
.dbc-full-width {
|
package/dist/styles/styles.css
CHANGED
|
@@ -61,34 +61,50 @@ body.dbc-app {
|
|
|
61
61
|
|
|
62
62
|
.dbc-table {
|
|
63
63
|
--card-label-width: 260px;
|
|
64
|
+
|
|
64
65
|
border-collapse: collapse;
|
|
65
66
|
font-size: var(--font-size-sm);
|
|
66
67
|
line-height: var(--line-height-normal);
|
|
67
|
-
|
|
68
|
-
tr + tr td {
|
|
69
|
-
padding-block: var(--spacing-xxs);
|
|
70
|
-
}
|
|
68
|
+
}
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
padding-right: var(--spacing-lg);
|
|
77
|
-
vertical-align: top;
|
|
78
|
-
text-align: left;
|
|
79
|
-
}
|
|
70
|
+
.dbc-table tr + tr th,
|
|
71
|
+
.dbc-table tr + tr td {
|
|
72
|
+
padding-block: var(--spacing-xxs);
|
|
73
|
+
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
/* LABELS (th) → match .metaLabel */
|
|
76
|
+
.dbc-table th {
|
|
77
|
+
white-space: nowrap;
|
|
78
|
+
text-align: left;
|
|
79
|
+
vertical-align: top;
|
|
80
|
+
max-width: var(--card-label-width);
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
text-overflow: ellipsis;
|
|
83
|
+
font-size: var(--font-size-xs);
|
|
84
|
+
color: var(--color-fg-subtle);
|
|
85
|
+
letter-spacing: var(--letter-spacing-wide);
|
|
86
|
+
text-transform: uppercase;
|
|
87
|
+
font-weight: var(--font-weight-default);
|
|
88
|
+
padding-right: var(--spacing-lg);
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
/* VALUES (td) → match .metaValue */
|
|
92
|
+
.dbc-table td {
|
|
93
|
+
vertical-align: top;
|
|
94
|
+
min-width: 0;
|
|
95
|
+
|
|
96
|
+
margin: 0; /* harmless on td, keeps parity with metaValue */
|
|
97
|
+
font-size: var(--font-size-sm);
|
|
98
|
+
color: var(--color-fg-default);
|
|
99
|
+
font-weight: var(--font-weight-medium);
|
|
100
|
+
|
|
101
|
+
word-break: break-word;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Optional: baseline alignment closer to metaRow */
|
|
105
|
+
.dbc-table th,
|
|
106
|
+
.dbc-table td {
|
|
107
|
+
vertical-align: baseline;
|
|
92
108
|
}
|
|
93
109
|
|
|
94
110
|
.dbc-full-width {
|
|
@@ -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
|
+
}
|