@shellui/core 0.2.0-alpha.4 → 0.2.0-beta.1

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 (61) hide show
  1. package/package.json +2 -2
  2. package/src/app.tsx +2 -2
  3. package/src/components/ContentView.tsx +70 -135
  4. package/src/components/LoadingOverlay.tsx +5 -1
  5. package/src/components/ui/sidebar.tsx +2 -124
  6. package/src/constants/loading.ts +2 -0
  7. package/src/features/config/types.ts +2 -0
  8. package/src/features/layouts/AppLayout.tsx +22 -19
  9. package/src/features/layouts/LayoutFallback.tsx +8 -0
  10. package/src/features/layouts/OverlayShell.tsx +23 -9
  11. package/src/features/layouts/{AppBarLayout.tsx → appbar/AppBarLayout.tsx} +72 -78
  12. package/src/features/layouts/{FullscreenLayout.tsx → fullscreen/FullscreenLayout.tsx} +5 -11
  13. package/src/features/layouts/sidebar/BottomNavItem.tsx +88 -0
  14. package/src/features/layouts/sidebar/MobileBottomNav.tsx +168 -0
  15. package/src/features/layouts/sidebar/NavigationContent.tsx +159 -0
  16. package/src/features/layouts/sidebar/SidebarIcons.tsx +93 -0
  17. package/src/features/layouts/sidebar/SidebarInner.tsx +48 -0
  18. package/src/features/layouts/sidebar/SidebarLayout.tsx +86 -0
  19. package/src/features/layouts/sidebar/sidebarUtils.ts +23 -0
  20. package/src/features/layouts/sidebar/types.ts +8 -0
  21. package/src/features/layouts/utils.ts +29 -1
  22. package/src/features/layouts/{WindowsLayout.tsx → windows/WindowsLayout.tsx} +199 -204
  23. package/src/features/settings/SettingsView.tsx +178 -181
  24. package/src/{components → routes/components}/HomeView.tsx +1 -1
  25. package/src/{components → routes/components}/IndexRoute.tsx +4 -4
  26. package/src/routes/components/NavigationItemRoute.tsx +19 -0
  27. package/src/{components → routes/components}/NotFoundView.tsx +9 -4
  28. package/src/{components → routes/components}/RouteErrorBoundary.tsx +1 -1
  29. package/src/routes/components/RouteFallback.tsx +8 -0
  30. package/src/routes/hooks/useNavigationItems.ts +84 -0
  31. package/src/{router → routes}/routes.tsx +18 -16
  32. package/src/components/ViewRoute.tsx +0 -48
  33. package/src/dist/CookiePreferencesView.52b5aec8.js +0 -1182
  34. package/src/dist/CookiePreferencesView.52b5aec8.js.map +0 -1
  35. package/src/dist/DefaultLayout.045a82ff.js +0 -1964
  36. package/src/dist/DefaultLayout.045a82ff.js.map +0 -1
  37. package/src/dist/DefaultLayout.4454f259.js +0 -4414
  38. package/src/dist/DefaultLayout.4454f259.js.map +0 -1
  39. package/src/dist/FullscreenLayout.555c4987.js +0 -1054
  40. package/src/dist/FullscreenLayout.555c4987.js.map +0 -1
  41. package/src/dist/HomeView.ddfa7b68.js +0 -771
  42. package/src/dist/HomeView.ddfa7b68.js.map +0 -1
  43. package/src/dist/NotFoundView.c75be4f1.js +0 -811
  44. package/src/dist/NotFoundView.c75be4f1.js.map +0 -1
  45. package/src/dist/SettingsView.052b03a6.js +0 -4965
  46. package/src/dist/SettingsView.052b03a6.js.map +0 -1
  47. package/src/dist/ViewRoute.e6e3b142.js +0 -1042
  48. package/src/dist/ViewRoute.e6e3b142.js.map +0 -1
  49. package/src/dist/WindowsLayout.08724167.js +0 -1762
  50. package/src/dist/WindowsLayout.08724167.js.map +0 -1
  51. package/src/dist/esm.f0d741e6.js +0 -29520
  52. package/src/dist/esm.f0d741e6.js.map +0 -1
  53. package/src/dist/favicon.4367ac1e.svg +0 -14
  54. package/src/dist/index.parcel.36d65383.js +0 -54089
  55. package/src/dist/index.parcel.36d65383.js.map +0 -1
  56. package/src/dist/index.parcel.ca6d8a47.css +0 -3493
  57. package/src/dist/index.parcel.ca6d8a47.css.map +0 -1
  58. package/src/dist/index.parcel.html +0 -88
  59. package/src/features/layouts/DefaultLayout.tsx +0 -660
  60. package/src/features/layouts/LayoutProviders.tsx +0 -20
  61. /package/src/{router → routes}/router.tsx +0 -0
@@ -1,660 +0,0 @@
1
- import { Link, useLocation, Outlet } from 'react-router';
2
- import { useMemo, useEffect, useState, useRef, useLayoutEffect } from 'react';
3
- import { useTranslation } from 'react-i18next';
4
- import { shellui } from '@shellui/sdk';
5
- import type { NavigationItem, NavigationGroup } from '../config/types';
6
- import {
7
- Sidebar,
8
- SidebarProvider,
9
- SidebarHeader,
10
- SidebarContent,
11
- SidebarFooter,
12
- SidebarGroup,
13
- SidebarGroupLabel,
14
- SidebarGroupContent,
15
- SidebarMenu,
16
- SidebarMenuItem,
17
- SidebarMenuButton,
18
- } from '../../components/ui/sidebar';
19
- import { cn } from '../../lib/utils';
20
- import { Z_INDEX } from '../../lib/z-index';
21
- import {
22
- filterNavigationByViewport,
23
- filterNavigationForSidebar,
24
- flattenNavigationItems,
25
- getActivePathPrefix,
26
- getNavPathPrefix,
27
- HOMEPAGE_NAV_ITEM,
28
- resolveLocalizedString as resolveNavLabel,
29
- splitNavigationByPosition,
30
- } from './utils';
31
- import { LayoutProviders } from './LayoutProviders';
32
- import { OverlayShell } from './OverlayShell';
33
-
34
- interface DefaultLayoutProps {
35
- title?: string;
36
- appIcon?: string;
37
- logo?: string;
38
- navigation: (NavigationItem | NavigationGroup)[];
39
- }
40
-
41
- // DuckDuckGo favicon URL for a given page URL (used when openIn === 'external' and no icon is set)
42
- const getExternalFaviconUrl = (url: string): string | null => {
43
- try {
44
- const parsed = new URL(url);
45
- const hostname = parsed.hostname;
46
- if (!hostname) return null;
47
- return `https://icons.duckduckgo.com/ip3/${hostname}.ico`;
48
- } catch {
49
- return null;
50
- }
51
- };
52
-
53
- const NavigationContent = ({
54
- navigation,
55
- }: {
56
- navigation: (NavigationItem | NavigationGroup)[];
57
- }) => {
58
- const location = useLocation();
59
- const { i18n } = useTranslation();
60
- const currentLanguage = i18n.language || 'en';
61
-
62
- // Helper function to resolve localized strings
63
- const resolveLocalizedString = (
64
- value: string | { en: string; fr: string; [key: string]: string },
65
- lang: string,
66
- ): string => {
67
- if (typeof value === 'string') {
68
- return value;
69
- }
70
- // Try current language first, then English as fallback
71
- return value[lang] || value.en || value.fr || Object.values(value)[0] || '';
72
- };
73
-
74
- // Check if at least one navigation item has an icon
75
- const hasAnyIcons = useMemo(() => {
76
- return navigation.some((item) => {
77
- if ('title' in item && 'items' in item) {
78
- // It's a group
79
- return (item as NavigationGroup).items.some((navItem) => !!navItem.icon);
80
- }
81
- // It's a standalone item
82
- return !!(item as NavigationItem).icon;
83
- });
84
- }, [navigation]);
85
-
86
- const flatItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
87
- const activePathPrefix = useMemo(
88
- () => getActivePathPrefix(location.pathname, flatItems),
89
- [location.pathname, flatItems],
90
- );
91
-
92
- // Helper to check if an item is a group
93
- const isGroup = (item: NavigationItem | NavigationGroup): item is NavigationGroup => {
94
- return 'title' in item && 'items' in item;
95
- };
96
-
97
- // Render a single nav item link or modal/drawer trigger
98
- const renderNavItem = (navItem: NavigationItem) => {
99
- const pathPrefix = getNavPathPrefix(navItem);
100
- const isOverlay = navItem.openIn === 'modal' || navItem.openIn === 'drawer';
101
- const isExternal = navItem.openIn === 'external';
102
- const isActive = !isOverlay && !isExternal && pathPrefix === activePathPrefix;
103
- const itemLabel = resolveLocalizedString(navItem.label, currentLanguage);
104
- const faviconUrl = isExternal && !navItem.icon ? getExternalFaviconUrl(navItem.url) : null;
105
- const iconSrc = navItem.icon ?? faviconUrl ?? null;
106
- const iconEl = iconSrc ? (
107
- <img
108
- src={iconSrc}
109
- alt=""
110
- className={cn('h-4 w-4', 'shrink-0')}
111
- />
112
- ) : hasAnyIcons ? (
113
- <span className="h-4 w-4 shrink-0" />
114
- ) : null;
115
- const externalIcon = isExternal ? (
116
- <ExternalLinkIcon className="ml-auto h-4 w-4 shrink-0 opacity-70" />
117
- ) : null;
118
- const content = (
119
- <>
120
- {iconEl}
121
- <span className="truncate">{itemLabel}</span>
122
- {externalIcon}
123
- </>
124
- );
125
- const linkOrTrigger =
126
- navItem.openIn === 'modal' ? (
127
- <button
128
- type="button"
129
- onClick={() => shellui.openModal(navItem.url)}
130
- className="flex items-center gap-2 w-full cursor-pointer text-left"
131
- >
132
- {content}
133
- </button>
134
- ) : navItem.openIn === 'drawer' ? (
135
- <button
136
- type="button"
137
- onClick={() => shellui.openDrawer({ url: navItem.url, position: navItem.drawerPosition })}
138
- className="flex items-center gap-2 w-full cursor-pointer text-left"
139
- >
140
- {content}
141
- </button>
142
- ) : navItem.openIn === 'external' ? (
143
- <a
144
- href={navItem.url}
145
- target="_blank"
146
- rel="noopener noreferrer"
147
- className="flex items-center gap-2 w-full"
148
- >
149
- {content}
150
- </a>
151
- ) : (
152
- <Link
153
- to={pathPrefix}
154
- className="flex items-center gap-2 w-full"
155
- >
156
- {content}
157
- </Link>
158
- );
159
- return (
160
- <SidebarMenuButton
161
- asChild
162
- isActive={isActive}
163
- className={cn('w-full', isActive && 'bg-sidebar-accent text-sidebar-accent-foreground')}
164
- >
165
- {linkOrTrigger}
166
- </SidebarMenuButton>
167
- );
168
- };
169
-
170
- // Render navigation items - handle both groups and standalone items
171
- return (
172
- <>
173
- {navigation.map((item) => {
174
- if (isGroup(item)) {
175
- // Render as a group
176
- const groupTitle = resolveLocalizedString(item.title, currentLanguage);
177
- return (
178
- <SidebarGroup
179
- key={groupTitle}
180
- className="mt-0"
181
- >
182
- <SidebarGroupLabel className="mb-1">{groupTitle}</SidebarGroupLabel>
183
- <SidebarGroupContent>
184
- <SidebarMenu className="gap-0.5">
185
- {item.items.map((navItem) => (
186
- <SidebarMenuItem key={navItem.path}>{renderNavItem(navItem)}</SidebarMenuItem>
187
- ))}
188
- </SidebarMenu>
189
- </SidebarGroupContent>
190
- </SidebarGroup>
191
- );
192
- } else {
193
- // Render as a standalone item
194
- return (
195
- <SidebarMenu
196
- key={item.path}
197
- className="gap-0.5"
198
- >
199
- <SidebarMenuItem>{renderNavItem(item)}</SidebarMenuItem>
200
- </SidebarMenu>
201
- );
202
- }
203
- })}
204
- </>
205
- );
206
- };
207
-
208
- /** Reusable sidebar inner: header, main nav, footer. Used in desktop Sidebar and mobile Drawer. */
209
- const SidebarInner = ({
210
- title,
211
- logo,
212
- startNav,
213
- endItems,
214
- }: {
215
- title?: string;
216
- logo?: string;
217
- startNav: (NavigationItem | NavigationGroup)[];
218
- endItems: (NavigationItem | NavigationGroup)[];
219
- }) => (
220
- <>
221
- <SidebarHeader className="border-b border-sidebar-border pb-4">
222
- {(title || logo) && (
223
- <Link
224
- to="/"
225
- className="flex items-center pl-1 pr-3 py-2 text-lg font-semibold text-sidebar-foreground hover:text-sidebar-foreground/80 transition-colors"
226
- >
227
- {logo && logo.trim() ? (
228
- <img
229
- src={logo}
230
- alt={title || 'Logo'}
231
- className="h-5 w-auto shrink-0 object-contain sidebar-logo"
232
- />
233
- ) : title ? (
234
- <span className="leading-none">{title}</span>
235
- ) : null}
236
- </Link>
237
- )}
238
- </SidebarHeader>
239
- <SidebarContent className="gap-1">
240
- <NavigationContent navigation={startNav} />
241
- </SidebarContent>
242
- {endItems.length > 0 && (
243
- <SidebarFooter>
244
- <NavigationContent navigation={endItems} />
245
- </SidebarFooter>
246
- )}
247
- </>
248
- );
249
-
250
- function resolveLocalizedLabel(
251
- value: string | { en: string; fr: string; [key: string]: string },
252
- lang: string,
253
- ): string {
254
- if (typeof value === 'string') return value;
255
- return value[lang] || value.en || value.fr || Object.values(value)[0] || '';
256
- }
257
-
258
- /** Approximate width per slot (icon + label + padding) and gap for dynamic slot count. */
259
- const BOTTOM_NAV_SLOT_WIDTH = 64;
260
- const BOTTOM_NAV_GAP = 4;
261
- const BOTTOM_NAV_PX = 12;
262
- /** Max slots in the row (Home + nav + optional More) to avoid overflow/duplicated wrap. */
263
- const BOTTOM_NAV_MAX_SLOTS = 6;
264
-
265
- /** True when the icon is a local app icon (/icons/); external images (avatars, favicons) are shown as-is. */
266
- const isAppIcon = (src: string) => src.startsWith('/icons/');
267
-
268
- /** Single nav item for bottom bar: icon + label, link or action. */
269
- const BottomNavItem = ({
270
- item,
271
- label,
272
- isActive,
273
- iconSrc,
274
- applyIconTheme,
275
- }: {
276
- item: NavigationItem;
277
- label: string;
278
- isActive: boolean;
279
- iconSrc: string | null;
280
- applyIconTheme: boolean;
281
- }) => {
282
- const pathPrefix = getNavPathPrefix(item);
283
- const content = (
284
- <span className="flex flex-col items-center justify-center gap-1 w-full min-w-0 max-w-full overflow-hidden">
285
- {iconSrc ? (
286
- <img
287
- src={iconSrc}
288
- alt=""
289
- className={cn(
290
- 'size-4 shrink-0 rounded-sm object-cover',
291
- applyIconTheme && 'opacity-90 dark:opacity-100 dark:invert',
292
- )}
293
- />
294
- ) : (
295
- <span className="size-4 shrink-0 rounded-sm bg-muted" />
296
- )}
297
- <span className="text-[11px] leading-tight truncate w-full min-w-0 text-center block">
298
- {label}
299
- </span>
300
- </span>
301
- );
302
- const baseClass = cn(
303
- 'flex flex-col items-center justify-center rounded-md py-1.5 px-2 min-w-0 max-w-full transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
304
- isActive
305
- ? 'bg-accent text-accent-foreground [&_span]:text-accent-foreground'
306
- : 'text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground [&_span]:inherit',
307
- );
308
- if (item.openIn === 'modal') {
309
- return (
310
- <button
311
- type="button"
312
- onClick={() => shellui.openModal(item.url)}
313
- className={baseClass}
314
- >
315
- {content}
316
- </button>
317
- );
318
- }
319
- if (item.openIn === 'drawer') {
320
- return (
321
- <button
322
- type="button"
323
- onClick={() => shellui.openDrawer({ url: item.url, position: item.drawerPosition })}
324
- className={baseClass}
325
- >
326
- {content}
327
- </button>
328
- );
329
- }
330
- if (item.openIn === 'external') {
331
- return (
332
- <a
333
- href={item.url}
334
- target="_blank"
335
- rel="noopener noreferrer"
336
- className={baseClass}
337
- >
338
- {content}
339
- </a>
340
- );
341
- }
342
- return (
343
- <Link
344
- to={pathPrefix}
345
- className={baseClass}
346
- >
347
- {content}
348
- </Link>
349
- );
350
- };
351
-
352
- /** Inline SVG: external-link icon. Bundled so consumers don't need to serve static SVGs. */
353
- const ExternalLinkIcon = ({ className }: { className?: string }) => (
354
- <svg
355
- xmlns="http://www.w3.org/2000/svg"
356
- width="24"
357
- height="24"
358
- viewBox="0 0 24 24"
359
- fill="none"
360
- stroke="currentColor"
361
- strokeWidth="2"
362
- strokeLinecap="round"
363
- strokeLinejoin="round"
364
- className={cn('shrink-0', className)}
365
- aria-hidden
366
- >
367
- <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
368
- <polyline points="15 3 21 3 21 9" />
369
- <line
370
- x1="10"
371
- y1="14"
372
- x2="21"
373
- y2="3"
374
- />
375
- </svg>
376
- );
377
-
378
- /** Caret up: expand (show second line). */
379
- const CaretUpIcon = ({ className }: { className?: string }) => (
380
- <svg
381
- xmlns="http://www.w3.org/2000/svg"
382
- width="24"
383
- height="24"
384
- viewBox="0 0 24 24"
385
- fill="none"
386
- stroke="currentColor"
387
- strokeWidth="2"
388
- strokeLinecap="round"
389
- strokeLinejoin="round"
390
- className={cn('shrink-0', className)}
391
- aria-hidden
392
- >
393
- <path d="m18 15-6-6-6 6" />
394
- </svg>
395
- );
396
-
397
- /** Caret down: collapse (hide second line). */
398
- const CaretDownIcon = ({ className }: { className?: string }) => (
399
- <svg
400
- xmlns="http://www.w3.org/2000/svg"
401
- width="24"
402
- height="24"
403
- viewBox="0 0 24 24"
404
- fill="none"
405
- stroke="currentColor"
406
- strokeWidth="2"
407
- strokeLinecap="round"
408
- strokeLinejoin="round"
409
- className={cn('shrink-0', className)}
410
- aria-hidden
411
- >
412
- <path d="m6 9 6 6 6-6" />
413
- </svg>
414
- );
415
-
416
- /** Home icon for mobile bottom bar (same as sidebar logo action). */
417
- const HomeIcon = ({ className }: { className?: string }) => (
418
- <svg
419
- xmlns="http://www.w3.org/2000/svg"
420
- width="24"
421
- height="24"
422
- viewBox="0 0 24 24"
423
- fill="none"
424
- stroke="currentColor"
425
- strokeWidth="2"
426
- strokeLinecap="round"
427
- strokeLinejoin="round"
428
- className={cn('shrink-0', className)}
429
- aria-hidden
430
- >
431
- <path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
432
- <polyline points="9 22 9 12 15 12 15 22" />
433
- </svg>
434
- );
435
-
436
- /** Mobile bottom nav: Home + nav items; More only when not all fit. Dynamic from width. Reuses HOMEPAGE_NAV_ITEM for label. */
437
- const MobileBottomNav = ({
438
- items,
439
- currentLanguage,
440
- }: {
441
- items: NavigationItem[];
442
- currentLanguage: string;
443
- }) => {
444
- const location = useLocation();
445
- const [expanded, setExpanded] = useState(false);
446
- const navRef = useRef<HTMLElement>(null);
447
- const [rowWidth, setRowWidth] = useState(0);
448
-
449
- const activePathPrefix = useMemo(
450
- () => getActivePathPrefix(location.pathname, items),
451
- [location.pathname, items],
452
- );
453
-
454
- useLayoutEffect(() => {
455
- const el = navRef.current;
456
- if (!el) return;
457
- const ro = new ResizeObserver((entries) => {
458
- const w = entries[0]?.contentRect.width ?? 0;
459
- setRowWidth(w);
460
- });
461
- ro.observe(el);
462
- setRowWidth(el.getBoundingClientRect().width);
463
- return () => ro.disconnect();
464
- }, []);
465
-
466
- const { rowItems, overflowItems, hasMore } = useMemo(() => {
467
- const list = items.slice();
468
- const contentWidth = Math.max(0, rowWidth - BOTTOM_NAV_PX * 2);
469
- const slotTotal = BOTTOM_NAV_SLOT_WIDTH + BOTTOM_NAV_GAP;
470
- const computedSlots =
471
- rowWidth > 0 ? Math.floor((contentWidth + BOTTOM_NAV_GAP) / slotTotal) : 5;
472
- const totalSlots = Math.min(Math.max(0, computedSlots), BOTTOM_NAV_MAX_SLOTS);
473
- const slotsForNav = totalSlots - 1;
474
- const allFit = list.length <= slotsForNav;
475
- const maxInRow = allFit ? list.length : Math.max(0, totalSlots - 2);
476
- const row = list.slice(0, maxInRow);
477
- const rowPaths = new Set(row.map((i) => i.path));
478
- const overflow = list.filter((item) => !rowPaths.has(item.path));
479
- return {
480
- rowItems: row,
481
- overflowItems: overflow,
482
- hasMore: overflow.length > 0,
483
- };
484
- }, [items, rowWidth]);
485
-
486
- useEffect(() => {
487
- setExpanded(false);
488
- }, [location.pathname]);
489
-
490
- const renderItem = (item: NavigationItem, index: number) => {
491
- const pathPrefix = getNavPathPrefix(item);
492
- const isOverlayOrExternal =
493
- item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external';
494
- const isActive = !isOverlayOrExternal && pathPrefix === activePathPrefix;
495
- const label = resolveNavLabel(item.label, currentLanguage);
496
- const faviconUrl =
497
- item.openIn === 'external' && !item.icon ? getExternalFaviconUrl(item.url) : null;
498
- const iconSrc = item.icon ?? faviconUrl ?? null;
499
- const applyIconTheme = iconSrc ? isAppIcon(iconSrc) : false;
500
- return (
501
- <BottomNavItem
502
- key={`${item.path}-${item.url}-${index}`}
503
- item={item}
504
- label={label}
505
- isActive={isActive}
506
- iconSrc={iconSrc}
507
- applyIconTheme={applyIconTheme}
508
- />
509
- );
510
- };
511
-
512
- return (
513
- <nav
514
- ref={navRef}
515
- className="fixed bottom-0 left-0 right-0 z-[9999] md:hidden border-t border-sidebar-border bg-sidebar-background overflow-hidden pt-2"
516
- style={{
517
- zIndex: Z_INDEX.SIDEBAR_TRIGGER,
518
- paddingBottom: 'calc(0.5rem + env(safe-area-inset-bottom, 0px))',
519
- }}
520
- >
521
- {/* Top row: Home + nav items + More/Less — single row, no wrap */}
522
- <div className="flex flex-row flex-nowrap items-center justify-center gap-1 px-3 overflow-x-hidden">
523
- <Link
524
- to="/"
525
- className={cn(
526
- 'flex flex-col items-center justify-center gap-1 rounded-md py-1.5 px-2 min-w-0 transition-colors cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
527
- location.pathname === '/' || location.pathname === ''
528
- ? 'bg-sidebar-accent text-sidebar-accent-foreground [&_span]:text-sidebar-accent-foreground'
529
- : 'text-sidebar-foreground/80 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground [&_span]:inherit',
530
- )}
531
- aria-label={resolveNavLabel(HOMEPAGE_NAV_ITEM.label, currentLanguage) || 'Home'}
532
- >
533
- <span className="size-4 shrink-0 flex items-center justify-center [&_svg]:text-current">
534
- <HomeIcon className="size-4" />
535
- </span>
536
- <span className="text-[11px] leading-tight">
537
- {resolveNavLabel(HOMEPAGE_NAV_ITEM.label, currentLanguage) || 'Home'}
538
- </span>
539
- </Link>
540
- {rowItems.map((item, i) => renderItem(item, i))}
541
- {hasMore && (
542
- <button
543
- type="button"
544
- onClick={() => setExpanded((e) => !e)}
545
- className={cn(
546
- 'flex flex-col items-center justify-center gap-1 rounded-md py-1.5 px-2 min-w-0 transition-colors cursor-pointer',
547
- 'text-muted-foreground hover:bg-accent/50 hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
548
- )}
549
- aria-expanded={expanded}
550
- aria-label={expanded ? 'Show less' : 'Show more'}
551
- >
552
- <span className="size-4 shrink-0 flex items-center justify-center">
553
- {expanded ? <CaretDownIcon className="size-4" /> : <CaretUpIcon className="size-4" />}
554
- </span>
555
- <span className="text-[11px] leading-tight">{expanded ? 'Less' : 'More'}</span>
556
- </button>
557
- )}
558
- </div>
559
-
560
- {/* Expanded: only overflow items — render list only when expanded so it clears when collapsed */}
561
- <div
562
- className={cn(
563
- 'grid transition-[grid-template-rows] duration-300 ease-out',
564
- expanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]',
565
- )}
566
- >
567
- <div className="min-h-0 overflow-hidden">
568
- <div className="px-4 pt-3 pb-2 border-t border-sidebar-border/50 mt-1">
569
- <div className="grid grid-cols-5 gap-2 justify-items-center max-w-xs mx-auto">
570
- {expanded ? overflowItems.map((item, i) => renderItem(item, i)) : null}
571
- </div>
572
- </div>
573
- </div>
574
- </div>
575
- </nav>
576
- );
577
- };
578
-
579
- const DefaultLayoutContent = ({ title, logo, navigation }: DefaultLayoutProps) => {
580
- const location = useLocation();
581
- const { i18n } = useTranslation();
582
- const currentLanguage = i18n.language || 'en';
583
-
584
- const { startNav, endItems, navigationItems, mobileNavItems } = useMemo(() => {
585
- const desktopNav = filterNavigationByViewport(navigation, 'desktop');
586
- const mobileNav = filterNavigationByViewport(navigation, 'mobile');
587
- const { start, end } = splitNavigationByPosition(desktopNav);
588
- const flat = flattenNavigationItems(desktopNav);
589
- const mobileFlat = flattenNavigationItems(mobileNav);
590
- return {
591
- startNav: filterNavigationForSidebar(start),
592
- endItems: end,
593
- navigationItems: flat,
594
- mobileNavItems: mobileFlat,
595
- };
596
- }, [navigation]);
597
-
598
- useEffect(() => {
599
- if (!title) return;
600
- const pathname = location.pathname.replace(/^\/+|\/+$/g, '') || '';
601
- const segment = pathname.split('/')[0];
602
- if (!segment) {
603
- const rootNavItem = navigationItems.find((item) => item.path === '' || item.path === '/');
604
- document.title = rootNavItem
605
- ? `${resolveLocalizedLabel(rootNavItem.label, currentLanguage)} | ${title}`
606
- : title;
607
- return;
608
- }
609
- const navItem = navigationItems.find((item) => item.path === segment);
610
- if (navItem) {
611
- const label = resolveLocalizedLabel(navItem.label, currentLanguage);
612
- document.title = `${label} | ${title}`;
613
- } else {
614
- document.title = title;
615
- }
616
- }, [location.pathname, title, navigationItems, currentLanguage]);
617
-
618
- return (
619
- <LayoutProviders>
620
- <SidebarProvider>
621
- <OverlayShell navigationItems={navigationItems}>
622
- <div className="flex h-screen overflow-hidden">
623
- {/* Desktop sidebar: visible from md up */}
624
- <Sidebar className={cn('hidden md:flex shrink-0')}>
625
- <SidebarInner
626
- title={title}
627
- logo={logo}
628
- startNav={startNav}
629
- endItems={endItems}
630
- />
631
- </Sidebar>
632
-
633
- <main className="flex-1 flex flex-col overflow-hidden bg-background relative min-w-0">
634
- <div className="flex-1 flex flex-col overflow-auto pb-16 md:pb-0">
635
- <Outlet />
636
- </div>
637
- </main>
638
- </div>
639
-
640
- {/* Mobile bottom nav: visible only below md */}
641
- <MobileBottomNav
642
- items={mobileNavItems}
643
- currentLanguage={currentLanguage}
644
- />
645
- </OverlayShell>
646
- </SidebarProvider>
647
- </LayoutProviders>
648
- );
649
- };
650
-
651
- export const DefaultLayout = ({ title, appIcon, logo, navigation }: DefaultLayoutProps) => {
652
- return (
653
- <DefaultLayoutContent
654
- title={title}
655
- appIcon={appIcon}
656
- logo={logo}
657
- navigation={navigation}
658
- />
659
- );
660
- };
@@ -1,20 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import { ModalProvider } from '../modal/ModalContext';
3
- import { DrawerProvider } from '../drawer/DrawerContext';
4
- import { SonnerProvider } from '../sonner/SonnerContext';
5
-
6
- interface LayoutProvidersProps {
7
- children: ReactNode;
8
- }
9
-
10
- /** Wraps layout content with Modal, Drawer and Sonner providers.
11
- * Note: DialogProvider is now at the app level in app.tsx */
12
- export function LayoutProviders({ children }: LayoutProvidersProps) {
13
- return (
14
- <ModalProvider>
15
- <DrawerProvider>
16
- <SonnerProvider>{children}</SonnerProvider>
17
- </DrawerProvider>
18
- </ModalProvider>
19
- );
20
- }
File without changes