@shellui/core 0.7.0-alpha.10 → 0.7.0-alpha.11

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 (44) hide show
  1. package/package.json +2 -2
  2. package/src/components/ui/drawer.tsx +47 -30
  3. package/src/components/ui/sheet.tsx +18 -12
  4. package/src/components/ui/sidebar.tsx +14 -6
  5. package/src/components/ui/tooltip.tsx +4 -2
  6. package/src/features/auth/components/LoginButton.spec.tsx +155 -0
  7. package/src/features/auth/components/LoginButton.tsx +52 -27
  8. package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
  9. package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
  10. package/src/features/layouts/OverlayShell.tsx +58 -40
  11. package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
  12. package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
  13. package/src/features/layouts/appbar/AppBarLayout.tsx +53 -81
  14. package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
  15. package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
  16. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +1 -1
  17. package/src/features/layouts/chrome/constants.ts +3 -0
  18. package/src/features/layouts/chrome/viewport.ts +11 -4
  19. package/src/features/layouts/floating/FloatingBottomDock.tsx +66 -25
  20. package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
  21. package/src/features/layouts/floating/FloatingSidebar.tsx +26 -8
  22. package/src/features/layouts/floating/moreSections.spec.ts +28 -0
  23. package/src/features/layouts/floating/moreSections.ts +31 -0
  24. package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
  25. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +10 -1
  26. package/src/features/layouts/sidebar/NavigationContent.tsx +4 -4
  27. package/src/features/layouts/sidebar/SidebarIcons.tsx +67 -0
  28. package/src/features/layouts/sidebar/SidebarInner.spec.tsx +109 -0
  29. package/src/features/layouts/sidebar/SidebarInner.tsx +49 -9
  30. package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
  31. package/src/features/layouts/windows/WindowsLayout.tsx +75 -44
  32. package/src/features/layouts/windows/deskDots.spec.ts +6 -4
  33. package/src/features/layouts/windows/deskDots.ts +8 -8
  34. package/src/features/overlays/ResponsiveModal.tsx +5 -3
  35. package/src/features/overlays/overlaySize.spec.ts +56 -16
  36. package/src/features/overlays/overlaySize.ts +114 -31
  37. package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
  38. package/src/features/overlays/useOverlayReportedSize.ts +8 -3
  39. package/src/i18n/translations/en/common.json +1 -0
  40. package/src/i18n/translations/fr/common.json +1 -0
  41. package/src/index.css +211 -32
  42. package/src/service-worker/devCaches.spec.ts +32 -0
  43. package/src/service-worker/devCaches.ts +27 -0
  44. package/src/service-worker/sw-dev.ts +23 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shellui/core",
3
- "version": "0.7.0-alpha.10",
3
+ "version": "0.7.0-alpha.11",
4
4
  "description": "Shellui Core - Core React application runtime",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -73,7 +73,7 @@
73
73
  "workbox-routing": "^7.4.0",
74
74
  "workbox-strategies": "^7.4.0",
75
75
  "workbox-window": "^7.4.0",
76
- "@shellui/sdk": "0.7.0-alpha.10"
76
+ "@shellui/sdk": "0.7.0-alpha.11"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "react": "^18.0.0 || ^19.0.0",
@@ -17,11 +17,13 @@ import {
17
17
  import { Drawer as VaulDrawer } from 'vaul';
18
18
  import { cn } from '../../lib/utils';
19
19
  import { Z_INDEX } from '../../lib/z-index';
20
+ import { readCssLengthPx } from '../../features/layouts/chrome/viewport';
20
21
 
21
22
  export type DrawerDirection = 'top' | 'bottom' | 'left' | 'right';
22
23
 
23
24
  const MIN_DRAWER_SIZE = 240;
24
- const VIEWPORT_MARGIN = 8;
25
+ /** Fallback edge offset (desktop gap) when the CSS token cannot be read. */
26
+ const FALLBACK_DRAWER_OFFSET_PX = 12;
25
27
 
26
28
  const Drawer = ({
27
29
  open,
@@ -65,7 +67,7 @@ const DrawerOverlay = forwardRef<
65
67
  <VaulDrawer.Overlay
66
68
  ref={ref}
67
69
  data-drawer-overlay
68
- className={cn('fixed inset-0 bg-black/50 backdrop-blur-[1px]', className)}
70
+ className={cn('fixed inset-0 bg-[var(--shellui-scrim)]', className)}
69
71
  style={{ zIndex: Z_INDEX.DRAWER_OVERLAY }}
70
72
  onClick={(e) => {
71
73
  if (!closeOnClick) {
@@ -80,42 +82,53 @@ const DrawerOverlay = forwardRef<
80
82
  ));
81
83
  DrawerOverlay.displayName = VaulDrawer.Overlay.displayName;
82
84
 
83
- /** Base layout classes per direction — max dimension is applied via style so size prop can override. */
85
+ /**
86
+ * Floating panel: a gap away from the window edge on its outer sides (the offsets
87
+ * include the safe area), all corners rounded, hairline border and soft shadow.
88
+ */
89
+ const drawerPanel =
90
+ 'fixed flex flex-col overflow-clip border border-[var(--shellui-drawer-border)] bg-background rounded-[var(--shellui-drawer-radius)] shadow-[var(--shellui-drawer-shadow)]';
91
+
92
+ /** Base layout classes per direction. Max dimension is applied via style so size prop can override. */
84
93
  const drawerContentByDirection: Record<DrawerDirection, string> = {
85
- bottom:
86
- 'fixed inset-x-0 bottom-0 mt-24 flex h-auto flex-col rounded-t-xl border border-border bg-background pb-[var(--shellui-safe-area-bottom)]',
87
- top: 'fixed inset-x-0 top-0 mb-24 flex h-auto flex-col rounded-b-xl border border-border bg-background pt-[var(--shellui-safe-area-top)]',
88
- left: 'fixed inset-y-0 left-0 mr-24 flex h-full w-auto flex-col rounded-r-xl border border-border bg-background pl-[var(--shellui-safe-area-left)]',
89
- right:
90
- 'fixed inset-y-0 right-0 ml-24 flex h-full w-auto flex-col rounded-l-xl border border-border bg-background pr-[var(--shellui-safe-area-right)]',
94
+ bottom: `${drawerPanel} bottom-[var(--shellui-drawer-bottom)] left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)] h-auto max-md:rounded-[var(--shellui-sheet-radius)]`,
95
+ top: `${drawerPanel} top-[var(--shellui-drawer-top)] left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)] h-auto`,
96
+ left: `${drawerPanel} top-[var(--shellui-drawer-top)] bottom-[var(--shellui-drawer-bottom)] left-[var(--shellui-drawer-left)] h-auto w-auto`,
97
+ right: `${drawerPanel} top-[var(--shellui-drawer-top)] bottom-[var(--shellui-drawer-bottom)] right-[var(--shellui-drawer-right)] h-auto w-auto`,
91
98
  };
92
99
 
93
- /** Free-edge resize handle (opposite the anchored side). */
100
+ /** Free-edge resize handle (opposite the anchored side), 8px, inside the panel. */
94
101
  const resizeHandleByDirection: Record<DrawerDirection, { className: string; cursor: string }> = {
95
102
  right: {
96
- className: 'absolute left-0 top-3 bottom-3 w-1.5 -translate-x-1/2',
103
+ className: 'absolute left-0 top-3 bottom-3 w-2',
97
104
  cursor: 'ew-resize',
98
105
  },
99
106
  left: {
100
- className: 'absolute right-0 top-3 bottom-3 w-1.5 translate-x-1/2',
107
+ className: 'absolute right-0 top-3 bottom-3 w-2',
101
108
  cursor: 'ew-resize',
102
109
  },
103
110
  bottom: {
104
- className: 'absolute top-0 left-3 right-3 h-1.5 -translate-y-1/2',
111
+ className: 'absolute top-0 left-3 right-3 h-2',
105
112
  cursor: 'ns-resize',
106
113
  },
107
114
  top: {
108
- className: 'absolute bottom-0 left-3 right-3 h-1.5 translate-y-1/2',
115
+ className: 'absolute bottom-0 left-3 right-3 h-2',
109
116
  cursor: 'ns-resize',
110
117
  },
111
118
  };
112
119
 
120
+ function readDrawerOffsetPx(side: 'top' | 'right' | 'bottom' | 'left'): number {
121
+ const px = readCssLengthPx(`var(--shellui-drawer-${side})`);
122
+ return px > 0 ? px : FALLBACK_DRAWER_OFFSET_PX;
123
+ }
124
+
125
+ /** Largest panel size: the viewport minus the offsets on both ends of the size axis. */
113
126
  function maxPrimarySize(direction: DrawerDirection): number {
114
127
  const isVertical = direction === 'top' || direction === 'bottom';
115
- return Math.max(
116
- MIN_DRAWER_SIZE,
117
- (isVertical ? window.innerHeight : window.innerWidth) - VIEWPORT_MARGIN,
118
- );
128
+ const margin = isVertical
129
+ ? readDrawerOffsetPx('top') + readDrawerOffsetPx('bottom')
130
+ : readDrawerOffsetPx('left') + readDrawerOffsetPx('right');
131
+ return Math.max(MIN_DRAWER_SIZE, (isVertical ? window.innerHeight : window.innerWidth) - margin);
119
132
  }
120
133
 
121
134
  function clampDrawerSize(px: number, direction: DrawerDirection): number {
@@ -264,22 +277,25 @@ const DrawerContent = forwardRef<ComponentRef<typeof VaulDrawer.Content>, Drawer
264
277
  ? isVertical
265
278
  ? {
266
279
  height: effectiveSize,
267
- maxHeight: `min(${effectiveSize}, calc(var(--shellui-overlay-max-height) - ${VIEWPORT_MARGIN}px))`,
280
+ maxHeight: `min(${effectiveSize}, var(--shellui-drawer-max-height))`,
268
281
  }
269
282
  : {
270
283
  width: effectiveSize,
271
- maxWidth: `min(${effectiveSize}, calc(100vw - ${VIEWPORT_MARGIN}px))`,
284
+ maxWidth: `min(${effectiveSize}, var(--shellui-drawer-max-width))`,
272
285
  }
273
286
  : size === null
274
287
  ? isVertical
275
- ? { maxHeight: 'var(--shellui-overlay-max-height)' }
276
- : { maxWidth: 'min(90vw, 100%)' }
288
+ ? { maxHeight: 'var(--shellui-drawer-max-height)' }
289
+ : { maxWidth: 'min(90vw, var(--shellui-drawer-max-width))' }
277
290
  : isVertical
278
291
  ? {
279
292
  height: effectiveSize,
280
- maxHeight: `min(${effectiveSize}, var(--shellui-overlay-max-height))`,
293
+ maxHeight: `min(${effectiveSize}, var(--shellui-drawer-max-height))`,
281
294
  }
282
- : { width: effectiveSize, maxWidth: `min(${effectiveSize}, 100%)` };
295
+ : {
296
+ width: effectiveSize,
297
+ maxWidth: `min(${effectiveSize}, var(--shellui-drawer-max-width))`,
298
+ };
283
299
 
284
300
  const resizeHandle = resizeHandleByDirection[pos];
285
301
 
@@ -387,7 +403,7 @@ DrawerHeader.displayName = 'DrawerHeader';
387
403
  const DrawerFooter = ({ className, ...props }: HTMLAttributes<HTMLDivElement>) => (
388
404
  <div
389
405
  className={cn(
390
- 'mt-auto flex flex-col-reverse gap-2 border-t border-border px-6 pt-4 pb-[max(1rem,var(--shellui-safe-area-bottom))] sm:flex-row sm:justify-end',
406
+ 'mt-auto flex flex-col-reverse gap-2 border-t border-border px-6 py-4 sm:flex-row sm:justify-end',
391
407
  className,
392
408
  )}
393
409
  {...props}
@@ -428,14 +444,15 @@ const DrawerHandle = forwardRef<
428
444
  ref={ref}
429
445
  data-drawer-handle
430
446
  className={cn(
431
- // !important overrides Vaul's injected `background: #e2e2e4` + 5px height
432
- 'mx-auto mt-1.5 h-[3px] w-8 shrink-0 rounded-full !bg-muted-foreground/70 !opacity-100',
447
+ // Same pill as the More sheet handle: 36 x 5px, 6px from the top (Vaul adds the 44px hit area).
448
+ 'mx-auto mt-1.5 h-[5px] w-9 shrink-0 rounded-full !opacity-100',
433
449
  className,
434
450
  )}
435
451
  style={{
436
- // Inline wins over Vaul stylesheet `background` / size when utilities lose the race
437
- background: 'color-mix(in oklch, var(--muted-foreground) 70%, transparent)',
438
- height: '3px',
452
+ // Inline wins over Vaul's injected `background: #e2e2e4`
453
+ background: 'color-mix(in oklch, var(--foreground) 22%, transparent)',
454
+ width: '36px',
455
+ height: '5px',
439
456
  borderRadius: '9999px',
440
457
  ...style,
441
458
  }}
@@ -35,26 +35,32 @@ const SheetOverlay = forwardRef<
35
35
  <SheetPrimitive.Overlay
36
36
  ref={ref}
37
37
  data-sheet-overlay=""
38
- className={cn('fixed inset-0 bg-black/50 backdrop-blur-[1px]', className)}
38
+ className={cn('fixed inset-0 bg-[var(--shellui-scrim)]', className)}
39
39
  style={{ zIndex: Z_INDEX.SIDEBAR_SHEET_OVERLAY, ...style }}
40
40
  {...props}
41
41
  />
42
42
  ));
43
43
  SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
44
44
 
45
- const sheetVariants = cva('fixed flex flex-col gap-4 bg-background shadow-lg', {
46
- variants: {
47
- side: {
48
- top: 'inset-x-0 top-0 border-b',
49
- bottom: 'inset-x-0 bottom-0 border-t',
50
- left: 'inset-y-0 left-0 h-full w-3/4 max-w-full border-r sm:max-w-sm',
51
- right: 'inset-y-0 right-0 h-full w-3/4 max-w-full border-l sm:max-w-sm',
45
+ /** Floating sheet: same offsets, radius, border and shadow as the drawer panel. */
46
+ const sheetVariants = cva(
47
+ 'fixed flex flex-col gap-4 overflow-clip border border-[var(--shellui-drawer-border)] bg-background rounded-[var(--shellui-drawer-radius)] shadow-[var(--shellui-drawer-shadow)]',
48
+ {
49
+ variants: {
50
+ side: {
51
+ top: 'top-[var(--shellui-drawer-top)] left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)]',
52
+ bottom:
53
+ 'bottom-[var(--shellui-drawer-bottom)] left-[var(--shellui-drawer-left)] right-[var(--shellui-drawer-right)] max-md:rounded-[var(--shellui-sheet-radius)]',
54
+ left: 'top-[var(--shellui-drawer-top)] bottom-[var(--shellui-drawer-bottom)] left-[var(--shellui-drawer-left)] w-3/4 max-w-[var(--shellui-drawer-max-width)] sm:max-w-sm',
55
+ right:
56
+ 'top-[var(--shellui-drawer-top)] bottom-[var(--shellui-drawer-bottom)] right-[var(--shellui-drawer-right)] w-3/4 max-w-[var(--shellui-drawer-max-width)] sm:max-w-sm',
57
+ },
58
+ },
59
+ defaultVariants: {
60
+ side: 'right',
52
61
  },
53
62
  },
54
- defaultVariants: {
55
- side: 'right',
56
- },
57
- });
63
+ );
58
64
 
59
65
  interface SheetContentProps
60
66
  extends
@@ -47,7 +47,8 @@ const SIDEBAR_WIDTH_DEFAULT_PX = 256;
47
47
  const SIDEBAR_WIDTH_MIN_PX = 230;
48
48
  const SIDEBAR_WIDTH_MAX_PX = 480;
49
49
  /** Cap at the viewport so a phone narrower than 18rem still gets a full-width sheet. */
50
- const SIDEBAR_WIDTH_MOBILE = 'min(18rem, 100%)';
50
+ /** Phone nav sheet width, capped so the floating sheet keeps its gap on both sides. */
51
+ const SIDEBAR_WIDTH_MOBILE = 'min(18rem, 100%, calc(100% - 2 * var(--shellui-drawer-gap)))';
51
52
  const SIDEBAR_WIDTH_ICON = '3rem';
52
53
  const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
53
54
  /** Ignore tiny pointer moves so a rail click still toggles. */
@@ -223,7 +224,7 @@ function SidebarProvider({
223
224
 
224
225
  return (
225
226
  <SidebarContext.Provider value={contextValue}>
226
- <TooltipProvider delayDuration={0}>
227
+ <TooltipProvider delayDuration={200}>
227
228
  <div
228
229
  data-slot="sidebar-wrapper"
229
230
  data-resizing={isResizing ? '' : undefined}
@@ -249,6 +250,9 @@ function SidebarProvider({
249
250
  );
250
251
  }
251
252
 
253
+ /** DOM id of the sidebar panel, for the trigger's `aria-controls`. */
254
+ export const SIDEBAR_PANEL_ID = 'shellui-sidebar';
255
+
252
256
  function Sidebar({
253
257
  side = 'left',
254
258
  variant = 'sidebar',
@@ -296,6 +300,7 @@ function Sidebar({
296
300
  data-sidebar="sidebar"
297
301
  data-slot="sidebar"
298
302
  data-mobile="true"
303
+ id={SIDEBAR_PANEL_ID}
299
304
  className="w-(--sidebar-width) max-w-full overflow-x-hidden bg-sidebar p-0 text-sidebar-foreground sm:max-w-full [&>button]:hidden"
300
305
  style={
301
306
  {
@@ -310,9 +315,7 @@ function Sidebar({
310
315
  <SheetTitle>{t('desktopChrome.navigation')}</SheetTitle>
311
316
  <SheetDescription>{t('shellChrome.sheetDescription')}</SheetDescription>
312
317
  </SheetHeader>
313
- <div className="flex h-full min-h-0 w-full flex-col overflow-hidden pt-[var(--shellui-safe-area-top)] pr-[var(--shellui-safe-area-right)] pl-[var(--shellui-safe-area-left)]">
314
- {children}
315
- </div>
318
+ <div className="flex h-full min-h-0 w-full flex-col overflow-hidden">{children}</div>
316
319
  </SheetContent>
317
320
  </Sheet>
318
321
  );
@@ -363,6 +366,7 @@ function Sidebar({
363
366
  <div
364
367
  data-sidebar="sidebar"
365
368
  data-slot="sidebar-inner"
369
+ id={SIDEBAR_PANEL_ID}
366
370
  className={cn(
367
371
  'flex h-full w-full flex-col bg-sidebar',
368
372
  'group-data-[variant=inset]:bg-transparent',
@@ -377,7 +381,7 @@ function Sidebar({
377
381
  }
378
382
 
379
383
  function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
380
- const { toggleSidebar } = useSidebar();
384
+ const { toggleSidebar, isMobile, open, openMobile } = useSidebar();
381
385
  const { t } = useTranslation();
382
386
 
383
387
  return (
@@ -388,6 +392,8 @@ function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<t
388
392
  variant="ghost"
389
393
  size="icon"
390
394
  aria-label={t('shellChrome.toggleSidebar')}
395
+ aria-expanded={isMobile ? openMobile : open}
396
+ aria-controls={SIDEBAR_PANEL_ID}
391
397
  className={cn(
392
398
  'size-7 touch-manipulation select-none [-webkit-touch-callout:none]',
393
399
  className,
@@ -769,6 +775,8 @@ function SidebarMenuButton({
769
775
  <TooltipContent
770
776
  side="right"
771
777
  align="center"
778
+ sideOffset={8}
779
+ className="rounded-[calc(var(--shellui-r-row)-1px)] border-0 bg-foreground px-2 py-1 text-xs font-medium text-background shadow-none"
772
780
  hidden={state !== 'collapsed' || isMobile}
773
781
  {...tooltip}
774
782
  />
@@ -32,15 +32,17 @@ TooltipContent.displayName = TooltipPrimitive.Content.displayName;
32
32
  export interface AppBarTooltipProps {
33
33
  label: string;
34
34
  children: ReactNode;
35
+ /** Defaults to below; the windows taskbar opens it above. */
36
+ side?: 'top' | 'bottom';
35
37
  }
36
38
 
37
39
  /** Themed tooltip for app-bar end buttons: no arrow, no animation. */
38
- function AppBarTooltip({ label, children }: AppBarTooltipProps) {
40
+ function AppBarTooltip({ label, children, side = 'bottom' }: AppBarTooltipProps) {
39
41
  return (
40
42
  <Tooltip delayDuration={200}>
41
43
  <TooltipTrigger asChild>{children}</TooltipTrigger>
42
44
  <TooltipContent
43
- side="bottom"
45
+ side={side}
44
46
  align="center"
45
47
  >
46
48
  {label}
@@ -0,0 +1,155 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from 'react';
3
+ import { createRoot, type Root } from 'react-dom/client';
4
+ import { MemoryRouter } from 'react-router';
5
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import en from '../../../i18n/translations/en/common.json';
7
+ import fr from '../../../i18n/translations/fr/common.json';
8
+ import { SidebarProvider } from '../../../components/ui/sidebar';
9
+ import { getAccountInitials, LoginButton } from './LoginButton';
10
+
11
+ type User = { name?: string; email?: string; profilePicture?: string };
12
+ const auth: { isAuthenticated: boolean; isLoading: boolean; user: User | null } = {
13
+ isAuthenticated: true,
14
+ isLoading: false,
15
+ user: null,
16
+ };
17
+
18
+ vi.mock('../hooks/useAuth', () => ({
19
+ useAuth: () => ({ ...auth, logout: vi.fn() }),
20
+ }));
21
+ vi.mock('../../config/useConfig', () => ({
22
+ useConfig: () => ({ config: { backend: { type: 'shellui' } } }),
23
+ }));
24
+ vi.mock('../../../hooks/use-mobile', () => ({ useIsMobile: () => false }));
25
+ vi.mock('react-i18next', () => ({
26
+ useTranslation: () => ({
27
+ t: (key: string, opts?: Record<string, string>) => {
28
+ const [group, leaf] = key.split('.') as [keyof typeof en, string];
29
+ const raw = (en[group] as Record<string, string>)[leaf] ?? opts?.defaultValue ?? key;
30
+ return raw.replace(/\{\{(\w+)\}\}/g, (_, k: string) => opts?.[k] ?? '');
31
+ },
32
+ }),
33
+ }));
34
+
35
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
36
+
37
+ let container: HTMLDivElement;
38
+ let root: Root;
39
+
40
+ beforeEach(() => {
41
+ container = document.createElement('div');
42
+ document.body.appendChild(container);
43
+ root = createRoot(container);
44
+ auth.isAuthenticated = true;
45
+ auth.isLoading = false;
46
+ auth.user = null;
47
+ });
48
+
49
+ afterEach(() => {
50
+ act(() => root.unmount());
51
+ container.remove();
52
+ });
53
+
54
+ function render(open = true) {
55
+ act(() => {
56
+ root.render(
57
+ <MemoryRouter>
58
+ <SidebarProvider defaultOpen={open}>
59
+ <LoginButton variant="sidebar" />
60
+ </SidebarProvider>
61
+ </MemoryRouter>,
62
+ );
63
+ });
64
+ return container.querySelector<HTMLButtonElement>('[data-shellui-account-trigger]');
65
+ }
66
+
67
+ describe('getAccountInitials', () => {
68
+ it('uses the first and last word of the name', () => {
69
+ expect(getAccountInitials('Alex Martin', 'alex@acme.dev')).toBe('AM');
70
+ expect(getAccountInitials(' jean claude van damme ', null)).toBe('JD');
71
+ expect(getAccountInitials('Émile', null)).toBe('É');
72
+ });
73
+
74
+ it('falls back to the email', () => {
75
+ expect(getAccountInitials('', 'zoe@acme.dev')).toBe('Z');
76
+ expect(getAccountInitials(null, null)).toBe('');
77
+ });
78
+ });
79
+
80
+ describe('sidebar account block', () => {
81
+ it('shows initials, name, email and the chevrons-up-down icon', () => {
82
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
83
+ const btn = render();
84
+ expect(btn).not.toBeNull();
85
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('AM');
86
+ expect(btn?.textContent).toContain('Alex Martin');
87
+ expect(btn?.querySelector('[data-shellui-account-email]')?.textContent).toBe('alex@acme.dev');
88
+ expect(btn?.querySelectorAll('svg path')).toHaveLength(2);
89
+ expect(btn?.getAttribute('aria-label')).toBe(
90
+ 'Open account menu for Alex Martin, alex@acme.dev',
91
+ );
92
+ expect(btn?.hasAttribute('data-shellui-no-drag')).toBe(true);
93
+ });
94
+
95
+ it('truncates long names and emails', () => {
96
+ auth.user = {
97
+ name: 'Maximilian Alexander von Hohenberg-Wittelsbach',
98
+ email: 'maximilian.alexander.von.hohenberg@very-long-company-domain.example',
99
+ };
100
+ const btn = render();
101
+ const email = btn?.querySelector('[data-shellui-account-email]');
102
+ expect(email?.className).toContain('truncate');
103
+ expect(email?.previousElementSibling?.className).toContain('truncate');
104
+ expect(email?.parentElement?.className).toContain('min-w-0');
105
+ });
106
+
107
+ it('shows the email as the name, once, when there is no name', () => {
108
+ auth.user = { email: 'zoe@acme.dev' };
109
+ const btn = render();
110
+ expect(btn?.querySelector('[data-shellui-account-email]')).toBeNull();
111
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('Z');
112
+ expect(btn?.getAttribute('aria-label')).toBe('Open account menu for zoe@acme.dev');
113
+ });
114
+
115
+ it('shows the profile picture instead of initials', () => {
116
+ auth.user = {
117
+ name: 'Alex Martin',
118
+ email: 'alex@acme.dev',
119
+ profilePicture: 'https://x.test/a.png',
120
+ };
121
+ const btn = render();
122
+ expect(btn?.querySelector('img')?.getAttribute('src')).toBe('https://x.test/a.png');
123
+ expect(btn?.querySelector('[data-shellui-account-initials]')).toBeNull();
124
+ });
125
+
126
+ it('collapsed icon mode hides the text and keeps the avatar', () => {
127
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
128
+ const btn = render(false);
129
+ expect(btn?.querySelector('[data-shellui-account-initials]')).not.toBeNull();
130
+ expect(btn?.querySelector('[data-shellui-account-email]')?.parentElement?.className).toContain(
131
+ 'group-data-[collapsible=icon]:hidden',
132
+ );
133
+ expect(btn?.querySelector('svg')?.getAttribute('class')).toContain(
134
+ 'group-data-[collapsible=icon]:hidden',
135
+ );
136
+ });
137
+
138
+ it('renders a two line skeleton while loading', () => {
139
+ auth.isLoading = true;
140
+ render();
141
+ const status = container.querySelector('[data-shellui-auth-loading]');
142
+ expect(status?.getAttribute('aria-label')).toBe(en.authMenu.loadingAccount);
143
+ expect(status?.querySelectorAll('[data-slot="skeleton"], .animate-pulse').length).toBe(3);
144
+ });
145
+ });
146
+
147
+ describe('account aria strings', () => {
148
+ it('exist in en and fr', () => {
149
+ for (const key of ['openAccountMenuAriaLabel', 'openAccountMenuWithEmailAriaLabel'] as const) {
150
+ expect(en.authMenu[key]).toContain('{{name}}');
151
+ expect(fr.authMenu[key]).toContain('{{name}}');
152
+ }
153
+ expect(fr.authMenu.openAccountMenuWithEmailAriaLabel).toContain('{{email}}');
154
+ });
155
+ });
@@ -11,7 +11,7 @@ import { useConfig } from '../../config/useConfig';
11
11
  import { getAdminPath } from '../../admin/config';
12
12
  import { isAdminPath } from '../../admin/utils';
13
13
  import { flattenNavigationItems, getNavPathPrefix } from '../../layouts/utils';
14
- import { LogoutIcon, SidebarCaretIcon } from './LoginButtonIcons';
14
+ import { ChevronsUpDownIcon, LogoutIcon } from './LoginButtonIcons';
15
15
  import {
16
16
  DropdownMenu,
17
17
  DropdownMenuContent,
@@ -24,6 +24,17 @@ import { Skeleton } from '../../../components/ui/skeleton';
24
24
 
25
25
  type LoginButtonVariant = 'sidebar' | 'appbar' | 'windows';
26
26
 
27
+ /** Up to two initials from the name, else the first letter of the email. */
28
+ export function getAccountInitials(name?: string | null, email?: string | null): string {
29
+ const words = (name ?? '').trim().split(/\s+/).filter(Boolean);
30
+ if (words.length > 0) {
31
+ const first = Array.from(words[0])[0] ?? '';
32
+ const last = words.length > 1 ? (Array.from(words[words.length - 1])[0] ?? '') : '';
33
+ return (first + last).toUpperCase();
34
+ }
35
+ return (Array.from((email ?? '').trim())[0] ?? '').toUpperCase();
36
+ }
37
+
27
38
  const AdministrationIcon = ({ className }: { className?: string }) => (
28
39
  <svg
29
40
  xmlns="http://www.w3.org/2000/svg"
@@ -79,13 +90,13 @@ const variantConfig: Record<
79
90
  sidebar: {
80
91
  button: {
81
92
  authenticated:
82
- 'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
93
+ 'shellui-account-row w-full h-10 gap-2.5 rounded-[var(--shellui-r-row)] px-2 text-[13.5px] text-left text-sidebar-foreground hover:bg-[var(--shellui-nav-hover)] hover:text-sidebar-foreground data-[state=open]:bg-[var(--shellui-nav-hover)] group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
83
94
  loggedOut:
84
95
  'w-full h-8 rounded-md px-2 text-sm text-left text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
85
96
  loading:
86
- 'w-full h-8 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-2!',
97
+ 'shellui-account-row w-full h-10 gap-2.5 px-2 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0!',
87
98
  },
88
- avatar: 'size-4',
99
+ avatar: 'size-6 text-[10.5px]',
89
100
  menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'right', align: 'start' },
90
101
  showDisplayName: true,
91
102
  showCaret: true,
@@ -98,7 +109,7 @@ const variantConfig: Record<
98
109
  'h-7 max-w-[220px] rounded-md px-2.5 text-xs text-muted-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
99
110
  loading: 'size-7 justify-center',
100
111
  },
101
- avatar: 'size-4',
112
+ avatar: 'size-4 text-[10px]',
102
113
  menu: { width: 'w-[min(16rem,calc(100vw-1.5rem))]', side: 'bottom', align: 'end' },
103
114
  showDisplayName: false,
104
115
  showCaret: false,
@@ -111,7 +122,7 @@ const variantConfig: Record<
111
122
  'h-8 max-w-[180px] rounded-md px-2 text-xs text-sidebar-foreground hover:bg-sidebar-accent/50 hover:text-sidebar-foreground',
112
123
  loading: 'h-8 w-8 justify-center',
113
124
  },
114
- avatar: 'h-4 w-4',
125
+ avatar: 'h-4 w-4 text-[10px]',
115
126
  menu: { width: 'w-[min(15rem,calc(100vw-1.5rem))]', side: 'top', align: 'end' },
116
127
  showDisplayName: false,
117
128
  showCaret: false,
@@ -144,14 +155,22 @@ export const LoginButton = ({
144
155
  return name || email || t('authMenu.userFallback');
145
156
  }, [t, user?.email, user?.name]);
146
157
 
147
- const fallbackInitial = displayName.charAt(0).toUpperCase();
158
+ const name = user?.name?.trim() || '';
159
+ const email = user?.email?.trim() || '';
160
+ const initials = getAccountInitials(name, email) || displayName.charAt(0).toUpperCase();
161
+ // Small avatars (app bar, taskbar) only fit one letter.
162
+ const avatarText = variant === 'sidebar' ? initials : initials.charAt(0);
163
+ const accountAriaLabel =
164
+ name && email
165
+ ? t('authMenu.openAccountMenuWithEmailAriaLabel', { name, email })
166
+ : t('authMenu.openAccountMenuAriaLabel', { name: displayName });
148
167
  const { showDisplayName, showCaret } = currentVariantConfig;
149
168
  const menuSide = variant === 'sidebar' && isMobile ? 'top' : currentVariantConfig.menu.side;
150
169
  const menuAlign = variant === 'sidebar' && isMobile ? 'start' : currentVariantConfig.menu.align;
151
170
  const menuCollisionPadding = isMobile ? 12 : 8;
152
171
 
153
172
  const baseButtonClasses = cn(
154
- 'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors cursor-pointer',
173
+ 'inline-flex items-center gap-2 min-w-0 shrink-0 transition-colors motion-reduce:transition-none cursor-pointer',
155
174
  'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
156
175
  'disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed',
157
176
  isAuthenticated
@@ -250,7 +269,10 @@ export const LoginButton = ({
250
269
  >
251
270
  <Skeleton className={cn('shrink-0 rounded-full', currentVariantConfig.avatar)} />
252
271
  {showDisplayName && (
253
- <Skeleton className="h-3 w-24 max-w-full group-data-[collapsible=icon]:hidden" />
272
+ <span className="flex min-w-0 flex-1 flex-col gap-1.5 group-data-[collapsible=icon]:hidden">
273
+ <Skeleton className="h-3 w-24 max-w-full" />
274
+ <Skeleton className="h-2.5 w-32 max-w-full" />
275
+ </span>
254
276
  )}
255
277
  </div>
256
278
  );
@@ -289,13 +311,16 @@ export const LoginButton = ({
289
311
  ref={triggerRef}
290
312
  type="button"
291
313
  className={baseButtonClasses}
292
- title={displayName}
293
- aria-label={t('authMenu.openAccountMenuAriaLabel', { name: displayName })}
314
+ title={name && email ? `${name}\n${email}` : displayName}
315
+ aria-label={accountAriaLabel}
316
+ data-shellui-account-trigger=""
317
+ data-shellui-no-drag=""
294
318
  >
295
319
  {user.profilePicture ? (
296
320
  <img
297
321
  src={user.profilePicture}
298
- alt={displayName}
322
+ alt=""
323
+ aria-hidden
299
324
  className={cn(
300
325
  'shrink-0 overflow-hidden rounded-full border border-sidebar-border object-cover aspect-square',
301
326
  currentVariantConfig.avatar,
@@ -305,30 +330,30 @@ export const LoginButton = ({
305
330
  ) : (
306
331
  <span
307
332
  className={cn(
308
- 'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-muted text-[10px] font-semibold leading-none',
333
+ 'flex shrink-0 aspect-square items-center justify-center overflow-hidden rounded-full border border-sidebar-border bg-sidebar-accent text-sidebar-foreground font-semibold leading-none',
309
334
  currentVariantConfig.avatar,
310
335
  )}
311
336
  aria-hidden
337
+ data-shellui-account-initials=""
312
338
  >
313
- {fallbackInitial}
339
+ {avatarText}
314
340
  </span>
315
341
  )}
316
342
  {showDisplayName && (
317
- <span className="truncate group-data-[collapsible=icon]:hidden">{displayName}</span>
343
+ <span className="flex min-w-0 flex-1 flex-col group-data-[collapsible=icon]:hidden">
344
+ <span className="truncate leading-tight">{displayName}</span>
345
+ {name && email ? (
346
+ <span
347
+ className="truncate text-[11.5px] leading-tight text-[var(--shellui-nav-label)]"
348
+ data-shellui-account-email=""
349
+ >
350
+ {email}
351
+ </span>
352
+ ) : null}
353
+ </span>
318
354
  )}
319
355
  {showCaret && (
320
- <span
321
- aria-hidden
322
- className={cn(
323
- 'ml-auto shrink-0 text-[10px] group-data-[collapsible=icon]:hidden',
324
- isMenuOpen ? 'text-foreground' : 'text-muted-foreground',
325
- )}
326
- >
327
- <SidebarCaretIcon
328
- isOpen={isMenuOpen}
329
- className="h-3 w-3"
330
- />
331
- </span>
356
+ <ChevronsUpDownIcon className="ml-auto size-4 shrink-0 text-[var(--shellui-nav-icon)] group-data-[collapsible=icon]:hidden" />
332
357
  )}
333
358
  </button>
334
359
  </DropdownMenuTrigger>
@@ -1,10 +1,5 @@
1
- export const SidebarCaretIcon = ({
2
- className,
3
- isOpen,
4
- }: {
5
- className?: string;
6
- isOpen: boolean;
7
- }) => (
1
+ /** lucide chevrons-up-down */
2
+ export const ChevronsUpDownIcon = ({ className }: { className?: string }) => (
8
3
  <svg
9
4
  xmlns="http://www.w3.org/2000/svg"
10
5
  width="24"
@@ -18,7 +13,8 @@ export const SidebarCaretIcon = ({
18
13
  className={className}
19
14
  aria-hidden
20
15
  >
21
- {isOpen ? <path d="m15 6-6 6 6 6" /> : <path d="m9 6 6 6-6 6" />}
16
+ <path d="m7 15 5 5 5-5" />
17
+ <path d="m7 9 5-5 5 5" />
22
18
  </svg>
23
19
  );
24
20