@shellui/core 0.4.1 → 0.5.0-alpha.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 (142) hide show
  1. package/README.md +2 -2
  2. package/package.json +15 -3
  3. package/schemas/curated-themes.json +4035 -0
  4. package/schemas/shellui.config.schema.json +961 -0
  5. package/schemas/shellui.theme.schema.json +187 -0
  6. package/src/app.tsx +4 -1
  7. package/src/components/ContentView.tsx +144 -9
  8. package/src/components/LoadingOverlay.tsx +1 -1
  9. package/src/components/ui/alert-dialog.tsx +1 -1
  10. package/src/components/ui/dialog.tsx +23 -5
  11. package/src/components/ui/drawer.tsx +282 -42
  12. package/src/components/ui/dropdown-menu.tsx +7 -2
  13. package/src/components/ui/input.tsx +21 -0
  14. package/src/components/ui/separator.tsx +23 -0
  15. package/src/components/ui/sheet.tsx +220 -0
  16. package/src/components/ui/sidebar.tsx +785 -221
  17. package/src/components/ui/skeleton.tsx +13 -0
  18. package/src/constants/urls.ts +1 -0
  19. package/src/features/admin/utils.ts +2 -45
  20. package/src/features/alertDialog/DialogContext.tsx +1 -1
  21. package/src/features/auth/components/LoginButton.tsx +25 -18
  22. package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
  23. package/src/features/auth/components/LoginView.tsx +131 -49
  24. package/src/features/config/types.ts +64 -82
  25. package/src/features/drawer/DrawerContext.tsx +55 -19
  26. package/src/features/layouts/AppLayout.tsx +3 -3
  27. package/src/features/layouts/OverlayShell.tsx +376 -77
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
  29. package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
  30. package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
  31. package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
  32. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
  33. package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
  34. package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
  35. package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
  36. package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
  37. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
  38. package/src/features/layouts/chrome/constants.ts +11 -0
  39. package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
  40. package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
  41. package/src/features/layouts/chrome/index.ts +26 -0
  42. package/src/features/layouts/chrome/runtime.ts +45 -0
  43. package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
  44. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
  45. package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
  46. package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
  47. package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
  48. package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
  49. package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
  50. package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
  51. package/src/features/layouts/sidebar/types.ts +3 -3
  52. package/src/features/layouts/utils.ts +73 -5
  53. package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
  54. package/src/features/modal/ModalContext.tsx +21 -8
  55. package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
  56. package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
  57. package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
  58. package/src/features/overlays/ResponsiveModal.tsx +483 -0
  59. package/src/features/overlays/overlaySize.spec.ts +71 -0
  60. package/src/features/overlays/overlaySize.ts +228 -0
  61. package/src/features/overlays/useOverlayReportedSize.ts +130 -0
  62. package/src/features/settings/SettingsProvider.tsx +66 -46
  63. package/src/features/settings/SettingsView.tsx +42 -47
  64. package/src/features/settings/components/Appearance.tsx +305 -55
  65. package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
  66. package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
  67. package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
  68. package/src/features/theme/applyTheme.ts +143 -0
  69. package/src/features/theme/color.ts +83 -0
  70. package/src/features/theme/curated/amber-minimal.json +86 -0
  71. package/src/features/theme/curated/amethyst-haze.json +86 -0
  72. package/src/features/theme/curated/astro-vista.json +86 -0
  73. package/src/features/theme/curated/bold-tech.json +86 -0
  74. package/src/features/theme/curated/bubblegum.json +86 -0
  75. package/src/features/theme/curated/caffeine.json +83 -0
  76. package/src/features/theme/curated/candyland.json +86 -0
  77. package/src/features/theme/curated/catppuccin.json +86 -0
  78. package/src/features/theme/curated/claude.json +86 -0
  79. package/src/features/theme/curated/claymorphism.json +86 -0
  80. package/src/features/theme/curated/clean-slate.json +86 -0
  81. package/src/features/theme/curated/cosmic-night.json +86 -0
  82. package/src/features/theme/curated/cyberpunk.json +86 -0
  83. package/src/features/theme/curated/darkmatter.json +86 -0
  84. package/src/features/theme/curated/doom-64.json +86 -0
  85. package/src/features/theme/curated/elegant-luxury.json +86 -0
  86. package/src/features/theme/curated/graphite.json +86 -0
  87. package/src/features/theme/curated/index.ts +260 -0
  88. package/src/features/theme/curated/kodama-grove.json +86 -0
  89. package/src/features/theme/curated/light-green.json +87 -0
  90. package/src/features/theme/curated/midnight-bloom.json +86 -0
  91. package/src/features/theme/curated/mocha-mousse.json +86 -0
  92. package/src/features/theme/curated/modern-minimal.json +86 -0
  93. package/src/features/theme/curated/mono.json +84 -0
  94. package/src/features/theme/curated/nature.json +86 -0
  95. package/src/features/theme/curated/neo-brutalism.json +86 -0
  96. package/src/features/theme/curated/northern-lights.json +86 -0
  97. package/src/features/theme/curated/notebook.json +87 -0
  98. package/src/features/theme/curated/ocean-breeze.json +86 -0
  99. package/src/features/theme/curated/pastel-dreams.json +86 -0
  100. package/src/features/theme/curated/perpetuity.json +86 -0
  101. package/src/features/theme/curated/quantum-rose.json +86 -0
  102. package/src/features/theme/curated/retro-arcade.json +86 -0
  103. package/src/features/theme/curated/sage-garden.json +86 -0
  104. package/src/features/theme/curated/shadcn.json +83 -0
  105. package/src/features/theme/curated/shellui.json +82 -0
  106. package/src/features/theme/curated/soft-pop.json +86 -0
  107. package/src/features/theme/curated/solar-dusk.json +86 -0
  108. package/src/features/theme/curated/starry-night.json +86 -0
  109. package/src/features/theme/curated/sunset-horizon.json +86 -0
  110. package/src/features/theme/curated/supabase.json +85 -0
  111. package/src/features/theme/curated/t3-chat.json +83 -0
  112. package/src/features/theme/curated/tangerine.json +86 -0
  113. package/src/features/theme/curated/twitter.json +86 -0
  114. package/src/features/theme/curated/vercel.json +86 -0
  115. package/src/features/theme/curated/vintage-paper.json +86 -0
  116. package/src/features/theme/curated/violet-bloom.json +87 -0
  117. package/src/features/theme/curated/zen-inspired.json +87 -0
  118. package/src/features/theme/index.ts +76 -0
  119. package/src/features/theme/normalize.ts +159 -0
  120. package/src/features/theme/registry.ts +50 -0
  121. package/src/features/theme/resolveConfig.ts +182 -0
  122. package/src/features/theme/safeApplyTheme.ts +147 -0
  123. package/src/features/theme/themes.spec.ts +276 -0
  124. package/src/features/theme/themes.ts +82 -558
  125. package/src/features/theme/tokenKeys.ts +60 -0
  126. package/src/features/theme/types.ts +170 -0
  127. package/src/features/theme/useTheme.tsx +48 -50
  128. package/src/hooks/use-mobile.tsx +19 -0
  129. package/src/i18n/translations/en/common.json +41 -0
  130. package/src/i18n/translations/en/settings.json +10 -2
  131. package/src/i18n/translations/fr/common.json +41 -0
  132. package/src/i18n/translations/fr/settings.json +10 -2
  133. package/src/index.css +372 -128
  134. package/src/index.ts +71 -0
  135. package/src/lib/z-index.ts +4 -1
  136. package/src/routes/components/IndexRoute.tsx +12 -2
  137. package/src/routes/components/NavigationItemRoute.tsx +1 -10
  138. package/src/routes/hooks/useNavigationItems.ts +29 -44
  139. package/src/routes/routes.tsx +58 -27
  140. package/tailwind.config.js +27 -27
  141. package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
  142. package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
@@ -0,0 +1,106 @@
1
+ import { IFRAME_FOREIGN_ATTR } from './constants';
2
+
3
+ export type DesktopBackIframe = {
4
+ isConnected: boolean;
5
+ src: string;
6
+ contentWindow: {
7
+ location: { href: string };
8
+ history: { back: () => void; forward: () => void };
9
+ } | null;
10
+ getAttribute: (name: string) => string | null;
11
+ removeAttribute: (name: string) => void;
12
+ };
13
+
14
+ export type DesktopBackResult = 'iframe' | 'overlay' | 'router';
15
+ export type DesktopForwardResult = 'iframe' | 'router';
16
+
17
+ /** Compare iframe locations; keeps hash so hash-router apps can go back/forward in-iframe. */
18
+ export function normalizeHref(href: string, base = 'http://localhost'): string {
19
+ try {
20
+ const url = new URL(href, base);
21
+ const path = url.pathname.replace(/\/$/, '') || '/';
22
+ return `${url.origin}${path === '/' ? '' : path}${url.search}${url.hash}`;
23
+ } catch {
24
+ return href.replace(/\/$/, '');
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Only handle foreign-origin navigations (e.g. OAuth). Same-origin SPA / hash routes are
30
+ * mirrored in the shell URL history — router back/forward + ContentView sync owns those.
31
+ * Calling iframe history.back() here would fight shell history (duplicate or skipped entries).
32
+ */
33
+ export function tryGoBackInIframe(iframe: DesktopBackIframe, _baseHref?: string): boolean {
34
+ if (!iframe.isConnected) return false;
35
+
36
+ if (iframe.getAttribute(IFRAME_FOREIGN_ATTR) === 'true') {
37
+ const assigned = iframe.getAttribute('src') || iframe.src;
38
+ if (assigned) {
39
+ iframe.src = assigned;
40
+ iframe.removeAttribute(IFRAME_FOREIGN_ATTR);
41
+ return true;
42
+ }
43
+ }
44
+
45
+ return false;
46
+ }
47
+
48
+ export function goBackInIframes(iframes: DesktopBackIframe[], baseHref?: string): boolean {
49
+ for (let index = iframes.length - 1; index >= 0; index -= 1) {
50
+ if (tryGoBackInIframe(iframes[index], baseHref)) return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+ export function goDesktopBack(options: {
56
+ iframes?: DesktopBackIframe[];
57
+ overlaysOpen?: boolean;
58
+ closeOverlays?: () => void;
59
+ goRouterBack?: () => void;
60
+ baseHref?: string;
61
+ }): DesktopBackResult {
62
+ if (options.iframes && goBackInIframes(options.iframes, options.baseHref)) {
63
+ return 'iframe';
64
+ }
65
+ if (options.overlaysOpen) {
66
+ options.closeOverlays?.();
67
+ return 'overlay';
68
+ }
69
+ options.goRouterBack?.();
70
+ return 'router';
71
+ }
72
+
73
+ /**
74
+ * Same-origin iframe forward is disabled for the same reason as back: shell URL history
75
+ * mirrors the app. Keep the helper for tests / potential foreign-doc use later.
76
+ */
77
+ export function tryGoForwardInIframe(iframe: DesktopBackIframe, baseHref?: string): boolean {
78
+ if (!iframe.isConnected) return false;
79
+ try {
80
+ const win = iframe.contentWindow;
81
+ if (!win) return false;
82
+ const before = normalizeHref(win.location.href, baseHref);
83
+ win.history.forward();
84
+ const after = normalizeHref(win.location.href, baseHref);
85
+ return after !== before;
86
+ } catch {
87
+ return false;
88
+ }
89
+ }
90
+
91
+ export function goForwardInIframes(_iframes: DesktopBackIframe[], _baseHref?: string): boolean {
92
+ // Shell owns mirrored SPA history — do not forward inside content iframes.
93
+ return false;
94
+ }
95
+
96
+ export function goDesktopForward(options: {
97
+ iframes?: DesktopBackIframe[];
98
+ goRouterForward?: () => void;
99
+ baseHref?: string;
100
+ }): DesktopForwardResult {
101
+ if (options.iframes && goForwardInIframes(options.iframes, options.baseHref)) {
102
+ return 'iframe';
103
+ }
104
+ options.goRouterForward?.();
105
+ return 'router';
106
+ }
@@ -0,0 +1,26 @@
1
+ export {
2
+ DESKTOP_TITLEBAR_HEIGHT_PX,
3
+ IFRAME_FOREIGN_ATTR,
4
+ MAC_TRAFFIC_LIGHTS_GAP_PX,
5
+ MAC_TRAFFIC_LIGHTS_WIDTH_PX,
6
+ } from './constants';
7
+ export {
8
+ goDesktopBack,
9
+ goBackInIframes,
10
+ tryGoBackInIframe,
11
+ goDesktopForward,
12
+ goForwardInIframes,
13
+ tryGoForwardInIframe,
14
+ } from './goDesktopBack';
15
+ export {
16
+ useIsTauriClient,
17
+ useMacOverlayChrome,
18
+ useMacTrafficLights,
19
+ isMacOSDesktop,
20
+ } from './runtime';
21
+ export { DesktopBackButton } from './DesktopBackButton';
22
+ export { DesktopForwardButton } from './DesktopForwardButton';
23
+ export { DesktopHistoryButtons } from './DesktopHistoryButtons';
24
+ export { ContentDragOverlay } from './ContentDragOverlay';
25
+ export { DesktopChrome } from './DesktopChrome';
26
+ export { CollapsedDesktopTitlebar } from './CollapsedDesktopTitlebar';
@@ -0,0 +1,45 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { isTauri } from '../../../service-worker/register';
3
+ import { useIsMobile } from '../../../hooks/use-mobile';
4
+
5
+ /** True for macOS desktop (not iOS/iPad, which can report MacIntel). */
6
+ export function isMacOSDesktop(): boolean {
7
+ if (typeof navigator === 'undefined') return false;
8
+ const platform = navigator.platform || '';
9
+ const touchIpad = platform === 'MacIntel' && navigator.maxTouchPoints > 1;
10
+ return platform.startsWith('Mac') && !touchIpad;
11
+ }
12
+
13
+ export function useIsTauriClient(): boolean {
14
+ const [value, setValue] = useState(() => isTauri());
15
+
16
+ useEffect(() => {
17
+ setValue(isTauri());
18
+ const timer = window.setTimeout(() => setValue(isTauri()), 200);
19
+ return () => window.clearTimeout(timer);
20
+ }, []);
21
+
22
+ return value;
23
+ }
24
+
25
+ /** Overlay titlebar chrome: Tauri on macOS, desktop (non-mobile) viewport. */
26
+ export function useMacOverlayChrome(): boolean {
27
+ const trafficLights = useMacTrafficLights();
28
+ const isMobile = useIsMobile();
29
+ return trafficLights && !isMobile;
30
+ }
31
+
32
+ /**
33
+ * Native macOS traffic lights are on the window (Tauri macOS), including
34
+ * narrow / mobile layouts where overlay chrome is otherwise disabled.
35
+ */
36
+ export function useMacTrafficLights(): boolean {
37
+ const tauri = useIsTauriClient();
38
+ const [isMac, setIsMac] = useState(false);
39
+
40
+ useEffect(() => {
41
+ setIsMac(isMacOSDesktop());
42
+ }, []);
43
+
44
+ return tauri && isMac;
45
+ }
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { NavigationItem } from '../config/types';
3
+ import { findMatchingNavigationItem, getActivePathPrefix, getNavPathPrefix } from './utils';
4
+
5
+ const root: NavigationItem = {
6
+ label: 'Home',
7
+ path: '',
8
+ url: 'http://localhost:5173/#/',
9
+ };
10
+
11
+ const home: NavigationItem = {
12
+ label: 'Home',
13
+ path: 'home',
14
+ url: 'http://localhost:5173/#/',
15
+ };
16
+
17
+ const themes: NavigationItem = {
18
+ label: 'Themes',
19
+ path: 'themes',
20
+ url: 'http://localhost:5173/#/themes',
21
+ };
22
+
23
+ describe('findMatchingNavigationItem', () => {
24
+ const items = [root, home, themes];
25
+
26
+ it('matches root at /', () => {
27
+ expect(findMatchingNavigationItem(items, '/')?.path).toBe('');
28
+ });
29
+
30
+ it('keeps deep links under / on the root app (not 404 / redirect)', () => {
31
+ expect(findMatchingNavigationItem(items, '/layout')?.path).toBe('');
32
+ expect(findMatchingNavigationItem(items, '/foo/bar')?.path).toBe('');
33
+ });
34
+
35
+ it('prefers a more specific nav path over root', () => {
36
+ expect(findMatchingNavigationItem(items, '/home')?.path).toBe('home');
37
+ expect(findMatchingNavigationItem(items, '/home/settings')?.path).toBe('home');
38
+ expect(findMatchingNavigationItem(items, '/themes')?.path).toBe('themes');
39
+ expect(findMatchingNavigationItem(items, '/themes/colors')?.path).toBe('themes');
40
+ });
41
+
42
+ it('returns undefined when nothing matches and there is no root item', () => {
43
+ expect(findMatchingNavigationItem([home, themes], '/unknown')).toBeUndefined();
44
+ });
45
+ });
46
+
47
+ describe('getActivePathPrefix', () => {
48
+ it('uses longest prefix including root deep links', () => {
49
+ const items = [root, home, themes];
50
+ expect(getActivePathPrefix('/', items)).toBe('/');
51
+ expect(getActivePathPrefix('/layout', items)).toBe('/');
52
+ expect(getActivePathPrefix('/home/x', items)).toBe('/home');
53
+ expect(getNavPathPrefix(root)).toBe('/');
54
+ });
55
+ });
@@ -3,6 +3,9 @@ import { Outlet, useLocation } from 'react-router';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import type { NavigationItem, NavigationGroup } from '../../config/types';
5
5
  import { flattenNavigationItems } from '../utils';
6
+ import { DesktopHistoryButtons } from '../chrome/DesktopHistoryButtons';
7
+ import { useIsTauriClient, useMacOverlayChrome } from '../chrome/runtime';
8
+ import { DESKTOP_TITLEBAR_HEIGHT_PX, MAC_TRAFFIC_LIGHTS_WIDTH_PX } from '../chrome/constants';
6
9
 
7
10
  interface FullscreenLayoutProps {
8
11
  title?: string;
@@ -22,6 +25,8 @@ function resolveLocalizedLabel(
22
25
  export function FullscreenLayout({ title, navigation, children }: FullscreenLayoutProps) {
23
26
  const location = useLocation();
24
27
  const { i18n } = useTranslation();
28
+ const isTauriEnv = useIsTauriClient();
29
+ const overlay = useMacOverlayChrome();
25
30
  const currentLanguage = i18n.language || 'en';
26
31
  const navigationItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
27
32
 
@@ -43,7 +48,18 @@ export function FullscreenLayout({ title, navigation, children }: FullscreenLayo
43
48
  }, [location.pathname, title, navigationItems, currentLanguage]);
44
49
 
45
50
  return (
46
- <main className="flex flex-col w-full h-screen overflow-hidden bg-background">
51
+ <main className="relative flex flex-col w-full h-screen overflow-hidden bg-background">
52
+ {isTauriEnv ? (
53
+ <div
54
+ className="pointer-events-auto absolute top-0 left-0 z-[46] flex items-center"
55
+ style={{
56
+ height: DESKTOP_TITLEBAR_HEIGHT_PX,
57
+ paddingLeft: overlay ? MAC_TRAFFIC_LIGHTS_WIDTH_PX : 8,
58
+ }}
59
+ >
60
+ <DesktopHistoryButtons />
61
+ </div>
62
+ ) : null}
47
63
  {children || <Outlet />}
48
64
  </main>
49
65
  );
@@ -0,0 +1,33 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { isFrameForAppUrl } from './utils';
3
+
4
+ describe('isFrameForAppUrl', () => {
5
+ it('matches same origin site-root app and deep-linked iframe paths', () => {
6
+ const app = 'http://localhost:5175/';
7
+ expect(isFrameForAppUrl('http://localhost:5175/', app)).toBe(true);
8
+ expect(isFrameForAppUrl('http://localhost:5175/company', app)).toBe(true);
9
+ expect(isFrameForAppUrl('http://localhost:5175/company/Test', app)).toBe(true);
10
+ });
11
+
12
+ it('matches nested app base paths', () => {
13
+ const app = 'https://files.example.com/app/';
14
+ expect(isFrameForAppUrl('https://files.example.com/app', app)).toBe(true);
15
+ expect(isFrameForAppUrl('https://files.example.com/app/company/docs', app)).toBe(true);
16
+ expect(isFrameForAppUrl('https://files.example.com/other/company', app)).toBe(false);
17
+ });
18
+
19
+ it('rejects other origins', () => {
20
+ expect(isFrameForAppUrl('http://localhost:5176/company', 'http://localhost:5175/')).toBe(false);
21
+ });
22
+
23
+ it('matches hash-router prefixes when the app URL includes a hash', () => {
24
+ const app = 'http://localhost:5174/#/';
25
+ expect(isFrameForAppUrl('http://localhost:5174/#/users', app)).toBe(true);
26
+ expect(
27
+ isFrameForAppUrl('http://localhost:5174/#/themes/foo', 'http://localhost:5174/#/themes'),
28
+ ).toBe(true);
29
+ expect(
30
+ isFrameForAppUrl('http://localhost:5174/#/other', 'http://localhost:5174/#/themes'),
31
+ ).toBe(false);
32
+ });
33
+ });
@@ -1,5 +1,5 @@
1
1
  import { Link, useLocation } from 'react-router';
2
- import { useMemo } from 'react';
2
+ import { useMemo, type ReactNode } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { shellui } from '@shellui/sdk';
5
5
  import type { NavigationItem, NavigationGroup } from '../../config/types';
@@ -14,12 +14,19 @@ import {
14
14
  import { cn } from '../../../lib/utils';
15
15
  import { getActivePathPrefix, getNavPathPrefix, flattenNavigationItems } from '../utils';
16
16
  import { getExternalFaviconUrl } from './sidebarUtils';
17
- import { ExternalLinkIcon } from './SidebarIcons';
17
+ import { ExternalLinkIcon, NavIcon } from './SidebarIcons';
18
+
19
+ const isGroup = (item: NavigationItem | NavigationGroup): item is NavigationGroup => {
20
+ return 'title' in item && 'items' in item;
21
+ };
18
22
 
19
23
  export function NavigationContent({
20
24
  navigation,
25
+ trailing,
21
26
  }: {
22
27
  navigation: (NavigationItem | NavigationGroup)[];
28
+ /** Appended as the last item in the final menu so spacing matches the stack (e.g. avatar). */
29
+ trailing?: ReactNode;
23
30
  }) {
24
31
  const location = useLocation();
25
32
  const { i18n } = useTranslation();
@@ -33,24 +40,34 @@ export function NavigationContent({
33
40
  return value[lang] || value.en || value.fr || Object.values(value)[0] || '';
34
41
  };
35
42
 
36
- const hasAnyIcons = useMemo(() => {
37
- return navigation.some((item) => {
38
- if ('title' in item && 'items' in item) {
39
- return (item as NavigationGroup).items.some((navItem) => !!navItem.icon);
40
- }
41
- return !!(item as NavigationItem).icon;
42
- });
43
- }, [navigation]);
44
-
45
43
  const flatItems = useMemo(() => flattenNavigationItems(navigation), [navigation]);
46
44
  const activePathPrefix = useMemo(
47
45
  () => getActivePathPrefix(location.pathname, flatItems),
48
46
  [location.pathname, flatItems],
49
47
  );
50
48
 
51
- const isGroup = (item: NavigationItem | NavigationGroup): item is NavigationGroup => {
52
- return 'title' in item && 'items' in item;
53
- };
49
+ // Chunk consecutive top-level items into one SidebarGroup so spacing matches
50
+ // items inside titled groups (one group padding, not one per item).
51
+ const sections = useMemo(() => {
52
+ const result: Array<
53
+ { type: 'group'; group: NavigationGroup } | { type: 'items'; items: NavigationItem[] }
54
+ > = [];
55
+
56
+ for (const item of navigation) {
57
+ if (isGroup(item)) {
58
+ result.push({ type: 'group', group: item });
59
+ continue;
60
+ }
61
+ const last = result[result.length - 1];
62
+ if (last?.type === 'items') {
63
+ last.items.push(item);
64
+ } else {
65
+ result.push({ type: 'items', items: [item] });
66
+ }
67
+ }
68
+
69
+ return result;
70
+ }, [navigation]);
54
71
 
55
72
  const renderNavItem = (navItem: NavigationItem) => {
56
73
  const pathPrefix = getNavPathPrefix(navItem);
@@ -60,17 +77,9 @@ export function NavigationContent({
60
77
  const itemLabel = resolveLocalizedString(navItem.label, currentLanguage);
61
78
  const faviconUrl = isExternal && !navItem.icon ? getExternalFaviconUrl(navItem.url) : null;
62
79
  const iconSrc = navItem.icon ?? faviconUrl ?? null;
63
- const iconEl = iconSrc ? (
64
- <img
65
- src={iconSrc}
66
- alt=""
67
- className={cn('h-4 w-4', 'shrink-0')}
68
- />
69
- ) : hasAnyIcons ? (
70
- <span className="h-4 w-4 shrink-0" />
71
- ) : null;
80
+ const iconEl = <NavIcon src={iconSrc} />;
72
81
  const externalIcon = isExternal ? (
73
- <ExternalLinkIcon className="ml-auto h-4 w-4 shrink-0 opacity-70" />
82
+ <ExternalLinkIcon className="ml-auto size-4 shrink-0 opacity-70" />
74
83
  ) : null;
75
84
  const content = (
76
85
  <>
@@ -117,6 +126,7 @@ export function NavigationContent({
117
126
  <SidebarMenuButton
118
127
  asChild
119
128
  isActive={isActive}
129
+ tooltip={itemLabel}
120
130
  className={cn('w-full', isActive && 'bg-sidebar-accent text-sidebar-accent-foreground')}
121
131
  >
122
132
  {linkOrTrigger}
@@ -124,34 +134,60 @@ export function NavigationContent({
124
134
  );
125
135
  };
126
136
 
137
+ const trailingItem = trailing ? (
138
+ <SidebarMenuItem key="__trailing">{trailing}</SidebarMenuItem>
139
+ ) : null;
140
+
141
+ if (sections.length === 0 && trailingItem) {
142
+ return (
143
+ <SidebarGroup className="mt-0">
144
+ <SidebarGroupContent>
145
+ <SidebarMenu className="gap-0.5">{trailingItem}</SidebarMenu>
146
+ </SidebarGroupContent>
147
+ </SidebarGroup>
148
+ );
149
+ }
150
+
127
151
  return (
128
152
  <>
129
- {navigation.map((item) => {
130
- if (isGroup(item)) {
131
- const groupTitle = resolveLocalizedString(item.title, currentLanguage);
153
+ {sections.map((section, sectionIndex) => {
154
+ const isLastSection = sectionIndex === sections.length - 1;
155
+ const menuTrailing = isLastSection ? trailingItem : null;
156
+
157
+ if (section.type === 'group') {
158
+ const groupTitle = resolveLocalizedString(section.group.title, currentLanguage);
132
159
  return (
133
160
  <SidebarGroup
134
- key={groupTitle}
161
+ key={`group-${groupTitle}-${sectionIndex}`}
135
162
  className="mt-0"
136
163
  >
137
164
  <SidebarGroupLabel className="mb-1">{groupTitle}</SidebarGroupLabel>
138
165
  <SidebarGroupContent>
139
166
  <SidebarMenu className="gap-0.5">
140
- {item.items.map((navItem) => (
167
+ {section.group.items.map((navItem) => (
141
168
  <SidebarMenuItem key={navItem.path}>{renderNavItem(navItem)}</SidebarMenuItem>
142
169
  ))}
170
+ {menuTrailing}
143
171
  </SidebarMenu>
144
172
  </SidebarGroupContent>
145
173
  </SidebarGroup>
146
174
  );
147
175
  }
176
+
148
177
  return (
149
- <SidebarMenu
150
- key={item.path}
151
- className="gap-0.5"
178
+ <SidebarGroup
179
+ key={`items-${section.items.map((i) => i.path).join('-')}-${sectionIndex}`}
180
+ className="mt-0"
152
181
  >
153
- <SidebarMenuItem>{renderNavItem(item)}</SidebarMenuItem>
154
- </SidebarMenu>
182
+ <SidebarGroupContent>
183
+ <SidebarMenu className="gap-0.5">
184
+ {section.items.map((navItem) => (
185
+ <SidebarMenuItem key={navItem.path}>{renderNavItem(navItem)}</SidebarMenuItem>
186
+ ))}
187
+ {menuTrailing}
188
+ </SidebarMenu>
189
+ </SidebarGroupContent>
190
+ </SidebarGroup>
155
191
  );
156
192
  })}
157
193
  </>
@@ -1,4 +1,5 @@
1
1
  import { cn } from '../../../lib/utils';
2
+ import { isAppIcon } from './sidebarUtils';
2
3
 
3
4
  /** Inline SVG: external-link icon. Bundled so consumers don't need to serve static SVGs. */
4
5
  export function ExternalLinkIcon({ className }: { className?: string }) {
@@ -28,8 +29,8 @@ export function ExternalLinkIcon({ className }: { className?: string }) {
28
29
  );
29
30
  }
30
31
 
31
- /** Caret up: expand (show second line). */
32
- export function CaretUpIcon({ className }: { className?: string }) {
32
+ /** Default nav icon when a navigation item has no custom icon. */
33
+ export function DefaultNavIcon({ className }: { className?: string }) {
33
34
  return (
34
35
  <svg
35
36
  xmlns="http://www.w3.org/2000/svg"
@@ -41,53 +42,51 @@ export function CaretUpIcon({ className }: { className?: string }) {
41
42
  strokeWidth="2"
42
43
  strokeLinecap="round"
43
44
  strokeLinejoin="round"
44
- className={cn('shrink-0', className)}
45
+ className={cn('size-4 shrink-0', className)}
45
46
  aria-hidden
46
47
  >
47
- <path d="m18 15-6-6-6 6" />
48
+ <circle
49
+ cx="12"
50
+ cy="12"
51
+ r="8"
52
+ />
48
53
  </svg>
49
54
  );
50
55
  }
51
56
 
52
- /** Caret down: collapse (hide second line). */
53
- export function CaretDownIcon({ className }: { className?: string }) {
54
- return (
55
- <svg
56
- xmlns="http://www.w3.org/2000/svg"
57
- width="24"
58
- height="24"
59
- viewBox="0 0 24 24"
60
- fill="none"
61
- stroke="currentColor"
62
- strokeWidth="2"
63
- strokeLinecap="round"
64
- strokeLinejoin="round"
65
- className={cn('shrink-0', className)}
66
- aria-hidden
67
- >
68
- <path d="m6 9 6 6 6-6" />
69
- </svg>
70
- );
71
- }
57
+ /**
58
+ * Nav icon that follows sidebar text color (including hover / active).
59
+ * Local `/icons/*.svg` use a CSS mask + `currentColor`; external images stay as `<img>`.
60
+ */
61
+ export function NavIcon({ src, className }: { src?: string | null; className?: string }) {
62
+ if (!src) {
63
+ return <DefaultNavIcon className={className} />;
64
+ }
65
+
66
+ if (isAppIcon(src)) {
67
+ return (
68
+ <span
69
+ aria-hidden
70
+ className={cn('size-4 shrink-0 bg-current', className)}
71
+ style={{
72
+ maskImage: `url("${src}")`,
73
+ WebkitMaskImage: `url("${src}")`,
74
+ maskSize: 'contain',
75
+ WebkitMaskSize: 'contain',
76
+ maskRepeat: 'no-repeat',
77
+ WebkitMaskRepeat: 'no-repeat',
78
+ maskPosition: 'center',
79
+ WebkitMaskPosition: 'center',
80
+ }}
81
+ />
82
+ );
83
+ }
72
84
 
73
- /** Home icon for mobile bottom bar (same as sidebar logo action). */
74
- export function HomeIcon({ className }: { className?: string }) {
75
85
  return (
76
- <svg
77
- xmlns="http://www.w3.org/2000/svg"
78
- width="24"
79
- height="24"
80
- viewBox="0 0 24 24"
81
- fill="none"
82
- stroke="currentColor"
83
- strokeWidth="2"
84
- strokeLinecap="round"
85
- strokeLinejoin="round"
86
- className={cn('shrink-0', className)}
87
- aria-hidden
88
- >
89
- <path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" />
90
- <polyline points="9 22 9 12 15 12 15 22" />
91
- </svg>
86
+ <img
87
+ src={src}
88
+ alt=""
89
+ className={cn('size-4 shrink-0', className)}
90
+ />
92
91
  );
93
92
  }