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

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 (46) 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/shell-divider.spec.tsx +63 -0
  5. package/src/components/ui/shell-divider.tsx +20 -0
  6. package/src/components/ui/sidebar.tsx +15 -7
  7. package/src/components/ui/tooltip.tsx +4 -2
  8. package/src/features/auth/components/LoginButton.spec.tsx +203 -0
  9. package/src/features/auth/components/LoginButton.tsx +77 -28
  10. package/src/features/auth/components/LoginButtonIcons.tsx +4 -8
  11. package/src/features/chromeActions/ChromeActionsHost.tsx +5 -1
  12. package/src/features/layouts/OverlayShell.tsx +58 -40
  13. package/src/features/layouts/appbar/AppBarItemIcon.spec.tsx +45 -0
  14. package/src/features/layouts/appbar/AppBarItemIcon.tsx +19 -0
  15. package/src/features/layouts/appbar/AppBarLayout.tsx +53 -81
  16. package/src/features/layouts/appbar/appBarOverflow.spec.ts +27 -0
  17. package/src/features/layouts/appbar/appBarOverflow.ts +42 -0
  18. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +1 -1
  19. package/src/features/layouts/chrome/constants.ts +3 -0
  20. package/src/features/layouts/chrome/viewport.ts +11 -4
  21. package/src/features/layouts/floating/FloatingBottomDock.tsx +67 -26
  22. package/src/features/layouts/floating/FloatingLayout.tsx +1 -0
  23. package/src/features/layouts/floating/FloatingSidebar.tsx +43 -20
  24. package/src/features/layouts/floating/moreSections.spec.ts +28 -0
  25. package/src/features/layouts/floating/moreSections.ts +31 -0
  26. package/src/features/layouts/fullscreen/FullscreenLayout.spec.tsx +68 -0
  27. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +10 -1
  28. package/src/features/layouts/sidebar/NavigationContent.tsx +4 -4
  29. package/src/features/layouts/sidebar/SidebarIcons.tsx +67 -0
  30. package/src/features/layouts/sidebar/SidebarInner.spec.tsx +149 -0
  31. package/src/features/layouts/sidebar/SidebarInner.tsx +60 -11
  32. package/src/features/layouts/sidebar/SidebarLayout.tsx +23 -13
  33. package/src/features/layouts/windows/WindowsLayout.tsx +93 -47
  34. package/src/features/layouts/windows/deskDots.spec.ts +6 -4
  35. package/src/features/layouts/windows/deskDots.ts +8 -8
  36. package/src/features/overlays/ResponsiveModal.tsx +5 -3
  37. package/src/features/overlays/overlaySize.spec.ts +56 -16
  38. package/src/features/overlays/overlaySize.ts +114 -31
  39. package/src/features/overlays/phoneDrawerAnchoring.spec.ts +187 -0
  40. package/src/features/overlays/useOverlayReportedSize.ts +8 -3
  41. package/src/i18n/translations/en/common.json +1 -0
  42. package/src/i18n/translations/fr/common.json +1 -0
  43. package/src/index.css +232 -42
  44. package/src/service-worker/devCaches.spec.ts +32 -0
  45. package/src/service-worker/devCaches.ts +27 -0
  46. 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.12",
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.12"
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
@@ -0,0 +1,63 @@
1
+ // @vitest-environment happy-dom
2
+ import { act } from 'react';
3
+ import { createRoot, type Root } from 'react-dom/client';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+ import { readFileSync } from 'node:fs';
6
+ import { resolve } from 'node:path';
7
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator } from './dropdown-menu';
8
+ import { ShellDivider } from './shell-divider';
9
+
10
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
11
+
12
+ let container: HTMLDivElement;
13
+ let root: Root;
14
+
15
+ beforeEach(() => {
16
+ container = document.createElement('div');
17
+ document.body.appendChild(container);
18
+ root = createRoot(container);
19
+ });
20
+
21
+ afterEach(() => {
22
+ act(() => root.unmount());
23
+ container.remove();
24
+ });
25
+
26
+ const css = readFileSync(resolve(__dirname, '../../index.css'), 'utf8');
27
+
28
+ describe('ShellDivider', () => {
29
+ it('renders the shared divider as a separator', () => {
30
+ act(() => root.render(<ShellDivider className="-mx-2" />));
31
+ const el = container.firstElementChild;
32
+ expect(el?.getAttribute('role')).toBe('separator');
33
+ expect(el?.className).toBe('shellui-divider -mx-2');
34
+ });
35
+
36
+ it('is a full-width hairline with no margin of its own (kit shell.css)', () => {
37
+ const rule = /\.shellui-divider \{([^}]*)\}/.exec(css)?.[1] ?? '';
38
+ expect(rule).toContain('height: 1px');
39
+ expect(rule).toContain('background: var(--shellui-hairline)');
40
+ expect(rule).not.toContain('margin');
41
+ });
42
+
43
+ it('is hidden in the sidebar inset footer (sidebar-inset spec: no footer hairline)', () => {
44
+ expect(css).toMatch(
45
+ /\[data-shellui-layout-variant='inset'\]\s+\.shellui-nav\[data-shellui-nav-footer\]\s+>\s+\[data-shellui-footer-divider\]\s*\{\s*background: transparent;/,
46
+ );
47
+ });
48
+
49
+ it('menus keep the full-bleed shadcn separator (kit .menu hr)', () => {
50
+ act(() =>
51
+ root.render(
52
+ <DropdownMenu open>
53
+ <DropdownMenuContent>
54
+ <DropdownMenuSeparator />
55
+ </DropdownMenuContent>
56
+ </DropdownMenu>,
57
+ ),
58
+ );
59
+ const sep = document.body.querySelector('[role="separator"]');
60
+ expect(sep?.className).toContain('-mx-1');
61
+ expect(sep?.className).toContain('bg-border');
62
+ });
63
+ });
@@ -0,0 +1,20 @@
1
+ import type { ComponentPropsWithoutRef } from 'react';
2
+ import { cn } from '../../lib/utils';
3
+
4
+ /**
5
+ * The one divider used inside the shell panels (see `.shellui-divider` in
6
+ * index.css): a full-width 1px --shellui-hairline, as in the layouts redesign
7
+ * kit. Inside a padded container, pass negative inline margins (e.g. `-mx-2`)
8
+ * so it still runs edge to edge.
9
+ */
10
+ export function ShellDivider({ className, ...props }: ComponentPropsWithoutRef<'div'>) {
11
+ return (
12
+ <div
13
+ role="separator"
14
+ aria-orientation="horizontal"
15
+ data-shellui-divider=""
16
+ className={cn('shellui-divider', className)}
17
+ {...props}
18
+ />
19
+ );
20
+ }
@@ -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,
@@ -592,7 +598,7 @@ function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof S
592
598
  <Separator
593
599
  data-slot="sidebar-separator"
594
600
  data-sidebar="separator"
595
- className={cn('mx-2 w-auto bg-sidebar-border', className)}
601
+ className={cn('shellui-divider', className)}
596
602
  {...props}
597
603
  />
598
604
  );
@@ -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,203 @@
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, dividerAbove = false) {
55
+ act(() => {
56
+ root.render(
57
+ <MemoryRouter>
58
+ <SidebarProvider defaultOpen={open}>
59
+ <LoginButton
60
+ variant="sidebar"
61
+ dividerAbove={dividerAbove}
62
+ />
63
+ </SidebarProvider>
64
+ </MemoryRouter>,
65
+ );
66
+ });
67
+ return container.querySelector<HTMLButtonElement>('[data-shellui-account-trigger]');
68
+ }
69
+
70
+ describe('getAccountInitials', () => {
71
+ it('uses the first and last word of the name', () => {
72
+ expect(getAccountInitials('Alex Martin', 'alex@acme.dev')).toBe('AM');
73
+ expect(getAccountInitials(' jean claude van damme ', null)).toBe('JD');
74
+ expect(getAccountInitials('Émile', null)).toBe('É');
75
+ });
76
+
77
+ it('falls back to the email', () => {
78
+ expect(getAccountInitials('', 'zoe@acme.dev')).toBe('Z');
79
+ expect(getAccountInitials(null, null)).toBe('');
80
+ });
81
+ });
82
+
83
+ describe('sidebar account block', () => {
84
+ it('shows initials, name, email and the chevrons-up-down icon', () => {
85
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
86
+ const btn = render();
87
+ expect(btn).not.toBeNull();
88
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('AM');
89
+ expect(btn?.textContent).toContain('Alex Martin');
90
+ expect(btn?.querySelector('[data-shellui-account-email]')?.textContent).toBe('alex@acme.dev');
91
+ expect(btn?.querySelectorAll('svg path')).toHaveLength(2);
92
+ expect(btn?.getAttribute('aria-label')).toBe(
93
+ 'Open account menu for Alex Martin, alex@acme.dev',
94
+ );
95
+ expect(btn?.hasAttribute('data-shellui-no-drag')).toBe(true);
96
+ });
97
+
98
+ it('truncates long names and emails', () => {
99
+ auth.user = {
100
+ name: 'Maximilian Alexander von Hohenberg-Wittelsbach',
101
+ email: 'maximilian.alexander.von.hohenberg@very-long-company-domain.example',
102
+ };
103
+ const btn = render();
104
+ const email = btn?.querySelector('[data-shellui-account-email]');
105
+ expect(email?.className).toContain('truncate');
106
+ expect(email?.previousElementSibling?.className).toContain('truncate');
107
+ expect(email?.parentElement?.className).toContain('min-w-0');
108
+ });
109
+
110
+ it('shows the email as the name, once, when there is no name', () => {
111
+ auth.user = { email: 'zoe@acme.dev' };
112
+ const btn = render();
113
+ expect(btn?.querySelector('[data-shellui-account-email]')).toBeNull();
114
+ expect(btn?.querySelector('[data-shellui-account-initials]')?.textContent).toBe('Z');
115
+ expect(btn?.getAttribute('aria-label')).toBe('Open account menu for zoe@acme.dev');
116
+ });
117
+
118
+ it('shows the profile picture instead of initials', () => {
119
+ auth.user = {
120
+ name: 'Alex Martin',
121
+ email: 'alex@acme.dev',
122
+ profilePicture: 'https://x.test/a.png',
123
+ };
124
+ const btn = render();
125
+ expect(btn?.querySelector('img')?.getAttribute('src')).toBe('https://x.test/a.png');
126
+ expect(btn?.querySelector('[data-shellui-account-initials]')).toBeNull();
127
+ });
128
+
129
+ it('collapsed icon mode hides the text and keeps the avatar', () => {
130
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
131
+ const btn = render(false);
132
+ expect(btn?.querySelector('[data-shellui-account-initials]')).not.toBeNull();
133
+ expect(btn?.querySelector('[data-shellui-account-email]')?.parentElement?.className).toContain(
134
+ 'group-data-[collapsible=icon]:hidden',
135
+ );
136
+ expect(btn?.querySelector('svg')?.getAttribute('class')).toContain(
137
+ 'group-data-[collapsible=icon]:hidden',
138
+ );
139
+ });
140
+
141
+ it('renders a two line skeleton while loading', () => {
142
+ auth.isLoading = true;
143
+ render();
144
+ const status = container.querySelector('[data-shellui-auth-loading]');
145
+ expect(status?.getAttribute('aria-label')).toBe(en.authMenu.loadingAccount);
146
+ expect(status?.querySelectorAll('[data-slot="skeleton"], .animate-pulse').length).toBe(3);
147
+ });
148
+ });
149
+
150
+ describe('account aria strings', () => {
151
+ it('exist in en and fr', () => {
152
+ for (const key of ['openAccountMenuAriaLabel', 'openAccountMenuWithEmailAriaLabel'] as const) {
153
+ expect(en.authMenu[key]).toContain('{{name}}');
154
+ expect(fr.authMenu[key]).toContain('{{name}}');
155
+ }
156
+ expect(fr.authMenu.openAccountMenuWithEmailAriaLabel).toContain('{{email}}');
157
+ });
158
+ });
159
+
160
+ describe('account divider', () => {
161
+ const divider = () => container.querySelector<HTMLElement>('[data-shellui-account-divider]');
162
+
163
+ it('draws the shared divider above the signed-in account block', () => {
164
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
165
+ const btn = render(true, true);
166
+ const line = divider();
167
+ expect(line).not.toBeNull();
168
+ expect(line?.getAttribute('role')).toBe('separator');
169
+ expect(line?.className).toContain('shellui-divider');
170
+ // Full width: cancels the 8px row inset of the footer group.
171
+ expect(line?.className).toContain('-mx-2');
172
+ // 4px of breathing room between the divider and the account row.
173
+ const pad = line?.nextElementSibling;
174
+ expect(pad?.className).toBe('pt-1');
175
+ expect(pad?.firstElementChild).toBe(btn);
176
+ });
177
+
178
+ it('stays in collapsed icon mode', () => {
179
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
180
+ render(false, true);
181
+ expect(divider()).not.toBeNull();
182
+ });
183
+
184
+ it('is off unless asked for', () => {
185
+ auth.user = { name: 'Alex Martin', email: 'alex@acme.dev' };
186
+ const btn = render(true, false);
187
+ expect(divider()).toBeNull();
188
+ expect(btn?.parentElement?.className).not.toBe('pt-1');
189
+ });
190
+
191
+ it('never shows for the signed-out login button', () => {
192
+ auth.isAuthenticated = false;
193
+ render(true, true);
194
+ expect(container.querySelector('a')?.textContent).toContain(en.authMenu.login);
195
+ expect(divider()).toBeNull();
196
+ });
197
+
198
+ it('never shows while loading', () => {
199
+ auth.isLoading = true;
200
+ render(true, true);
201
+ expect(divider()).toBeNull();
202
+ });
203
+ });