@djangocfg/layouts 2.1.252 → 2.1.255
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 +18 -18
- package/src/layouts/PrivateLayout/PrivateLayout.tsx +22 -0
- package/src/layouts/PrivateLayout/components/PrivateContent.tsx +17 -21
- package/src/layouts/PrivateLayout/components/PrivateSidebar.tsx +136 -92
- package/src/layouts/_components/PrivateSidebarAccount.tsx +139 -103
- package/src/utils/index.ts +1 -0
- package/src/utils/sidebarNav.ts +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.255",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -74,14 +74,14 @@
|
|
|
74
74
|
"check": "tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@djangocfg/api": "^2.1.
|
|
78
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
79
|
-
"@djangocfg/i18n": "^2.1.
|
|
80
|
-
"@djangocfg/monitor": "^2.1.
|
|
81
|
-
"@djangocfg/debuger": "^2.1.
|
|
82
|
-
"@djangocfg/ui-core": "^2.1.
|
|
83
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
84
|
-
"@djangocfg/ui-tools": "^2.1.
|
|
77
|
+
"@djangocfg/api": "^2.1.255",
|
|
78
|
+
"@djangocfg/centrifugo": "^2.1.255",
|
|
79
|
+
"@djangocfg/i18n": "^2.1.255",
|
|
80
|
+
"@djangocfg/monitor": "^2.1.255",
|
|
81
|
+
"@djangocfg/debuger": "^2.1.255",
|
|
82
|
+
"@djangocfg/ui-core": "^2.1.255",
|
|
83
|
+
"@djangocfg/ui-nextjs": "^2.1.255",
|
|
84
|
+
"@djangocfg/ui-tools": "^2.1.255",
|
|
85
85
|
"@hookform/resolvers": "^5.2.2",
|
|
86
86
|
"consola": "^3.4.2",
|
|
87
87
|
"lucide-react": "^0.545.0",
|
|
@@ -109,15 +109,15 @@
|
|
|
109
109
|
"uuid": "^11.1.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@djangocfg/api": "^2.1.
|
|
113
|
-
"@djangocfg/i18n": "^2.1.
|
|
114
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
115
|
-
"@djangocfg/monitor": "^2.1.
|
|
116
|
-
"@djangocfg/debuger": "^2.1.
|
|
117
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
118
|
-
"@djangocfg/ui-core": "^2.1.
|
|
119
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
120
|
-
"@djangocfg/ui-tools": "^2.1.
|
|
112
|
+
"@djangocfg/api": "^2.1.255",
|
|
113
|
+
"@djangocfg/i18n": "^2.1.255",
|
|
114
|
+
"@djangocfg/centrifugo": "^2.1.255",
|
|
115
|
+
"@djangocfg/monitor": "^2.1.255",
|
|
116
|
+
"@djangocfg/debuger": "^2.1.255",
|
|
117
|
+
"@djangocfg/typescript-config": "^2.1.255",
|
|
118
|
+
"@djangocfg/ui-core": "^2.1.255",
|
|
119
|
+
"@djangocfg/ui-nextjs": "^2.1.255",
|
|
120
|
+
"@djangocfg/ui-tools": "^2.1.255",
|
|
121
121
|
"@types/node": "^24.7.2",
|
|
122
122
|
"@types/react": "^19.1.0",
|
|
123
123
|
"@types/react-dom": "^19.1.0",
|
|
@@ -26,6 +26,8 @@ export interface SidebarItem {
|
|
|
26
26
|
href: string;
|
|
27
27
|
icon?: string | LucideIconType;
|
|
28
28
|
badge?: string | number;
|
|
29
|
+
/** Collapsed rail: shown in tooltip; defaults to `label`. */
|
|
30
|
+
tooltip?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export interface SidebarGroupConfig {
|
|
@@ -42,6 +44,16 @@ export interface SidebarConfig {
|
|
|
42
44
|
groups: SidebarGroupConfig[];
|
|
43
45
|
/** Home link href */
|
|
44
46
|
homeHref?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Custom block inside the scrollable nav column, **above** all `groups`
|
|
49
|
+
* (below the brand header, same horizontal padding as nav).
|
|
50
|
+
*/
|
|
51
|
+
menuStart?: ReactNode;
|
|
52
|
+
/**
|
|
53
|
+
* Custom block inside the scrollable nav column, **below** all `groups`
|
|
54
|
+
* (above `footer` + account block).
|
|
55
|
+
*/
|
|
56
|
+
menuEnd?: ReactNode;
|
|
45
57
|
/** Custom footer component rendered at the bottom of the sidebar */
|
|
46
58
|
footer?: ReactNode;
|
|
47
59
|
}
|
|
@@ -49,6 +61,16 @@ export interface SidebarConfig {
|
|
|
49
61
|
export interface HeaderConfig {
|
|
50
62
|
/** Shown next to the logo when the sidebar is expanded */
|
|
51
63
|
title?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Brand mark in the sidebar header (Lucide icon name or component).
|
|
66
|
+
* If omitted, a single-letter monogram from `brandLetter` / `title` is shown.
|
|
67
|
+
*/
|
|
68
|
+
brandIcon?: string | LucideIconType;
|
|
69
|
+
/**
|
|
70
|
+
* Monogram when `brandIcon` is not set (one visible character).
|
|
71
|
+
* Defaults to the first letter of `title`, uppercased.
|
|
72
|
+
*/
|
|
73
|
+
brandLetter?: string;
|
|
52
74
|
/** User menu groups (account panel in the sidebar footer) */
|
|
53
75
|
groups?: UserMenuConfig['groups'];
|
|
54
76
|
/** Auth page path (for sign in button) */
|
|
@@ -22,29 +22,25 @@ export function PrivateContent({
|
|
|
22
22
|
padding = 'default',
|
|
23
23
|
hasSidebar = true,
|
|
24
24
|
}: PrivateContentProps) {
|
|
25
|
+
const mobileToolbarClass = cn(
|
|
26
|
+
'sticky top-0 z-40 flex shrink-0 items-center gap-2 border-b border-border/50 bg-background/95 py-2 pl-2 pr-3 backdrop-blur-md supports-[backdrop-filter]:bg-background/80',
|
|
27
|
+
'md:hidden',
|
|
28
|
+
);
|
|
29
|
+
const scrollAreaClass = cn(
|
|
30
|
+
'min-h-0 flex-1 overflow-y-auto',
|
|
31
|
+
padding === 'default' && 'p-4 sm:p-6 lg:p-8',
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const mobileToolbar = hasSidebar ? (
|
|
35
|
+
<div className={mobileToolbarClass}>
|
|
36
|
+
<SidebarTrigger className="shrink-0" aria-label="Open menu" />
|
|
37
|
+
</div>
|
|
38
|
+
) : null;
|
|
39
|
+
|
|
25
40
|
return (
|
|
26
41
|
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
className={cn(
|
|
30
|
-
'sticky top-0 z-40 flex shrink-0 items-center gap-2 border-b border-border/50 bg-background/95 py-2 pl-2 pr-3 backdrop-blur-md supports-[backdrop-filter]:bg-background/80',
|
|
31
|
-
'md:hidden',
|
|
32
|
-
)}
|
|
33
|
-
>
|
|
34
|
-
<SidebarTrigger
|
|
35
|
-
className="shrink-0"
|
|
36
|
-
aria-label="Open menu"
|
|
37
|
-
/>
|
|
38
|
-
</div>
|
|
39
|
-
)}
|
|
40
|
-
<div
|
|
41
|
-
className={cn(
|
|
42
|
-
'min-h-0 flex-1 overflow-y-auto',
|
|
43
|
-
padding === 'default' && 'p-4 sm:p-6 lg:p-8',
|
|
44
|
-
)}
|
|
45
|
-
>
|
|
46
|
-
{children}
|
|
47
|
-
</div>
|
|
42
|
+
{mobileToolbar}
|
|
43
|
+
<div className={scrollAreaClass}>{children}</div>
|
|
48
44
|
</div>
|
|
49
45
|
);
|
|
50
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Private sidebar: header (brand only when expanded; icon mode shows expand trigger only),
|
|
3
|
-
* nav groups, account footer.
|
|
3
|
+
* nav groups, account footer. Item-count density when **expanded**; collapsed rail always uses `default` metrics so icons match.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
'use client';
|
|
@@ -32,61 +32,70 @@ import { LucideIcon } from '../../../components';
|
|
|
32
32
|
import type { I18nLayoutConfig } from '../../AppLayout/AppLayout';
|
|
33
33
|
import type { HeaderConfig, SidebarItem, SidebarConfig } from '../PrivateLayout';
|
|
34
34
|
|
|
35
|
+
/** Few items → roomier rows; many items → tighter. Same breakpoints for demo, CarAPIS, etc. */
|
|
36
|
+
const DENSITY_COMFORTABLE_MAX = 6;
|
|
37
|
+
const DENSITY_DEFAULT_MAX = 14;
|
|
38
|
+
|
|
35
39
|
type NavDensity = 'comfortable' | 'default' | 'compact';
|
|
36
40
|
|
|
37
41
|
function navDensityFromCount(n: number): NavDensity {
|
|
38
|
-
if (n <=
|
|
39
|
-
if (n <=
|
|
42
|
+
if (n <= DENSITY_COMFORTABLE_MAX) return 'comfortable';
|
|
43
|
+
if (n <= DENSITY_DEFAULT_MAX) return 'default';
|
|
40
44
|
return 'compact';
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
/**
|
|
44
|
-
* Nav rows
|
|
45
|
-
* Avoids `sidebar-accent` in light — project tokens often map to near-black and wash out labels.
|
|
48
|
+
* Nav rows use semantic sidebar tokens so light/dark follows ui-core theme vars.
|
|
46
49
|
*/
|
|
47
50
|
const navItemClass = cn(
|
|
48
51
|
'border-0 font-normal shadow-none transition-colors',
|
|
49
|
-
'text-
|
|
50
|
-
'data-[active=true]:font-medium',
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'data-[active=true]:
|
|
55
|
-
'[&>svg]:shrink-0 [&>svg]:text-muted-foreground [&>svg]:opacity-85',
|
|
56
|
-
'data-[active=true]:[&>svg]:text-zinc-800 data-[active=true]:[&>svg]:opacity-100',
|
|
57
|
-
'dark:data-[active=true]:[&>svg]:text-zinc-50',
|
|
52
|
+
'text-sidebar-foreground/70',
|
|
53
|
+
'data-[active=true]:font-medium data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',
|
|
54
|
+
'hover:bg-sidebar-accent/70 hover:text-sidebar-accent-foreground',
|
|
55
|
+
'data-[active=true]:hover:bg-sidebar-accent',
|
|
56
|
+
'[&>svg]:shrink-0 [&>svg]:text-sidebar-foreground/70 [&>svg]:opacity-85',
|
|
57
|
+
'data-[active=true]:[&>svg]:text-sidebar-accent-foreground data-[active=true]:[&>svg]:opacity-100',
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
const DENSITY = {
|
|
61
61
|
comfortable: {
|
|
62
62
|
menu: 'gap-1.5',
|
|
63
|
-
group: 'gap-
|
|
63
|
+
group: 'gap-2',
|
|
64
|
+
groupPad: 'px-2 py-1',
|
|
64
65
|
label:
|
|
65
|
-
'h-7 uppercase text-[10px] font-light leading-none tracking-[0.14em] text-
|
|
66
|
+
'h-7 uppercase text-[10px] font-light leading-none tracking-[0.14em] text-sidebar-foreground/40',
|
|
66
67
|
buttonSize: 'lg' as const,
|
|
67
68
|
iconClass: 'h-5 w-5',
|
|
68
69
|
extraButton: 'rounded-lg !px-3',
|
|
70
|
+
headerRowInset: 'pl-2',
|
|
69
71
|
},
|
|
70
72
|
default: {
|
|
71
73
|
menu: 'gap-1',
|
|
72
|
-
group: 'gap-
|
|
74
|
+
group: 'gap-1.5',
|
|
75
|
+
groupPad: 'px-2 py-1',
|
|
73
76
|
label:
|
|
74
|
-
'uppercase text-[9px] font-light leading-none tracking-[0.12em] text-
|
|
77
|
+
'uppercase text-[9px] font-light leading-none tracking-[0.12em] text-sidebar-foreground/50',
|
|
75
78
|
buttonSize: 'default' as const,
|
|
76
79
|
iconClass: 'h-4 w-4',
|
|
77
80
|
extraButton: 'rounded-lg',
|
|
81
|
+
headerRowInset: 'pl-1.5',
|
|
78
82
|
},
|
|
79
83
|
compact: {
|
|
80
84
|
menu: 'gap-0.5',
|
|
81
|
-
group: 'gap-
|
|
85
|
+
group: 'gap-0.5',
|
|
86
|
+
groupPad: 'px-2 py-0.5',
|
|
82
87
|
label:
|
|
83
|
-
'h-6 uppercase text-[8px] font-light leading-none tracking-[0.1em] text-
|
|
88
|
+
'h-6 uppercase text-[8px] font-light leading-none tracking-[0.1em] text-sidebar-foreground/40',
|
|
84
89
|
buttonSize: 'sm' as const,
|
|
85
90
|
iconClass: 'h-3.5 w-3.5',
|
|
86
91
|
extraButton: 'rounded-md !px-2',
|
|
92
|
+
headerRowInset: 'pl-1.5',
|
|
87
93
|
},
|
|
88
94
|
} as const;
|
|
89
95
|
|
|
96
|
+
/** Icon rail: always the same geometry — ignore comfortable/compact (larger/smaller rows only when expanded). */
|
|
97
|
+
const RAIL_NAV = DENSITY.default;
|
|
98
|
+
|
|
90
99
|
interface PrivateSidebarProps {
|
|
91
100
|
sidebar: SidebarConfig;
|
|
92
101
|
header?: HeaderConfig;
|
|
@@ -104,6 +113,7 @@ export function PrivateSidebar({ sidebar, header, i18n, pathname: pathnameProp }
|
|
|
104
113
|
if (isMobile) setOpenMobile(false);
|
|
105
114
|
}, [pathname, isMobile, setOpenMobile]);
|
|
106
115
|
const brandTitle = header?.title?.trim() || 'Dashboard';
|
|
116
|
+
const brandMonogram = (header?.brandLetter?.trim().charAt(0) || brandTitle.charAt(0) || 'D').toUpperCase();
|
|
107
117
|
|
|
108
118
|
const allItems = React.useMemo(
|
|
109
119
|
() => sidebar.groups.flatMap((g) => g.items),
|
|
@@ -111,86 +121,120 @@ export function PrivateSidebar({ sidebar, header, i18n, pathname: pathnameProp }
|
|
|
111
121
|
);
|
|
112
122
|
|
|
113
123
|
const density = React.useMemo(() => navDensityFromCount(allItems.length), [allItems.length]);
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
(
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
const tierNav = DENSITY[density];
|
|
125
|
+
/** Expanded: follow item-count tier; collapsed rail: fixed `default` sizing so icons stay uniform. */
|
|
126
|
+
const menuNav = state === 'collapsed' ? RAIL_NAV : tierNav;
|
|
127
|
+
|
|
128
|
+
const isActive = React.useCallback(
|
|
129
|
+
(href: string) => {
|
|
130
|
+
const matches = pathname === href || pathname.startsWith(`${href}/`);
|
|
131
|
+
if (!matches) return false;
|
|
132
|
+
return !allItems.some(
|
|
133
|
+
(other) =>
|
|
134
|
+
other.href !== href &&
|
|
135
|
+
other.href.startsWith(`${href}/`) &&
|
|
136
|
+
(pathname === other.href || pathname.startsWith(`${other.href}/`)),
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
[pathname, allItems],
|
|
140
|
+
);
|
|
126
141
|
|
|
127
142
|
const expanded = state === 'expanded';
|
|
128
143
|
|
|
144
|
+
const headerRowClass = cn('flex items-center gap-2', tierNav.headerRowInset);
|
|
145
|
+
const brandMark = header?.brandIcon ? (
|
|
146
|
+
<LucideIcon icon={header.brandIcon} className="h-4 w-4 text-sidebar-primary-foreground" />
|
|
147
|
+
) : (
|
|
148
|
+
<span className="text-[11px] font-bold leading-none tracking-tight text-sidebar-primary-foreground">
|
|
149
|
+
{brandMonogram}
|
|
150
|
+
</span>
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const showMenuStart = sidebar.menuStart != null && sidebar.menuStart !== false;
|
|
154
|
+
const showMenuEnd = sidebar.menuEnd != null && sidebar.menuEnd !== false;
|
|
155
|
+
const menuStartSlot = showMenuStart ? (
|
|
156
|
+
<div className="w-full min-w-0 shrink-0 px-2">{sidebar.menuStart}</div>
|
|
157
|
+
) : null;
|
|
158
|
+
const menuEndSlot = showMenuEnd ? (
|
|
159
|
+
<div className="w-full min-w-0 shrink-0 px-2">{sidebar.menuEnd}</div>
|
|
160
|
+
) : null;
|
|
161
|
+
|
|
162
|
+
const sidebarContentClass = cn('gap-2', menuNav.group);
|
|
163
|
+
|
|
164
|
+
const renderedGroups = React.useMemo(() => {
|
|
165
|
+
const navButtonClass = cn(navItemClass, menuNav.extraButton);
|
|
166
|
+
const groupLabelClass = cn('px-2', menuNav.label);
|
|
167
|
+
const sidebarGroupClass = cn('gap-0', menuNav.groupPad);
|
|
168
|
+
|
|
169
|
+
return sidebar.groups.map((group) => {
|
|
170
|
+
if (group.dynamic && group.items.length === 0) return null;
|
|
171
|
+
const items = group.items.map((item: SidebarItem) => {
|
|
172
|
+
const iconProp = typeof item.icon === 'string' ? item.icon : item.icon;
|
|
173
|
+
const tooltipText = item.tooltip ?? item.label;
|
|
174
|
+
return (
|
|
175
|
+
<SidebarMenuItem key={item.href}>
|
|
176
|
+
<SidebarMenuButton
|
|
177
|
+
asChild
|
|
178
|
+
isActive={isActive(item.href)}
|
|
179
|
+
size={menuNav.buttonSize}
|
|
180
|
+
tooltip={tooltipText}
|
|
181
|
+
className={navButtonClass}
|
|
182
|
+
>
|
|
183
|
+
<Link href={item.href}>
|
|
184
|
+
{item.icon ? <LucideIcon icon={iconProp} className={menuNav.iconClass} /> : null}
|
|
185
|
+
<span>{item.label}</span>
|
|
186
|
+
{item.badge ? <SidebarMenuBadge>{item.badge}</SidebarMenuBadge> : null}
|
|
187
|
+
</Link>
|
|
188
|
+
</SidebarMenuButton>
|
|
189
|
+
</SidebarMenuItem>
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<SidebarGroup key={group.label} className={sidebarGroupClass}>
|
|
195
|
+
<SidebarGroupLabel className={groupLabelClass}>{group.label}</SidebarGroupLabel>
|
|
196
|
+
<SidebarGroupContent>
|
|
197
|
+
<SidebarMenu className={menuNav.menu}>{items}</SidebarMenu>
|
|
198
|
+
</SidebarGroupContent>
|
|
199
|
+
</SidebarGroup>
|
|
200
|
+
);
|
|
201
|
+
});
|
|
202
|
+
}, [sidebar.groups, isActive, menuNav]);
|
|
203
|
+
|
|
204
|
+
const expandedHeader = (
|
|
205
|
+
<div className={headerRowClass}>
|
|
206
|
+
<Link
|
|
207
|
+
href={homeHref}
|
|
208
|
+
className="flex min-w-0 flex-1 items-center gap-2 rounded-md py-0.5 outline-none ring-sidebar-ring focus-visible:ring-2"
|
|
209
|
+
>
|
|
210
|
+
<div className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-sidebar-primary">{brandMark}</div>
|
|
211
|
+
<span className="truncate text-sm font-semibold tracking-tight text-sidebar-foreground">{brandTitle}</span>
|
|
212
|
+
</Link>
|
|
213
|
+
<SidebarTrigger className="shrink-0" aria-label="Collapse sidebar" />
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const collapsedHeader = (
|
|
218
|
+
<div className="flex justify-center py-1">
|
|
219
|
+
<SidebarTrigger aria-label="Expand sidebar" />
|
|
220
|
+
</div>
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const sidebarHeaderContent = expanded ? expandedHeader : collapsedHeader;
|
|
224
|
+
const footerExtra = sidebar.footer ? <div className="mb-2">{sidebar.footer}</div> : null;
|
|
225
|
+
|
|
129
226
|
return (
|
|
130
227
|
<Sidebar collapsible="icon">
|
|
131
|
-
<SidebarHeader className="px-2
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
>
|
|
138
|
-
<div className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-primary">
|
|
139
|
-
<span className="text-[11px] font-bold leading-none tracking-tight text-primary-foreground">
|
|
140
|
-
D
|
|
141
|
-
</span>
|
|
142
|
-
</div>
|
|
143
|
-
<span className="truncate text-sm font-semibold tracking-tight text-foreground">
|
|
144
|
-
{brandTitle}
|
|
145
|
-
</span>
|
|
146
|
-
</Link>
|
|
147
|
-
<SidebarTrigger className="shrink-0" aria-label="Collapse sidebar" />
|
|
148
|
-
</div>
|
|
149
|
-
) : (
|
|
150
|
-
<div className="flex justify-center py-0.5">
|
|
151
|
-
<SidebarTrigger aria-label="Expand sidebar" />
|
|
152
|
-
</div>
|
|
153
|
-
)}
|
|
154
|
-
</SidebarHeader>
|
|
155
|
-
|
|
156
|
-
<SidebarContent className={cn('gap-2', d.group)}>
|
|
157
|
-
{sidebar.groups.map((group) => {
|
|
158
|
-
if (group.dynamic && group.items.length === 0) return null;
|
|
159
|
-
return (
|
|
160
|
-
<SidebarGroup key={group.label} className="gap-0">
|
|
161
|
-
<SidebarGroupLabel className={cn('px-2', d.label)}>{group.label}</SidebarGroupLabel>
|
|
162
|
-
<SidebarGroupContent>
|
|
163
|
-
<SidebarMenu className={d.menu}>
|
|
164
|
-
{group.items.map((item: SidebarItem) => (
|
|
165
|
-
<SidebarMenuItem key={item.href}>
|
|
166
|
-
<SidebarMenuButton
|
|
167
|
-
asChild
|
|
168
|
-
isActive={isActive(item.href)}
|
|
169
|
-
size={d.buttonSize}
|
|
170
|
-
className={cn(navItemClass, d.extraButton)}
|
|
171
|
-
>
|
|
172
|
-
<Link href={item.href}>
|
|
173
|
-
{item.icon && (
|
|
174
|
-
<LucideIcon
|
|
175
|
-
icon={typeof item.icon === 'string' ? item.icon : item.icon}
|
|
176
|
-
className={d.iconClass}
|
|
177
|
-
/>
|
|
178
|
-
)}
|
|
179
|
-
<span>{item.label}</span>
|
|
180
|
-
{item.badge && <SidebarMenuBadge>{item.badge}</SidebarMenuBadge>}
|
|
181
|
-
</Link>
|
|
182
|
-
</SidebarMenuButton>
|
|
183
|
-
</SidebarMenuItem>
|
|
184
|
-
))}
|
|
185
|
-
</SidebarMenu>
|
|
186
|
-
</SidebarGroupContent>
|
|
187
|
-
</SidebarGroup>
|
|
188
|
-
);
|
|
189
|
-
})}
|
|
228
|
+
<SidebarHeader className="px-2 pt-3.5 pb-2">{sidebarHeaderContent}</SidebarHeader>
|
|
229
|
+
|
|
230
|
+
<SidebarContent className={sidebarContentClass}>
|
|
231
|
+
{menuStartSlot}
|
|
232
|
+
{renderedGroups}
|
|
233
|
+
{menuEndSlot}
|
|
190
234
|
</SidebarContent>
|
|
191
235
|
|
|
192
236
|
<SidebarFooter className="p-2">
|
|
193
|
-
{
|
|
237
|
+
{footerExtra}
|
|
194
238
|
<PrivateSidebarAccount header={header} i18n={i18n} />
|
|
195
239
|
</SidebarFooter>
|
|
196
240
|
</Sidebar>
|
|
@@ -39,8 +39,28 @@ export function PrivateSidebarAccount({ header, i18n }: PrivateSidebarAccountPro
|
|
|
39
39
|
const { user } = useAuth();
|
|
40
40
|
const handleLogout = useLogout();
|
|
41
41
|
const t = useAppT();
|
|
42
|
-
const { state } = useSidebar();
|
|
43
|
-
const [
|
|
42
|
+
const { state, setOpen: setSidebarOpen } = useSidebar();
|
|
43
|
+
const [accountOpen, setAccountOpen] = React.useState(false);
|
|
44
|
+
const accountRootRef = React.useRef<HTMLDivElement>(null);
|
|
45
|
+
const narrow = state === 'collapsed';
|
|
46
|
+
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (state === 'collapsed') setAccountOpen(false);
|
|
49
|
+
}, [state]);
|
|
50
|
+
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (!accountOpen) return;
|
|
53
|
+
|
|
54
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
55
|
+
const root = accountRootRef.current;
|
|
56
|
+
if (root && !root.contains(event.target as Node)) {
|
|
57
|
+
setAccountOpen(false);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
document.addEventListener('pointerdown', handlePointerDown);
|
|
62
|
+
return () => document.removeEventListener('pointerdown', handlePointerDown);
|
|
63
|
+
}, [accountOpen]);
|
|
44
64
|
|
|
45
65
|
const signOutLabel = t('layouts.profile.signOut');
|
|
46
66
|
|
|
@@ -56,113 +76,129 @@ export function PrivateSidebarAccount({ header, i18n }: PrivateSidebarAccountPro
|
|
|
56
76
|
const displayName = user.display_username || user.email || 'User';
|
|
57
77
|
const userInitial = displayName.charAt(0).toUpperCase();
|
|
58
78
|
const userAvatar = user.avatar || '';
|
|
59
|
-
const narrow = state === 'collapsed';
|
|
60
79
|
const hasEmailOrLinks = Boolean(user.email) || accountLinks.length > 0;
|
|
61
80
|
|
|
81
|
+
const triggerClassName = cn(
|
|
82
|
+
'h-auto min-h-10 w-full gap-2 rounded-md px-2 py-2 text-left hover:bg-sidebar-accent',
|
|
83
|
+
narrow && 'justify-center px-0',
|
|
84
|
+
);
|
|
85
|
+
const chevronClassName = cn(
|
|
86
|
+
'h-4 w-4 shrink-0 text-sidebar-foreground/65 transition-transform duration-200',
|
|
87
|
+
accountOpen && 'rotate-180',
|
|
88
|
+
);
|
|
89
|
+
const accountPanelClassName = cn(
|
|
90
|
+
'mt-2 flex flex-col gap-3 rounded-lg border border-sidebar-border/60 bg-sidebar-accent/45 p-3 shadow-sm',
|
|
91
|
+
'dark:border-sidebar-border dark:bg-sidebar-accent/20',
|
|
92
|
+
);
|
|
93
|
+
const accountActionsClassName = cn(
|
|
94
|
+
'flex min-h-10 items-center gap-2',
|
|
95
|
+
hasEmailOrLinks && 'border-t border-sidebar-border/50 pt-3',
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const onAccountTriggerClick = React.useCallback(() => {
|
|
99
|
+
if (narrow) setSidebarOpen(true);
|
|
100
|
+
}, [narrow, setSidebarOpen]);
|
|
101
|
+
|
|
102
|
+
const accountLinkRows = React.useMemo(
|
|
103
|
+
() =>
|
|
104
|
+
accountLinks.map((item) => {
|
|
105
|
+
const Icon = item.icon;
|
|
106
|
+
return (
|
|
107
|
+
<Link
|
|
108
|
+
key={item.href}
|
|
109
|
+
href={item.href!}
|
|
110
|
+
className="flex items-center gap-2 rounded-md px-2 py-1.5 text-sm leading-snug text-sidebar-foreground transition-colors hover:bg-sidebar-accent"
|
|
111
|
+
>
|
|
112
|
+
{Icon ? <Icon className="h-4 w-4 shrink-0 text-sidebar-foreground/65" /> : null}
|
|
113
|
+
<span className="truncate">{item.label}</span>
|
|
114
|
+
</Link>
|
|
115
|
+
);
|
|
116
|
+
}),
|
|
117
|
+
[accountLinks],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const emailBlock = user.email ? (
|
|
121
|
+
<p className="truncate text-xs leading-snug text-sidebar-foreground/65">{user.email}</p>
|
|
122
|
+
) : null;
|
|
123
|
+
|
|
124
|
+
const accountLinksNav =
|
|
125
|
+
accountLinks.length > 0 ? (
|
|
126
|
+
<nav className="flex max-h-40 flex-col gap-0.5 overflow-y-auto" aria-label="Account">
|
|
127
|
+
{accountLinkRows}
|
|
128
|
+
</nav>
|
|
129
|
+
) : null;
|
|
130
|
+
|
|
131
|
+
const expandedTriggerMeta = narrow ? null : (
|
|
132
|
+
<>
|
|
133
|
+
<span className="min-w-0 flex-1 truncate text-left text-sm font-medium leading-tight text-sidebar-foreground">
|
|
134
|
+
{displayName}
|
|
135
|
+
</span>
|
|
136
|
+
<ChevronDown className={chevronClassName} aria-hidden />
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
const localeThemeGroup = i18n ? (
|
|
141
|
+
<LocaleSwitcher
|
|
142
|
+
locale={i18n.locale}
|
|
143
|
+
locales={i18n.locales}
|
|
144
|
+
onChange={i18n.onLocaleChange}
|
|
145
|
+
variant="ghost"
|
|
146
|
+
size="icon"
|
|
147
|
+
showTriggerLabel={false}
|
|
148
|
+
showIcon={false}
|
|
149
|
+
className="h-8 w-8 shrink-0 text-base leading-none"
|
|
150
|
+
/>
|
|
151
|
+
) : null;
|
|
152
|
+
|
|
62
153
|
return (
|
|
63
|
-
<
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)}
|
|
74
|
-
>
|
|
75
|
-
<Avatar className="h-8 w-8 shrink-0">
|
|
76
|
-
<AvatarImage src={userAvatar} alt={displayName} />
|
|
77
|
-
<AvatarFallback className="text-xs">{userInitial}</AvatarFallback>
|
|
78
|
-
</Avatar>
|
|
79
|
-
{!narrow && (
|
|
80
|
-
<>
|
|
81
|
-
<span className="min-w-0 flex-1 truncate text-left text-sm font-medium leading-tight">
|
|
82
|
-
{displayName}
|
|
83
|
-
</span>
|
|
84
|
-
<ChevronDown
|
|
85
|
-
className={cn(
|
|
86
|
-
'h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200',
|
|
87
|
-
open && 'rotate-180',
|
|
88
|
-
)}
|
|
89
|
-
aria-hidden
|
|
90
|
-
/>
|
|
91
|
-
</>
|
|
92
|
-
)}
|
|
93
|
-
</Button>
|
|
94
|
-
</CollapsibleTrigger>
|
|
95
|
-
|
|
96
|
-
<CollapsibleContent className="overflow-hidden data-[state=closed]:hidden">
|
|
97
|
-
<div
|
|
98
|
-
className={cn(
|
|
99
|
-
'mt-2 flex flex-col gap-3 rounded-lg border border-zinc-200/90 bg-zinc-50/80 p-3 shadow-sm',
|
|
100
|
-
'dark:border-sidebar-border dark:bg-sidebar-accent/15',
|
|
101
|
-
)}
|
|
102
|
-
>
|
|
103
|
-
{user.email && (
|
|
104
|
-
<p className="truncate text-xs leading-snug text-muted-foreground">{user.email}</p>
|
|
105
|
-
)}
|
|
106
|
-
|
|
107
|
-
{accountLinks.length > 0 && (
|
|
108
|
-
<nav className="flex max-h-40 flex-col gap-0.5 overflow-y-auto" aria-label="Account">
|
|
109
|
-
{accountLinks.map((item) => {
|
|
110
|
-
const Icon = item.icon;
|
|
111
|
-
return (
|
|
112
|
-
<Link
|
|
113
|
-
key={item.href}
|
|
114
|
-
href={item.href!}
|
|
115
|
-
className="flex items-center gap-2 rounded-md px-2 py-1.5 text-sm leading-snug text-zinc-800 transition-colors hover:bg-zinc-200/70 dark:text-foreground dark:hover:bg-sidebar-accent"
|
|
116
|
-
>
|
|
117
|
-
{Icon && (
|
|
118
|
-
<Icon className="h-4 w-4 shrink-0 text-zinc-500 dark:text-muted-foreground" />
|
|
119
|
-
)}
|
|
120
|
-
<span className="truncate">{item.label}</span>
|
|
121
|
-
</Link>
|
|
122
|
-
);
|
|
123
|
-
})}
|
|
124
|
-
</nav>
|
|
125
|
-
)}
|
|
126
|
-
|
|
127
|
-
<div
|
|
128
|
-
className={cn(
|
|
129
|
-
'flex min-h-10 items-center gap-2',
|
|
130
|
-
hasEmailOrLinks && 'border-t border-border/50 pt-3 dark:border-sidebar-border/40',
|
|
131
|
-
)}
|
|
154
|
+
<div ref={accountRootRef} className="w-full min-w-0 border-t border-sidebar-border/45 pt-2">
|
|
155
|
+
<Collapsible open={accountOpen} onOpenChange={setAccountOpen} className="w-full min-w-0">
|
|
156
|
+
<CollapsibleTrigger asChild>
|
|
157
|
+
<Button
|
|
158
|
+
type="button"
|
|
159
|
+
variant="ghost"
|
|
160
|
+
aria-expanded={accountOpen}
|
|
161
|
+
aria-label={narrow ? 'Account' : undefined}
|
|
162
|
+
className={triggerClassName}
|
|
163
|
+
onClick={onAccountTriggerClick}
|
|
132
164
|
>
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
165
|
+
<Avatar className="h-8 w-8 shrink-0">
|
|
166
|
+
<AvatarImage src={userAvatar} alt={displayName} />
|
|
167
|
+
<AvatarFallback className="text-xs">{userInitial}</AvatarFallback>
|
|
168
|
+
</Avatar>
|
|
169
|
+
{expandedTriggerMeta}
|
|
170
|
+
</Button>
|
|
171
|
+
</CollapsibleTrigger>
|
|
172
|
+
|
|
173
|
+
<CollapsibleContent className="overflow-hidden data-[state=closed]:hidden">
|
|
174
|
+
<div className={accountPanelClassName}>
|
|
175
|
+
{emailBlock}
|
|
176
|
+
{accountLinksNav}
|
|
177
|
+
|
|
178
|
+
<div className={accountActionsClassName}>
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
onClick={handleLogout}
|
|
182
|
+
className="flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-2 text-left text-sm text-destructive hover:bg-destructive/10"
|
|
183
|
+
>
|
|
184
|
+
<LogOut className="h-4 w-4 shrink-0" />
|
|
185
|
+
<span className="truncate">{signOutLabel}</span>
|
|
186
|
+
</button>
|
|
187
|
+
<div
|
|
188
|
+
className="flex shrink-0 items-center gap-0.5 border-l border-sidebar-border/50 pl-2"
|
|
189
|
+
role="group"
|
|
190
|
+
aria-label="Language and theme"
|
|
191
|
+
>
|
|
192
|
+
{localeThemeGroup}
|
|
193
|
+
<ThemeToggle
|
|
194
|
+
size="compact"
|
|
195
|
+
className="h-8 w-8 shrink-0 focus-visible:ring-1 focus-visible:ring-sidebar-ring focus-visible:ring-offset-0"
|
|
156
196
|
/>
|
|
157
|
-
|
|
158
|
-
<ThemeToggle
|
|
159
|
-
size="compact"
|
|
160
|
-
className="h-8 w-8 shrink-0 focus-visible:ring-1 focus-visible:ring-sidebar-ring focus-visible:ring-offset-0"
|
|
161
|
-
/>
|
|
197
|
+
</div>
|
|
162
198
|
</div>
|
|
163
199
|
</div>
|
|
164
|
-
</
|
|
165
|
-
</
|
|
166
|
-
</
|
|
200
|
+
</CollapsibleContent>
|
|
201
|
+
</Collapsible>
|
|
202
|
+
</div>
|
|
167
203
|
);
|
|
168
204
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LucideIcon as LucideIconType } from 'lucide-react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Maps menu/route `icon` values into `SidebarItem['icon']`.
|
|
5
|
+
* Supports Lucide icon **name** (`"LayoutDashboard"`), a **Lucide component**, or legacy `{ name: string }`.
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeSidebarNavIcon(icon: unknown): string | LucideIconType | undefined {
|
|
8
|
+
if (icon == null) return undefined;
|
|
9
|
+
if (typeof icon === 'string') return icon;
|
|
10
|
+
if (typeof icon === 'function') return icon as LucideIconType;
|
|
11
|
+
if (typeof icon === 'object' && icon !== null && 'name' in icon) {
|
|
12
|
+
const n = (icon as { name?: unknown }).name;
|
|
13
|
+
if (typeof n === 'string' && n.length > 0) return n;
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|