feat(app): editor sidebar hidden below 1 280 px, menu one tap away

AC9: on the draft editor path AppLayout uses the xl class set (sidebar
from 1 280 px, menu button and brand below); other pages keep lg.
AppLayout split: Sidebar and TopBar in ShellChrome.tsx. MobileDrawer
takes closesFrom ('64rem' | '80rem') and also closes at setup when
its query already matches.

Rewritten assertions (R-24):
- shell.AppLayout "opens the mobile drawer" and shell.navigation
  "carries the same entries into the mobile drawer": stub a narrow
  matchMedia, the drawer now closes at setup at the happy-dom width.
New: unit tests (class sets, 64rem/80rem close, setup close, leave
guard on a drawer link) and editor-shell.spec F journeys (sidebar at
1024/1180/1279/1280, one-tap menu, drawer open at 1180, guard).
This commit is contained in:
bchanot committed 2026-11-08 19:25:49 +01:00
1 parent 89da8d3f55
commit 580ff28214
6 files changed
+317 -74

No files matched your search

@@ -0,0 +1,113 @@
import { Link, useLocation } from 'react-router-dom'
import Brand from '@/components/brand/Brand'
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
import Icon from '@/components/ui/Icon'
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
import SignOutButton from './SignOutButton'
import UserBadge, { AvatarCircle } from './UserBadge'
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
/**
* Where the sidebar shows and the top bar swaps its menu button for the page title.
* Tailwind needs literal class strings: two static sets, never a built string.
*/
export interface ShellBreakpoint {
sidebar: string
menuControl: string
title: string
/** The width from which the drawer has no reason to stay open. */
closesFrom: '64rem' | '80rem'
}
/** Every page but the editor: the sidebar from 1 024 px (Tailwind `lg`). */
export const DEFAULT_SHELL: ShellBreakpoint = {
sidebar: 'hidden lg:flex lg:w-64 lg:shrink-0 lg:flex-col',
menuControl: 'lg:hidden',
title: 'hidden lg:block',
closesFrom: '64rem',
}
/** The draft editor needs the width for its three columns: sidebar from 1 280 px (`xl`). */
export const EDITOR_SHELL: ShellBreakpoint = {
sidebar: 'hidden xl:flex xl:w-64 xl:shrink-0 xl:flex-col',
menuControl: 'xl:hidden',
title: 'hidden xl:block',
closesFrom: '80rem',
}
/** Title of the current /app page for the top bar, from the nav table. */
function pageTitleKey(pathname: string): string {
const match = NAV_ITEMS.find((item) =>
item.end ? item.to === pathname : pathname.startsWith(item.to) && item.to !== '/',
)
return match?.labelKey ?? 'shell.nav.dashboard'
}
export function Sidebar({ shell }: { shell: ShellBreakpoint }) {
const t = useT()
return (
<aside
className={`${shell.sidebar} border-r border-[var(--color-border)] bg-[var(--color-surface)]`}
>
<div className="px-5 py-5">
<Link to="/app" aria-label={t('shell.nav.dashboard')} className="inline-block">
<Brand size="md" />
</Link>
</div>
<div className="flex-1 px-3">
<SidebarNav />
</div>
<div className="space-y-3 border-t border-[var(--color-border)] px-4 py-4">
<UserBadge />
<SignOutButton className="w-full" />
</div>
</aside>
)
}
interface TopBarProps {
shell: ShellBreakpoint
menuOpen: boolean
onOpenMenu: () => void
}
export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
const t = useT()
const { pathname } = useLocation()
const profile = useAuthStore((s) => s.profile)
const user = useAuthStore((s) => s.user)
const displayName = profile?.display_name ?? user?.email ?? ''
return (
<header className="sticky top-0 z-30 flex h-14 items-center gap-3 border-b border-[var(--color-border)] bg-[var(--color-surface)]/95 px-3 backdrop-blur-sm sm:px-6 pt-[env(safe-area-inset-top)]">
<button
type="button"
onClick={onOpenMenu}
aria-label={t('shell.open_menu')}
aria-expanded={menuOpen}
className={`grid h-11 w-11 place-items-center rounded-lg text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] ${shell.menuControl}`}
>
<Icon name="menu" />
</button>
<Link to="/app" className={shell.menuControl} aria-label={t('shell.nav.dashboard')}>
<Brand size="sm" />
</Link>
<h1 className={`${shell.title} text-sm font-medium text-[var(--color-ink-muted)]`}>
{t(pageTitleKey(pathname))}
</h1>
<div className="ml-auto flex items-center gap-2 sm:gap-3">
<LanguageSwitcher />
<Link
to="/app/account"
aria-label={t('shell.nav.account')}
data-testid="topbar-account"
className="flex min-h-11 items-center gap-2 rounded-full pr-1 pl-1 text-sm text-[var(--color-ink)] hover:bg-[var(--color-surface-strong)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)] sm:pr-3"
>
<AvatarCircle size="sm" />
<span className="hidden max-w-[12rem] truncate sm:inline">{displayName}</span>
</Link>
</div>
</header>
)
}