📱 bottom sheet menu on phones, and keep the tab bar on messages
Browse files at this commite1e53aefd60ebaae06f47299e082cf94b4d26063Parent: d92d9c6- feat
- 📱 bottom sheet menu on phones, and keep the tab bar on messages
2 changed files +140 -34
src/components/layout/app-shell.tsxmodified+10 -34
| @@ -8,10 +8,11 @@ import { NavBar } from "@/components/layout/nav-bar"; | |||
| 8 | import { NotificationCenter } from "@/components/layout/notification-center"; | 8 | import { NotificationCenter } from "@/components/layout/notification-center"; |
| 9 | import { routeLabelKey } from "@/components/layout/nav-items"; | 9 | import { routeLabelKey } from "@/components/layout/nav-items"; |
| 10 | import { ShellMessagesButton } from "@/components/layout/shell-messages-button"; | 10 | import { ShellMessagesButton } from "@/components/layout/shell-messages-button"; |
| 11 | +import { MobileNavSheet } from "@/components/layout/mobile-nav-sheet"; | ||
| 11 | import { SideNav } from "@/components/layout/side-nav"; | 12 | import { SideNav } from "@/components/layout/side-nav"; |
| 12 | import { SidebarAccount } from "@/components/layout/sidebar-account"; | 13 | import { SidebarAccount } from "@/components/layout/sidebar-account"; |
| 13 | import { Button } from "@/components/ui/button"; | 14 | import { Button } from "@/components/ui/button"; |
| 14 | -import { IconChevronLeft, IconPanelLeft, IconSearch, IconSparkles, IconX } from "@/components/ui/icons"; | 15 | +import { IconChevronLeft, IconPanelLeft, IconSearch, IconSparkles } from "@/components/ui/icons"; |
| 15 | import { Toaster } from "@/components/ui/toast"; | 16 | import { Toaster } from "@/components/ui/toast"; |
| 16 | import { useAuth } from "@/stores/auth-context"; | 17 | import { useAuth } from "@/stores/auth-context"; |
| 17 | import { ShellFeedProvider } from "@/stores/shell-feed-context"; | 18 | import { ShellFeedProvider } from "@/stores/shell-feed-context"; |
| @@ -96,37 +97,12 @@ export function AppShell(props: ParentProps) { | |||
| 96 | </aside> | 97 | </aside> |
| 97 | </Show> | 98 | </Show> |
| 98 | 99 | ||
| 99 | - <Show when={mobileOpen() && auth.user()}> | 100 | + <Show when={auth.user()}> |
| 100 | - <div class="fixed inset-0 z-50 lg:hidden"> | 101 | + <MobileNavSheet |
| 101 | - <button | 102 | + open={mobileOpen()} |
| 102 | - type="button" | 103 | + onClose={() => setMobileOpen(false)} |
| 103 | - class="absolute inset-0 bg-black/40 transition-opacity" | 104 | + onLogout={logout} |
| 104 | - aria-label={t("nav.close")} | 105 | + /> |
| 105 | - onClick={() => setMobileOpen(false)} | ||
| 106 | - /> | ||
| 107 | - <aside class="absolute inset-y-0 left-0 flex w-60 max-w-[85vw] flex-col border-r border-border bg-sidebar pb-[max(env(safe-area-inset-bottom),var(--android-nav-inset,0px))] pt-[env(safe-area-inset-top)] text-sidebar-foreground shadow-2xl shadow-black/20"> | ||
| 108 | - <div class="flex h-14 shrink-0 items-center justify-between gap-2 border-b border-border px-3"> | ||
| 109 | - <Link to="/" class="flex min-w-0 items-center gap-2.5" onClick={() => setMobileOpen(false)}> | ||
| 110 | - <span class="flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-primary text-xs font-bold text-primary-foreground">H</span> | ||
| 111 | - <span class="truncate text-base font-semibold text-foreground dark:text-white">{t("app.name")}</span> | ||
| 112 | - </Link> | ||
| 113 | - <Button | ||
| 114 | - type="button" | ||
| 115 | - variant="ghost" | ||
| 116 | - size="sm" | ||
| 117 | - class="h-8 w-8 shrink-0 rounded-md px-0 text-muted-foreground hover:bg-secondary hover:text-foreground dark:text-white/70 dark:hover:bg-white/8 dark:hover:text-white" | ||
| 118 | - aria-label={t("nav.close")} | ||
| 119 | - onClick={() => setMobileOpen(false)} | ||
| 120 | - > | ||
| 121 | - <IconX class="h-4 w-4" /> | ||
| 122 | - </Button> | ||
| 123 | - </div> | ||
| 124 | - <div class="min-h-0 flex-1 overflow-y-auto px-1.5 py-2.5"> | ||
| 125 | - <SideNav onNavigate={() => setMobileOpen(false)} /> | ||
| 126 | - </div> | ||
| 127 | - <SidebarAccount onLogout={logout} /> | ||
| 128 | - </aside> | ||
| 129 | - </div> | ||
| 130 | </Show> | 106 | </Show> |
| 131 | 107 | ||
| 132 | <main class="min-w-0 flex-1"> | 108 | <main class="min-w-0 flex-1"> |
| @@ -183,7 +159,7 @@ export function AppShell(props: ParentProps) { | |||
| 183 | <div | 159 | <div |
| 184 | class={cn( | 160 | class={cn( |
| 185 | "mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-6", | 161 | "mx-auto w-full px-4 py-6 sm:px-6 lg:px-8 lg:py-6", |
| 186 | - auth.user() && !wide() && "pb-[calc(5rem+env(safe-area-inset-bottom))] lg:pb-6", | 162 | + auth.user() && !fullScreen() && "pb-[calc(5rem+max(env(safe-area-inset-bottom),var(--android-nav-inset,0px)))] lg:pb-6", |
| 187 | wide() ? "max-w-none" : "max-w-[1280px] xl:max-w-[1600px] 2xl:max-w-none", | 163 | wide() ? "max-w-none" : "max-w-[1280px] xl:max-w-[1600px] 2xl:max-w-none", |
| 188 | )} | 164 | )} |
| 189 | > | 165 | > |
| @@ -193,7 +169,7 @@ export function AppShell(props: ParentProps) { | |||
| 193 | </div> | 169 | </div> |
| 194 | {/* MobileTabBar stays inside the provider — it is a shell surface, so a | 170 | {/* MobileTabBar stays inside the provider — it is a shell surface, so a |
| 195 | useShellFeed() badge there must not throw. */} | 171 | useShellFeed() badge there must not throw. */} |
| 196 | - <Show when={auth.user() && !wide()}> | 172 | + <Show when={auth.user() && !fullScreen()}> |
| 197 | <MobileTabBar onMenu={() => setMobileOpen(true)} /> | 173 | <MobileTabBar onMenu={() => setMobileOpen(true)} /> |
| 198 | </Show> | 174 | </Show> |
| 199 | </ShellFeedProvider> | 175 | </ShellFeedProvider> |
src/components/layout/mobile-nav-sheet.tsxadded+130 -0
| @@ -0,0 +1,130 @@ | |||
| 1 | +import { For, Show } from "solid-js"; | ||
| 2 | +import { Link, useRouterState } from "@tanstack/solid-router"; | ||
| 3 | +import { routeNavItem, sidebarNavGroups, type NavItem } from "@/components/layout/nav-items"; | ||
| 4 | +import { SidebarAccount } from "@/components/layout/sidebar-account"; | ||
| 5 | +import { IconX } from "@/components/ui/icons"; | ||
| 6 | +import { cn } from "@/lib/cn"; | ||
| 7 | +import { useAuth } from "@/stores/auth-context"; | ||
| 8 | +import { useShellFeed } from "@/stores/shell-feed-context"; | ||
| 9 | +import { useT } from "@/stores/preferences-context"; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * The phone-sized navigation menu: a sheet that rises from the bottom of the | ||
| 13 | + * screen, where a thumb already is, instead of the side drawer this replaces. | ||
| 14 | + * | ||
| 15 | + * It stays mounted and is moved off-screen when closed, so opening and closing | ||
| 16 | + * both animate; a `<Show>` around it would make it appear and disappear in one | ||
| 17 | + * frame. | ||
| 18 | + */ | ||
| 19 | +export function MobileNavSheet(props: { | ||
| 20 | + open: boolean; | ||
| 21 | + onClose: () => void; | ||
| 22 | + onLogout: () => void | Promise<void>; | ||
| 23 | +}) { | ||
| 24 | + const auth = useAuth(); | ||
| 25 | + const t = useT(); | ||
| 26 | + const feed = useShellFeed(); | ||
| 27 | + const pathname = useRouterState({ select: (state) => state.location.pathname }); | ||
| 28 | + | ||
| 29 | + // The primary destinations are already one tap away in the tab bar, so the | ||
| 30 | + // sheet lists everything else. | ||
| 31 | + const groups = () => sidebarNavGroups(auth.user()?.role); | ||
| 32 | + const current = () => routeNavItem(pathname(), auth.user()?.role); | ||
| 33 | + const badgeFor = (item: NavItem) => (item.id === "messages" ? feed.unreadMessages().total : 0); | ||
| 34 | + | ||
| 35 | + return ( | ||
| 36 | + <div | ||
| 37 | + class={cn("fixed inset-0 z-[60] lg:hidden", props.open ? "visible" : "invisible")} | ||
| 38 | + aria-hidden={props.open ? undefined : "true"} | ||
| 39 | + > | ||
| 40 | + <button | ||
| 41 | + type="button" | ||
| 42 | + aria-label={t("nav.close")} | ||
| 43 | + onClick={props.onClose} | ||
| 44 | + class={cn( | ||
| 45 | + "absolute inset-0 h-full w-full cursor-default bg-black/45 transition-opacity duration-300", | ||
| 46 | + props.open ? "opacity-100" : "opacity-0", | ||
| 47 | + )} | ||
| 48 | + /> | ||
| 49 | + | ||
| 50 | + <div | ||
| 51 | + role="dialog" | ||
| 52 | + aria-modal="true" | ||
| 53 | + aria-label={t("nav.menu")} | ||
| 54 | + class={cn( | ||
| 55 | + "absolute inset-x-0 bottom-0 flex max-h-[75vh] flex-col rounded-t-3xl border-t border-border bg-background", | ||
| 56 | + "pb-[max(env(safe-area-inset-bottom),var(--android-nav-inset,0px))]", | ||
| 57 | + "transition-transform duration-300 ease-out", | ||
| 58 | + props.open ? "translate-y-0" : "translate-y-full", | ||
| 59 | + )} | ||
| 60 | + > | ||
| 61 | + {/* Grab handle: the affordance that says this panel is draggable-looking | ||
| 62 | + and dismissible, even though dismissal is by tap. */} | ||
| 63 | + <div class="flex justify-center pt-3"> | ||
| 64 | + <span class="h-1 w-10 rounded-full bg-border" /> | ||
| 65 | + </div> | ||
| 66 | + | ||
| 67 | + <div class="flex items-center justify-between px-6 pb-3 pt-3"> | ||
| 68 | + <h2 class="text-lg font-semibold">{t("nav.menu")}</h2> | ||
| 69 | + <button | ||
| 70 | + type="button" | ||
| 71 | + onClick={props.onClose} | ||
| 72 | + aria-label={t("nav.close")} | ||
| 73 | + class="topbar-control flex h-9 w-9 items-center justify-center rounded-md outline-hidden focus-visible:ring-2 focus-visible:ring-ring" | ||
| 74 | + > | ||
| 75 | + <IconX class="h-4 w-4" /> | ||
| 76 | + </button> | ||
| 77 | + </div> | ||
| 78 | + | ||
| 79 | + <div class="no-scrollbar min-h-0 flex-1 overflow-y-auto overscroll-contain px-4"> | ||
| 80 | + <For each={groups()}> | ||
| 81 | + {(group) => ( | ||
| 82 | + <div class="mt-3 first:mt-0"> | ||
| 83 | + <p class="px-2 text-xs font-medium uppercase tracking-wide text-muted-foreground"> | ||
| 84 | + {t(group.labelKey)} | ||
| 85 | + </p> | ||
| 86 | + <div class="mt-1.5 flex flex-col"> | ||
| 87 | + <For each={group.items}> | ||
| 88 | + {(item) => { | ||
| 89 | + const active = () => current()?.id === item.id; | ||
| 90 | + return ( | ||
| 91 | + <Link | ||
| 92 | + to={item.to} | ||
| 93 | + onClick={props.onClose} | ||
| 94 | + aria-current={active() ? "page" : undefined} | ||
| 95 | + class={cn( | ||
| 96 | + "flex items-center gap-3 rounded-md px-2 py-3 transition-colors active:bg-muted", | ||
| 97 | + active() ? "text-primary" : "text-foreground", | ||
| 98 | + )} | ||
| 99 | + > | ||
| 100 | + <span | ||
| 101 | + class={cn( | ||
| 102 | + "inline-flex size-9 shrink-0 items-center justify-center rounded-md", | ||
| 103 | + active() ? "bg-primary/10 text-primary" : "bg-muted text-foreground", | ||
| 104 | + )} | ||
| 105 | + > | ||
| 106 | + <item.Icon class="h-4.5 w-4.5" /> | ||
| 107 | + </span> | ||
| 108 | + <span class="min-w-0 flex-1 truncate text-sm font-medium"> | ||
| 109 | + {t(item.labelKey)} | ||
| 110 | + </span> | ||
| 111 | + <Show when={badgeFor(item) > 0}> | ||
| 112 | + <span class="flex h-5 min-w-5 items-center justify-center rounded-full bg-rose-500 px-1.5 text-[10px] font-bold text-white"> | ||
| 113 | + {badgeFor(item) > 99 ? "99+" : badgeFor(item)} | ||
| 114 | + </span> | ||
| 115 | + </Show> | ||
| 116 | + </Link> | ||
| 117 | + ); | ||
| 118 | + }} | ||
| 119 | + </For> | ||
| 120 | + </div> | ||
| 121 | + </div> | ||
| 122 | + )} | ||
| 123 | + </For> | ||
| 124 | + </div> | ||
| 125 | + | ||
| 126 | + <SidebarAccount onLogout={props.onLogout} /> | ||
| 127 | + </div> | ||
| 128 | + </div> | ||
| 129 | + ); | ||
| 130 | +} | ||