@umituz/web-dashboard 9.0.2 → 10.1.0
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/package.json +1 -1
- package/src/domains/layouts/components/DashboardHeader.tsx +13 -7
- package/src/domains/layouts/components/DashboardLayout.test.tsx +38 -1
- package/src/domains/layouts/components/DashboardLayout.tsx +0 -2
- package/src/domains/layouts/components/DashboardSidebar.tsx +30 -26
- package/src/domains/layouts/components/labels.ts +3 -2
- package/src/domains/layouts/types/layout.ts +2 -1
- package/src/styles/chrome.css +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/web-dashboard",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Installable app skeleton for the fleet — layouts, analytics (dependency-free SVG charts), calendar, onboarding flow permissions/module registry; udb-* stylesheet on design-system tokens",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Bell, X, Sun, Moon, Menu, User, Settings, LogOut,
|
|
3
|
-
ChevronDown, Search
|
|
3
|
+
ChevronDown, Search, PanelLeftOpen, PanelLeftClose
|
|
4
4
|
} from "lucide-react";
|
|
5
5
|
import { Button, Kbd } from "@umituz/web-design-system/atoms";
|
|
6
6
|
import { Avatar, AvatarImage } from "@umituz/web-design-system/molecules";
|
|
@@ -82,12 +82,18 @@ export const DashboardHeader = ({
|
|
|
82
82
|
<Menu className="udb-header__toggle-icon" />
|
|
83
83
|
</Button>
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
<Button
|
|
86
|
+
variant="ghost"
|
|
87
|
+
size="icon"
|
|
88
|
+
className="udb-header__desktop-toggle"
|
|
89
|
+
onClick={() => setCollapsed(!collapsed)}
|
|
90
|
+
title={collapsed ? labels.expandSidebar : labels.collapseSidebar}
|
|
91
|
+
aria-label={collapsed ? labels.expandSidebar : labels.collapseSidebar}
|
|
92
|
+
>
|
|
93
|
+
{collapsed
|
|
94
|
+
? <PanelLeftOpen className="udb-header__toggle-icon" aria-hidden="true" />
|
|
95
|
+
: <PanelLeftClose className="udb-header__toggle-icon" aria-hidden="true" />}
|
|
96
|
+
</Button>
|
|
91
97
|
<h2 className="udb-header__title">
|
|
92
98
|
{title}
|
|
93
99
|
</h2>
|
|
@@ -191,7 +191,7 @@ describe("DashboardSidebar (secondaryLabel)", () => {
|
|
|
191
191
|
</Routes>
|
|
192
192
|
</MemoryRouter>
|
|
193
193
|
);
|
|
194
|
-
const toggle = document.querySelector<HTMLButtonElement>("button.udb-
|
|
194
|
+
const toggle = document.querySelector<HTMLButtonElement>("button.udb-header__desktop-toggle");
|
|
195
195
|
toggle?.click();
|
|
196
196
|
expect(onCollapsedChange).toHaveBeenCalledWith(true);
|
|
197
197
|
});
|
|
@@ -221,6 +221,43 @@ describe("DashboardSidebar (untitled group)", () => {
|
|
|
221
221
|
});
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
+
describe("DashboardSidebar (exclusive accordion)", () => {
|
|
225
|
+
const accordionConfig: DashboardLayoutConfig = {
|
|
226
|
+
sidebarGroups: [
|
|
227
|
+
{
|
|
228
|
+
title: "Alpha",
|
|
229
|
+
items: [{ path: "/alpha", label: "Alpha page", icon: Home, end: false }],
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
title: "Beta",
|
|
233
|
+
items: [{ path: "/beta", label: "Beta page", icon: Home, end: false }],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
brandName: "Test",
|
|
237
|
+
defaultTitle: "Workspace",
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
it("opens only the group containing the active route", () => {
|
|
241
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
242
|
+
expect(screen.getByRole("link", { name: /alpha page/i })).toBeTruthy();
|
|
243
|
+
expect(screen.queryByRole("link", { name: /beta page/i })).toBeNull();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("switches to the clicked group and closes the previous one", () => {
|
|
247
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
248
|
+
fireEvent.click(screen.getByRole("button", { name: /beta/i }));
|
|
249
|
+
expect(screen.getByRole("link", { name: /beta page/i })).toBeTruthy();
|
|
250
|
+
expect(screen.queryByRole("link", { name: /alpha page/i })).toBeNull();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("closes the open group on a second click", () => {
|
|
254
|
+
renderAt("/alpha", { config: accordionConfig });
|
|
255
|
+
const alpha = screen.getByRole("button", { name: /alpha/i });
|
|
256
|
+
fireEvent.click(alpha);
|
|
257
|
+
expect(screen.queryByRole("link", { name: /alpha page/i })).toBeNull();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
224
261
|
describe("DashboardLayout (contentFallback)", () => {
|
|
225
262
|
const NeverResolves = lazy(() => new Promise<{ default: React.ComponentType }>(() => {}));
|
|
226
263
|
|
|
@@ -190,7 +190,6 @@ export const DashboardLayout = ({
|
|
|
190
190
|
>
|
|
191
191
|
<DashboardSidebar
|
|
192
192
|
collapsed={collapsed}
|
|
193
|
-
setCollapsed={setCollapsed}
|
|
194
193
|
{...sidebarProps}
|
|
195
194
|
/>
|
|
196
195
|
</aside>
|
|
@@ -206,7 +205,6 @@ export const DashboardLayout = ({
|
|
|
206
205
|
>
|
|
207
206
|
<DashboardSidebar
|
|
208
207
|
collapsed={false}
|
|
209
|
-
setCollapsed={() => setMobileOpen(false)}
|
|
210
208
|
{...sidebarProps}
|
|
211
209
|
/>
|
|
212
210
|
</aside>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useState, type ReactNode } from "react";
|
|
1
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
2
2
|
import { Link, useLocation } from "react-router";
|
|
3
3
|
|
|
4
4
|
import { Button } from "@umituz/web-design-system/atoms";
|
|
5
5
|
import { cn } from "@umituz/web-design-system/utils/cn";
|
|
6
6
|
import { BrandLogo } from "./BrandLogo";
|
|
7
7
|
import { isPathActive } from "../utils/dashboard";
|
|
8
|
-
import {
|
|
8
|
+
import { ChevronDown, ChevronRight } from "lucide-react";
|
|
9
9
|
import type { DashboardSidebarProps, SidebarAction } from "../types/layout";
|
|
10
10
|
import type { DashboardUser } from "../types/user";
|
|
11
11
|
import type { SidebarGroup } from "../types/sidebar";
|
|
@@ -23,7 +23,6 @@ interface DashboardSidebarPropsExtended extends DashboardSidebarProps {
|
|
|
23
23
|
|
|
24
24
|
export const DashboardSidebar = ({
|
|
25
25
|
collapsed,
|
|
26
|
-
setCollapsed,
|
|
27
26
|
sidebarGroups,
|
|
28
27
|
brandName,
|
|
29
28
|
brandTagline,
|
|
@@ -34,13 +33,21 @@ export const DashboardSidebar = ({
|
|
|
34
33
|
user,
|
|
35
34
|
}: DashboardSidebarPropsExtended) => {
|
|
36
35
|
const location = useLocation();
|
|
37
|
-
const
|
|
36
|
+
const activeGroupTitle = () =>
|
|
37
|
+
sidebarGroups.find(group =>
|
|
38
|
+
group.items.some(item => isPathActive(location.pathname, item.path, item.end))
|
|
39
|
+
)?.title ?? null;
|
|
40
|
+
const [openGroup, setOpenGroup] = useState<string | null>(activeGroupTitle);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setOpenGroup(prev => {
|
|
44
|
+
const next = activeGroupTitle();
|
|
45
|
+
return next === null ? prev : next;
|
|
46
|
+
});
|
|
47
|
+
}, [location.pathname]);
|
|
38
48
|
|
|
39
49
|
const toggleGroup = (title: string) => {
|
|
40
|
-
|
|
41
|
-
...prev,
|
|
42
|
-
[title]: !prev[title]
|
|
43
|
-
}));
|
|
50
|
+
setOpenGroup(prev => (prev === title ? null : title));
|
|
44
51
|
};
|
|
45
52
|
|
|
46
53
|
const renderAction = (label: string, icon: ReactNode, linkProps?: { to: string }) => {
|
|
@@ -96,7 +103,7 @@ export const DashboardSidebar = ({
|
|
|
96
103
|
|
|
97
104
|
const groupTitle = group.title;
|
|
98
105
|
const groupKey = groupTitle ?? `group-${groupIndex}`;
|
|
99
|
-
const
|
|
106
|
+
const isGroupOpen = groupTitle !== undefined && openGroup === groupTitle;
|
|
100
107
|
|
|
101
108
|
return (
|
|
102
109
|
<div key={groupKey} className="udb-sidebar__group">
|
|
@@ -111,10 +118,10 @@ export const DashboardSidebar = ({
|
|
|
111
118
|
</span>
|
|
112
119
|
|
|
113
120
|
<span className="udb-sidebar__group-chevron">
|
|
114
|
-
{
|
|
115
|
-
<ChevronRight className="udb-sidebar__chevron-icon" />
|
|
116
|
-
) : (
|
|
121
|
+
{isGroupOpen ? (
|
|
117
122
|
<ChevronDown className="udb-sidebar__chevron-icon" />
|
|
123
|
+
) : (
|
|
124
|
+
<ChevronRight className="udb-sidebar__chevron-icon" />
|
|
118
125
|
)}
|
|
119
126
|
</span>
|
|
120
127
|
|
|
@@ -122,7 +129,7 @@ export const DashboardSidebar = ({
|
|
|
122
129
|
|
|
123
130
|
)}
|
|
124
131
|
|
|
125
|
-
{(
|
|
132
|
+
{(groupTitle === undefined || isGroupOpen || collapsed) && filteredItems.map((item) => {
|
|
126
133
|
const active = isPathActive(location.pathname, item.path, item.end);
|
|
127
134
|
const collapsedTitle =
|
|
128
135
|
item.badge !== undefined && item.badge !== ""
|
|
@@ -158,20 +165,17 @@ export const DashboardSidebar = ({
|
|
|
158
165
|
|
|
159
166
|
</nav>
|
|
160
167
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
{!collapsed && labels?.system && (
|
|
165
|
-
<p className="udb-sidebar__footer-label">
|
|
166
|
-
{labels.system}
|
|
167
|
-
</p>
|
|
168
|
+
{(sidebarFooter || (!collapsed && labels?.system)) && (
|
|
169
|
+
<div className="udb-sidebar__footer">
|
|
170
|
+
{sidebarFooter && <div className="udb-sidebar__footer-slot">{sidebarFooter}</div>}
|
|
168
171
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
{!collapsed && labels?.system && (
|
|
173
|
+
<p className="udb-sidebar__footer-label">
|
|
174
|
+
{labels.system}
|
|
175
|
+
</p>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
)}
|
|
175
179
|
|
|
176
180
|
</div>
|
|
177
181
|
|
|
@@ -3,14 +3,15 @@ import type { DashboardLayoutLabels } from '../types/layout';
|
|
|
3
3
|
/**
|
|
4
4
|
* English shell labels — the reference text for `DashboardLayout`.
|
|
5
5
|
* Hosts rendering English pass this constant instead of re-declaring the
|
|
6
|
-
*
|
|
7
|
-
* shape.
|
|
6
|
+
* strings; localized hosts build their own object from the same shape.
|
|
8
7
|
*/
|
|
9
8
|
export const defaultLayoutLabels: DashboardLayoutLabels = {
|
|
10
9
|
skipToContent: 'Skip to content',
|
|
11
10
|
navigation: 'Navigation',
|
|
12
11
|
searchResults: 'Search results',
|
|
13
12
|
header: {
|
|
13
|
+
expandSidebar: 'Expand sidebar',
|
|
14
|
+
collapseSidebar: 'Collapse sidebar',
|
|
14
15
|
switchToLight: 'Switch to light',
|
|
15
16
|
switchToDark: 'Switch to dark',
|
|
16
17
|
notificationsTitle: 'Notifications',
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export interface DashboardHeaderLabels {
|
|
2
|
+
expandSidebar: string;
|
|
3
|
+
collapseSidebar: string;
|
|
2
4
|
switchToLight: string;
|
|
3
5
|
switchToDark: string;
|
|
4
6
|
notificationsTitle: string;
|
|
@@ -74,7 +76,6 @@ export interface CommandPaletteConfig {
|
|
|
74
76
|
|
|
75
77
|
export interface DashboardSidebarProps {
|
|
76
78
|
collapsed: boolean;
|
|
77
|
-
setCollapsed: (collapsed: boolean) => void;
|
|
78
79
|
labels?: DashboardSidebarLabels;
|
|
79
80
|
}
|
|
80
81
|
|
package/src/styles/chrome.css
CHANGED
|
@@ -335,13 +335,6 @@
|
|
|
335
335
|
letter-spacing: 0.1em;
|
|
336
336
|
color: var(--udb-sidebar-muted);
|
|
337
337
|
}
|
|
338
|
-
.udb-sidebar__footer-btn {
|
|
339
|
-
color: var(--udb-sidebar-text);
|
|
340
|
-
}
|
|
341
|
-
.udb-sidebar__footer-icon {
|
|
342
|
-
width: 16px;
|
|
343
|
-
height: 16px;
|
|
344
|
-
}
|
|
345
338
|
.udb-header {
|
|
346
339
|
display: flex;
|
|
347
340
|
height: var(--udb-header-height);
|