Skip to content
TypeScript

feat: make the app shell responsive

Vipul Kumar9cfa4de5ed61
diff --git a/src/components/shell/app-shell.tsx b/src/components/shell/app-shell.tsx
index 4628649..9c77b61 100644
--- a/src/components/shell/app-shell.tsx
+++ b/src/components/shell/app-shell.tsx
@@ -6,7 +6,7 @@ import { TitleBar } from "./title-bar";
export function AppShell({ children }: { children: React.ReactNode }) {
return (
- <div className="flex h-full min-w-[1100px] flex-col bg-app">
+ <div className="flex h-full flex-col bg-app">
<TitleBar />
<div className="flex min-h-0 flex-1 overflow-hidden">
<Sidebar />
diff --git a/src/components/shell/global-search.tsx b/src/components/shell/global-search.tsx
index 3769e68..45fbac2 100644
--- a/src/components/shell/global-search.tsx
+++ b/src/components/shell/global-search.tsx
@@ -29,12 +29,12 @@ export function GlobalSearchTrigger() {
<button
type="button"
onClick={() => openOverlay({ kind: "search" })}
- className="flex h-[30px] w-60 items-center gap-2 rounded-lg border border-control bg-surface px-2.5 text-left outline-none transition-[border-color,box-shadow] duration-150 hover-fine:border-segment focus-visible:ring-3 focus-visible:ring-brand/15"
+ className="press flex h-[30px] w-[30px] items-center justify-center gap-2 rounded-lg border border-control bg-surface text-left outline-none transition-[border-color,box-shadow] duration-150 hover-fine:border-segment focus-visible:ring-3 focus-visible:ring-brand/15 md:w-48 md:justify-start md:px-2.5 md:active:scale-100 xl:w-60"
aria-label="Search"
aria-keyshortcuts="Meta+K"
>
<Icon name="search" />
- <span className="t-14 min-w-0 flex-1 text-placeholder">Search...</span>
+ <span className="t-14 hidden min-w-0 flex-1 text-placeholder md:block">Search...</span>
</button>
);
}
@@ -92,7 +92,7 @@ export function GlobalSearch() {
onOpenChange={(v) => !v && close()}
title="Search"
description="Search pages, events, requests and documents"
- className="data-open:animate-none data-closed:animate-none sm:max-w-[560px]"
+ className="data-open:animate-none data-closed:animate-none sm:max-w-[560px] max-sm:top-2 max-sm:bottom-auto max-sm:left-2 max-sm:w-[calc(100%-1rem)] max-sm:max-h-[70dvh] max-sm:rounded-2xl max-sm:pb-0"
>
{/* cmdk needs a <Command> root around its input and list. */}
<Command>
diff --git a/src/components/shell/mobile-nav.tsx b/src/components/shell/mobile-nav.tsx
new file mode 100644
index 0000000..894a749
--- /dev/null
+++ b/src/components/shell/mobile-nav.tsx
@@ -0,0 +1,38 @@
+"use client";
+
+import { usePathname } from "next/navigation";
+import { useState } from "react";
+import { MenuIcon } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { Sheet, SheetContent, SheetDescription, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
+import { SidebarBody } from "./sidebar";
+import { Brand } from "./workspace-switcher";
+
+/** Below `lg` the sidebar slides in from the left. Closes itself on navigation. */
+export function MobileNav() {
+ const pathname = usePathname();
+ const [open, setOpen] = useState(false);
+ const [lastPath, setLastPath] = useState(pathname);
+ if (pathname !== lastPath) {
+ setLastPath(pathname);
+ setOpen(false);
+ }
+
+ return (
+ <Sheet open={open} onOpenChange={setOpen}>
+ <SheetTrigger asChild>
+ <Button variant="ghost" size="icon" aria-label="Open navigation" className="ml-2 lg:hidden">
+ <MenuIcon className="size-4 text-fg" />
+ </Button>
+ </SheetTrigger>
+ <SheetContent side="left" showCloseButton={false} className="w-[280px] max-w-[85vw] gap-0 border-hairline bg-app p-0">
+ <SheetTitle className="sr-only">Navigation</SheetTitle>
+ <SheetDescription className="sr-only">Pages, settings and your account</SheetDescription>
+ <div className="h-[53px] shrink-0 border-b border-hairline">
+ <Brand className="w-full border-r-0" />
+ </div>
+ <SidebarBody className="pb-[max(0.75rem,env(safe-area-inset-bottom))]" />
+ </SheetContent>
+ </Sheet>
+ );
+}
diff --git a/src/components/shell/sidebar.tsx b/src/components/shell/sidebar.tsx
index b40b58b..0ab7d8a 100644
--- a/src/components/shell/sidebar.tsx
+++ b/src/components/shell/sidebar.tsx
@@ -28,7 +28,7 @@ function NavLink({ item, active }: { item: NavItem; active: boolean }) {
href={item.href}
aria-current={active ? "page" : undefined}
className={cn(
- "flex h-8 w-full items-center gap-2 rounded-lg px-2 outline-none transition-[background-color,color] duration-150",
+ "flex h-8 w-full items-center gap-2 rounded-lg px-2 outline-none transition-[background-color,color] duration-150 max-lg:h-10",
"focus-visible:ring-2 focus-visible:ring-brand/40",
active ? "bg-selected text-fg" : "text-fg-2 hover-fine:bg-hover hover-fine:text-fg",
)}
@@ -53,7 +53,7 @@ function ThemeRow() {
const mounted = useSyncExternalStore(noopSubscribe, () => true, () => false);
const dark = mounted && resolvedTheme === "dark";
return (
- <label className="flex h-8 w-full cursor-pointer items-center gap-2 overflow-hidden rounded-lg px-2 text-fg-2 transition-colors duration-150 hover-fine:bg-hover">
+ <label className="flex h-8 w-full max-lg:h-10 cursor-pointer items-center gap-2 overflow-hidden rounded-lg px-2 text-fg-2 transition-colors duration-150 hover-fine:bg-hover">
<Icon name="moon" />
<span className="t-14 salt min-w-0 flex-1">Dark mode</span>
<Switch
@@ -111,13 +111,14 @@ function AccountMenu() {
);
}
-export function Sidebar() {
+/** Navigation + utilities, shared by the desktop sidebar and the mobile nav sheet. */
+export function SidebarBody({ className }: { className?: string }) {
const pathname = usePathname();
const isActive = (href: string) => pathname === href || pathname.startsWith(href + "/");
return (
- <aside className="flex h-full w-60 shrink-0 flex-col justify-between overflow-hidden border-r border-hairline bg-app p-3">
- <nav aria-label="Primary" className="flex w-full flex-col gap-4 overflow-hidden">
+ <div className={cn("flex min-h-0 flex-1 flex-col justify-between gap-6 overflow-y-auto p-3 [scrollbar-width:none]", className)}>
+ <nav aria-label="Primary" className="flex w-full flex-col gap-4">
{NAV_GROUPS.map((group) => (
<div key={group.label} className="flex w-full flex-col gap-0.5">
<SectionLabel>{group.label}</SectionLabel>
@@ -127,13 +128,22 @@ export function Sidebar() {
</div>
))}
</nav>
- <div className="flex w-full flex-col gap-3 overflow-hidden">
+ <div className="flex w-full flex-col gap-3">
<div className="flex w-full flex-col gap-0.5">
<ThemeRow />
<NavLink item={SETTINGS_ITEM} active={isActive(SETTINGS_ITEM.href)} />
</div>
<AccountMenu />
</div>
+ </div>
+ );
+}
+
+/** Fixed 240px sidebar from the design; hidden below `lg`, where the nav sheet takes over. */
+export function Sidebar() {
+ return (
+ <aside className="hidden h-full w-60 shrink-0 flex-col overflow-hidden border-r border-hairline bg-app lg:flex">
+ <SidebarBody />
</aside>
);
}
diff --git a/src/components/shell/title-bar.tsx b/src/components/shell/title-bar.tsx
index d0f2887..b5e4524 100644
--- a/src/components/shell/title-bar.tsx
+++ b/src/components/shell/title-bar.tsx
@@ -17,6 +17,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
import { pageTitle } from "@/lib/nav";
import { openOverlay } from "@/stores/overlay-store";
import { GlobalSearchTrigger } from "./global-search";
+import { MobileNav } from "./mobile-nav";
import { NotificationsPopover } from "./notifications-popover";
import { Brand } from "./workspace-switcher";
@@ -58,19 +59,27 @@ function HelpMenu() {
export function TitleBar() {
const pathname = usePathname();
return (
- <header className="flex h-[53px] w-full shrink-0 items-center overflow-hidden border-b border-hairline bg-app pr-4">
- <Brand />
- <div className="flex h-full min-w-0 flex-1 items-center overflow-hidden pl-4">
+ <header className="flex h-[53px] w-full shrink-0 items-center overflow-hidden border-b border-hairline bg-app pr-3 pt-[env(safe-area-inset-top)] sm:pr-4">
+ <Brand className="hidden lg:flex" />
+ <MobileNav />
+ <div className="flex h-full min-w-0 flex-1 items-center overflow-hidden pl-2 lg:pl-4">
<h1 className="t-16 min-w-0 flex-1 truncate font-medium text-fg">{pageTitle(pathname)}</h1>
</div>
- <div className="flex shrink-0 items-center gap-2">
+ <div className="flex shrink-0 items-center gap-1.5 sm:gap-2">
<GlobalSearchTrigger />
- <HelpMenu />
+ <div className="hidden md:contents">
+ <HelpMenu />
+ </div>
<NotificationsPopover />
- <div className="h-4 w-px bg-hairline" aria-hidden />
- <Button variant="brand" className="gap-1.5" onClick={() => openOverlay({ kind: "request" })}>
+ <div className="hidden h-4 w-px bg-hairline sm:block" aria-hidden />
+ <Button
+ variant="brand"
+ className="gap-1.5 max-sm:w-[30px] max-sm:px-0"
+ aria-label="Request time-off"
+ onClick={() => openOverlay({ kind: "request" })}
+ >
<Icon name="request-time-off" className="text-white" />
- Request time-off
+ <span className="max-sm:sr-only">Request time-off</span>
</Button>
</div>
</header>
diff --git a/src/components/shell/workspace-switcher.tsx b/src/components/shell/workspace-switcher.tsx
index 732cd6f..e9fe752 100644
--- a/src/components/shell/workspace-switcher.tsx
+++ b/src/components/shell/workspace-switcher.tsx
@@ -22,9 +22,10 @@ import {
} from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
+import { cn } from "@/lib/utils";
import { selectWorkspaceName, useAppStore } from "@/stores/app-store";
-export function Brand() {
+export function Brand({ className }: { className?: string }) {
const name = useAppStore(selectWorkspaceName);
const workspaces = useAppStore((s) => s.workspaces);
const workspaceId = useAppStore((s) => s.workspaceId);
@@ -34,7 +35,7 @@ export function Brand() {
const [draft, setDraft] = useState("");
return (
- <div className="flex h-full w-60 shrink-0 items-center gap-2 overflow-hidden border-r border-hairline px-3">
+ <div className={cn("flex h-full w-60 shrink-0 items-center gap-2 overflow-hidden border-r border-hairline px-3", className)}>
<span className="salt truncate text-[16px] leading-none font-semibold tracking-[-0.48px] text-fg">{name}</span>
<span className="h-px min-w-px flex-1" />
<DropdownMenu>