Sidebar
Full app layouts built on the shadcn/ui sidebar: a rail that folds to icons, floating and inset panels, a nested docs tree, a workspace switcher, and a second sidebar on the right for details. Each one becomes a sheet on phones.
6 examples below. They wear whichever DressCode theme you install.
Folds to icons
Grouped links with counts and a user menu. Folded, it is a rail of icons with tooltips.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-icon-collapse.jsoncomponents/dresscode/sidebar-icon-collapse.tsx
"use client"
// An app sidebar that folds to a rail of icons (the trigger, the rail on its edge, or Ctrl/⌘ B), with a
// tooltip on each icon while folded, grouped links with counts, and the signed-in user at the foot.
// On phones it opens as a sheet. It sits in a 640px frame here: in your app, drop the frame classes on
// SidebarProvider and "absolute h-full" on Sidebar so it fills the window.
import * as React from "react"
import {
BadgeCheck,
Bell,
ChartColumn,
ChevronsUpDown,
CreditCard,
FileText,
LayoutDashboard,
LifeBuoy,
LogOut,
Orbit,
Package,
Plus,
Repeat,
Search,
Settings,
Users,
Wallet,
} from "lucide-react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarRail,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { cn } from "@/lib/utils"
type NavItem = { title: string; icon: typeof FileText; count?: number; active?: boolean }
const NAV: { label: string; items: NavItem[] }[] = [
{
label: "Billing",
items: [
{ title: "Overview", icon: LayoutDashboard },
{ title: "Invoices", icon: FileText, count: 5, active: true },
{ title: "Payments", icon: Wallet, count: 3 },
{ title: "Recurring", icon: Repeat },
],
},
{
label: "Business",
items: [
{ title: "Clients", icon: Users, count: 28 },
{ title: "Products", icon: Package },
{ title: "Reports", icon: ChartColumn },
],
},
]
const SECONDARY: NavItem[] = [
{ title: "Settings", icon: Settings },
{ title: "Help and support", icon: LifeBuoy },
]
type Status = "Draft" | "Sent" | "Viewed" | "Overdue" | "Paid"
const INVOICES: { id: string; client: string; issued: string; due: string; amount: number; status: Status }[] = [
{ id: "INV-1048", client: "Fernwood Studio", issued: "Nov 22", due: "Dec 6", amount: 4200, status: "Draft" },
{ id: "INV-1047", client: "Kato & Lee", issued: "Nov 20", due: "Dec 4", amount: 1860, status: "Sent" },
{ id: "INV-1046", client: "Pellucid Health", issued: "Nov 14", due: "Nov 28", amount: 3150, status: "Viewed" },
{ id: "INV-1045", client: "Northfield Co.", issued: "Nov 3", due: "Nov 17", amount: 2400, status: "Overdue" },
{ id: "INV-1044", client: "Marlow & Finch", issued: "Oct 30", due: "Nov 13", amount: 960, status: "Overdue" },
{ id: "INV-1043", client: "Juniper Bakery", issued: "Oct 28", due: "Nov 11", amount: 1500, status: "Overdue" },
{ id: "INV-1042", client: "Tessellate Labs", issued: "Oct 24", due: "Nov 7", amount: 5680, status: "Paid" },
{ id: "INV-1041", client: "Kato & Lee", issued: "Oct 21", due: "Nov 4", amount: 1860, status: "Paid" },
]
const FILTERS = ["All", "Open", "Overdue", "Draft", "Paid"] as const
type Filter = (typeof FILTERS)[number]
const isOpen = (s: Status) => s === "Sent" || s === "Viewed" || s === "Overdue"
const matches = (f: Filter, s: Status) => f === "All" || (f === "Open" ? isOpen(s) : s === f)
const money = (n: number) => n.toLocaleString("en-US", { style: "currency", currency: "USD" })
const STATUS_BADGE: Record<Status, React.ComponentProps<typeof Badge>["variant"]> = {
Draft: "outline",
Sent: "secondary",
Viewed: "secondary",
Overdue: "destructive",
Paid: "default",
}
const noop = () => () => {}
/** "⌘" on Apple keyboards, "Ctrl" everywhere else (and on the server). */
function useModKey() {
return React.useSyncExternalStore(
noop,
() => (/Mac|iPhone|iPad/.test(navigator.platform) ? "⌘" : "Ctrl"),
() => "Ctrl",
)
}
export default function SidebarIconCollapse() {
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border bg-background">
<AppSidebar />
<SidebarInset className="min-w-0 overflow-hidden">
<TopBar />
<div className="flex-1 overflow-y-auto">
<InvoicesPage />
</div>
</SidebarInset>
</SidebarProvider>
)
}
function AppSidebar() {
return (
<Sidebar collapsible="icon" className="absolute h-full">
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" tooltip="Orbit" render={<a href="#" />}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground">
<Orbit />
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">Orbit</span>
<span className="truncate text-xs text-muted-foreground">Ruiz Studio</span>
</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
{NAV.map((group) => (
<SidebarGroup key={group.label}>
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{group.items.map((item) => (
<NavLink key={item.title} item={item} />
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
))}
<SidebarGroup className="mt-auto">
<SidebarGroupContent>
<SidebarMenu>
{SECONDARY.map((item) => (
<NavLink key={item.title} item={item} />
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<UserMenu />
</SidebarFooter>
<SidebarRail />
</Sidebar>
)
}
function NavLink({ item }: { item: NavItem }) {
return (
<SidebarMenuItem>
<SidebarMenuButton
isActive={item.active}
// Folded, the count moves into the tooltip.
tooltip={{
children: (
<>
{item.title}
{item.count ? <span className="tabular-nums opacity-70">{item.count}</span> : null}
</>
),
}}
render={<a href="#" aria-current={item.active ? "page" : undefined} />}
>
<item.icon />
<span>{item.title}</span>
</SidebarMenuButton>
{item.count ? <SidebarMenuBadge>{item.count}</SidebarMenuBadge> : null}
</SidebarMenuItem>
)
}
function UserMenu() {
const { isMobile } = useSidebar()
return (
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger
render={<SidebarMenuButton size="lg" tooltip="Ada Lin" className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground" />}
>
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">ada@ruiz.studio</span>
</span>
<ChevronsUpDown className="ml-auto" />
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "top" : "right"} align="end" sideOffset={8} className="w-56">
<DropdownMenuGroup>
<DropdownMenuLabel className="flex items-center gap-2 px-1.5 py-1.5 font-normal text-foreground">
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span className="grid min-w-0 leading-tight">
<span className="truncate text-sm font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">ada@ruiz.studio</span>
</span>
</DropdownMenuLabel>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<BadgeCheck /> Account
</DropdownMenuItem>
<DropdownMenuItem>
<CreditCard /> Plan and billing
</DropdownMenuItem>
<DropdownMenuItem>
<Bell /> Notifications
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem>
<LogOut /> Log out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
)
}
function TopBar() {
const mod = useModKey()
return (
<header className="flex h-14 shrink-0 items-center gap-2 border-b px-3 sm:px-4">
<Tooltip>
<TooltipTrigger render={<SidebarTrigger className="-ml-1" />} />
<TooltipContent side="bottom">
Toggle sidebar
<KbdGroup>
<Kbd>{mod}</Kbd>
<Kbd>B</Kbd>
</KbdGroup>
</TooltipContent>
</Tooltip>
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb className="min-w-0">
<BreadcrumbList className="flex-nowrap">
<BreadcrumbItem className="hidden sm:inline-flex">
<BreadcrumbLink href="#">Billing</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="hidden sm:list-item" />
<BreadcrumbItem>
<BreadcrumbPage>Invoices</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<div className="ml-auto flex items-center gap-1.5">
<Button variant="ghost" size="icon-sm" aria-label="Search invoices">
<Search />
</Button>
<Button size="sm" aria-label="New invoice">
<Plus />
<span className="hidden sm:inline">New invoice</span>
</Button>
</div>
</header>
)
}
function InvoicesPage() {
const [filter, setFilter] = React.useState<Filter>("All")
const rows = INVOICES.filter((i) => matches(filter, i.status))
const open = INVOICES.filter((i) => isOpen(i.status))
const overdue = INVOICES.filter((i) => i.status === "Overdue")
const paid = INVOICES.filter((i) => i.status === "Paid")
const sum = (list: typeof INVOICES) => money(list.reduce((s, i) => s + i.amount, 0))
const stats = [
{ label: "Outstanding", value: sum(open), note: `${open.length} open invoices` },
{ label: "Overdue", value: sum(overdue), note: `${overdue.length} past their due date`, alert: true },
{ label: "Paid in November", value: sum(paid), note: "12% more than October" },
]
return (
<div className="flex flex-col gap-6 p-4 sm:p-6">
<div>
<h2 className="text-xl font-semibold tracking-tight">Invoices</h2>
<p className="mt-1 text-sm text-muted-foreground">Everything you have billed this quarter, newest first.</p>
</div>
<dl className="grid gap-3 sm:grid-cols-3">
{stats.map((s) => (
<div key={s.label} className="rounded-xl border bg-card p-4 text-card-foreground">
<dt className="text-sm text-muted-foreground">{s.label}</dt>
<dd className={cn("mt-1 text-2xl font-semibold tracking-tight tabular-nums", s.alert && "text-destructive")}>{s.value}</dd>
<dd className="mt-0.5 text-xs text-muted-foreground">{s.note}</dd>
</div>
))}
</dl>
<div className="rounded-xl border bg-card text-card-foreground">
<div role="group" aria-label="Filter by status" className="flex gap-1 overflow-x-auto border-b p-2">
{FILTERS.map((f) => {
const count = INVOICES.filter((i) => matches(f, i.status)).length
return (
<Button key={f} variant={filter === f ? "secondary" : "ghost"} size="sm" aria-pressed={filter === f} onClick={() => setFilter(f)}>
{f}
<span className="text-muted-foreground tabular-nums">{count}</span>
</Button>
)
})}
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead className="pl-4">Invoice</TableHead>
<TableHead>Client</TableHead>
<TableHead className="hidden md:table-cell">Issued</TableHead>
<TableHead>Due</TableHead>
<TableHead className="text-right">Amount</TableHead>
<TableHead className="pr-4">Status</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{rows.map((i) => (
<TableRow key={i.id}>
<TableCell className="pl-4 font-medium">
<a href="#" className="hover:underline">
{i.id}
</a>
</TableCell>
<TableCell>{i.client}</TableCell>
<TableCell className="hidden text-muted-foreground md:table-cell">{i.issued}</TableCell>
<TableCell className={cn(i.status === "Overdue" ? "text-destructive" : "text-muted-foreground")}>{i.due}</TableCell>
<TableCell className="text-right tabular-nums">{money(i.amount)}</TableCell>
<TableCell className="pr-4">
<Badge variant={STATUS_BADGE[i.status]}>{i.status}</Badge>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
)
}npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-floating.jsoncomponents/dresscode/sidebar-floating.tsx
"use client"
// A floating sidebar (it hovers off the edge with its own border and shadow) for a projects app:
// a search field that filters the links ("/" jumps to it), projects with a menu each and an add button,
// and a plan card in the footer that counts against the free limit and can be dismissed.
// It sits in a 640px frame here: in your app, drop the frame classes on SidebarProvider and
// "absolute h-full" on Sidebar so it fills the window.
import * as React from "react"
import {
Archive,
CalendarDays,
CircleCheck,
House,
Inbox,
Link2,
MoreHorizontal,
Plus,
Search,
Share2,
Sparkles,
X,
} from "lucide-react"
import { Avatar, AvatarFallback, AvatarGroup, AvatarGroupCount } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { Checkbox } from "@/components/ui/checkbox"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Kbd } from "@/components/ui/kbd"
import { Progress } from "@/components/ui/progress"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupAction,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInput,
SidebarInset,
SidebarMenu,
SidebarMenuAction,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
import { cn } from "@/lib/utils"
const WORKSPACE = [
{ title: "Home", icon: House },
{ title: "My tasks", icon: CircleCheck, count: 5 },
{ title: "Inbox", icon: Inbox, count: 2 },
{ title: "Calendar", icon: CalendarDays },
]
// chart-2 is the faintest in most themes, so it comes last.
const COLORS = ["bg-(--chart-1)", "bg-(--chart-5)", "bg-(--chart-3)", "bg-(--chart-4)", "bg-(--chart-2)"]
type Project = { id: string; title: string; color: string }
const INITIAL_PROJECTS: Project[] = [
{ id: "website", title: "Website refresh", color: COLORS[0] },
{ id: "mobile", title: "Mobile app v2", color: COLORS[1] },
{ id: "brand", title: "Brand guidelines", color: COLORS[2] },
{ id: "research", title: "Customer research", color: COLORS[3] },
]
const ACTIVE = "website"
const FREE_LIMIT = 5
type Task = { id: string; title: string; section: "In progress" | "To do" | "Done"; who: string; due: string; tag: string }
const TASKS: Task[] = [
{ id: "t1", title: "Write the homepage copy", section: "In progress", who: "AL", due: "Nov 26", tag: "Copy" },
{ id: "t2", title: "Design the pricing page", section: "In progress", who: "TO", due: "Nov 28", tag: "Design" },
{ id: "t3", title: "Redirect the old blog URLs", section: "In progress", who: "ML", due: "Dec 2", tag: "Build" },
{ id: "t4", title: "Pick photos for the case studies", section: "To do", who: "AL", due: "Dec 3", tag: "Design" },
{ id: "t5", title: "Review the docs navigation", section: "To do", who: "TO", due: "Dec 5", tag: "Docs" },
{ id: "t6", title: "Test every form on a phone", section: "To do", who: "ML", due: "Dec 8", tag: "Testing" },
{ id: "t7", title: "Agree on the sitemap", section: "Done", who: "JR", due: "Nov 12", tag: "Planning" },
{ id: "t8", title: "Audit the current pages", section: "Done", who: "AL", due: "Nov 15", tag: "Planning" },
]
export default function SidebarFloating() {
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border bg-background">
<ProjectsSidebar />
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-14 shrink-0 items-center gap-2 px-3 sm:px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb className="min-w-0">
<BreadcrumbList className="flex-nowrap">
<BreadcrumbItem className="hidden sm:inline-flex">
<BreadcrumbLink href="#">Projects</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="hidden sm:list-item" />
<BreadcrumbItem className="min-w-0">
<BreadcrumbPage className="truncate">Website refresh</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<div className="ml-auto flex items-center gap-3">
<AvatarGroup role="group" className="hidden sm:flex" aria-label="5 people on this project">
{["AL", "TO", "ML"].map((i) => (
<Avatar key={i}>
<AvatarFallback className="text-xs">{i}</AvatarFallback>
</Avatar>
))}
<AvatarGroupCount className="text-xs">+2</AvatarGroupCount>
</AvatarGroup>
<Button variant="outline" size="sm">
<Share2 /> Share
</Button>
</div>
</header>
<div className="flex-1 overflow-y-auto">
<ProjectPage />
</div>
</SidebarInset>
</SidebarProvider>
)
}
function ProjectsSidebar() {
const { isMobile } = useSidebar()
const [query, setQuery] = React.useState("")
const [projects, setProjects] = React.useState(INITIAL_PROJECTS)
const [planOpen, setPlanOpen] = React.useState(true)
const inputRef = React.useRef<HTMLInputElement>(null)
// "/" jumps to the search field unless you are already typing somewhere.
React.useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== "/" || e.metaKey || e.ctrlKey || e.altKey) return
if ((e.target as HTMLElement).closest("input, textarea, select, [contenteditable=true]")) return
e.preventDefault()
inputRef.current?.focus()
}
window.addEventListener("keydown", onKey)
return () => window.removeEventListener("keydown", onKey)
}, [])
const q = query.trim().toLowerCase()
const links = WORKSPACE.filter((l) => l.title.toLowerCase().includes(q))
const found = projects.filter((p) => p.title.toLowerCase().includes(q))
const atLimit = projects.length >= FREE_LIMIT
const clearSearch = () => {
setQuery("")
inputRef.current?.focus()
}
const addProject = () => {
if (atLimit) return
const n = projects.filter((p) => p.title.startsWith("Untitled project")).length
const used = new Set(projects.map((p) => p.color))
setProjects([
...projects,
{ id: `p${Date.now()}`, title: n ? `Untitled project ${n + 1}` : "Untitled project", color: COLORS.find((c) => !used.has(c)) ?? COLORS[4] },
])
}
return (
<Sidebar variant="floating" className="absolute h-full">
<SidebarHeader className="gap-3">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" render={<a href="#" />}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-xs font-semibold text-primary-foreground">RS</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">Ruiz Studio</span>
<span className="truncate text-xs text-muted-foreground">Team workspace</span>
</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
<form role="search" className="relative" onSubmit={(e) => e.preventDefault()}>
<label htmlFor="sidebar-floating-search" className="sr-only">
Search pages and projects
</label>
<Search className="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" aria-hidden="true" />
<SidebarInput
ref={inputRef}
id="sidebar-floating-search"
type="search"
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={(e) => {
if (e.key === "Escape" && query) {
e.preventDefault()
setQuery("")
}
}}
placeholder="Search"
autoComplete="off"
className="pr-8 pl-8 [&::-webkit-search-cancel-button]:hidden"
/>
{query ? (
<button
type="button"
onClick={clearSearch}
aria-label="Clear search"
className="absolute top-1/2 right-1.5 flex size-5 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring [&>svg]:size-3.5"
>
<X />
</button>
) : (
<Kbd className="absolute top-1/2 right-1.5 -translate-y-1/2" aria-hidden="true">
/
</Kbd>
)}
</form>
</SidebarHeader>
<SidebarContent>
{links.length ? (
<SidebarGroup>
<SidebarGroupLabel>Workspace</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{links.map((l) => (
<SidebarMenuItem key={l.title}>
<SidebarMenuButton render={<a href="#" />}>
<l.icon />
<span>{l.title}</span>
</SidebarMenuButton>
{l.count ? <SidebarMenuBadge>{l.count}</SidebarMenuBadge> : null}
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
) : null}
{found.length || !q ? (
<SidebarGroup>
<SidebarGroupLabel>Projects</SidebarGroupLabel>
<SidebarGroupAction
onClick={addProject}
disabled={atLimit}
aria-label={atLimit ? "New project (free plan limit reached)" : "New project"}
title={atLimit ? "Free plan limit reached" : "New project"}
className="disabled:pointer-events-none disabled:opacity-50"
>
<Plus />
</SidebarGroupAction>
<SidebarGroupContent>
<SidebarMenu>
{found.map((p) => (
<SidebarMenuItem key={p.id}>
<SidebarMenuButton isActive={p.id === ACTIVE} render={<a href="#" aria-current={p.id === ACTIVE ? "page" : undefined} />}>
<span className="flex size-4 shrink-0 items-center justify-center" aria-hidden="true">
<span className={cn("size-2.5 rounded-[3px] ring-1 ring-foreground/15 ring-inset", p.color)} />
</span>
<span>{p.title}</span>
</SidebarMenuButton>
<DropdownMenu>
<DropdownMenuTrigger render={<SidebarMenuAction showOnHover aria-label={`More for ${p.title}`} />}>
<MoreHorizontal />
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "bottom" : "right"} align={isMobile ? "end" : "start"} className="w-48">
<DropdownMenuItem onClick={() => navigator.clipboard?.writeText(`${location.origin}${location.pathname}#${p.id}`).catch(() => {})}>
<Link2 /> Copy link
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
variant="destructive"
disabled={p.id === ACTIVE}
onClick={() => setProjects((all) => all.filter((x) => x.id !== p.id))}
>
<Archive /> Archive project
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
))}
{!projects.length ? <li className="px-2 py-1.5 text-xs text-muted-foreground">No projects yet.</li> : null}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
) : null}
{q && !links.length && !found.length ? (
<div role="status" className="flex flex-col items-center gap-2 px-4 py-8 text-center">
<Search className="size-5 text-muted-foreground" aria-hidden="true" />
<p className="text-sm font-medium">No matches for “{query.trim()}”</p>
<p className="text-xs text-muted-foreground">Try a project name, or a page like Inbox.</p>
<Button variant="outline" size="sm" className="mt-1" onClick={clearSearch}>
Clear search
</Button>
</div>
) : null}
</SidebarContent>
<SidebarFooter>
{planOpen ? (
<section aria-labelledby="sidebar-floating-plan" className="relative rounded-lg border bg-background p-3 text-sm">
<button
type="button"
onClick={() => setPlanOpen(false)}
aria-label="Dismiss"
className="absolute top-2 right-2 flex size-6 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-ring [&>svg]:size-3.5"
>
<X />
</button>
<h3 id="sidebar-floating-plan" className="font-medium">
Free plan
</h3>
<p className="mt-0.5 pr-6 text-xs text-muted-foreground">
{atLimit ? "All 5 projects used. Upgrade for unlimited projects and guests." : `${projects.length} of ${FREE_LIMIT} projects used`}
</p>
<Progress value={(projects.length / FREE_LIMIT) * 100} aria-label="Projects used" className="mt-2.5" />
<Button size="sm" className="mt-3 w-full">
<Sparkles /> Upgrade to Pro
</Button>
</section>
) : (
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton render={<a href="#" />}>
<Sparkles />
<span>Upgrade to Pro</span>
</SidebarMenuButton>
<SidebarMenuBadge>
{projects.length}/{FREE_LIMIT}
</SidebarMenuBadge>
</SidebarMenuItem>
</SidebarMenu>
)}
</SidebarFooter>
</Sidebar>
)
}
function ProjectPage() {
const [done, setDone] = React.useState<Set<string>>(() => new Set(TASKS.filter((t) => t.section === "Done").map((t) => t.id)))
const pct = Math.round((done.size / TASKS.length) * 100)
const toggle = (id: string, on: boolean) =>
setDone((prev) => {
const next = new Set(prev)
if (on) next.add(id)
else next.delete(id)
return next
})
return (
<div className="flex flex-col gap-6 px-4 pt-2 pb-8 sm:px-6">
<div className="flex flex-wrap items-end justify-between gap-4">
<div className="min-w-0">
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-xl font-semibold tracking-tight">Website refresh</h2>
<Badge variant="secondary">On track</Badge>
</div>
<p className="mt-1 text-sm text-muted-foreground">New marketing site and docs. Launches on January 15.</p>
</div>
<div className="w-full sm:w-56">
<div className="flex justify-between text-xs text-muted-foreground">
<span>
{done.size} of {TASKS.length} tasks done
</span>
<span className="tabular-nums">{pct}%</span>
</div>
<Progress value={pct} aria-label="Project progress" className="mt-2" />
</div>
</div>
{(["In progress", "To do", "Done"] as const).map((section) => {
const tasks = TASKS.filter((t) => t.section === section)
return (
<section key={section} aria-labelledby={`sidebar-floating-${section}`}>
<h3 id={`sidebar-floating-${section}`} className="mb-2 flex items-center gap-2 text-sm font-medium">
{section}
<span className="text-muted-foreground tabular-nums">{tasks.length}</span>
</h3>
<ul className="divide-y rounded-xl border bg-card text-card-foreground">
{tasks.map((t) => {
const checked = done.has(t.id)
return (
<li key={t.id} className="flex items-center gap-3 px-4 py-2.5">
<Checkbox id={`sidebar-floating-${t.id}`} checked={checked} onCheckedChange={(v) => toggle(t.id, v)} />
<label
htmlFor={`sidebar-floating-${t.id}`}
className={cn("min-w-0 flex-1 truncate text-sm", checked && "text-muted-foreground line-through")}
>
{t.title}
</label>
<Badge variant="outline" className="hidden sm:inline-flex">
{t.tag}
</Badge>
<span className="w-12 text-right text-xs text-muted-foreground tabular-nums">{t.due}</span>
<Avatar size="sm">
<AvatarFallback>{t.who}</AvatarFallback>
</Avatar>
</li>
)
})}
</ul>
</section>
)
})}
</div>
)
}npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-inset.jsoncomponents/dresscode/sidebar-inset.tsx
"use client"
// An inset sidebar: the page sits in a rounded panel on the sidebar's color, the layout of most
// dashboards. Folding it (trigger, Ctrl/⌘ B) slides the nav away and the panel takes the full width;
// the cards reflow on the panel's own width, not the window's.
// It sits in a 640px frame here: in your app, drop the frame classes on SidebarProvider and
// "absolute h-full" on Sidebar so it fills the window.
import * as React from "react"
import {
ChartColumn,
ChevronsUpDown,
CreditCard,
Download,
FileSignature,
FileText,
LayoutDashboard,
LifeBuoy,
LogOut,
MoreHorizontal,
Orbit,
Plus,
Receipt,
Settings,
TrendingDown,
TrendingUp,
UserRound,
Users,
Wallet,
} from "lucide-react"
import { Area, AreaChart, CartesianGrid, XAxis, YAxis } from "recharts"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbPage } from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@/components/ui/chart"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
const MAIN = [
{ title: "Dashboard", icon: LayoutDashboard, active: true },
{ title: "Invoices", icon: FileText, count: 5 },
{ title: "Clients", icon: Users },
{ title: "Payments", icon: Wallet },
{ title: "Reports", icon: ChartColumn },
]
const DOCUMENTS = [
{ title: "Contracts", icon: FileSignature },
{ title: "Estimates", icon: Receipt },
{ title: "Tax forms", icon: FileText },
]
const SECONDARY = [
{ title: "Settings", icon: Settings },
{ title: "Get help", icon: LifeBuoy },
]
const initials = (name: string) =>
name
.split(" ")
.filter((w) => /^[A-Z]/.test(w))
.slice(0, 2)
.map((w) => w[0])
.join("")
const money = (n: number, digits = 2) =>
n.toLocaleString("en-US", { style: "currency", currency: "USD", minimumFractionDigits: digits, maximumFractionDigits: digits })
// 13 weeks of payments received, ending today (Nov 24). Quieter on weekends, rising slowly.
const DAYS = Array.from({ length: 91 }, (_, i) => {
const date = new Date(Date.UTC(2026, 7, 26 + i))
const weekend = date.getUTCDay() === 0 || date.getUTCDay() === 6
const revenue = Math.round((1150 + i * 6 + 420 * Math.sin(i / 5.5) + 180 * Math.sin(i / 1.7)) * (weekend ? 0.55 : 1))
return { label: date.toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" }), revenue }
})
const WEEKS = Array.from({ length: Math.ceil(DAYS.length / 7) }, (_, w) => {
const week = DAYS.slice(w * 7, w * 7 + 7)
return { label: week[0].label, tip: `Week of ${week[0].label}`, revenue: week.reduce((s, d) => s + d.revenue, 0) }
})
const RANGES = [
{ value: "90", label: "3 months" },
{ value: "30", label: "30 days" },
{ value: "7", label: "7 days" },
]
const chartConfig = { revenue: { label: "Revenue", color: "var(--chart-1)" } } satisfies ChartConfig
const STATS = [
{ label: "Revenue", value: money(48210), change: "+12.4%", up: true, note: "This month, up from $42,890" },
{ label: "Outstanding", value: money(9870), change: "+$1,240", up: true, note: "5 open invoices, 3 overdue" },
{ label: "New clients", value: "6", change: "+2", up: true, note: "Two came from referrals" },
{ label: "Days to pay", value: "11.2", change: "-1.8", up: false, note: "On average, faster since reminders" },
]
const PAYMENTS = [
{ client: "Tessellate Labs", invoice: "INV-1042", method: "Bank transfer", date: "Nov 24", amount: 5680 },
{ client: "Kato & Lee", invoice: "INV-1041", method: "Card", date: "Nov 23", amount: 1860 },
{ client: "Fernwood Studio", invoice: "INV-1039", method: "Card", date: "Nov 21", amount: 4200 },
{ client: "Juniper Bakery", invoice: "INV-1037", method: "Payment link", date: "Nov 19", amount: 640 },
{ client: "Northfield Co.", invoice: "INV-1035", method: "Bank transfer", date: "Nov 17", amount: 2400 },
]
export default function SidebarInsetExample() {
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border">
<AppSidebar />
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-14 shrink-0 items-center gap-2 border-b px-3 sm:px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb>
<BreadcrumbList>
<BreadcrumbItem>
<BreadcrumbPage>Dashboard</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<div className="ml-auto flex items-center gap-2">
<Button variant="outline" size="sm" aria-label="Export">
<Download />
<span className="hidden sm:inline">Export</span>
</Button>
<Button size="sm" aria-label="New invoice">
<Plus />
<span className="hidden sm:inline">New invoice</span>
</Button>
</div>
</header>
<div className="@container/main flex-1 overflow-y-auto">
<Dashboard />
</div>
</SidebarInset>
</SidebarProvider>
)
}
function AppSidebar() {
return (
<Sidebar variant="inset" className="absolute h-full">
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" render={<a href="#" />}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground">
<Orbit />
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">Orbit</span>
<span className="truncate text-xs text-muted-foreground">Ruiz Studio</span>
</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
{MAIN.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton isActive={item.active} render={<a href="#" aria-current={item.active ? "page" : undefined} />}>
<item.icon />
<span>{item.title}</span>
</SidebarMenuButton>
{item.count ? <SidebarMenuBadge>{item.count}</SidebarMenuBadge> : null}
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Documents</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{DOCUMENTS.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton render={<a href="#" />}>
<item.icon />
<span>{item.title}</span>
</SidebarMenuButton>
</SidebarMenuItem>
))}
<SidebarMenuItem>
<SidebarMenuButton className="text-sidebar-foreground/70">
<MoreHorizontal />
<span>More</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup className="mt-auto">
<SidebarGroupContent>
<SidebarMenu>
{SECONDARY.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton size="sm" render={<a href="#" />}>
<item.icon />
<span>{item.title}</span>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<UserMenu />
</SidebarFooter>
</Sidebar>
)
}
function UserMenu() {
const { isMobile } = useSidebar()
return (
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger render={<SidebarMenuButton size="lg" className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground" />}>
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">ada@ruiz.studio</span>
</span>
<ChevronsUpDown className="ml-auto" />
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "top" : "right"} align="end" sideOffset={8} className="w-52">
<DropdownMenuGroup>
<DropdownMenuLabel>ada@ruiz.studio</DropdownMenuLabel>
<DropdownMenuItem>
<UserRound /> Profile
</DropdownMenuItem>
<DropdownMenuItem>
<CreditCard /> Plan and billing
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem>
<LogOut /> Log out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
)
}
function Dashboard() {
const [range, setRange] = React.useState("90")
// Three months reads better week by week; 30 and 7 days stay daily.
const data = range === "90" ? WEEKS : DAYS.slice(-Number(range)).map((d) => ({ ...d, tip: d.label }))
const total = data.reduce((s, d) => s + d.revenue, 0)
const rangeLabel = RANGES.find((r) => r.value === range)?.label.toLowerCase()
return (
<div className="flex flex-col gap-4 p-4 sm:p-6">
<div className="grid gap-3 @md/main:grid-cols-2 @3xl/main:grid-cols-4">
{STATS.map((s) => (
<div key={s.label} className="rounded-xl border bg-card p-4 text-card-foreground">
<div className="flex items-start justify-between gap-2">
<p className="text-sm text-muted-foreground">{s.label}</p>
<Badge variant="outline" className="shrink-0">
{s.up ? <TrendingUp aria-hidden="true" /> : <TrendingDown aria-hidden="true" />}
{s.change}
</Badge>
</div>
<p className="mt-2 text-2xl font-semibold tracking-tight tabular-nums">{s.value}</p>
<p className="mt-1 text-xs text-muted-foreground">{s.note}</p>
</div>
))}
</div>
<section aria-labelledby="sidebar-inset-revenue" className="rounded-xl border bg-card p-4 text-card-foreground sm:p-5">
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
<h2 id="sidebar-inset-revenue" className="font-semibold">
Payments received
</h2>
<p className="mt-0.5 text-sm text-muted-foreground">
{money(total, 0)} in the last {rangeLabel}
</p>
</div>
<ToggleGroup
variant="outline"
size="sm"
spacing={0}
value={[range]}
onValueChange={(v: string[]) => v[0] && setRange(v[0])}
aria-label="Date range"
>
{RANGES.map((r) => (
<ToggleGroupItem key={r.value} value={r.value} className="px-3">
{r.label}
</ToggleGroupItem>
))}
</ToggleGroup>
</div>
<ChartContainer config={chartConfig} className="mt-4 aspect-auto h-[220px] w-full">
<AreaChart data={data} margin={{ left: 0, right: 8, top: 8 }}>
<defs>
<linearGradient id="sidebar-inset-fill" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="var(--color-revenue)" stopOpacity={0.4} />
<stop offset="95%" stopColor="var(--color-revenue)" stopOpacity={0.02} />
</linearGradient>
</defs>
<CartesianGrid vertical={false} />
<XAxis dataKey="label" tickLine={false} axisLine={false} tickMargin={8} minTickGap={32} />
<YAxis tickLine={false} axisLine={false} width={44} tickFormatter={(v: number) => (v ? `$${+(v / 1000).toFixed(1)}k` : "$0")} />
<ChartTooltip
cursor={false}
content={
<ChartTooltipContent
labelFormatter={(label, payload) => payload?.[0]?.payload?.tip ?? label}
formatter={(value) => (
<div className="flex w-full items-center gap-2">
<span className="size-2.5 shrink-0 rounded-[2px] bg-(--color-revenue)" />
<span className="text-muted-foreground">Received</span>
<span className="ml-auto font-medium text-foreground tabular-nums">{money(Number(value), 0)}</span>
</div>
)}
/>
}
/>
<Area dataKey="revenue" type="monotone" fill="url(#sidebar-inset-fill)" stroke="var(--color-revenue)" strokeWidth={2} animationDuration={400} />
</AreaChart>
</ChartContainer>
</section>
<section aria-labelledby="sidebar-inset-payments" className="rounded-xl border bg-card text-card-foreground">
<div className="flex items-center justify-between gap-2 px-4 pt-4 pb-2 sm:px-5">
<h2 id="sidebar-inset-payments" className="font-semibold">
Recent payments
</h2>
<Button variant="ghost" size="sm" nativeButton={false} render={<a href="#" />}>
View all
</Button>
</div>
<ul className="divide-y">
{PAYMENTS.map((p) => (
<li key={p.invoice} className="flex items-center gap-3 px-4 py-3 sm:px-5">
<Avatar size="sm">
<AvatarFallback>{initials(p.client)}</AvatarFallback>
</Avatar>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{p.client}</p>
<p className="truncate text-xs text-muted-foreground">
{p.invoice} · {p.method}
</p>
</div>
<span className="hidden text-xs text-muted-foreground @md/main:inline">{p.date}</span>
<span className="w-24 text-right text-sm font-medium tabular-nums">{money(p.amount)}</span>
</li>
))}
</ul>
</section>
</div>
)
}Nested docs tree
Sections, pages and sub-pages that fold, four levels deep, with badges and a version menu.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-nested.jsoncomponents/dresscode/sidebar-nested.tsx
"use client"
// A docs sidebar four levels deep: sections that fold, pages that open into sub-pages, and sub-pages
// with their own children, built from Collapsible. Badges mark what is new, updated or in beta; the path
// to the open page starts unfolded, a button folds everything, and a menu switches the docs version.
// It sits in a 640px frame here: in your app, drop the frame classes on SidebarProvider and
// "absolute h-full" on Sidebar so it fills the window.
import * as React from "react"
import {
ArrowLeft,
ArrowRight,
BookOpen,
Braces,
ChevronRight,
ChevronsDownUp,
ChevronsUpDown,
FileText,
Gauge,
Info,
KeyRound,
ListOrdered,
Rocket,
ThumbsDown,
ThumbsUp,
TriangleAlert,
Users,
Wallet,
Webhook,
} from "lucide-react"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Badge } from "@/components/ui/badge"
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
SidebarProvider,
SidebarTrigger,
} from "@/components/ui/sidebar"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { cn } from "@/lib/utils"
type Page = { id: string; title: string; badge?: string; pages?: Page[] }
type Item = { id: string; title: string; icon: typeof FileText; badge?: string; pages?: Page[] }
type Section = { id: string; title: string; items: Item[] }
const ACTIVE = "schedules"
const SECTIONS: Section[] = [
{
id: "start",
title: "Get started",
items: [
{ id: "intro", title: "Introduction", icon: BookOpen },
{ id: "quickstart", title: "Quickstart", icon: Rocket },
{ id: "auth", title: "Authentication", icon: KeyRound, badge: "Updated" },
],
},
{
id: "guides",
title: "Guides",
items: [
{
id: "invoices",
title: "Invoices",
icon: FileText,
pages: [
{ id: "create", title: "Create an invoice" },
{ id: "taxes", title: "Taxes and discounts" },
{
id: "reminders",
title: "Reminders",
pages: [
{ id: "schedules", title: "Schedules" },
{ id: "templates", title: "Email templates" },
{ id: "quiet-hours", title: "Quiet hours", badge: "New" },
],
},
{ id: "partial", title: "Partial payments", badge: "New" },
{ id: "credit-notes", title: "Credit notes" },
],
},
{
id: "payments",
title: "Payments",
icon: Wallet,
pages: [
{ id: "links", title: "Payment links" },
{ id: "refunds", title: "Refunds" },
{ id: "payouts", title: "Payouts" },
],
},
{
id: "clients",
title: "Clients",
icon: Users,
pages: [
{ id: "import", title: "Import clients" },
{ id: "portal", title: "Client portal" },
],
},
{
id: "webhooks",
title: "Webhooks",
icon: Webhook,
badge: "Beta",
pages: [
{ id: "events", title: "Events" },
{ id: "secrets", title: "Signing secrets" },
{ id: "retries", title: "Retries and failures" },
],
},
],
},
{
id: "api",
title: "API reference",
items: [
{ id: "api-overview", title: "Overview", icon: Braces },
{ id: "errors", title: "Errors", icon: TriangleAlert },
{ id: "pagination", title: "Pagination", icon: ListOrdered },
{ id: "rate-limits", title: "Rate limits", icon: Gauge },
],
},
]
// Everything that can fold, and the path to the open page, which starts unfolded.
const ALL_IDS = SECTIONS.flatMap((s) => [s.id, ...s.items.flatMap((i) => (i.pages ? [i.id, ...i.pages.filter((p) => p.pages).map((p) => p.id)] : []))])
const START_OPEN = ["start", "guides", "invoices", "reminders"]
const VERSIONS = [
{ value: "3.2", label: "Version 3.2", note: "Latest" },
{ value: "3.1", label: "Version 3.1", note: "Supported until March 2027" },
{ value: "2.9", label: "Version 2.9", note: "Legacy" },
]
// Height animation for every folding panel; skipped when the visitor prefers less motion.
const PANEL = "h-(--collapsible-panel-height) overflow-hidden transition-[height] duration-200 ease-out data-ending-style:h-0 data-starting-style:h-0 motion-reduce:transition-none"
const SCHEDULE = [
{ when: "3 days before", email: "A friendly heads-up", on: true },
{ when: "On the due date", email: "Payment is due today", on: true },
{ when: "7 days after", email: "First reminder", on: true },
{ when: "14 days after", email: "Second reminder, with the late fee", on: false },
]
export default function SidebarNested() {
const [open, setOpen] = React.useState<Set<string>>(() => new Set(START_OPEN))
const [version, setVersion] = React.useState("3.2")
const toggle = (id: string, isOpen: boolean) =>
setOpen((prev) => {
const next = new Set(prev)
if (isOpen) next.add(id)
else next.delete(id)
return next
})
const anyOpen = open.size > 0
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border bg-background">
<Sidebar className="absolute h-full">
<SidebarHeader>
<VersionSwitcher version={version} onChange={setVersion} />
</SidebarHeader>
<SidebarContent>
{SECTIONS.map((section) => (
<Collapsible
key={section.id}
open={open.has(section.id)}
onOpenChange={(o) => toggle(section.id, o)}
className="group/section"
render={<SidebarGroup />}
>
<SidebarGroupLabel
render={<CollapsibleTrigger />}
className="w-full hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
>
{section.title}
<ChevronRight className="ml-auto transition-transform duration-200 group-data-open/section:rotate-90 motion-reduce:transition-none" />
</SidebarGroupLabel>
<CollapsibleContent className={PANEL}>
<SidebarGroupContent>
<SidebarMenu>
{section.items.map((item) =>
item.pages ? (
<FoldingItem key={item.id} item={item} open={open} toggle={toggle} />
) : (
<SidebarMenuItem key={item.id}>
<SidebarMenuButton render={<a href="#" />}>
<item.icon />
<span className="truncate">{item.title}</span>
{item.badge ? (
<Badge variant="secondary" className="ml-auto h-4 px-1.5 text-[10px]">
{item.badge}
</Badge>
) : null}
</SidebarMenuButton>
</SidebarMenuItem>
),
)}
</SidebarMenu>
</SidebarGroupContent>
</CollapsibleContent>
</Collapsible>
))}
</SidebarContent>
<SidebarFooter className="border-t">
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="sm" className="text-muted-foreground" onClick={() => setOpen(anyOpen ? new Set() : new Set(ALL_IDS))}>
{anyOpen ? <ChevronsDownUp /> : <ChevronsUpDown />}
<span>{anyOpen ? "Collapse all" : "Expand all"}</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
</Sidebar>
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-14 shrink-0 items-center gap-2 border-b px-3 sm:px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb className="min-w-0">
<BreadcrumbList className="flex-nowrap">
{["Guides", "Invoices", "Reminders"].map((c, i) => (
<React.Fragment key={c}>
<BreadcrumbItem className={cn("hidden", i === 2 ? "sm:inline-flex" : "md:inline-flex")}>
<BreadcrumbLink href="#">{c}</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className={cn("hidden", i === 2 ? "sm:list-item" : "md:list-item")} />
</React.Fragment>
))}
<BreadcrumbItem>
<BreadcrumbPage>Schedules</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<Badge variant="outline" className="ml-auto shrink-0">
v{version}
</Badge>
</header>
<div className="@container/main flex-1 overflow-y-auto">
<Article version={version} onLatest={() => setVersion("3.2")} />
</div>
</SidebarInset>
</SidebarProvider>
)
}
function VersionSwitcher({ version, onChange }: { version: string; onChange: (v: string) => void }) {
const current = VERSIONS.find((v) => v.value === version) ?? VERSIONS[0]
return (
<SidebarMenu className="min-w-0 flex-1">
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger render={<SidebarMenuButton size="lg" className="data-popup-open:bg-sidebar-accent" />}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground">
<BookOpen />
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">Orbit docs</span>
<span className="truncate text-xs text-muted-foreground">{current.label}</span>
</span>
<ChevronsUpDown className="ml-auto text-muted-foreground" />
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-56">
<DropdownMenuGroup>
<DropdownMenuLabel>Docs version</DropdownMenuLabel>
<DropdownMenuRadioGroup value={version} onValueChange={(v) => onChange(String(v))}>
{VERSIONS.map((v) => (
<DropdownMenuRadioItem key={v.value} value={v.value} closeOnClick>
<span className="grid leading-tight">
<span>{v.label}</span>
<span className="text-xs text-muted-foreground">{v.note}</span>
</span>
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
)
}
function FoldingItem({ item, open, toggle }: { item: Item; open: Set<string>; toggle: (id: string, open: boolean) => void }) {
return (
<Collapsible open={open.has(item.id)} onOpenChange={(o) => toggle(item.id, o)} className="group/item" render={<SidebarMenuItem />}>
<CollapsibleTrigger render={<SidebarMenuButton />}>
<item.icon />
<span className="truncate">{item.title}</span>
{item.badge ? (
<Badge variant="secondary" className="ml-auto h-4 px-1.5 text-[10px]">
{item.badge}
</Badge>
) : null}
<ChevronRight
className={cn(
"text-muted-foreground transition-transform duration-200 group-data-open/item:rotate-90 motion-reduce:transition-none",
!item.badge && "ml-auto",
)}
/>
</CollapsibleTrigger>
<CollapsibleContent className={PANEL}>
<SidebarMenuSub>
{item.pages?.map((page) =>
page.pages ? (
<Collapsible
key={page.id}
open={open.has(page.id)}
onOpenChange={(o) => toggle(page.id, o)}
className="group/sub"
render={<SidebarMenuSubItem />}
>
<CollapsibleTrigger render={<SidebarMenuSubButton render={<button type="button" />} className="w-full" />}>
<span className="truncate">{page.title}</span>
<ChevronRight className="ml-auto text-muted-foreground! transition-transform duration-200 group-data-open/sub:rotate-90 motion-reduce:transition-none" />
</CollapsibleTrigger>
<CollapsibleContent className={PANEL}>
<SidebarMenuSub className="mr-0 pr-0">
{page.pages.map((child) => (
<PageLink key={child.id} page={child} />
))}
</SidebarMenuSub>
</CollapsibleContent>
</Collapsible>
) : (
<PageLink key={page.id} page={page} />
),
)}
</SidebarMenuSub>
</CollapsibleContent>
</Collapsible>
)
}
function PageLink({ page }: { page: Page }) {
const active = page.id === ACTIVE
return (
<SidebarMenuSubItem>
<SidebarMenuSubButton href="#" isActive={active} aria-current={active ? "page" : undefined} className="data-active:font-medium">
<span className="truncate">{page.title}</span>
{page.badge ? (
<Badge variant="secondary" className="ml-auto h-4 shrink-0 px-1.5 text-[10px]">
{page.badge}
</Badge>
) : null}
</SidebarMenuSubButton>
</SidebarMenuSubItem>
)
}
const TOC = [
{ id: "how", title: "How schedules work" },
{ id: "default", title: "The default schedule" },
{ id: "change", title: "Change the schedule" },
]
function Article({ version, onLatest }: { version: string; onLatest: () => void }) {
const [helpful, setHelpful] = React.useState<null | boolean>(null)
return (
<div className="mx-auto grid max-w-4xl gap-10 px-4 py-6 sm:px-8 sm:py-8 @3xl/main:grid-cols-[minmax(0,1fr)_11rem]">
<article className="min-w-0 text-sm leading-relaxed">
{version !== "3.2" ? (
<Alert className="mb-6">
<Info />
<AlertTitle>You're reading the docs for version {version}</AlertTitle>
<AlertDescription>
Some settings moved in 3.2.{" "}
<button type="button" onClick={onLatest} className="font-medium text-foreground underline underline-offset-4">
Read the latest
</button>
</AlertDescription>
</Alert>
) : null}
<p className="text-xs text-muted-foreground">Guides · Updated Nov 18</p>
<h2 className="mt-1 text-2xl font-semibold tracking-tight">Reminder schedules</h2>
<p className="mt-3 text-base text-muted-foreground">
Orbit emails your client when an invoice is about to fall due and keeps nudging, politely, until it's paid.
</p>
<h3 id="how" className="mt-8 scroll-mt-4 text-lg font-semibold">
How schedules work
</h3>
<p className="mt-2">
A schedule is a list of moments, counted from each invoice's due date. At each one, Orbit sends the matching email template. Reminders
stop by themselves once the invoice is paid, voided or marked as sent by post.
</p>
<h3 id="default" className="mt-8 scroll-mt-4 text-lg font-semibold">
The default schedule
</h3>
<div className="mt-3 rounded-lg border">
<Table>
<TableHeader>
<TableRow>
<TableHead className="pl-3">When</TableHead>
<TableHead>Email</TableHead>
<TableHead className="pr-3 text-right">Default</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{SCHEDULE.map((r) => (
<TableRow key={r.when}>
<TableCell className="pl-3">{r.when}</TableCell>
<TableCell className="text-muted-foreground">{r.email}</TableCell>
<TableCell className="pr-3 text-right">{r.on ? "On" : "Off"}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
<h3 id="change" className="mt-8 scroll-mt-4 text-lg font-semibold">
Change the schedule
</h3>
<ol className="mt-2 list-decimal space-y-1.5 pl-5">
<li>Open Settings, then Reminders.</li>
<li>Pick a moment to edit, or add one with Add a reminder.</li>
<li>Choose the template it sends, then save. Invoices already sent pick up the change.</li>
</ol>
<div className="mt-10 flex flex-wrap items-center gap-3 border-t pt-6">
{helpful === null ? (
<>
<span className="text-muted-foreground">Was this page helpful?</span>
<Button variant="outline" size="sm" onClick={() => setHelpful(true)}>
<ThumbsUp /> Yes
</Button>
<Button variant="outline" size="sm" onClick={() => setHelpful(false)}>
<ThumbsDown /> No
</Button>
</>
) : (
<p role="status" className="text-muted-foreground">
{helpful ? "Thanks, glad it helped." : "Thanks. We read every answer and use it to fix the docs."}
</p>
)}
</div>
<nav aria-label="Previous and next page" className="mt-6 grid gap-3 sm:grid-cols-2">
<a href="#" className="rounded-lg border p-3 transition-colors hover:bg-muted">
<span className="flex items-center gap-1 text-xs text-muted-foreground">
<ArrowLeft className="size-3.5" /> Previous
</span>
<span className="mt-0.5 block font-medium">Taxes and discounts</span>
</a>
<a href="#" className="rounded-lg border p-3 text-right transition-colors hover:bg-muted">
<span className="flex items-center justify-end gap-1 text-xs text-muted-foreground">
Next <ArrowRight className="size-3.5" />
</span>
<span className="mt-0.5 block font-medium">Email templates</span>
</a>
</nav>
</article>
<nav aria-label="On this page" className="hidden @3xl/main:block">
<div className="sticky top-0">
<p className="text-xs font-medium text-muted-foreground">On this page</p>
<ul className="mt-2 space-y-2 text-sm">
{TOC.map((t, i) => (
<li key={t.id}>
<a href={`#${t.id}`} className={cn("transition-colors hover:text-foreground", i === 0 ? "font-medium text-foreground" : "text-muted-foreground")}>
{t.title}
</a>
</li>
))}
</ul>
</div>
</nav>
</div>
)
}Workspace switcher
Switch workspaces from the header, create from a quick menu, and open the user menu at the foot.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-team-switcher.jsoncomponents/dresscode/sidebar-team-switcher.tsx
"use client"
// A sidebar for an app with several workspaces: a switcher at the top (each workspace has its own
// numbers and activity, and you can create a new one), a quick-create menu ("C" opens it) whose forms
// land in the activity feed, and the user's menu at the foot. A new workspace starts empty.
// It sits in a 640px frame here: in your app, drop the frame classes on SidebarProvider and
// "absolute h-full" on Sidebar so it fills the window.
import * as React from "react"
import {
BadgeCheck,
BellRing,
ChartColumn,
ChevronsUpDown,
CircleDollarSign,
CirclePlus,
CreditCard,
FilePen,
FileText,
LayoutDashboard,
LifeBuoy,
LogOut,
Plus,
Settings,
UserPlus,
Users,
Wallet,
} from "lucide-react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { Kbd } from "@/components/ui/kbd"
import { Label } from "@/components/ui/label"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarRail,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
type ActivityKind = "invoice" | "estimate" | "payment" | "client" | "reminder"
type Activity = { id: string; kind: ActivityKind; title: string; detail: string; when: string }
type Workspace = { id: string; name: string; plan: string; outstanding: number; overdue: number; clients: string[]; activity: Activity[]; next: number }
type Kind = "invoice" | "estimate" | "client" | "workspace"
const INITIAL: Workspace[] = [
{
id: "ruiz",
name: "Ruiz Studio",
plan: "Pro plan",
outstanding: 9870,
overdue: 3,
clients: ["Fernwood Studio", "Kato & Lee", "Pellucid Health", "Northfield Co.", "Juniper Bakery", "Tessellate Labs"],
next: 1049,
activity: [
{ id: "a1", kind: "payment", title: "Kato & Lee paid INV-1041", detail: "$1,860.00 by card", when: "10 min ago" },
{ id: "a2", kind: "reminder", title: "Reminder sent to Pellucid Health", detail: "INV-1036 is 15 days late", when: "1 hour ago" },
{ id: "a3", kind: "invoice", title: "You created INV-1048", detail: "Fernwood Studio · $4,200.00", when: "Yesterday" },
{ id: "a4", kind: "estimate", title: "Northfield Co. accepted EST-0212", detail: "$2,400.00, now invoice INV-1045", when: "Nov 21" },
],
},
{
id: "kato",
name: "Kato & Lee",
plan: "Team plan",
outstanding: 24350,
overdue: 1,
clients: ["Marlow & Finch", "Harlow Dental", "Brightwater Inn"],
next: 318,
activity: [
{ id: "b1", kind: "invoice", title: "Ben Kato created INV-0317", detail: "Harlow Dental · $12,000.00", when: "2 hours ago" },
{ id: "b2", kind: "payment", title: "Brightwater Inn paid INV-0311", detail: "$3,480.00 by bank transfer", when: "Yesterday" },
],
},
{
id: "side",
name: "Ada's freelance",
plan: "Free plan",
outstanding: 600,
overdue: 0,
clients: ["Oakline Press"],
next: 12,
activity: [{ id: "c1", kind: "invoice", title: "You created INV-0011", detail: "Oakline Press · $600.00", when: "Nov 2" }],
},
]
const ICONS: Record<ActivityKind, typeof FileText> = {
invoice: FileText,
estimate: FilePen,
payment: CircleDollarSign,
client: UserPlus,
reminder: BellRing,
}
const money = (n: number) => n.toLocaleString("en-US", { style: "currency", currency: "USD" })
const initials = (name: string) =>
name
.split(/\s+/)
.filter((w) => /^[A-Za-z]/.test(w))
.slice(0, 2)
.map((w) => w[0].toUpperCase())
.join("")
export default function SidebarTeamSwitcher() {
const [workspaces, setWorkspaces] = React.useState(INITIAL)
const [currentId, setCurrentId] = React.useState(INITIAL[0].id)
const [dialog, setDialog] = React.useState<{ kind: Kind; open: boolean }>({ kind: "invoice", open: false })
const [announcement, setAnnouncement] = React.useState("")
const ws = workspaces.find((w) => w.id === currentId) ?? workspaces[0]
const openDialog = (kind: Kind) => setDialog({ kind, open: true })
const save = (kind: Kind, v: Record<string, string>) => {
if (kind === "workspace") {
const id = `ws${Date.now()}`
setWorkspaces((all) => [...all, { id, name: v.name, plan: "Free plan", outstanding: 0, overdue: 0, clients: [], activity: [], next: 1 }])
setCurrentId(id)
setAnnouncement(`Workspace ${v.name} created`)
return
}
const amount = Number(v.amount)
const update = (w: Workspace): Workspace => {
if (kind === "client") {
const row: Activity = { id: `n${Date.now()}`, kind: "client", title: `You added ${v.name}`, detail: v.email, when: "Just now" }
return { ...w, clients: [...w.clients, v.name], activity: [row, ...w.activity] }
}
const num = `${kind === "invoice" ? "INV" : "EST"}-${String(w.next).padStart(4, "0")}`
const row: Activity = {
id: `n${Date.now()}`,
kind,
title: `You created ${kind === "invoice" ? "" : "estimate "}${num}`,
detail: `${v.client} · ${money(amount)}${kind === "invoice" ? ` · due in ${v.terms} days` : ""}`,
when: "Just now",
}
return { ...w, next: w.next + 1, outstanding: kind === "invoice" ? w.outstanding + amount : w.outstanding, activity: [row, ...w.activity] }
}
setWorkspaces((all) => all.map((w) => (w.id === ws.id ? update(w) : w)))
setAnnouncement(kind === "client" ? `${v.name} added` : `Draft ${kind} created`)
}
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border bg-background">
<Sidebar collapsible="icon" className="absolute h-full">
<SidebarHeader>
<WorkspaceSwitcher workspaces={workspaces} current={ws} onSwitch={setCurrentId} onNew={() => openDialog("workspace")} />
</SidebarHeader>
<SidebarContent>
<QuickCreate onCreate={openDialog} />
<SidebarGroup>
<SidebarGroupLabel>Billing</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<NavLink title="Overview" icon={LayoutDashboard} active />
<NavLink title="Invoices" icon={FileText} count={ws.overdue ? `${ws.overdue} late` : undefined} />
<NavLink title="Payments" icon={Wallet} />
<NavLink title="Clients" icon={Users} count={ws.clients.length || undefined} />
<NavLink title="Reports" icon={ChartColumn} />
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup className="mt-auto">
<SidebarGroupContent>
<SidebarMenu>
<NavLink title="Settings" icon={Settings} />
<NavLink title="Help and support" icon={LifeBuoy} />
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<UserMenu />
</SidebarFooter>
<SidebarRail />
</Sidebar>
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-14 shrink-0 items-center gap-2 border-b px-3 sm:px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb className="min-w-0">
<BreadcrumbList className="flex-nowrap">
<BreadcrumbItem className="hidden min-w-0 sm:inline-flex">
<BreadcrumbLink href="#" className="truncate">
{ws.name}
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="hidden sm:list-item" />
<BreadcrumbItem>
<BreadcrumbPage>Overview</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
</header>
<div className="flex-1 overflow-y-auto">
<Overview ws={ws} onCreate={openDialog} />
</div>
</SidebarInset>
<CreateDialog
kind={dialog.kind}
open={dialog.open}
onOpenChange={(open) => setDialog((d) => ({ ...d, open }))}
onKindChange={(kind) => setDialog({ kind, open: true })}
ws={ws}
onSave={save}
/>
<p role="status" className="sr-only">
{announcement}
</p>
</SidebarProvider>
)
}
function WorkspaceSwitcher({
workspaces,
current,
onSwitch,
onNew,
}: {
workspaces: Workspace[]
current: Workspace
onSwitch: (id: string) => void
onNew: () => void
}) {
const { isMobile } = useSidebar()
return (
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger
render={
<SidebarMenuButton
size="lg"
tooltip={current.name}
className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground"
aria-label={`Workspace: ${current.name}. Switch workspace`}
/>
}
>
<span aria-hidden="true" className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-xs font-semibold text-primary-foreground">
{initials(current.name)}
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">{current.name}</span>
<span className="truncate text-xs text-muted-foreground">{current.plan}</span>
</span>
<ChevronsUpDown className="ml-auto" />
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "bottom" : "right"} align="start" sideOffset={isMobile ? 4 : 8} className="w-60">
<DropdownMenuGroup>
<DropdownMenuLabel>Workspaces</DropdownMenuLabel>
<DropdownMenuRadioGroup value={current.id} onValueChange={(v) => onSwitch(String(v))}>
{workspaces.map((w) => (
<DropdownMenuRadioItem key={w.id} value={w.id} closeOnClick className="gap-2 py-1.5">
<span aria-hidden="true" className="flex size-6 shrink-0 items-center justify-center rounded-md border text-[10px] font-semibold">
{initials(w.name)}
</span>
<span className="grid min-w-0 leading-tight">
<span className="truncate">{w.name}</span>
<span className="truncate text-xs text-muted-foreground">{w.plan}</span>
</span>
</DropdownMenuRadioItem>
))}
</DropdownMenuRadioGroup>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={onNew} className="gap-2 py-1.5">
<span className="flex size-6 items-center justify-center rounded-md border border-dashed">
<Plus className="size-3.5" />
</span>
Create a workspace
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
)
}
function QuickCreate({ onCreate }: { onCreate: (kind: Kind) => void }) {
const { isMobile, state } = useSidebar()
const [open, setOpen] = React.useState(false)
// "C" opens the menu from anywhere, unless you are typing or another menu or dialog is open.
React.useEffect(() => {
if (isMobile || state !== "expanded") return
const onKey = (e: KeyboardEvent) => {
if (e.key.toLowerCase() !== "c" || e.metaKey || e.ctrlKey || e.altKey) return
if ((e.target as HTMLElement).closest("input, textarea, select, [contenteditable=true], [role=dialog], [role=menu]")) return
e.preventDefault()
setOpen(true)
}
window.addEventListener("keydown", onKey)
return () => window.removeEventListener("keydown", onKey)
}, [isMobile, state])
const items = [
{ kind: "invoice" as const, label: "Invoice", icon: FileText },
{ kind: "estimate" as const, label: "Estimate", icon: FilePen },
{ kind: "client" as const, label: "Client", icon: UserPlus },
]
return (
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu open={open} onOpenChange={setOpen}>
<DropdownMenuTrigger
render={
<SidebarMenuButton
tooltip="Quick create"
className="bg-primary font-medium text-primary-foreground hover:bg-primary/90 hover:text-primary-foreground active:bg-primary/90 active:text-primary-foreground data-popup-open:bg-primary/90 data-popup-open:text-primary-foreground"
/>
}
>
<CirclePlus />
<span>Quick create</span>
<Kbd className="ml-auto bg-primary-foreground/15 text-primary-foreground group-data-[collapsible=icon]:hidden">C</Kbd>
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "bottom" : "right"} align="start" sideOffset={8} className="w-48">
<DropdownMenuGroup>
<DropdownMenuLabel>Create</DropdownMenuLabel>
{items.map((i) => (
<DropdownMenuItem key={i.kind} onClick={() => onCreate(i.kind)}>
<i.icon /> {i.label}
</DropdownMenuItem>
))}
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
)
}
function NavLink({ title, icon: Icon, count, active }: { title: string; icon: typeof FileText; count?: number | string; active?: boolean }) {
return (
<SidebarMenuItem>
<SidebarMenuButton isActive={active} tooltip={title} render={<a href="#" aria-current={active ? "page" : undefined} />}>
<Icon />
<span>{title}</span>
</SidebarMenuButton>
{count ? <SidebarMenuBadge>{count}</SidebarMenuBadge> : null}
</SidebarMenuItem>
)
}
function UserMenu() {
const { isMobile } = useSidebar()
const [summary, setSummary] = React.useState(true)
return (
<SidebarMenu>
<SidebarMenuItem>
<DropdownMenu>
<DropdownMenuTrigger
render={<SidebarMenuButton size="lg" tooltip="Ada Lin" className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground" />}
>
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">ada@ruiz.studio</span>
</span>
<ChevronsUpDown className="ml-auto" />
</DropdownMenuTrigger>
<DropdownMenuContent side={isMobile ? "top" : "right"} align="end" sideOffset={8} className="w-60">
<DropdownMenuGroup>
<DropdownMenuLabel className="flex items-center gap-2 py-1.5 font-normal text-foreground">
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span className="grid min-w-0 leading-tight">
<span className="truncate text-sm font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">ada@ruiz.studio</span>
</span>
</DropdownMenuLabel>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<BadgeCheck /> Account
</DropdownMenuItem>
<DropdownMenuItem>
<CreditCard /> Plan and billing
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuLabel>Email me</DropdownMenuLabel>
<DropdownMenuCheckboxItem checked={summary} onCheckedChange={setSummary}>
A weekly summary
</DropdownMenuCheckboxItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem>
<LogOut /> Log out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</SidebarMenuItem>
</SidebarMenu>
)
}
function Overview({ ws, onCreate }: { ws: Workspace; onCreate: (kind: Kind) => void }) {
const stats = [
{ label: "Outstanding", value: money(ws.outstanding) },
{ label: "Overdue invoices", value: String(ws.overdue) },
{ label: "Clients", value: String(ws.clients.length) },
]
return (
<div className="flex flex-col gap-6 p-4 sm:p-6">
<div>
<h2 className="text-xl font-semibold tracking-tight">Overview</h2>
<p className="mt-1 text-sm text-muted-foreground">
{ws.name} on the {ws.plan.replace(" plan", "")} plan.
</p>
</div>
<dl className="grid gap-3 sm:grid-cols-3">
{stats.map((s) => (
<div key={s.label} className="rounded-xl border bg-card p-4 text-card-foreground">
<dt className="text-sm text-muted-foreground">{s.label}</dt>
<dd className="mt-1 text-2xl font-semibold tracking-tight tabular-nums">{s.value}</dd>
</div>
))}
</dl>
<section aria-labelledby="sidebar-team-activity" className="rounded-xl border bg-card text-card-foreground">
<h3 id="sidebar-team-activity" className="border-b px-4 py-3 font-medium">
Recent activity
</h3>
{ws.activity.length ? (
<ul className="divide-y">
{ws.activity.map((a) => {
const Icon = ICONS[a.kind]
return (
<li key={a.id} className="flex items-center gap-3 px-4 py-3">
<span className="flex size-8 shrink-0 items-center justify-center rounded-full border bg-background text-muted-foreground">
<Icon className="size-4" />
</span>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{a.title}</p>
<p className="truncate text-xs text-muted-foreground">{a.detail}</p>
</div>
<span className="shrink-0 text-xs text-muted-foreground">{a.when}</span>
</li>
)
})}
</ul>
) : (
<div className="flex flex-col items-center px-4 py-10 text-center">
<span className="flex size-10 items-center justify-center rounded-full border bg-background text-muted-foreground">
<FileText className="size-5" />
</span>
<p className="mt-3 font-medium">Nothing here yet</p>
<p className="mt-1 max-w-xs text-sm text-muted-foreground">Add your first client, then send them an invoice. Everything that happens shows up here.</p>
<div className="mt-4 flex flex-wrap justify-center gap-2">
<Button variant="outline" size="sm" onClick={() => onCreate("client")}>
<UserPlus /> Add a client
</Button>
<Button size="sm" onClick={() => onCreate("invoice")} disabled={!ws.clients.length}>
<FileText /> New invoice
</Button>
</div>
</div>
)}
</section>
</div>
)
}
const COPY: Record<Kind, { title: string; description: (ws: Workspace) => string; submit: string }> = {
invoice: { title: "New invoice", description: (ws) => `Saved as a draft in ${ws.name}. Add line items before you send it.`, submit: "Create draft" },
estimate: { title: "New estimate", description: () => "Your client can accept it online. It becomes an invoice when they do.", submit: "Create estimate" },
client: { title: "Add a client", description: (ws) => `They get invoices and reminders from ${ws.name} at this address.`, submit: "Add client" },
workspace: { title: "Create a workspace", description: () => "A separate set of clients, invoices and settings. It starts on the Free plan.", submit: "Create workspace" },
}
function CreateDialog({
kind,
open,
onOpenChange,
onKindChange,
ws,
onSave,
}: {
kind: Kind
open: boolean
onOpenChange: (open: boolean) => void
onKindChange: (kind: Kind) => void
ws: Workspace
onSave: (kind: Kind, values: Record<string, string>) => void
}) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
{/* The form remounts for each kind (and each time the dialog opens), so it always starts blank. */}
<CreateForm
key={kind}
kind={kind}
ws={ws}
onKindChange={onKindChange}
onSave={(values) => {
onSave(kind, values)
onOpenChange(false)
}}
/>
</DialogContent>
</Dialog>
)
}
function CreateForm({
kind,
ws,
onKindChange,
onSave,
}: {
kind: Kind
ws: Workspace
onKindChange: (kind: Kind) => void
onSave: (values: Record<string, string>) => void
}) {
const copy = COPY[kind]
const needsClient = (kind === "invoice" || kind === "estimate") && !ws.clients.length
const [client, setClient] = React.useState(ws.clients[0] ?? "")
const [terms, setTerms] = React.useState("14")
const clientItems = ws.clients.map((c) => ({ value: c, label: c }))
const termItems = [
{ value: "7", label: "In 7 days" },
{ value: "14", label: "In 14 days" },
{ value: "30", label: "In 30 days" },
]
const submit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const data = Object.fromEntries(new FormData(e.currentTarget)) as Record<string, string>
onSave({ ...data, client, terms })
}
return (
<form onSubmit={submit} className="grid gap-4">
<DialogHeader>
<DialogTitle>{copy.title}</DialogTitle>
<DialogDescription>{copy.description(ws)}</DialogDescription>
</DialogHeader>
{needsClient ? (
<div className="rounded-lg border border-dashed p-4 text-center text-sm">
<p className="font-medium">{ws.name} has no clients yet</p>
<p className="mt-1 text-muted-foreground">Add one first, then come back to bill them.</p>
<Button type="button" variant="outline" size="sm" className="mt-3" onClick={() => onKindChange("client")}>
<UserPlus /> Add a client
</Button>
</div>
) : kind === "invoice" || kind === "estimate" ? (
<div className="grid gap-4">
<div className="grid gap-2">
<Label htmlFor="sidebar-team-client">Client</Label>
<Select items={clientItems} value={client} onValueChange={(v) => v != null && setClient(String(v))}>
<SelectTrigger id="sidebar-team-client" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
{clientItems.map((c) => (
<SelectItem key={c.value} value={c.value}>
{c.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="grid gap-2">
<Label htmlFor="sidebar-team-amount">Amount (USD)</Label>
<Input id="sidebar-team-amount" name="amount" type="number" inputMode="decimal" min="1" step="0.01" placeholder="1200.00" required autoFocus />
</div>
{kind === "invoice" ? (
<div className="grid gap-2">
<Label htmlFor="sidebar-team-terms">Due</Label>
<Select items={termItems} value={terms} onValueChange={(v) => v != null && setTerms(String(v))}>
<SelectTrigger id="sidebar-team-terms" className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
{termItems.map((t) => (
<SelectItem key={t.value} value={t.value}>
{t.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
) : null}
</div>
</div>
) : kind === "client" ? (
<div className="grid gap-4">
<div className="grid gap-2">
<Label htmlFor="sidebar-team-name">Name or company</Label>
<Input id="sidebar-team-name" name="name" placeholder="Linden Street Clinic" required autoFocus autoComplete="off" />
</div>
<div className="grid gap-2">
<Label htmlFor="sidebar-team-email">Billing email</Label>
<Input id="sidebar-team-email" name="email" type="email" placeholder="accounts@example.com" required autoComplete="off" />
</div>
</div>
) : (
<div className="grid gap-2">
<Label htmlFor="sidebar-team-ws">Workspace name</Label>
<Input id="sidebar-team-ws" name="name" placeholder="Side projects" required autoFocus autoComplete="off" />
</div>
)}
<DialogFooter>
<DialogClose render={<Button type="button" variant="outline" />}>Cancel</DialogClose>
{needsClient ? null : <Button type="submit">{copy.submit}</Button>}
</DialogFooter>
</form>
)
}Right details panel
A support inbox: nav on the left, the picked conversation's details in a sidebar on the right.
npx shadcn@latest add https://dresscodeui.com/r/dresscode/sidebar-right-panel.jsoncomponents/dresscode/sidebar-right-panel.tsx
"use client"
// Two sidebars: the app's nav on the left (folds to icons) and a details panel on the right
// (side="right") for a support inbox. Folders and labels filter the list; picking a conversation fills
// the panel, where its status, priority and owner can be changed. Arrow keys move through the list.
// On phones the panel opens as a sheet from the right. The details panel has its own SidebarProvider,
// controlled from the header button, so Ctrl/⌘ B still folds only the nav.
// It sits in a 640px frame here: in your app, drop the frame classes on the outer SidebarProvider and
// "absolute h-full" on both sidebars so they fill the window.
import * as React from "react"
import { AlarmClock, AtSign, CheckCheck, Inbox, LifeBuoy, PanelRight, Reply, Settings, UserRound, X } from "lucide-react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator } from "@/components/ui/breadcrumb"
import { Button } from "@/components/ui/button"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarInset,
SidebarMenu,
SidebarMenuBadge,
SidebarMenuButton,
SidebarMenuItem,
SidebarProvider,
SidebarRail,
SidebarSeparator,
SidebarTrigger,
useSidebar,
} from "@/components/ui/sidebar"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
import { cn } from "@/lib/utils"
type Status = "Open" | "Pending" | "Closed"
type Priority = "Low" | "Normal" | "High"
type LabelId = "billing" | "bug" | "feature"
type Conversation = {
id: string
name: string
email: string
company: string
plan: string
since: string
invoices: number
subject: string
body: string[]
time: string
unread: boolean
mentioned?: boolean
snoozed?: string
labels: LabelId[]
assignee: string
priority: Priority
status: Status
}
const ME = "Ada Lin"
const TEAM = ["Unassigned", "Ada Lin", "Sam Reid", "Mei Chen"]
const LABELS: { id: LabelId; title: string; dot: string }[] = [
{ id: "billing", title: "Billing", dot: "bg-(--chart-1)" },
{ id: "bug", title: "Bug", dot: "bg-(--chart-5)" },
{ id: "feature", title: "Feature request", dot: "bg-(--chart-4)" },
]
const INITIAL: Conversation[] = [
{
id: "c1",
name: "Priya Nair",
email: "priya@fernwood.studio",
company: "Fernwood Studio",
plan: "Pro, yearly",
since: "March 2024",
invoices: 312,
subject: "Card declined on our renewal",
body: [
"Hi, our card was declined this morning when the Pro plan renewed. We've added a new card since.",
"Can you retry the charge? Our reminders are paused and two clients are already late.",
],
time: "9:41",
unread: true,
labels: ["billing"],
assignee: "Ada Lin",
priority: "High",
status: "Open",
},
{
id: "c2",
name: "Tom Okafor",
email: "tom@katolee.co",
company: "Kato & Lee",
plan: "Team, monthly",
since: "June 2025",
invoices: 87,
subject: "Can clients pay in two installments?",
body: ["A few of our bigger clients asked to split payments. Is there a way to send one invoice with two due dates?"],
time: "8:15",
unread: true,
labels: ["feature"],
assignee: "Unassigned",
priority: "Normal",
status: "Open",
},
{
id: "c3",
name: "Grace Huang",
email: "grace@pellucid.health",
company: "Pellucid Health",
plan: "Pro, monthly",
since: "January 2025",
invoices: 154,
subject: "Reminder emails landing in spam",
body: ["Three clients told us this week that our reminders went to their spam folder. Nothing changed on our side as far as I know."],
time: "Yesterday",
unread: false,
labels: ["bug"],
assignee: "Ada Lin",
priority: "High",
status: "Open",
},
{
id: "c4",
name: "Leo Martins",
email: "leo@juniperbakery.com",
company: "Juniper Bakery",
plan: "Free",
since: "October 2026",
invoices: 6,
subject: "How do I add VAT to an invoice?",
body: ["We just registered for VAT. @Ada Lin said there's a setting for it but I can't find where to turn it on."],
time: "Yesterday",
unread: false,
mentioned: true,
labels: ["billing"],
assignee: "Sam Reid",
priority: "Low",
status: "Pending",
},
{
id: "c5",
name: "Hana Sato",
email: "hana@northfield.co",
company: "Northfield Co.",
plan: "Pro, yearly",
since: "August 2023",
invoices: 506,
subject: "Export every invoice for our accountant",
body: ["Our accountant needs all invoices from this tax year as PDFs, ideally in one file. No rush, the deadline is in January."],
time: "Mon",
unread: false,
snoozed: "Thursday",
labels: [],
assignee: "Ada Lin",
priority: "Normal",
status: "Pending",
},
{
id: "c6",
name: "Oliver Brandt",
email: "oliver@tessellate.dev",
company: "Tessellate Labs",
plan: "Team, yearly",
since: "May 2024",
invoices: 221,
subject: "Thanks, the payout arrived",
body: ["All good now, the payout landed this morning. Thanks for chasing the bank."],
time: "Nov 20",
unread: false,
labels: ["billing"],
assignee: "Mei Chen",
priority: "Normal",
status: "Closed",
},
]
type Filter = { kind: "folder"; id: "inbox" | "mine" | "mentions" | "snoozed" | "done" } | { kind: "label"; id: LabelId }
const FOLDERS = [
{ id: "inbox" as const, title: "Inbox", icon: Inbox },
{ id: "mine" as const, title: "Assigned to me", icon: UserRound },
{ id: "mentions" as const, title: "Mentions", icon: AtSign },
{ id: "snoozed" as const, title: "Snoozed", icon: AlarmClock },
{ id: "done" as const, title: "Done", icon: CheckCheck },
]
const ignore = () => {}
const isOpen = (c: Conversation) => c.status !== "Closed" && !c.snoozed
function inFilter(c: Conversation, f: Filter) {
if (f.kind === "label") return c.labels.includes(f.id) && c.status !== "Closed"
if (f.id === "inbox") return isOpen(c)
if (f.id === "mine") return isOpen(c) && c.assignee === ME
if (f.id === "mentions") return !!c.mentioned && c.status !== "Closed"
if (f.id === "snoozed") return !!c.snoozed && c.status !== "Closed"
return c.status === "Closed"
}
const filterTitle = (f: Filter) => (f.kind === "folder" ? FOLDERS.find((x) => x.id === f.id)!.title : LABELS.find((x) => x.id === f.id)!.title)
const initials = (name: string) =>
name
.split(" ")
.map((w) => w[0])
.join("")
.slice(0, 2)
export default function SidebarRightPanel() {
const [items, setItems] = React.useState(INITIAL)
const [filter, setFilter] = React.useState<Filter>({ kind: "folder", id: "inbox" })
const [selectedId, setSelectedId] = React.useState<string | null>("c1")
const [detailsOpen, setDetailsOpen] = React.useState(true)
const visible = items.filter((c) => inFilter(c, filter))
// The open conversation stays in the panel even if a change moves it out of the list.
const selected = items.find((c) => c.id === selectedId) ?? null
const update = (id: string, patch: Partial<Conversation>) => setItems((all) => all.map((c) => (c.id === id ? { ...c, ...patch } : c)))
const select = (id: string) => {
setSelectedId(id)
update(id, { unread: false })
}
const pickFilter = (f: Filter) => {
setFilter(f)
setSelectedId(items.find((c) => inFilter(c, f))?.id ?? null)
}
const markDone = (id: string) => {
const i = visible.findIndex((c) => c.id === id)
const next = visible[i + 1] ?? visible[i - 1]
update(id, { status: "Closed", snoozed: undefined })
setSelectedId(next && next.id !== id ? next.id : null)
}
return (
<SidebarProvider className="relative h-[640px] min-h-0 overflow-hidden rounded-xl border bg-background">
<NavSidebar items={items} filter={filter} onFilter={pickFilter} />
<SidebarInset className="min-w-0 overflow-hidden">
<header className="flex h-14 shrink-0 items-center gap-2 border-b px-3 sm:px-4">
<SidebarTrigger className="-ml-1" />
<Separator orientation="vertical" className="mr-1 h-4 data-vertical:self-center" />
<Breadcrumb className="min-w-0">
<BreadcrumbList className="flex-nowrap">
<BreadcrumbItem className="hidden sm:inline-flex">
<BreadcrumbLink href="#">Support</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbSeparator className="hidden sm:list-item" />
<BreadcrumbItem className="min-w-0">
<BreadcrumbPage className="truncate">{filterTitle(filter)}</BreadcrumbPage>
</BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<Tooltip>
<TooltipTrigger
render={
<Button
variant="ghost"
size="icon-sm"
className="-mr-1 ml-auto hidden md:inline-flex"
aria-pressed={detailsOpen}
aria-label={detailsOpen ? "Hide details" : "Show details"}
onClick={() => setDetailsOpen((o) => !o)}
/>
}
>
<PanelRight />
</TooltipTrigger>
<TooltipContent side="bottom">{detailsOpen ? "Hide details" : "Show details"}</TooltipContent>
</Tooltip>
</header>
{/* The details panel's own provider: open follows the header button only. */}
<SidebarProvider open={detailsOpen} onOpenChange={ignore} className="relative min-h-0 flex-1" style={{ "--sidebar-width": "18rem" } as React.CSSProperties}>
<ConversationList title={filterTitle(filter)} items={visible} selectedId={selected?.id ?? null} onSelect={select} />
<DetailsSidebar conversation={selected} onChange={update} onDone={markDone} onClose={() => setDetailsOpen(false)} />
</SidebarProvider>
</SidebarInset>
</SidebarProvider>
)
}
function NavSidebar({ items, filter, onFilter }: { items: Conversation[]; filter: Filter; onFilter: (f: Filter) => void }) {
const { isMobile, setOpenMobile } = useSidebar()
const [away, setAway] = React.useState(false)
const go = (f: Filter) => {
onFilter(f)
if (isMobile) setOpenMobile(false)
}
const count = (f: Filter) => {
const list = items.filter((c) => inFilter(c, f))
return f.kind === "folder" && f.id === "inbox" ? list.filter((c) => c.unread).length : list.length
}
return (
<Sidebar collapsible="icon" className="absolute h-full">
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" tooltip="Orbit support" render={<a href="#" />}>
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary text-primary-foreground">
<LifeBuoy />
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-semibold">Orbit support</span>
<span className="truncate text-xs text-muted-foreground">4 teammates online</span>
</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupContent>
<SidebarMenu>
{FOLDERS.map((f) => {
const target: Filter = { kind: "folder", id: f.id }
const active = filter.kind === "folder" && filter.id === f.id
const n = count(target)
return (
<SidebarMenuItem key={f.id}>
<SidebarMenuButton isActive={active} aria-current={active ? "page" : undefined} tooltip={f.title} onClick={() => go(target)}>
<f.icon />
<span>{f.title}</span>
</SidebarMenuButton>
{n && f.id !== "done" ? <SidebarMenuBadge>{n}</SidebarMenuBadge> : null}
</SidebarMenuItem>
)
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup>
<SidebarGroupLabel>Labels</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{LABELS.map((l) => {
const target: Filter = { kind: "label", id: l.id }
const active = filter.kind === "label" && filter.id === l.id
return (
<SidebarMenuItem key={l.id}>
<SidebarMenuButton isActive={active} aria-current={active ? "page" : undefined} tooltip={l.title} onClick={() => go(target)}>
<span className="flex size-4 shrink-0 items-center justify-center" aria-hidden="true">
<span className={cn("size-2.5 rounded-full ring-1 ring-foreground/15 ring-inset", l.dot)} />
</span>
<span>{l.title}</span>
</SidebarMenuButton>
{count(target) ? <SidebarMenuBadge>{count(target)}</SidebarMenuBadge> : null}
</SidebarMenuItem>
)
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarGroup className="mt-auto">
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton tooltip="Settings" render={<a href="#" />}>
<Settings />
<span>Settings</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<SidebarMenu>
<SidebarMenuItem>
{/* Availability: new conversations are only assigned to people who are available. */}
<SidebarMenuButton
size="lg"
tooltip={away ? "Ada Lin, away" : "Ada Lin, available"}
aria-pressed={away}
aria-label={`Ada Lin, ${away ? "away" : "available"}. Set yourself ${away ? "available" : "away"}`}
onClick={() => setAway((a) => !a)}
>
<span className="relative shrink-0">
<Avatar className="rounded-lg">
<AvatarFallback className="rounded-lg text-xs">AL</AvatarFallback>
</Avatar>
<span
className={cn("absolute -right-0.5 -bottom-0.5 size-2.5 rounded-full ring-2 ring-sidebar", away ? "bg-muted-foreground" : "bg-primary")}
aria-hidden="true"
/>
</span>
<span className="grid min-w-0 flex-1 text-left leading-tight">
<span className="truncate font-medium">Ada Lin</span>
<span className="truncate text-xs text-muted-foreground">{away ? "Away" : "Available"}</span>
</span>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarFooter>
<SidebarRail />
</Sidebar>
)
}
function ConversationList({
title,
items,
selectedId,
onSelect,
}: {
title: string
items: Conversation[]
selectedId: string | null
onSelect: (id: string) => void
}) {
const { isMobile, setOpenMobile } = useSidebar() // the details panel's
const refs = React.useRef(new Map<string, HTMLButtonElement>())
const onKeyDown = (e: React.KeyboardEvent) => {
if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return
e.preventDefault()
const i = items.findIndex((c) => c.id === selectedId)
const next = items[Math.min(items.length - 1, Math.max(0, i + (e.key === "ArrowDown" ? 1 : -1)))]
if (!next) return
onSelect(next.id)
refs.current.get(next.id)?.focus()
}
return (
<div className="flex min-w-0 flex-1 flex-col">
<div className="flex h-11 shrink-0 items-center justify-between border-b px-4 text-sm">
<h2 className="font-medium">{title}</h2>
<span className="text-muted-foreground tabular-nums">
{items.length} {items.length === 1 ? "conversation" : "conversations"}
</span>
</div>
{items.length ? (
<ul aria-label={title} onKeyDown={onKeyDown} className="flex-1 divide-y overflow-y-auto">
{items.map((c) => {
const selected = c.id === selectedId
return (
<li key={c.id}>
<button
type="button"
ref={(el) => {
if (el) refs.current.set(c.id, el)
else refs.current.delete(c.id)
}}
aria-current={selected ? "true" : undefined}
onClick={() => {
onSelect(c.id)
if (isMobile) setOpenMobile(true)
}}
className={cn(
"flex w-full gap-3 px-4 py-3 text-left outline-none transition-colors hover:bg-muted/60 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset",
selected && "bg-muted hover:bg-muted",
)}
>
<Avatar className="mt-0.5">
<AvatarFallback className="text-xs">{initials(c.name)}</AvatarFallback>
</Avatar>
<span className="grid min-w-0 flex-1 gap-0.5">
<span className="flex items-center gap-2">
<span className={cn("truncate text-sm", c.unread ? "font-semibold" : "font-medium")}>{c.name}</span>
{c.unread ? (
<span className="size-2 shrink-0 rounded-full bg-primary">
<span className="sr-only">Unread</span>
</span>
) : null}
<span className="ml-auto shrink-0 text-xs text-muted-foreground">{c.snoozed ? `Until ${c.snoozed}` : c.time}</span>
</span>
<span className={cn("truncate text-sm", c.unread ? "text-foreground" : "text-muted-foreground")}>{c.subject}</span>
<span className="truncate text-xs text-muted-foreground">{c.body[0]}</span>
{c.labels.length ? (
<span className="mt-1 flex gap-1">
{c.labels.map((id) => {
const l = LABELS.find((x) => x.id === id)!
return (
<Badge key={id} variant="outline" className="gap-1.5">
<span className={cn("size-1.5 rounded-full ring-1 ring-foreground/15 ring-inset", l.dot)} aria-hidden="true" />
{l.title}
</Badge>
)
})}
</span>
) : null}
</span>
</button>
</li>
)
})}
</ul>
) : (
<div className="flex flex-1 flex-col items-center justify-center px-6 text-center">
<span className="flex size-10 items-center justify-center rounded-full border text-muted-foreground">
<CheckCheck className="size-5" />
</span>
<p className="mt-3 font-medium">Nothing in {title}</p>
<p className="mt-1 max-w-xs text-sm text-muted-foreground">New conversations land here as customers write in.</p>
</div>
)}
</div>
)
}
function DetailsSidebar({
conversation: c,
onChange,
onDone,
onClose,
}: {
conversation: Conversation | null
onChange: (id: string, patch: Partial<Conversation>) => void
onDone: (id: string) => void
onClose: () => void
}) {
const { isMobile, setOpenMobile } = useSidebar() // the details panel's
const close = () => (isMobile ? setOpenMobile(false) : onClose())
return (
<Sidebar side="right" className="absolute h-full">
<SidebarHeader className="flex-row items-start gap-2 border-b p-3">
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground">Details</p>
<h2 className="line-clamp-2 text-sm font-semibold">{c ? c.subject : "No conversation selected"}</h2>
</div>
<Button variant="ghost" size="icon-sm" onClick={close} aria-label="Close details" className="-mt-0.5 -mr-1 shrink-0">
<X />
</Button>
</SidebarHeader>
{c ? (
<>
<SidebarContent>
<SidebarGroup>
<div className="flex items-center gap-3 px-2 pt-1">
<Avatar size="lg">
<AvatarFallback>{initials(c.name)}</AvatarFallback>
</Avatar>
<div className="min-w-0">
<p className="truncate text-sm font-medium">{c.name}</p>
<p className="truncate text-xs text-muted-foreground">{c.email}</p>
</div>
</div>
<dl className="mt-3 grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 px-2 text-xs">
<dt className="text-muted-foreground">Company</dt>
<dd className="truncate text-right">{c.company}</dd>
<dt className="text-muted-foreground">Plan</dt>
<dd className="truncate text-right">{c.plan}</dd>
<dt className="text-muted-foreground">Customer since</dt>
<dd className="truncate text-right">{c.since}</dd>
<dt className="text-muted-foreground">Invoices sent</dt>
<dd className="text-right tabular-nums">{c.invoices}</dd>
</dl>
</SidebarGroup>
<SidebarSeparator className="mx-0" />
<SidebarGroup>
<SidebarGroupLabel>Properties</SidebarGroupLabel>
<div className="grid gap-2 px-2">
<Field label="Status" value={c.status} options={["Open", "Pending", "Closed"]} onChange={(v) => onChange(c.id, { status: v as Status })} />
<Field label="Priority" value={c.priority} options={["Low", "Normal", "High"]} onChange={(v) => onChange(c.id, { priority: v as Priority })} />
<Field label="Owner" value={c.assignee} options={TEAM} onChange={(v) => onChange(c.id, { assignee: v })} />
</div>
</SidebarGroup>
<SidebarSeparator className="mx-0" />
<SidebarGroup>
<SidebarGroupLabel>Latest message</SidebarGroupLabel>
<div className="space-y-2 px-2 text-sm leading-relaxed">
{c.body.map((p) => (
<p key={p}>{p}</p>
))}
<p className="text-xs text-muted-foreground">
{c.name.split(" ")[0]}, {c.time}
</p>
</div>
</SidebarGroup>
</SidebarContent>
<SidebarFooter className="flex-row border-t p-3">
<Button size="sm" className="flex-1">
<Reply /> Reply
</Button>
<Button size="sm" variant="outline" className="flex-1" disabled={c.status === "Closed"} onClick={() => onDone(c.id)}>
<CheckCheck /> Mark done
</Button>
</SidebarFooter>
</>
) : (
<SidebarContent className="items-center justify-center p-6 text-center">
<p className="text-sm font-medium">Pick a conversation</p>
<p className="mt-1 text-sm text-muted-foreground">Its customer, status and latest message show up here.</p>
</SidebarContent>
)}
</Sidebar>
)
}
function Field({ label, value, options, onChange }: { label: string; value: string; options: string[]; onChange: (v: string) => void }) {
const id = React.useId()
const items = options.map((o) => ({ value: o, label: o }))
return (
<div className="grid grid-cols-[5rem_1fr] items-center gap-2">
<label htmlFor={id} className="text-xs text-muted-foreground">
{label}
</label>
<Select items={items} value={value} onValueChange={(v) => v != null && onChange(String(v))}>
<SelectTrigger id={id} size="sm" className="w-full bg-background">
<SelectValue />
</SelectTrigger>
<SelectContent>
{items.map((o) => (
<SelectItem key={o.value} value={o.value}>
{o.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)
}