Workspace

An application shell with a rail, side panels, a header, a toolbar and a status bar.

The rail switches sections; each button’s name shows in a tooltip. The left panel runs the full height, and beside it the header spans the main column and the right panel. Each panel is always open from its breakpoint up (md by default; give a second panel xl, so the canvas keeps room). Below it, the panel lies over the page: the toggle at its end of the header opens it, and a tap outside or Escape closes it. The canvas scrolls, and the status bar holds counts and state. Give the workspace a height: the full page, or a box.

Preview
app.tsx
import {
  BookOpen,
  CircleX,
  Columns3,
  FileText,
  LayoutGrid,
  LayoutPanelTop,
  Megaphone,
  RectangleVertical,
  SlidersHorizontal,
  TriangleAlert,
  User,
} from "lucide-react"

import { Conversation, Message, MessageStep } from "~/components/conversation"
import { PanelNav, PanelNavItem, PanelNavSection } from "~/components/panel-nav"
import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
  BreadcrumbSeparator,
} from "~/components/ui/breadcrumb"
import { Sidebar, SidebarTrigger } from "~/components/ui/sidebar"
import { Toggle, ToggleGroup } from "~/components/ui/toggle"
import {
  Workspace,
  WorkspaceBody,
  WorkspaceCanvas,
  WorkspaceColumns,
  WorkspaceHeader,
  WorkspaceMain,
  WorkspaceRail,
  WorkspaceRailButton,
  WorkspaceRailFooter,
  WorkspaceStatusBar,
  WorkspaceStatusItem,
  WorkspaceToolbar,
} from "~/components/workspace"

export default function Example() {
  return (
    <Workspace className="h-160">
      <WorkspaceRail aria-label="Sections">
        <WorkspaceRailButton label="Publications">
          <LayoutGrid />
        </WorkspaceRailButton>
        <WorkspaceRailButton label="Stories">
          <FileText />
        </WorkspaceRailButton>
        <WorkspaceRailButton label="Print" active>
          <LayoutPanelTop />
        </WorkspaceRailButton>
        <WorkspaceRailFooter>
          <WorkspaceRailButton label="Account">
            <User />
          </WorkspaceRailButton>
        </WorkspaceRailFooter>
      </WorkspaceRail>
      <WorkspaceColumns>
        <Sidebar side="left" title="Print" size="sm">
          <PanelNav aria-label="Print">
            <PanelNavSection title="Edition · Weekend">
              <PanelNavItem href="#pages" icon=<LayoutPanelTop /> active>
                Pages
              </PanelNavItem>
              <PanelNavItem href="#setup" icon=<SlidersHorizontal />>
                Setup
              </PanelNavItem>
              <PanelNavItem href="#ads" icon=<Megaphone />>
                Ads
              </PanelNavItem>
            </PanelNavSection>
          </PanelNav>
        </Sidebar>
        <WorkspaceBody>
          <WorkspaceHeader>
            <SidebarTrigger side="left" />
            <Breadcrumb className="min-w-0 flex-1">
              <BreadcrumbList overflow="scroll">
                <BreadcrumbItem>
                  <BreadcrumbLink href="#publications">Publications</BreadcrumbLink>
                </BreadcrumbItem>
                <BreadcrumbSeparator />
                <BreadcrumbItem>
                  <BreadcrumbLink href="#daily-brew">The Daily Brew</BreadcrumbLink>
                </BreadcrumbItem>
                <BreadcrumbSeparator />
                <BreadcrumbItem>
                  <BreadcrumbPage>Weekend Edition</BreadcrumbPage>
                </BreadcrumbItem>
              </BreadcrumbList>
            </Breadcrumb>
            <SidebarTrigger side="right" />
          </WorkspaceHeader>
          <WorkspaceColumns>
            <WorkspaceMain>
              <WorkspaceToolbar aria-label="Page view">
                <ToggleGroup aria-label="Pages shown" defaultValue={["spread"]}>
                  <Toggle value="single" aria-label="Single page">
                    <RectangleVertical />
                  </Toggle>
                  <Toggle value="spread" aria-label="Spread">
                    <BookOpen />
                  </Toggle>
                </ToggleGroup>
                <Toggle aria-label="Show guides" defaultPressed>
                  <Columns3 />
                </Toggle>
              </WorkspaceToolbar>
              <WorkspaceCanvas>
                <div className="aspect-3/4 h-80 bg-background shadow-lg ring-1 ring-foreground/5" />
              </WorkspaceCanvas>
              <WorkspaceStatusBar>
                <WorkspaceStatusItem tone="destructive">
                  <CircleX />2 errors
                </WorkspaceStatusItem>
                <WorkspaceStatusItem tone="warning">
                  <TriangleAlert />0 warnings
                </WorkspaceStatusItem>
              </WorkspaceStatusBar>
            </WorkspaceMain>
            <Sidebar side="right" breakpoint="xl" title="Pagination agent" size="md">
              <Conversation aria-label="Pagination agent" className="h-full">
                <Message from="user">Fit the council story on A1.</Message>
                <MessageStep>read_page_layout · complete</MessageStep>
                <MessageStep>apply_layout_operation · complete</MessageStep>
                <Message from="assistant" name="Agent">
                  The story fits in two columns. No overflow remains.
                </Message>
              </Conversation>
            </Sidebar>
          </WorkspaceColumns>
        </WorkspaceBody>
      </WorkspaceColumns>
    </Workspace>
  )
}

Dependencies

What it's built from and what's built from it in Base, read from the imports in its source.

Installation

Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.

With the CLI

terminal
npx shadcn@latest add https://design.zepez.dev/r/base/workspace.json

Manually

Add the components it uses first, listed under Dependencies.

Then copy the source:

components/workspace.tsx
import * as React from "react"

import { Button } from "~/components/ui/button"
import { ScrollArea } from "~/components/ui/scroll-area"
import { SidebarProvider } from "~/components/ui/sidebar"
import { textVariants } from "~/components/ui/text"
import { Tooltip, TooltipContent, TooltipTrigger } from "~/components/ui/tooltip"
import { cn } from "~/lib/utils"

/*
 * An application workspace: an icon rail, a left `Sidebar` the full height,
 * and beside it a header over the main column and a right `Sidebar`. Each
 * sidebar's `SidebarTrigger` sits at its end of the header, and shows only
 * where the sidebar is a drawer. The main column holds an optional toolbar,
 * the canvas and a status bar.
 *
 * <Workspace>
 *   <WorkspaceRail>…</WorkspaceRail>
 *   <WorkspaceColumns>
 *     <Sidebar side="left" title="…">…</Sidebar>
 *     <WorkspaceBody>
 *       <WorkspaceHeader>
 *         <SidebarTrigger side="left" />…<SidebarTrigger side="right" />
 *       </WorkspaceHeader>
 *       <WorkspaceColumns>
 *         <WorkspaceMain>
 *           <WorkspaceToolbar>…</WorkspaceToolbar>
 *           <WorkspaceCanvas>…</WorkspaceCanvas>
 *           <WorkspaceStatusBar>…</WorkspaceStatusBar>
 *         </WorkspaceMain>
 *         <Sidebar side="right" breakpoint="xl" title="…">…</Sidebar>
 *       </WorkspaceColumns>
 *     </WorkspaceBody>
 *   </WorkspaceColumns>
 * </Workspace>
 */

/**
 * The whole workspace. Give it a height: the full page, or a fixed box. It connects the
 * `Sidebar`s inside it to their `SidebarTrigger`s.
 */
function Workspace({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <SidebarProvider>
      <div
        data-slot="workspace"
        className={cn(
          textVariants({ size: "sm" }),
          "flex h-full min-h-0 w-full overflow-hidden bg-background text-foreground",
          className,
        )}
        {...props}
      />
    </SidebarProvider>
  )
}

/** The column of section icons down the left edge, with an optional footer. */
function WorkspaceRail({ className, ...props }: React.ComponentProps<"nav">) {
  return (
    <nav
      data-slot="workspace-rail"
      className={cn(
        "flex w-13 shrink-0 flex-col items-center gap-2xs border-r border-border bg-surface py-sm",
        className,
      )}
      {...props}
    />
  )
}

/** Pushes what follows it to the bottom of the rail, like account and theme buttons. */
function WorkspaceRailFooter({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-rail-footer"
      className={cn("mt-auto flex flex-col items-center gap-2xs", className)}
      {...props}
    />
  )
}

type WorkspaceRailButtonProps = Omit<React.ComponentProps<typeof Button>, "children"> & {
  /** The section's icon. */
  children?: React.ReactNode
  /** The section's name: the tooltip, and the button's accessible name. */
  label: string
  /** Whether this is the section you're in. */
  active?: boolean
}

/** A section in the rail: an icon with its name in a tooltip. The active one is filled. */
function WorkspaceRailButton({
  label,
  active = false,
  className,
  children,
  ...props
}: WorkspaceRailButtonProps) {
  return (
    <Tooltip>
      <TooltipTrigger
        render={
          <Button
            variant="ghost"
            size="icon-lg"
            aria-label={label}
            aria-current={active ? "page" : undefined}
            className={cn(
              // The current section stays filled on hover: Button's ghost hover would grey it out under
              // its primary-foreground text.
              "text-muted-foreground hover:text-foreground aria-[current=page]:bg-primary aria-[current=page]:text-primary-foreground aria-[current=page]:hover:bg-primary/85 aria-[current=page]:hover:text-primary-foreground [&_svg:not([class*='size-'])]:size-5",
              className,
            )}
            {...props}
          />
        }
      >
        {children}
      </TooltipTrigger>
      <TooltipContent side="right">{label}</TooltipContent>
    </Tooltip>
  )
}

/** Everything right of the rail: the header above the columns. */
function WorkspaceBody({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-body"
      className={cn("flex min-w-0 flex-1 flex-col", className)}
      {...props}
    />
  )
}

/** The strip along the top of the body: the panel toggles at its ends, usually a breadcrumb between. */
function WorkspaceHeader({ className, ...props }: React.ComponentProps<"header">) {
  return (
    <header
      data-slot="workspace-header"
      className={cn(
        "flex h-11 shrink-0 items-center gap-sm border-b border-border px-lg md:px-xl",
        className,
      )}
      {...props}
    />
  )
}

/**
 * Sidebars beside what's between them: the left `Sidebar` beside the body, and in the body, the
 * main column beside the right one.
 */
function WorkspaceColumns({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-columns"
      className={cn("relative flex min-h-0 min-w-0 flex-1", className)}
      {...props}
    />
  )
}

type WorkspaceMainProps = React.ComponentProps<"main"> & {
  /** `plain` sits on the page's background instead of the tinted surface, for reading rather than working. */
  variant?: "surface" | "plain"
}

/** The middle column. */
function WorkspaceMain({ variant = "surface", className, ...props }: WorkspaceMainProps) {
  return (
    <main
      data-slot="workspace-main"
      data-variant={variant}
      className={cn(
        "relative flex min-w-0 flex-1 flex-col bg-surface data-[variant=plain]:bg-background",
        className,
      )}
      {...props}
    />
  )
}

/** A row of tools above the canvas, centered. */
function WorkspaceToolbar({ className, children, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="workspace-toolbar"
      role="toolbar"
      className={cn(
        "flex h-11 shrink-0 items-center justify-center gap-2xs border-b border-border bg-background px-md",
        className,
      )}
      {...props}
    >
      {children}
    </div>
  )
}

type WorkspaceCanvasProps = React.ComponentProps<"div"> & {
  /**
   * Which ways it scrolls. Both by default, for work wider than the column, like a page spread.
   * Use `vertical` for content that should wrap to the column's width, like a document.
   */
  orientation?: "vertical" | "both"
}

/** The scrolling work area. Its content is centered unless you say otherwise. */
function WorkspaceCanvas({ orientation = "both", className, ...props }: WorkspaceCanvasProps) {
  return (
    <ScrollArea orientation={orientation} className="min-h-0 flex-1">
      <div
        data-slot="workspace-canvas"
        className={cn("flex flex-1 items-center justify-center p-lg md:p-2xl", className)}
        {...props}
      />
    </ScrollArea>
  )
}

/** The strip along the bottom of the main column, for counts and state. */
function WorkspaceStatusBar({ className, ...props }: React.ComponentProps<"footer">) {
  return (
    <footer
      data-slot="workspace-status-bar"
      className={cn(
        textVariants({ size: "xs", tone: "muted" }),
        "flex h-8 shrink-0 items-center gap-lg border-t border-border bg-background px-md",
        className,
      )}
      {...props}
    />
  )
}

/** One count or state in the status bar. `destructive` and `warning` color its icon. */
function WorkspaceStatusItem({
  tone = "default",
  className,
  ...props
}: React.ComponentProps<"span"> & { tone?: "default" | "destructive" | "warning" }) {
  return (
    <span
      data-slot="workspace-status-item"
      data-tone={tone}
      className={cn(
        "inline-flex items-center gap-xs text-foreground [&_svg]:size-3.5 [&_svg]:shrink-0 data-[tone=destructive]:[&_svg]:text-destructive data-[tone=warning]:[&_svg]:text-warning",
        className,
      )}
      {...props}
    />
  )
}

export {
  Workspace,
  WorkspaceBody,
  WorkspaceCanvas,
  WorkspaceColumns,
  WorkspaceHeader,
  WorkspaceMain,
  WorkspaceRail,
  WorkspaceRailButton,
  WorkspaceRailFooter,
  WorkspaceStatusBar,
  WorkspaceStatusItem,
  WorkspaceToolbar,
}
export type { WorkspaceCanvasProps, WorkspaceRailButtonProps }

API reference

Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.

Workspace

The whole workspace. Give it a height: the full page, or a fixed box. It connects the Sidebars inside it to their SidebarTriggers.

Takes the props of a native div.

WorkspaceBody

Everything right of the rail: the header above the columns.

Takes the props of a native div.

WorkspaceCanvas

The scrolling work area. Its content is centered unless you say otherwise.

orientationours

Which ways it scrolls. Both by default, for work wider than the column, like a page spread. Use vertical for content that should wrap to the column's width, like a document.

Type "both" | "vertical" · Default both

WorkspaceColumns

Sidebars beside what's between them: the left Sidebar beside the body, and in the body, the main column beside the right one.

Takes the props of a native div.

WorkspaceHeader

The strip along the top of the body: the panel toggles at its ends, usually a breadcrumb between.

Takes the props of a native div.

WorkspaceMain

The middle column.

variantours

plain sits on the page's background instead of the tinted surface, for reading rather than working.

Type "surface" | "plain" · Default surface

WorkspaceRail

The column of section icons down the left edge, with an optional footer.

Takes the props of a native div.

WorkspaceRailButton

A section in the rail: an icon with its name in a tooltip. The active one is filled.

activeours

Whether this is the section you're in.

Type boolean · Default false

childrenours

The section's icon.

Type ReactNode

label*ours

The section's name: the tooltip, and the button's accessible name.

Type string

sizeours

Height and padding. The icon sizes are square, for a button holding only an icon.

Type NonNullable<"xs" | "sm" | "md" | "lg" | "icon-xs" | "icon-sm" | "icon" | "icon-lg">

variantours

How much the button stands out. destructive is a tint, for actions that can't be undone.

Type NonNullable<"primary" | "destructive" | "secondary" | "outline" | "ghost" | "link">

className

Class names, or a function of the part's state that returns them.

Type string | ((state: ButtonState) => string)

debug

Logs every state change with its reason to the console, in development builds.

Type boolean

disabled

Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.

Type boolean · Default false

focusableWhenDisabled

Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.

Type boolean · Default false

onClick

Runs when the button is pressed. Return a Promise to make the button pending until it settles: it gets aria-busy, aria-disabled and data-pending, keeps focus, ignores presses meanwhile, so a form can't submit twice, and says pendingAnnouncement after a second. The event's element is whatever render renders, like a link. details.source says how it was pressed, for changes made after an await.

Type (event: MouseEvent<HTMLElement, MouseEvent>, details: ActionDetails) => unknown

pendingAnnouncement

What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Type string · Default "Loading"

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<ButtonState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: ButtonState) => CSSProperties)

type

What a native button does in a form: "submit" submits it and "reset" resets it. Ignored when the button renders as something else.

Type "button" | "submit" | "reset" · Default "button"

WorkspaceRailFooter

Pushes what follows it to the bottom of the rail, like account and theme buttons.

Takes the props of a native div.

WorkspaceStatusBar

The strip along the bottom of the main column, for counts and state.

Takes the props of a native div.

WorkspaceStatusItem

One count or state in the status bar. destructive and warning color its icon.

toneours

Type "default" | "destructive" | "warning" · Default default

WorkspaceToolbar

A row of tools above the canvas, centered.

Takes the props of a native div.