🧭 Cloudflare-style collapsed sidebar and school breadcrumb
Browse files at this commit1aafbb6ffad1ba0c9cf2b001c4fdc551da168cfcParent: 6f21fd4- feat
- 🧭 Cloudflare-style collapsed sidebar and school breadcrumb
5 changed files +181 -78
- docs/ui/navigation-patterns.md +10 -2
- src/components/layout/app-shell.tsx +41 -35
- src/components/layout/rail-tip.tsx +27 -0
- src/components/layout/side-nav.tsx +51 -30
- src/components/layout/sidebar-account.tsx +52 -11
docs/ui/navigation-patterns.mdmodified+10 -2
| @@ -7,8 +7,16 @@ Use one of two patterns for every new interaction: | |||
| 7 | 7 | ||
| 8 | ## Application shell | 8 | ## Application shell |
| 9 | 9 | ||
| 10 | -- Desktop uses one fixed role navigation: `15rem` expanded and `4rem` | 10 | +- Desktop uses one fixed role navigation: `260px` expanded and a `56px` |
| 11 | - collapsed. Collapse preference persists. | 11 | + icon rail collapsed. Collapse preference persists. The collapse toggle sits |
| 12 | + in the sidebar footer beside the account chip (stacked above the avatar on | ||
| 13 | + the rail), off the pointer's path from the nav to the page. | ||
| 14 | +- The rail: 36px square hit areas with centred icons, a label tooltip on the | ||
| 15 | + right for every control, a hairline instead of section headers, and the | ||
| 16 | + active item marked by its tint plus a bar on the rail's outer edge. The | ||
| 17 | + sidebar's logo row matches the top header (49px) so their hairlines meet. | ||
| 18 | +- The school name opens the top header as account context, "School / Page", | ||
| 19 | + muted and truncated; the sidebar names it only in the logo's tooltip. | ||
| 12 | - Everything comes from `src/components/layout/nav-items.ts`: a group tree | 20 | - Everything comes from `src/components/layout/nav-items.ts`: a group tree |
| 13 | per role (`ADMIN_GROUPS` for manager and admin, `TEACHER_GROUPS`, | 21 | per role (`ADMIN_GROUPS` for manager and admin, `TEACHER_GROUPS`, |
| 14 | `STUDENT_GROUPS`, `PARENT_GROUPS`), filtered by role (`minRole`, | 22 | `STUDENT_GROUPS`, `PARENT_GROUPS`), filtered by role (`minRole`, |
src/components/layout/app-shell.tsxmodified+41 -35
| @@ -15,7 +15,9 @@ import { ShellMessagesButton } from "@/components/layout/shell-messages-button"; | |||
| 15 | import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet"; | 15 | import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet"; |
| 16 | import { SideNav } from "@/components/layout/side-nav"; | 16 | import { SideNav } from "@/components/layout/side-nav"; |
| 17 | import { SidebarAccount } from "@/components/layout/sidebar-account"; | 17 | import { SidebarAccount } from "@/components/layout/sidebar-account"; |
| 18 | -import { IconPanelLeft, IconSparkles } from "@/components/ui/icons"; | 18 | +import { IconSparkles } from "@/components/ui/icons"; |
| 19 | +import { TooltipTrigger } from "@/components/ui/tooltip"; | ||
| 20 | +import { RailTip } from "@/components/layout/rail-tip"; | ||
| 19 | import { Toaster } from "@/components/ui/toast"; | 21 | import { Toaster } from "@/components/ui/toast"; |
| 20 | import { useAuth } from "@/stores/auth-context"; | 22 | import { useAuth } from "@/stores/auth-context"; |
| 21 | import { useModules } from "@/stores/modules-context"; | 23 | import { useModules } from "@/stores/modules-context"; |
| @@ -30,7 +32,8 @@ import { createMediaQuery } from "@/lib/create-media-query"; | |||
| 30 | import { ModuleGate } from "@/components/layout/module-gate"; | 32 | import { ModuleGate } from "@/components/layout/module-gate"; |
| 31 | 33 | ||
| 32 | const SIDEBAR_EXPANDED = "w-[260px]"; | 34 | const SIDEBAR_EXPANDED = "w-[260px]"; |
| 33 | -const SIDEBAR_COLLAPSED = "w-24"; | 35 | +// 56px: the icon rail, in the 48–56px band Linear and shadcn's icon mode use. |
| 36 | +const SIDEBAR_COLLAPSED = "w-14"; | ||
| 34 | 37 | ||
| 35 | export function AppShell(props: ParentProps) { | 38 | export function AppShell(props: ParentProps) { |
| 36 | const auth = useAuth(); | 39 | const auth = useAuth(); |
| @@ -42,6 +45,7 @@ export function AppShell(props: ParentProps) { | |||
| 42 | const [mobileOpen, setMobileOpen] = createSignal(false); | 45 | const [mobileOpen, setMobileOpen] = createSignal(false); |
| 43 | const [profileOpen, setProfileOpen] = createSignal(false); | 46 | const [profileOpen, setProfileOpen] = createSignal(false); |
| 44 | const collapsed = () => prefs.sidebarCollapsed(); | 47 | const collapsed = () => prefs.sidebarCollapsed(); |
| 48 | + const brandLabel = () => (school.name() ? `${t("app.name")} · ${school.name()}` : t("app.name")); | ||
| 45 | const location = useLocation(); | 49 | const location = useLocation(); |
| 46 | const fullScreen = () => location().pathname.startsWith("/exam-room/"); | 50 | const fullScreen = () => location().pathname.startsWith("/exam-room/"); |
| 47 | // Below lg the header gives way to the floating action button. Chosen in | 51 | // Below lg the header gives way to the floating action button. Chosen in |
| @@ -105,29 +109,34 @@ export function AppShell(props: ParentProps) { | |||
| 105 | collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED, | 109 | collapsed() ? SIDEBAR_COLLAPSED : SIDEBAR_EXPANDED, |
| 106 | )} | 110 | )} |
| 107 | > | 111 | > |
| 112 | + {/* Same box as the top header (49px, pt-1.5, border-border/70), so | ||
| 113 | + the two hairlines run as one line across the page in both | ||
| 114 | + sidebar states. */} | ||
| 108 | <div | 115 | <div |
| 109 | class={cn( | 116 | class={cn( |
| 110 | - "flex h-[45px] shrink-0 items-center border-b border-border/70", | 117 | + "flex h-[49px] shrink-0 items-center border-b border-border/70 pt-1.5", |
| 111 | collapsed() ? "justify-center px-2" : "px-3", | 118 | collapsed() ? "justify-center px-2" : "px-3", |
| 112 | )} | 119 | )} |
| 113 | > | 120 | > |
| 114 | - <Link | 121 | + <RailTip label={brandLabel()} enabled={collapsed()}> |
| 115 | - to="/" | 122 | + <TooltipTrigger |
| 116 | - class={cn("flex min-w-0 items-center gap-2.5", collapsed() ? "justify-center" : "flex-1")} | 123 | + as={Link} |
| 117 | - title={school.name() ? `${t("app.name")} · ${school.name()}` : t("app.name")} | 124 | + to="/" |
| 118 | - > | 125 | + class={cn( |
| 119 | - <span class="flex h-8 w-8 shrink-0 items-center justify-center text-foreground"> | 126 | + "flex min-w-0 items-center gap-2.5 rounded-md outline-hidden focus-visible:ring-2 focus-visible:ring-ring", |
| 120 | - <LogoMark size={28} /> | 127 | + collapsed() ? "justify-center" : "flex-1", |
| 121 | - </span> | 128 | + )} |
| 122 | - <Show when={!collapsed()}> | 129 | + aria-label={brandLabel()} |
| 123 | - <span class="flex min-w-0 flex-col leading-tight"> | 130 | + title={collapsed() ? undefined : brandLabel()} |
| 124 | - <span class="truncate text-base font-semibold tracking-tight text-foreground dark:text-white 2xl:text-lg">{t("app.name")}</span> | 131 | + > |
| 125 | - <Show when={school.name()}> | 132 | + <span class="flex h-8 w-8 shrink-0 items-center justify-center text-foreground"> |
| 126 | - {(name) => <span class="truncate text-xs font-medium text-muted-foreground">{name()}</span>} | 133 | + <LogoMark size={collapsed() ? 24 : 28} /> |
| 127 | - </Show> | ||
| 128 | </span> | 134 | </span> |
| 129 | - </Show> | 135 | + <Show when={!collapsed()}> |
| 130 | - </Link> | 136 | + <span class="truncate text-base font-semibold tracking-tight text-foreground dark:text-white 2xl:text-lg">{t("app.name")}</span> |
| 137 | + </Show> | ||
| 138 | + </TooltipTrigger> | ||
| 139 | + </RailTip> | ||
| 131 | </div> | 140 | </div> |
| 132 | 141 | ||
| 133 | <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 py-2.5"> | 142 | <div class="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 py-2.5"> |
| @@ -138,21 +147,7 @@ export function AppShell(props: ParentProps) { | |||
| 138 | /> | 147 | /> |
| 139 | </div> | 148 | </div> |
| 140 | 149 | ||
| 141 | - <SidebarAccount collapsed={collapsed()} onLogout={logout} /> | 150 | + <SidebarAccount collapsed={collapsed()} onLogout={logout} onToggleCollapse={() => prefs.toggleSidebar()} /> |
| 142 | - | ||
| 143 | - {/* Collapse toggle rides the corner where the sidebar's right edge | ||
| 144 | - meets the header's bottom border. */} | ||
| 145 | - <button | ||
| 146 | - type="button" | ||
| 147 | - class="absolute right-0 top-[45px] z-10 flex h-7 w-7 -translate-y-1/2 translate-x-1/2 items-center justify-center rounded-md border border-border bg-background text-muted-foreground shadow-xs outline-hidden transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring" | ||
| 148 | - aria-label={collapsed() ? t("nav.expand") : t("nav.collapse")} | ||
| 149 | - aria-expanded={!collapsed()} | ||
| 150 | - title={collapsed() ? t("nav.expand") : t("nav.collapse")} | ||
| 151 | - onClick={() => prefs.toggleSidebar()} | ||
| 152 | - > | ||
| 153 | - <IconPanelLeft class={cn("h-4 w-4 transition-transform duration-200", collapsed() && "rotate-180")} /> | ||
| 154 | - </button> | ||
| 155 | - | ||
| 156 | </aside> | 151 | </aside> |
| 157 | </Show> | 152 | </Show> |
| 158 | 153 | ||
| @@ -171,7 +166,18 @@ export function AppShell(props: ParentProps) { | |||
| 171 | <main class="min-w-0 flex-1" inert={mobileOpen() || undefined}> | 166 | <main class="min-w-0 flex-1" inert={mobileOpen() || undefined}> |
| 172 | <Show when={auth.user() && !fullScreen() && !phone()}> | 167 | <Show when={auth.user() && !fullScreen() && !phone()}> |
| 173 | <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[49px] items-center gap-3 border-b border-border/70 bg-background px-4 pt-1.5 sm:px-6 lg:px-4"> | 168 | <header class="sticky top-[env(safe-area-inset-top)] z-30 flex h-[49px] items-center gap-3 border-b border-border/70 bg-background px-4 pt-1.5 sm:px-6 lg:px-4"> |
| 174 | - <div class="flex min-w-0 shrink-0 items-center gap-2 sm:w-52 lg:w-[260px]"> | 169 | + <div class="flex min-w-0 items-center gap-2 text-sm"> |
| 170 | + {/* Account context first, Cloudflare-style: "School / Page". */} | ||
| 171 | + <Show when={school.name()}> | ||
| 172 | + {(name) => ( | ||
| 173 | + <> | ||
| 174 | + <span class="hidden max-w-56 truncate font-medium text-muted-foreground sm:block" title={name()}> | ||
| 175 | + {name()} | ||
| 176 | + </span> | ||
| 177 | + <span aria-hidden="true" class="hidden shrink-0 text-muted-foreground/50 sm:block">/</span> | ||
| 178 | + </> | ||
| 179 | + )} | ||
| 180 | + </Show> | ||
| 175 | {/* The page's h1 unless the page renders its own. */} | 181 | {/* The page's h1 unless the page renders its own. */} |
| 176 | <Dynamic | 182 | <Dynamic |
| 177 | component={pageHeading() === null ? "h1" : "span"} | 183 | component={pageHeading() === null ? "h1" : "span"} |
src/components/layout/rail-tip.tsxadded+27 -0
| @@ -0,0 +1,27 @@ | |||
| 1 | +import type { ParentProps } from "solid-js"; | ||
| 2 | +import { Tooltip, TooltipContent } from "@/components/ui/tooltip"; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * The collapsed sidebar's label tooltip. The rail shows icons only, so each | ||
| 6 | + * control names itself to the right of the rail on hover and on keyboard | ||
| 7 | + * focus. Wrap a `TooltipTrigger` (usually with `as={...}` so the real control | ||
| 8 | + * is the trigger); with `enabled` off the tooltip never opens, which is how | ||
| 9 | + * the expanded sidebar, whose rows carry visible labels, stays quiet. | ||
| 10 | + */ | ||
| 11 | +export function RailTip(props: ParentProps<{ label: string; enabled: boolean }>) { | ||
| 12 | + return ( | ||
| 13 | + // `open={false}` as well as `disabled`: a tip already open when the rail | ||
| 14 | + // expands (the collapse toggle, clicked) must close, not linger. | ||
| 15 | + <Tooltip | ||
| 16 | + placement="right" | ||
| 17 | + gutter={12} | ||
| 18 | + openDelay={200} | ||
| 19 | + closeDelay={0} | ||
| 20 | + disabled={!props.enabled} | ||
| 21 | + open={props.enabled ? undefined : false} | ||
| 22 | + > | ||
| 23 | + {props.children} | ||
| 24 | + <TooltipContent class="px-2.5 py-1.5 font-medium">{props.label}</TooltipContent> | ||
| 25 | + </Tooltip> | ||
| 26 | + ); | ||
| 27 | +} | ||
src/components/layout/side-nav.tsxmodified+51 -30
| @@ -3,6 +3,8 @@ import { Link, useNavigate, useRouterState } from "@tanstack/solid-router"; | |||
| 3 | import { HOME_ITEM, routeNavItem, visibleNavGroups, type NavGroup, type NavItem } from "@/components/layout/nav-items"; | 3 | import { HOME_ITEM, routeNavItem, visibleNavGroups, type NavGroup, type NavItem } from "@/components/layout/nav-items"; |
| 4 | import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; | 4 | import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu"; |
| 5 | import { IconChevronRight } from "@/components/ui/icons"; | 5 | import { IconChevronRight } from "@/components/ui/icons"; |
| 6 | +import { TooltipTrigger } from "@/components/ui/tooltip"; | ||
| 7 | +import { RailTip } from "@/components/layout/rail-tip"; | ||
| 6 | import { cn } from "@/lib/cn"; | 8 | import { cn } from "@/lib/cn"; |
| 7 | import { useAuth } from "@/stores/auth-context"; | 9 | import { useAuth } from "@/stores/auth-context"; |
| 8 | import { useModules } from "@/stores/modules-context"; | 10 | import { useModules } from "@/stores/modules-context"; |
| @@ -11,6 +13,15 @@ import { useT } from "@/stores/preferences-context"; | |||
| 11 | 13 | ||
| 12 | const FOLDED_KEY = "hezarfen.navFolded"; | 14 | const FOLDED_KEY = "hezarfen.navFolded"; |
| 13 | 15 | ||
| 16 | +// The collapsed rail: one square hit area per control, icon dead centre, and | ||
| 17 | +// the active control marked twice — the tinted square plus a bar on the rail's | ||
| 18 | +// outer edge — because an icon alone carries no label to read the state from. | ||
| 19 | +const RAIL_ITEM = | ||
| 20 | + "relative mx-auto flex size-9 shrink-0 items-center justify-center rounded-lg outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-ring"; | ||
| 21 | +const RAIL_ACTIVE = | ||
| 22 | + "bg-primary/10 text-primary-text before:absolute before:-left-2.5 before:top-1/2 before:h-5 before:w-[3px] before:-translate-y-1/2 before:rounded-r-full before:bg-primary"; | ||
| 23 | +const RAIL_IDLE = "text-muted-foreground hover:bg-muted/70 hover:text-foreground"; | ||
| 24 | + | ||
| 14 | function readFolded(): Record<string, boolean> { | 25 | function readFolded(): Record<string, boolean> { |
| 15 | try { | 26 | try { |
| 16 | const parsed: unknown = JSON.parse(localStorage.getItem(FOLDED_KEY) ?? "{}"); | 27 | const parsed: unknown = JSON.parse(localStorage.getItem(FOLDED_KEY) ?? "{}"); |
| @@ -81,26 +92,40 @@ export function SideNav(props: { | |||
| 81 | {(item) => { | 92 | {(item) => { |
| 82 | const active = () => current()?.id === item.id; | 93 | const active = () => current()?.id === item.id; |
| 83 | return ( | 94 | return ( |
| 84 | - <Link | 95 | + <RailTip label={t(item.labelKey)} enabled={Boolean(props.collapsed)}> |
| 85 | - to={item.to} | 96 | + <TooltipTrigger |
| 86 | - onClick={() => props.onNavigate?.()} | 97 | + as={Link} |
| 87 | - title={t(item.labelKey)} | 98 | + to={item.to} |
| 88 | - aria-current={active() ? "page" : undefined} | 99 | + onClick={() => props.onNavigate?.()} |
| 89 | - class={cn( | 100 | + title={props.collapsed ? undefined : t(item.labelKey)} |
| 90 | - "relative flex h-[34px] items-center rounded-lg text-[13px] font-medium outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-ring", | 101 | + aria-label={props.collapsed ? t(item.labelKey) : undefined} |
| 91 | - props.collapsed ? "mx-auto h-10 w-12 justify-center px-0" : "gap-3 px-3", | 102 | + aria-current={active() ? "page" : undefined} |
| 92 | - active() | 103 | + class={cn( |
| 93 | - ? "bg-primary/10 text-primary-text" | 104 | + props.collapsed |
| 94 | - : "text-muted-foreground hover:bg-muted/70 hover:text-foreground", | 105 | + ? cn(RAIL_ITEM, active() ? RAIL_ACTIVE : RAIL_IDLE) |
| 95 | - )} | 106 | + : cn( |
| 96 | - > | 107 | + "relative flex h-[34px] items-center gap-3 rounded-lg px-3 text-[13px] font-medium outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-ring", |
| 97 | - <item.Icon class="h-4 w-4 shrink-0" /> | 108 | + active() |
| 98 | - <span class={props.collapsed ? "sr-only" : "truncate"}>{t(item.labelKey)}</span> | 109 | + ? "bg-primary/10 text-primary-text" |
| 99 | - </Link> | 110 | + : "text-muted-foreground hover:bg-muted/70 hover:text-foreground", |
| 111 | + ), | ||
| 112 | + )} | ||
| 113 | + > | ||
| 114 | + <item.Icon class="h-4 w-4 shrink-0" /> | ||
| 115 | + <Show when={!props.collapsed}> | ||
| 116 | + <span class="truncate">{t(item.labelKey)}</span> | ||
| 117 | + </Show> | ||
| 118 | + </TooltipTrigger> | ||
| 119 | + </RailTip> | ||
| 100 | ); | 120 | ); |
| 101 | }} | 121 | }} |
| 102 | </For> | 122 | </For> |
| 103 | </div> | 123 | </div> |
| 124 | + {/* The rail has no section headers to read, so a hairline separates | ||
| 125 | + Home from the section menus instead. */} | ||
| 126 | + <Show when={props.collapsed && home().length > 0}> | ||
| 127 | + <div role="separator" class="mx-auto my-1 h-px w-6 shrink-0 bg-border" /> | ||
| 128 | + </Show> | ||
| 104 | <For each={groups()}> | 129 | <For each={groups()}> |
| 105 | {(group) => { | 130 | {(group) => { |
| 106 | const active = () => group.items.some((item) => current()?.id === item.id); | 131 | const active = () => group.items.some((item) => current()?.id === item.id); |
| @@ -176,20 +201,16 @@ export function SideNav(props: { | |||
| 176 | </section> | 201 | </section> |
| 177 | } | 202 | } |
| 178 | > | 203 | > |
| 179 | - <DropdownMenu placement="right-start" gutter={8}> | 204 | + <DropdownMenu placement="right-start" gutter={12}> |
| 180 | - <DropdownMenuTrigger | 205 | + <RailTip label={t(group.labelKey)} enabled> |
| 181 | - class={cn( | 206 | + <TooltipTrigger |
| 182 | - "relative mx-auto flex h-10 w-12 items-center justify-center rounded-md outline-hidden transition-colors focus-visible:ring-2 focus-visible:ring-ring", | 207 | + as={DropdownMenuTrigger} |
| 183 | - active() | 208 | + class={cn(RAIL_ITEM, active() ? RAIL_ACTIVE : RAIL_IDLE)} |
| 184 | - ? "bg-primary/10 text-primary-text" | 209 | + aria-label={t(group.labelKey)} |
| 185 | - : "text-muted-foreground hover:bg-muted/70 hover:text-foreground", | 210 | + > |
| 186 | - )} | 211 | + <group.Icon class="h-4 w-4 shrink-0" /> |
| 187 | - aria-label={t(group.labelKey)} | 212 | + </TooltipTrigger> |
| 188 | - title={t(group.labelKey)} | 213 | + </RailTip> |
| 189 | - > | ||
| 190 | - <group.Icon class="h-4 w-4 shrink-0" /> | ||
| 191 | - <IconChevronRight class={cn("absolute right-1 h-3 w-3", active() ? "opacity-100" : "opacity-60")} /> | ||
| 192 | - </DropdownMenuTrigger> | ||
| 193 | <DropdownMenuContent class="w-52 p-1"> | 214 | <DropdownMenuContent class="w-52 p-1"> |
| 194 | <div class="px-2.5 py-1.5 text-xs font-semibold text-muted-foreground"> | 215 | <div class="px-2.5 py-1.5 text-xs font-semibold text-muted-foreground"> |
| 195 | {t(group.labelKey)} | 216 | {t(group.labelKey)} |
src/components/layout/sidebar-account.tsxmodified+52 -11
| @@ -8,24 +8,51 @@ import { | |||
| 8 | DropdownMenuSeparator, | 8 | DropdownMenuSeparator, |
| 9 | DropdownMenuTrigger, | 9 | DropdownMenuTrigger, |
| 10 | } from "@/components/ui/dropdown-menu"; | 10 | } from "@/components/ui/dropdown-menu"; |
| 11 | -import { IconChevronRight, IconLogout } from "@/components/ui/icons"; | 11 | +import { IconChevronRight, IconLogout, IconPanelLeft } from "@/components/ui/icons"; |
| 12 | +import { TooltipTrigger } from "@/components/ui/tooltip"; | ||
| 13 | +import { RailTip } from "@/components/layout/rail-tip"; | ||
| 12 | import { accountDisplayName, createAccountMenu } from "@/components/layout/account-menu"; | 14 | import { accountDisplayName, createAccountMenu } from "@/components/layout/account-menu"; |
| 13 | import { ThemeModeControl } from "@/components/layout/theme-mode-control"; | 15 | import { ThemeModeControl } from "@/components/layout/theme-mode-control"; |
| 14 | import { UserAvatar } from "@/components/users/user-avatar"; | 16 | import { UserAvatar } from "@/components/users/user-avatar"; |
| 15 | import { useT } from "@/stores/preferences-context"; | 17 | import { useT } from "@/stores/preferences-context"; |
| 16 | import { cn } from "@/lib/cn"; | 18 | import { cn } from "@/lib/cn"; |
| 17 | 19 | ||
| 18 | -/** Desktop sidebar footer: the account chip and its dropdown. Phones reach | 20 | +/** Desktop sidebar footer: the account chip and its dropdown, plus the |
| 19 | - * the same actions as a view inside the menu sheet (MobileAccountPanel). */ | 21 | + * sidebar's collapse toggle. Phones reach the same account actions as a view |
| 22 | + * inside the menu sheet (MobileAccountPanel). | ||
| 23 | + * | ||
| 24 | + * The toggle lives in its own bottom row on purpose. It used to float on the | ||
| 25 | + * sidebar's right edge at the header line — on the pointer's path from the | ||
| 26 | + * logo and the nav to the page — and got hit by accident. The bottom corner | ||
| 27 | + * is off that path yet still one click away in both states. */ | ||
| 20 | export function SidebarAccount(props: { | 28 | export function SidebarAccount(props: { |
| 21 | collapsed?: boolean; | 29 | collapsed?: boolean; |
| 22 | onLogout: () => void | Promise<void>; | 30 | onLogout: () => void | Promise<void>; |
| 31 | + onToggleCollapse?: () => void; | ||
| 23 | }) { | 32 | }) { |
| 24 | const t = useT(); | 33 | const t = useT(); |
| 25 | const [profileOpen, setProfileOpen] = createSignal(false); | 34 | const [profileOpen, setProfileOpen] = createSignal(false); |
| 26 | const menu = createAccountMenu({ onLogout: props.onLogout, onOpenSettings: () => setProfileOpen(true) }); | 35 | const menu = createAccountMenu({ onLogout: props.onLogout, onOpenSettings: () => setProfileOpen(true) }); |
| 27 | const actions = () => menu.actions().filter((action) => action.id !== "logout"); | 36 | const actions = () => menu.actions().filter((action) => action.id !== "logout"); |
| 28 | const logout = () => menu.actions().find((action) => action.id === "logout"); | 37 | const logout = () => menu.actions().find((action) => action.id === "logout"); |
| 38 | + const toggleLabel = () => (props.collapsed ? t("nav.expand") : t("nav.collapse")); | ||
| 39 | + // A quiet square alone in the sidebar's last row, under the account block, | ||
| 40 | + // in both states (the Cloudflare dashboard pattern): the rail keeps a way | ||
| 41 | + // back out, and nothing else sits close enough to hit it by mistake. | ||
| 42 | + const collapseToggle = () => ( | ||
| 43 | + <RailTip label={toggleLabel()} enabled={Boolean(props.collapsed)}> | ||
| 44 | + <TooltipTrigger | ||
| 45 | + type="button" | ||
| 46 | + class="flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-hidden transition-colors hover:bg-muted/70 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring dark:hover:bg-white/8" | ||
| 47 | + aria-label={toggleLabel()} | ||
| 48 | + aria-expanded={!props.collapsed} | ||
| 49 | + title={props.collapsed ? undefined : toggleLabel()} | ||
| 50 | + onClick={() => props.onToggleCollapse?.()} | ||
| 51 | + > | ||
| 52 | + <IconPanelLeft class={cn("h-4 w-4 transition-transform duration-200", props.collapsed && "rotate-180")} /> | ||
| 53 | + </TooltipTrigger> | ||
| 54 | + </RailTip> | ||
| 55 | + ); | ||
| 29 | 56 | ||
| 30 | return ( | 57 | return ( |
| 31 | <> | 58 | <> |
| @@ -33,15 +60,23 @@ export function SidebarAccount(props: { | |||
| 33 | {(u) => { | 60 | {(u) => { |
| 34 | const name = () => accountDisplayName(u()); | 61 | const name = () => accountDisplayName(u()); |
| 35 | return ( | 62 | return ( |
| 36 | - <div class={cn("shrink-0 border-t border-border/80 p-2 dark:border-white/8", props.collapsed && "px-2 py-2") }> | 63 | + <div |
| 37 | - <DropdownMenu placement="right-end" gutter={8}> | 64 | + class={cn( |
| 38 | - <DropdownMenuTrigger | 65 | + "flex shrink-0 border-t border-border/80 dark:border-white/8", |
| 66 | + props.collapsed ? "justify-center px-1.5 py-2" : "items-center p-2", | ||
| 67 | + )} | ||
| 68 | + > | ||
| 69 | + <DropdownMenu placement="right-end" gutter={12}> | ||
| 70 | + <RailTip label={name()} enabled={Boolean(props.collapsed)}> | ||
| 71 | + <TooltipTrigger | ||
| 72 | + as={DropdownMenuTrigger} | ||
| 39 | class={cn( | 73 | class={cn( |
| 40 | - "flex w-full items-center text-left outline-hidden transition-colors", | 74 | + "flex items-center text-left outline-hidden transition-colors", |
| 75 | + !props.collapsed && "w-full", | ||
| 41 | "focus-visible:ring-2 focus-visible:ring-ring", | 76 | "focus-visible:ring-2 focus-visible:ring-ring", |
| 42 | props.collapsed | 77 | props.collapsed |
| 43 | - ? "h-9 justify-center rounded-md px-0 text-foreground hover:bg-muted/70 data-expanded:bg-muted/70 dark:text-white dark:hover:bg-white/8 dark:data-expanded:bg-white/8" | 78 | + ? "size-9 justify-center rounded-lg px-0 text-foreground hover:bg-muted/70 data-expanded:bg-muted/70 dark:text-white dark:hover:bg-white/8 dark:data-expanded:bg-white/8" |
| 44 | - : "h-10 gap-2 rounded-md px-2 text-foreground hover:bg-muted/70 data-expanded:bg-muted/70 dark:text-white dark:hover:bg-white/8 dark:data-expanded:bg-white/8", | 79 | + : "h-10 min-w-0 gap-2 rounded-md px-2 text-foreground hover:bg-muted/70 data-expanded:bg-muted/70 dark:text-white dark:hover:bg-white/8 dark:data-expanded:bg-white/8", |
| 45 | )} | 80 | )} |
| 46 | aria-label={t("nav.account")} | 81 | aria-label={t("nav.account")} |
| 47 | > | 82 | > |
| @@ -50,7 +85,7 @@ export function SidebarAccount(props: { | |||
| 50 | name={name()} | 85 | name={name()} |
| 51 | hasAvatar={menu.hasAvatar()} | 86 | hasAvatar={menu.hasAvatar()} |
| 52 | size="sm" | 87 | size="sm" |
| 53 | - class={props.collapsed ? "h-9 w-9" : undefined} | 88 | + class={props.collapsed ? "h-7 w-7" : undefined} |
| 54 | /> | 89 | /> |
| 55 | <Show when={!props.collapsed}> | 90 | <Show when={!props.collapsed}> |
| 56 | <span class="min-w-0 flex-1"> | 91 | <span class="min-w-0 flex-1"> |
| @@ -61,7 +96,8 @@ export function SidebarAccount(props: { | |||
| 61 | </span> | 96 | </span> |
| 62 | <IconChevronRight class="h-3.5 w-3.5 shrink-0 text-muted-foreground dark:text-white/50" /> | 97 | <IconChevronRight class="h-3.5 w-3.5 shrink-0 text-muted-foreground dark:text-white/50" /> |
| 63 | </Show> | 98 | </Show> |
| 64 | - </DropdownMenuTrigger> | 99 | + </TooltipTrigger> |
| 100 | + </RailTip> | ||
| 65 | 101 | ||
| 66 | <DropdownMenuContent class="w-72 rounded-xl border-border bg-popover p-0 text-popover-foreground shadow-xl shadow-black/10"> | 102 | <DropdownMenuContent class="w-72 rounded-xl border-border bg-popover p-0 text-popover-foreground shadow-xl shadow-black/10"> |
| 67 | <DropdownMenuItem | 103 | <DropdownMenuItem |
| @@ -113,6 +149,11 @@ export function SidebarAccount(props: { | |||
| 113 | ); | 149 | ); |
| 114 | }} | 150 | }} |
| 115 | </Show> | 151 | </Show> |
| 152 | + <Show when={props.onToggleCollapse}> | ||
| 153 | + <div class={cn("flex shrink-0 border-t border-border/80 py-1.5 dark:border-white/8", props.collapsed ? "justify-center px-1.5" : "px-2")}> | ||
| 154 | + {collapseToggle()} | ||
| 155 | + </div> | ||
| 156 | + </Show> | ||
| 116 | <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> | 157 | <AccountProfileDialog open={profileOpen()} onOpenChange={setProfileOpen} /> |
| 117 | </> | 158 | </> |
| 118 | ); | 159 | ); |