@shellui/core 0.2.0-beta.0 → 0.2.0-beta.2

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 (60) hide show
  1. package/package.json +2 -2
  2. package/src/app.tsx +1 -1
  3. package/src/components/ContentView.tsx +22 -61
  4. package/src/components/LoadingOverlay.tsx +1 -1
  5. package/src/components/ui/sidebar.tsx +2 -124
  6. package/src/features/layouts/AppLayout.tsx +22 -19
  7. package/src/features/layouts/LayoutFallback.tsx +8 -0
  8. package/src/features/layouts/OverlayShell.tsx +21 -40
  9. package/src/features/layouts/{AppBarLayout.tsx → appbar/AppBarLayout.tsx} +72 -78
  10. package/src/features/layouts/{FullscreenLayout.tsx → fullscreen/FullscreenLayout.tsx} +5 -11
  11. package/src/features/layouts/sidebar/BottomNavItem.tsx +88 -0
  12. package/src/features/layouts/sidebar/MobileBottomNav.tsx +168 -0
  13. package/src/features/layouts/sidebar/NavigationContent.tsx +159 -0
  14. package/src/features/layouts/sidebar/SidebarIcons.tsx +93 -0
  15. package/src/features/layouts/sidebar/SidebarInner.tsx +48 -0
  16. package/src/features/layouts/sidebar/SidebarLayout.tsx +86 -0
  17. package/src/features/layouts/sidebar/sidebarUtils.ts +23 -0
  18. package/src/features/layouts/sidebar/types.ts +8 -0
  19. package/src/features/layouts/utils.ts +1 -1
  20. package/src/features/layouts/{WindowsLayout.tsx → windows/WindowsLayout.tsx} +199 -204
  21. package/src/features/settings/SettingsView.tsx +177 -180
  22. package/src/{components → routes/components}/HomeView.tsx +1 -1
  23. package/src/{components → routes/components}/IndexRoute.tsx +4 -4
  24. package/src/routes/components/NavigationItemRoute.tsx +19 -0
  25. package/src/{components → routes/components}/NotFoundView.tsx +3 -3
  26. package/src/{components → routes/components}/RouteErrorBoundary.tsx +1 -1
  27. package/src/routes/components/RouteFallback.tsx +8 -0
  28. package/src/routes/hooks/useNavigationItems.ts +84 -0
  29. package/src/{router → routes}/routes.tsx +10 -18
  30. package/src/components/ViewRoute.tsx +0 -74
  31. package/src/dist/CookiePreferencesView.52b5aec8.js +0 -1182
  32. package/src/dist/CookiePreferencesView.52b5aec8.js.map +0 -1
  33. package/src/dist/DefaultLayout.045a82ff.js +0 -1964
  34. package/src/dist/DefaultLayout.045a82ff.js.map +0 -1
  35. package/src/dist/DefaultLayout.4454f259.js +0 -4414
  36. package/src/dist/DefaultLayout.4454f259.js.map +0 -1
  37. package/src/dist/FullscreenLayout.555c4987.js +0 -1054
  38. package/src/dist/FullscreenLayout.555c4987.js.map +0 -1
  39. package/src/dist/HomeView.ddfa7b68.js +0 -771
  40. package/src/dist/HomeView.ddfa7b68.js.map +0 -1
  41. package/src/dist/NotFoundView.c75be4f1.js +0 -811
  42. package/src/dist/NotFoundView.c75be4f1.js.map +0 -1
  43. package/src/dist/SettingsView.052b03a6.js +0 -4965
  44. package/src/dist/SettingsView.052b03a6.js.map +0 -1
  45. package/src/dist/ViewRoute.e6e3b142.js +0 -1042
  46. package/src/dist/ViewRoute.e6e3b142.js.map +0 -1
  47. package/src/dist/WindowsLayout.08724167.js +0 -1762
  48. package/src/dist/WindowsLayout.08724167.js.map +0 -1
  49. package/src/dist/esm.f0d741e6.js +0 -29520
  50. package/src/dist/esm.f0d741e6.js.map +0 -1
  51. package/src/dist/favicon.4367ac1e.svg +0 -14
  52. package/src/dist/index.parcel.36d65383.js +0 -54089
  53. package/src/dist/index.parcel.36d65383.js.map +0 -1
  54. package/src/dist/index.parcel.ca6d8a47.css +0 -3493
  55. package/src/dist/index.parcel.ca6d8a47.css.map +0 -1
  56. package/src/dist/index.parcel.html +0 -88
  57. package/src/features/layouts/DefaultLayout.tsx +0 -670
  58. package/src/features/layouts/LayoutProviders.tsx +0 -20
  59. /package/src/{constants.ts → constants/loading.ts} +0 -0
  60. /package/src/{router → routes}/router.tsx +0 -0
@@ -1,670 +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: optional Home + nav items; More only when not all fit. Dynamic from width. Reuses HOMEPAGE_NAV_ITEM for label. Home is shown only when no nav item is defined for "/". */
437
- const MobileBottomNav = ({
438
- items,
439
- currentLanguage,
440
- showHomeButton,
441
- }: {
442
- items: NavigationItem[];
443
- currentLanguage: string;
444
- /** When false, do not show the Home button (e.g. when a nav item for "/" exists). */
445
- showHomeButton: boolean;
446
- }) => {
447
- const location = useLocation();
448
- const [expanded, setExpanded] = useState(false);
449
- const navRef = useRef<HTMLElement>(null);
450
- const [rowWidth, setRowWidth] = useState(0);
451
-
452
- const activePathPrefix = useMemo(
453
- () => getActivePathPrefix(location.pathname, items),
454
- [location.pathname, items],
455
- );
456
-
457
- useLayoutEffect(() => {
458
- const el = navRef.current;
459
- if (!el) return;
460
- const ro = new ResizeObserver((entries) => {
461
- const w = entries[0]?.contentRect.width ?? 0;
462
- setRowWidth(w);
463
- });
464
- ro.observe(el);
465
- setRowWidth(el.getBoundingClientRect().width);
466
- return () => ro.disconnect();
467
- }, []);
468
-
469
- const { rowItems, overflowItems, hasMore } = useMemo(() => {
470
- const list = items.slice();
471
- const contentWidth = Math.max(0, rowWidth - BOTTOM_NAV_PX * 2);
472
- const slotTotal = BOTTOM_NAV_SLOT_WIDTH + BOTTOM_NAV_GAP;
473
- const computedSlots =
474
- rowWidth > 0 ? Math.floor((contentWidth + BOTTOM_NAV_GAP) / slotTotal) : 5;
475
- const totalSlots = Math.min(Math.max(0, computedSlots), BOTTOM_NAV_MAX_SLOTS);
476
- const slotsForNav = showHomeButton ? totalSlots - 1 : totalSlots;
477
- const allFit = list.length <= slotsForNav;
478
- const maxInRow = allFit
479
- ? list.length
480
- : Math.max(0, showHomeButton ? totalSlots - 2 : totalSlots - 1);
481
- const row = list.slice(0, maxInRow);
482
- const rowPaths = new Set(row.map((i) => i.path));
483
- const overflow = list.filter((item) => !rowPaths.has(item.path));
484
- return {
485
- rowItems: row,
486
- overflowItems: overflow,
487
- hasMore: overflow.length > 0,
488
- };
489
- }, [items, rowWidth, showHomeButton]);
490
-
491
- useEffect(() => {
492
- setExpanded(false);
493
- }, [location.pathname]);
494
-
495
- const renderItem = (item: NavigationItem, index: number) => {
496
- const pathPrefix = getNavPathPrefix(item);
497
- const isOverlayOrExternal =
498
- item.openIn === 'modal' || item.openIn === 'drawer' || item.openIn === 'external';
499
- const isActive = !isOverlayOrExternal && pathPrefix === activePathPrefix;
500
- const label = resolveNavLabel(item.label, currentLanguage);
501
- const faviconUrl =
502
- item.openIn === 'external' && !item.icon ? getExternalFaviconUrl(item.url) : null;
503
- const iconSrc = item.icon ?? faviconUrl ?? null;
504
- const applyIconTheme = iconSrc ? isAppIcon(iconSrc) : false;
505
- return (
506
- <BottomNavItem
507
- key={`${item.path}-${item.url}-${index}`}
508
- item={item}
509
- label={label}
510
- isActive={isActive}
511
- iconSrc={iconSrc}
512
- applyIconTheme={applyIconTheme}
513
- />
514
- );
515
- };
516
-
517
- return (
518
- <nav
519
- ref={navRef}
520
- className="fixed bottom-0 left-0 right-0 z-[9999] md:hidden border-t border-sidebar-border bg-sidebar-background overflow-hidden pt-2"
521
- style={{
522
- zIndex: Z_INDEX.SIDEBAR_TRIGGER,
523
- paddingBottom: 'calc(0.5rem + env(safe-area-inset-bottom, 0px))',
524
- }}
525
- >
526
- {/* Top row: optional Home + nav items + More/Less — single row, no wrap */}
527
- <div className="flex flex-row flex-nowrap items-center justify-center gap-1 px-3 overflow-x-hidden">
528
- {showHomeButton && (
529
- <Link
530
- to="/"
531
- className={cn(
532
- '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',
533
- location.pathname === '/' || location.pathname === ''
534
- ? 'bg-sidebar-accent text-sidebar-accent-foreground [&_span]:text-sidebar-accent-foreground'
535
- : 'text-sidebar-foreground/80 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground [&_span]:inherit',
536
- )}
537
- aria-label={resolveNavLabel(HOMEPAGE_NAV_ITEM.label, currentLanguage) || 'Home'}
538
- >
539
- <span className="size-4 shrink-0 flex items-center justify-center [&_svg]:text-current">
540
- <HomeIcon className="size-4" />
541
- </span>
542
- <span className="text-[11px] leading-tight">
543
- {resolveNavLabel(HOMEPAGE_NAV_ITEM.label, currentLanguage) || 'Home'}
544
- </span>
545
- </Link>
546
- )}
547
- {rowItems.map((item, i) => renderItem(item, i))}
548
- {hasMore && (
549
- <button
550
- type="button"
551
- onClick={() => setExpanded((e) => !e)}
552
- className={cn(
553
- 'flex flex-col items-center justify-center gap-1 rounded-md py-1.5 px-2 min-w-0 transition-colors cursor-pointer',
554
- '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',
555
- )}
556
- aria-expanded={expanded}
557
- aria-label={expanded ? 'Show less' : 'Show more'}
558
- >
559
- <span className="size-4 shrink-0 flex items-center justify-center">
560
- {expanded ? <CaretDownIcon className="size-4" /> : <CaretUpIcon className="size-4" />}
561
- </span>
562
- <span className="text-[11px] leading-tight">{expanded ? 'Less' : 'More'}</span>
563
- </button>
564
- )}
565
- </div>
566
-
567
- {/* Expanded: only overflow items — render list only when expanded so it clears when collapsed */}
568
- <div
569
- className={cn(
570
- 'grid transition-[grid-template-rows] duration-300 ease-out',
571
- expanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]',
572
- )}
573
- >
574
- <div className="min-h-0 overflow-hidden">
575
- <div className="px-4 pt-3 pb-2 border-t border-sidebar-border/50 mt-1">
576
- <div className="grid grid-cols-5 gap-2 justify-items-center max-w-xs mx-auto">
577
- {expanded ? overflowItems.map((item, i) => renderItem(item, i)) : null}
578
- </div>
579
- </div>
580
- </div>
581
- </div>
582
- </nav>
583
- );
584
- };
585
-
586
- const DefaultLayoutContent = ({ title, logo, navigation }: DefaultLayoutProps) => {
587
- const location = useLocation();
588
- const { i18n } = useTranslation();
589
- const currentLanguage = i18n.language || 'en';
590
-
591
- const { startNav, endItems, navigationItems, mobileNavItems, hasRootNavItem } = useMemo(() => {
592
- const desktopNav = filterNavigationByViewport(navigation, 'desktop');
593
- const mobileNav = filterNavigationByViewport(navigation, 'mobile');
594
- const { start, end } = splitNavigationByPosition(desktopNav);
595
- const flat = flattenNavigationItems(desktopNav);
596
- const mobileFlat = flattenNavigationItems(mobileNav);
597
- const hasRoot = flat.some((item) => item.path === '' || item.path === '/');
598
- return {
599
- startNav: filterNavigationForSidebar(start),
600
- endItems: end,
601
- navigationItems: flat,
602
- mobileNavItems: mobileFlat,
603
- hasRootNavItem: hasRoot,
604
- };
605
- }, [navigation]);
606
-
607
- useEffect(() => {
608
- if (!title) return;
609
- const pathname = location.pathname.replace(/^\/+|\/+$/g, '') || '';
610
- const segment = pathname.split('/')[0];
611
- if (!segment) {
612
- const rootNavItem = navigationItems.find((item) => item.path === '' || item.path === '/');
613
- document.title = rootNavItem
614
- ? `${resolveLocalizedLabel(rootNavItem.label, currentLanguage)} | ${title}`
615
- : title;
616
- return;
617
- }
618
- const navItem = navigationItems.find((item) => item.path === segment);
619
- if (navItem) {
620
- const label = resolveLocalizedLabel(navItem.label, currentLanguage);
621
- document.title = `${label} | ${title}`;
622
- } else {
623
- document.title = title;
624
- }
625
- }, [location.pathname, title, navigationItems, currentLanguage]);
626
-
627
- return (
628
- <LayoutProviders>
629
- <SidebarProvider>
630
- <OverlayShell navigationItems={navigationItems}>
631
- <div className="flex h-screen overflow-hidden">
632
- {/* Desktop sidebar: visible from md up */}
633
- <Sidebar className={cn('hidden md:flex shrink-0')}>
634
- <SidebarInner
635
- title={title}
636
- logo={logo}
637
- startNav={startNav}
638
- endItems={endItems}
639
- />
640
- </Sidebar>
641
-
642
- <main className="flex-1 flex flex-col overflow-hidden bg-background relative min-w-0">
643
- <div className="flex-1 flex flex-col overflow-auto pb-16 md:pb-0">
644
- <Outlet />
645
- </div>
646
- </main>
647
- </div>
648
-
649
- {/* Mobile bottom nav: visible only below md; Home button only when no view for / */}
650
- <MobileBottomNav
651
- items={mobileNavItems}
652
- currentLanguage={currentLanguage}
653
- showHomeButton={!hasRootNavItem}
654
- />
655
- </OverlayShell>
656
- </SidebarProvider>
657
- </LayoutProviders>
658
- );
659
- };
660
-
661
- export const DefaultLayout = ({ title, appIcon, logo, navigation }: DefaultLayoutProps) => {
662
- return (
663
- <DefaultLayoutContent
664
- title={title}
665
- appIcon={appIcon}
666
- logo={logo}
667
- navigation={navigation}
668
- />
669
- );
670
- };
@@ -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
File without changes