@djangocfg/layouts 2.1.252 → 2.1.254
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 +124 -87
- 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.254",
|
|
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.254",
|
|
78
|
+
"@djangocfg/centrifugo": "^2.1.254",
|
|
79
|
+
"@djangocfg/i18n": "^2.1.254",
|
|
80
|
+
"@djangocfg/monitor": "^2.1.254",
|
|
81
|
+
"@djangocfg/debuger": "^2.1.254",
|
|
82
|
+
"@djangocfg/ui-core": "^2.1.254",
|
|
83
|
+
"@djangocfg/ui-nextjs": "^2.1.254",
|
|
84
|
+
"@djangocfg/ui-tools": "^2.1.254",
|
|
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.254",
|
|
113
|
+
"@djangocfg/i18n": "^2.1.254",
|
|
114
|
+
"@djangocfg/centrifugo": "^2.1.254",
|
|
115
|
+
"@djangocfg/monitor": "^2.1.254",
|
|
116
|
+
"@djangocfg/debuger": "^2.1.254",
|
|
117
|
+
"@djangocfg/typescript-config": "^2.1.254",
|
|
118
|
+
"@djangocfg/ui-core": "^2.1.254",
|
|
119
|
+
"@djangocfg/ui-nextjs": "^2.1.254",
|
|
120
|
+
"@djangocfg/ui-tools": "^2.1.254",
|
|
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
|
}
|
|
@@ -41,49 +41,53 @@ function navDensityFromCount(n: number): NavDensity {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Nav rows
|
|
45
|
-
* Avoids `sidebar-accent` in light — project tokens often map to near-black and wash out labels.
|
|
44
|
+
* Nav rows use semantic sidebar tokens so light/dark follows ui-core theme vars.
|
|
46
45
|
*/
|
|
47
46
|
const navItemClass = cn(
|
|
48
47
|
'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',
|
|
48
|
+
'text-sidebar-foreground/70',
|
|
49
|
+
'data-[active=true]:font-medium data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',
|
|
50
|
+
'hover:bg-sidebar-accent/70 hover:text-sidebar-accent-foreground',
|
|
51
|
+
'data-[active=true]:hover:bg-sidebar-accent',
|
|
52
|
+
'[&>svg]:shrink-0 [&>svg]:text-sidebar-foreground/70 [&>svg]:opacity-85',
|
|
53
|
+
'data-[active=true]:[&>svg]:text-sidebar-accent-foreground data-[active=true]:[&>svg]:opacity-100',
|
|
58
54
|
);
|
|
59
55
|
|
|
60
56
|
const DENSITY = {
|
|
61
57
|
comfortable: {
|
|
62
58
|
menu: 'gap-1.5',
|
|
63
|
-
group: 'gap-
|
|
59
|
+
group: 'gap-2',
|
|
60
|
+
/** Tighter than default SidebarGroup `p-2` (doubles Y between groups). */
|
|
61
|
+
groupPad: 'px-2 py-1',
|
|
64
62
|
label:
|
|
65
|
-
'h-7 uppercase text-[10px] font-light leading-none tracking-[0.14em] text-
|
|
63
|
+
'h-7 uppercase text-[10px] font-light leading-none tracking-[0.14em] text-sidebar-foreground/40',
|
|
66
64
|
buttonSize: 'lg' as const,
|
|
67
65
|
iconClass: 'h-5 w-5',
|
|
68
66
|
extraButton: 'rounded-lg !px-3',
|
|
67
|
+
/** Extra left inset so brand aligns with nav icons (group p-2 + button px). */
|
|
68
|
+
headerRowInset: 'pl-3',
|
|
69
69
|
},
|
|
70
70
|
default: {
|
|
71
71
|
menu: 'gap-1',
|
|
72
|
-
group: 'gap-
|
|
72
|
+
group: 'gap-1.5',
|
|
73
|
+
groupPad: 'px-2 py-1',
|
|
73
74
|
label:
|
|
74
|
-
'uppercase text-[9px] font-light leading-none tracking-[0.12em] text-
|
|
75
|
+
'uppercase text-[9px] font-light leading-none tracking-[0.12em] text-sidebar-foreground/50',
|
|
75
76
|
buttonSize: 'default' as const,
|
|
76
77
|
iconClass: 'h-4 w-4',
|
|
77
78
|
extraButton: 'rounded-lg',
|
|
79
|
+
headerRowInset: 'pl-2',
|
|
78
80
|
},
|
|
79
81
|
compact: {
|
|
80
82
|
menu: 'gap-0.5',
|
|
81
|
-
group: 'gap-
|
|
83
|
+
group: 'gap-0.5',
|
|
84
|
+
groupPad: 'px-2 py-0.5',
|
|
82
85
|
label:
|
|
83
|
-
'h-6 uppercase text-[8px] font-light leading-none tracking-[0.1em] text-
|
|
86
|
+
'h-6 uppercase text-[8px] font-light leading-none tracking-[0.1em] text-sidebar-foreground/40',
|
|
84
87
|
buttonSize: 'sm' as const,
|
|
85
88
|
iconClass: 'h-3.5 w-3.5',
|
|
86
89
|
extraButton: 'rounded-md !px-2',
|
|
90
|
+
headerRowInset: 'pl-2',
|
|
87
91
|
},
|
|
88
92
|
} as const;
|
|
89
93
|
|
|
@@ -104,6 +108,7 @@ export function PrivateSidebar({ sidebar, header, i18n, pathname: pathnameProp }
|
|
|
104
108
|
if (isMobile) setOpenMobile(false);
|
|
105
109
|
}, [pathname, isMobile, setOpenMobile]);
|
|
106
110
|
const brandTitle = header?.title?.trim() || 'Dashboard';
|
|
111
|
+
const brandMonogram = (header?.brandLetter?.trim().charAt(0) || brandTitle.charAt(0) || 'D').toUpperCase();
|
|
107
112
|
|
|
108
113
|
const allItems = React.useMemo(
|
|
109
114
|
() => sidebar.groups.flatMap((g) => g.items),
|
|
@@ -113,84 +118,116 @@ export function PrivateSidebar({ sidebar, header, i18n, pathname: pathnameProp }
|
|
|
113
118
|
const density = React.useMemo(() => navDensityFromCount(allItems.length), [allItems.length]);
|
|
114
119
|
const d = DENSITY[density];
|
|
115
120
|
|
|
116
|
-
const isActive = (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
(
|
|
121
|
-
other
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
const isActive = React.useCallback(
|
|
122
|
+
(href: string) => {
|
|
123
|
+
const matches = pathname === href || pathname.startsWith(`${href}/`);
|
|
124
|
+
if (!matches) return false;
|
|
125
|
+
return !allItems.some(
|
|
126
|
+
(other) =>
|
|
127
|
+
other.href !== href &&
|
|
128
|
+
other.href.startsWith(`${href}/`) &&
|
|
129
|
+
(pathname === other.href || pathname.startsWith(`${other.href}/`)),
|
|
130
|
+
);
|
|
131
|
+
},
|
|
132
|
+
[pathname, allItems],
|
|
133
|
+
);
|
|
126
134
|
|
|
127
135
|
const expanded = state === 'expanded';
|
|
128
136
|
|
|
137
|
+
const headerRowClass = cn('flex items-center gap-2', d.headerRowInset);
|
|
138
|
+
const brandMark = header?.brandIcon ? (
|
|
139
|
+
<LucideIcon icon={header.brandIcon} className="h-4 w-4 text-sidebar-primary-foreground" />
|
|
140
|
+
) : (
|
|
141
|
+
<span className="text-[11px] font-bold leading-none tracking-tight text-sidebar-primary-foreground">
|
|
142
|
+
{brandMonogram}
|
|
143
|
+
</span>
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const showMenuStart = sidebar.menuStart != null && sidebar.menuStart !== false;
|
|
147
|
+
const showMenuEnd = sidebar.menuEnd != null && sidebar.menuEnd !== false;
|
|
148
|
+
const menuStartSlot = showMenuStart ? (
|
|
149
|
+
<div className="w-full min-w-0 shrink-0 px-2">{sidebar.menuStart}</div>
|
|
150
|
+
) : null;
|
|
151
|
+
const menuEndSlot = showMenuEnd ? (
|
|
152
|
+
<div className="w-full min-w-0 shrink-0 px-2">{sidebar.menuEnd}</div>
|
|
153
|
+
) : null;
|
|
154
|
+
|
|
155
|
+
const sidebarContentClass = cn('gap-2', d.group);
|
|
156
|
+
|
|
157
|
+
const renderedGroups = React.useMemo(() => {
|
|
158
|
+
const navButtonClass = cn(navItemClass, d.extraButton);
|
|
159
|
+
const groupLabelClass = cn('px-2', d.label);
|
|
160
|
+
const sidebarGroupClass = cn('gap-0', d.groupPad);
|
|
161
|
+
|
|
162
|
+
return sidebar.groups.map((group) => {
|
|
163
|
+
if (group.dynamic && group.items.length === 0) return null;
|
|
164
|
+
const items = group.items.map((item: SidebarItem) => {
|
|
165
|
+
const iconProp = typeof item.icon === 'string' ? item.icon : item.icon;
|
|
166
|
+
const tooltipText = item.tooltip ?? item.label;
|
|
167
|
+
return (
|
|
168
|
+
<SidebarMenuItem key={item.href}>
|
|
169
|
+
<SidebarMenuButton
|
|
170
|
+
asChild
|
|
171
|
+
isActive={isActive(item.href)}
|
|
172
|
+
size={d.buttonSize}
|
|
173
|
+
tooltip={tooltipText}
|
|
174
|
+
className={navButtonClass}
|
|
175
|
+
>
|
|
176
|
+
<Link href={item.href}>
|
|
177
|
+
{item.icon ? <LucideIcon icon={iconProp} className={d.iconClass} /> : null}
|
|
178
|
+
<span>{item.label}</span>
|
|
179
|
+
{item.badge ? <SidebarMenuBadge>{item.badge}</SidebarMenuBadge> : null}
|
|
180
|
+
</Link>
|
|
181
|
+
</SidebarMenuButton>
|
|
182
|
+
</SidebarMenuItem>
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<SidebarGroup key={group.label} className={sidebarGroupClass}>
|
|
188
|
+
<SidebarGroupLabel className={groupLabelClass}>{group.label}</SidebarGroupLabel>
|
|
189
|
+
<SidebarGroupContent>
|
|
190
|
+
<SidebarMenu className={d.menu}>{items}</SidebarMenu>
|
|
191
|
+
</SidebarGroupContent>
|
|
192
|
+
</SidebarGroup>
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
}, [sidebar.groups, isActive, d]);
|
|
196
|
+
|
|
197
|
+
const expandedHeader = (
|
|
198
|
+
<div className={headerRowClass}>
|
|
199
|
+
<Link
|
|
200
|
+
href={homeHref}
|
|
201
|
+
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"
|
|
202
|
+
>
|
|
203
|
+
<div className="flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-sidebar-primary">{brandMark}</div>
|
|
204
|
+
<span className="truncate text-sm font-semibold tracking-tight text-sidebar-foreground">{brandTitle}</span>
|
|
205
|
+
</Link>
|
|
206
|
+
<SidebarTrigger className="shrink-0" aria-label="Collapse sidebar" />
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const collapsedHeader = (
|
|
211
|
+
<div className="flex justify-center py-1">
|
|
212
|
+
<SidebarTrigger aria-label="Expand sidebar" />
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
const sidebarHeaderContent = expanded ? expandedHeader : collapsedHeader;
|
|
217
|
+
const footerExtra = sidebar.footer ? <div className="mb-2">{sidebar.footer}</div> : null;
|
|
218
|
+
|
|
129
219
|
return (
|
|
130
220
|
<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
|
-
})}
|
|
221
|
+
<SidebarHeader className="px-2 pt-2.5 pb-2">{sidebarHeaderContent}</SidebarHeader>
|
|
222
|
+
|
|
223
|
+
<SidebarContent className={sidebarContentClass}>
|
|
224
|
+
{menuStartSlot}
|
|
225
|
+
{renderedGroups}
|
|
226
|
+
{menuEndSlot}
|
|
190
227
|
</SidebarContent>
|
|
191
228
|
|
|
192
229
|
<SidebarFooter className="p-2">
|
|
193
|
-
{
|
|
230
|
+
{footerExtra}
|
|
194
231
|
<PrivateSidebarAccount header={header} i18n={i18n} />
|
|
195
232
|
</SidebarFooter>
|
|
196
233
|
</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
|
+
}
|