Skip to content

Open source CapCut alternative.

TypeScript

feat(site): su shell folds the rail into a sheet on phones

David Le905ff32654ef
diff --git a/site/src/app/su/SuHeader.tsx b/site/src/app/su/SuHeader.tsx
index c5f1982d..53063cf0 100644
--- a/site/src/app/su/SuHeader.tsx
+++ b/site/src/app/su/SuHeader.tsx
@@ -3,19 +3,28 @@
import { usePathname } from "next/navigation";
import { suSurfaceAt } from "@/app/su/nav";
+import { SidebarTrigger } from "@/components/ui/sidebar";
// The title is the surface's; the description and action belong to whichever
-// tab is showing, since a section's tabs each drive their own work.
+// tab is showing, since a section's tabs each drive their own work. On a
+// phone the rail is off screen, so the header carries the button that opens it.
export function SuHeader() {
const pathname = usePathname();
const { surface, tab } = suSurfaceAt(pathname);
return (
- <div className="sticky top-0 z-20 mx-auto flex w-full max-w-6xl shrink-0 items-start justify-between gap-4 bg-background px-10 pt-9 pb-4">
- <div>
- <h1 className="text-lg font-semibold tracking-tight">{surface.title}</h1>
- {tab.description ? (
- <p className="mt-1 text-sm text-muted-foreground">{tab.description}</p>
- ) : null}
+ <div className="sticky top-0 z-20 mx-auto flex w-full max-w-6xl shrink-0 items-start justify-between gap-4 bg-background px-4 pt-4 pb-4 md:px-10 md:pt-9">
+ <div className="flex min-w-0 items-start gap-2">
+ <SidebarTrigger className="-ml-1.5 shrink-0 md:hidden" />
+ <div className="min-w-0">
+ <h1 className="text-lg font-semibold tracking-tight">
+ {surface.title}
+ </h1>
+ {tab.description ? (
+ <p className="mt-1 text-sm text-muted-foreground">
+ {tab.description}
+ </p>
+ ) : null}
+ </div>
</div>
{tab.Action ? <tab.Action /> : null}
</div>
diff --git a/site/src/app/su/SuShell.tsx b/site/src/app/su/SuShell.tsx
index 5ffa3f7c..eaf706c7 100644
--- a/site/src/app/su/SuShell.tsx
+++ b/site/src/app/su/SuShell.tsx
@@ -5,11 +5,16 @@ import type { ReactNode } from "react";
import { NoSessionReplay } from "@/app/_components/NoSessionReplay";
import { SuHeader } from "@/app/su/SuHeader";
import { SuSidebar } from "@/app/su/SuSidebar";
+import { SidebarProvider } from "@/components/ui/sidebar";
import { useWarmAnalyticsRollup } from "@/queries/analytics";
// The section's two-pane shell. It mounts only for a super user: the proxy
// (src/proxy.ts) has already checked the session and the role before the
// route runs.
+//
+// The sidebar provider is the outermost element so the header's menu button
+// and the rail share one open state: on a phone the rail is a sheet the
+// header opens, on a wider screen it is the fixed left column.
export function SuShell({ children }: { children: ReactNode }) {
useWarmAnalyticsRollup();
// The section paints the white product surface. `app-surface` is what
@@ -22,16 +27,16 @@ export function SuShell({ children }: { children: ReactNode }) {
// NotFoundError out of insertBefore and takes the page down. These surfaces
// are dense text tables, which is exactly what a translator reaches for.
return (
- <div
+ <SidebarProvider
translate="no"
- className="app-surface flex h-screen bg-background font-system text-foreground antialiased"
+ className="app-surface h-screen min-h-0 bg-background font-system text-foreground antialiased"
>
<NoSessionReplay />
<SuSidebar />
<main className="flex min-w-0 flex-1 flex-col overflow-y-auto">
<SuHeader />
<div className="min-h-0 flex-1">
- <div className="mx-auto h-full w-full max-w-6xl px-10">
+ <div className="mx-auto h-full w-full max-w-6xl px-4 md:px-10">
{/* The header is sticky and opaque, so the top of the gap below
it lives here: a focus ring on the first control needs room
that the header cannot paint over. */}
@@ -39,6 +44,6 @@ export function SuShell({ children }: { children: ReactNode }) {
</div>
</div>
</main>
- </div>
+ </SidebarProvider>
);
}
diff --git a/site/src/app/su/SuSidebar.tsx b/site/src/app/su/SuSidebar.tsx
index 081883be..bc90886f 100644
--- a/site/src/app/su/SuSidebar.tsx
+++ b/site/src/app/su/SuSidebar.tsx
@@ -23,7 +23,7 @@ import {
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
- SidebarProvider,
+ useSidebar,
} from "@/components/ui/sidebar";
import { SU_APP_ORIGIN } from "@/cut/lib/hosts";
@@ -53,6 +53,10 @@ function PendingFill() {
// section with tabs is a collapsible item that opens onto its tabs; it starts
// open while one of them is showing, and lands on its first tab when clicked.
//
+// On a wide screen the rail is a fixed column that never collapses. Under the
+// sidebar's mobile breakpoint it becomes a sheet, opened from the header and
+// closed by the navigation it triggers.
+//
// Every page is prefetched when the rail mounts. A link prefetches itself
// once it is on screen, which leaves the tabs of a closed section cold until
// the section opens — and a click right after opening it beat the prefetch,
@@ -61,105 +65,108 @@ export function SuSidebar() {
const pathname = usePathname();
const router = useRouter();
const here = suSurfaceAt(pathname);
+ const { isMobile, setOpenMobile } = useSidebar();
useEffect(() => {
for (const href of RAIL_PAGES) router.prefetch(href);
}, [router]);
+ useEffect(() => {
+ setOpenMobile(false);
+ }, [pathname, setOpenMobile]);
+
return (
- <SidebarProvider className="min-h-0 w-auto shrink-0">
- <Sidebar
- collapsible="none"
- className="w-60 border-r border-sidebar-border"
- >
- <SidebarHeader className="mb-3 flex-row items-center gap-2.5 px-4 pt-4">
- <span className="grid size-9 shrink-0 place-items-center p-0.5">
- <img
- src="/donkey-logo.svg"
- alt="Donkey Cut"
- width={36}
- height={36}
- className="block h-full w-full object-contain"
- />
- </span>
- <span className="text-[17px] font-semibold tracking-tight">
- Super user
- </span>
- </SidebarHeader>
+ <Sidebar
+ collapsible={isMobile ? "offcanvas" : "none"}
+ className="hidden w-60 shrink-0 border-r border-sidebar-border md:flex"
+ >
+ <SidebarHeader className="mb-3 flex-row items-center gap-2.5 px-4 pt-4">
+ <span className="grid size-9 shrink-0 place-items-center p-0.5">
+ <img
+ src="/donkey-logo.svg"
+ alt="Donkey Cut"
+ width={36}
+ height={36}
+ className="block h-full w-full object-contain"
+ />
+ </span>
+ <span className="text-[17px] font-semibold tracking-tight">
+ Super user
+ </span>
+ </SidebarHeader>
- <SidebarContent>
- <SidebarGroup>
- <SidebarMenu className="gap-0.5">
- {SU_NAV.map((surface) => {
- const { href, label, icon: Icon, tabs } = surface;
- const active = here.surface === surface;
- if (!tabs) {
- return (
- <SidebarMenuItem key={label}>
- <SidebarMenuButton
- isActive={active}
- render={<Link href={href} />}
- className="relative isolate h-9 px-2.5"
- >
- <PendingFill />
- <Icon />
- <span>{label}</span>
- </SidebarMenuButton>
- </SidebarMenuItem>
- );
- }
+ <SidebarContent>
+ <SidebarGroup>
+ <SidebarMenu className="gap-0.5">
+ {SU_NAV.map((surface) => {
+ const { href, label, icon: Icon, tabs } = surface;
+ const active = here.surface === surface;
+ if (!tabs) {
return (
- <Collapsible
- key={label}
- defaultOpen={active}
- className="group/collapsible"
- render={<SidebarMenuItem />}
- >
- <CollapsibleTrigger
- render={<SidebarMenuButton className="h-9 px-2.5" />}
+ <SidebarMenuItem key={label}>
+ <SidebarMenuButton
+ isActive={active}
+ render={<Link href={href} />}
+ className="relative isolate h-9 px-2.5"
>
+ <PendingFill />
<Icon />
<span>{label}</span>
- <ChevronRight className="ml-auto transition-transform duration-200 group-data-open/collapsible:rotate-90" />
- </CollapsibleTrigger>
- <CollapsibleContent>
- <SidebarMenuSub>
- {tabs.map((tab) => (
- <SidebarMenuSubItem key={tab.href}>
- <SidebarMenuSubButton
- isActive={active && here.tab === tab}
- render={<Link href={tab.href} />}
- className="relative isolate"
- >
- <PendingFill />
- <span>{tab.label}</span>
- </SidebarMenuSubButton>
- </SidebarMenuSubItem>
- ))}
- </SidebarMenuSub>
- </CollapsibleContent>
- </Collapsible>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
);
- })}
- </SidebarMenu>
- </SidebarGroup>
- </SidebarContent>
-
- {/* The app is a different host, so this is a document load. */}
- <SidebarFooter>
- <SidebarMenu>
- <SidebarMenuItem>
- <SidebarMenuButton
- render={<a href={`${SU_APP_ORIGIN}/app`} />}
- className="h-9 px-2.5"
- >
- <ArrowLeft />
- <span>Back to app</span>
- </SidebarMenuButton>
- </SidebarMenuItem>
+ }
+ return (
+ <Collapsible
+ key={label}
+ defaultOpen={active}
+ className="group/collapsible"
+ render={<SidebarMenuItem />}
+ >
+ <CollapsibleTrigger
+ render={<SidebarMenuButton className="h-9 px-2.5" />}
+ >
+ <Icon />
+ <span>{label}</span>
+ <ChevronRight className="ml-auto transition-transform duration-200 group-data-open/collapsible:rotate-90" />
+ </CollapsibleTrigger>
+ <CollapsibleContent>
+ <SidebarMenuSub>
+ {tabs.map((tab) => (
+ <SidebarMenuSubItem key={tab.href}>
+ <SidebarMenuSubButton
+ isActive={active && here.tab === tab}
+ render={<Link href={tab.href} />}
+ className="relative isolate"
+ >
+ <PendingFill />
+ <span>{tab.label}</span>
+ </SidebarMenuSubButton>
+ </SidebarMenuSubItem>
+ ))}
+ </SidebarMenuSub>
+ </CollapsibleContent>
+ </Collapsible>
+ );
+ })}
</SidebarMenu>
- </SidebarFooter>
- </Sidebar>
- </SidebarProvider>
+ </SidebarGroup>
+ </SidebarContent>
+
+ {/* The app is a different host, so this is a document load. */}
+ <SidebarFooter>
+ <SidebarMenu>
+ <SidebarMenuItem>
+ <SidebarMenuButton
+ render={<a href={`${SU_APP_ORIGIN}/app`} />}
+ className="h-9 px-2.5"
+ >
+ <ArrowLeft />
+ <span>Back to app</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ </SidebarMenu>
+ </SidebarFooter>
+ </Sidebar>
);
}
diff --git a/site/src/app/su/analytics/product/page.tsx b/site/src/app/su/analytics/product/page.tsx
index 26c8a767..25f1de26 100644
--- a/site/src/app/su/analytics/product/page.tsx
+++ b/site/src/app/su/analytics/product/page.tsx
@@ -575,7 +575,7 @@ function ChartCard({
children: React.ReactNode;
}) {
return (
- <div className={cn("rounded-xl border bg-card p-5", className)}>
+ <div className={cn("min-w-0 overflow-hidden rounded-xl border bg-card p-5", className)}>
<p className="font-medium">{title}</p>
<p className="text-sm text-muted-foreground">{subtitle}</p>
<div className="mt-4">{children}</div>
diff --git a/site/src/components/Sortable.tsx b/site/src/components/Sortable.tsx
index 6dc596df..36968369 100644
--- a/site/src/components/Sortable.tsx
+++ b/site/src/components/Sortable.tsx
@@ -234,7 +234,7 @@ export function SortCard({
onDragStart(e);
}}
className={cn(
- "group relative h-full rounded-xl [&>div]:h-full",
+ "group relative h-full min-w-0 rounded-xl [&>div]:h-full",
dragging &&
"bg-muted/40 outline-2 outline-dashed -outline-offset-2 outline-muted-foreground/30 [&>*]:invisible",
className,
diff --git a/site/src/components/ui/chart.tsx b/site/src/components/ui/chart.tsx
index b38897d2..2c024091 100644
--- a/site/src/components/ui/chart.tsx
+++ b/site/src/components/ui/chart.tsx
@@ -65,7 +65,7 @@ function ChartContainer({
data-slot="chart"
data-chart={chartId}
className={cn(
- "flex aspect-video select-none justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden [&_.recharts-tooltip-wrapper]:z-10",
+ "flex aspect-video min-w-0 select-none justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden [&_.recharts-tooltip-wrapper]:z-10",
className
)}
{...props}