For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to documentation URLs. Homepage markdown is available at /llms.md/content.md. An agent skill is available at /.well-known/agent-skills/site-skill.md.

Sheet

The Sheet component from this design system, built on Base UI.

Installation

$ pnpm dlx shadcn@latest add @cobalt/sheet

Options

  • overlayClassName on SheetContent styles the backdrop, for example bg-transparent or bg-background/60 backdrop-blur-xs for a panel that keeps the page visible.

  • size="flush" on SheetContent removes the margin and the rounded corners, so the panel fills its edge and nothing of the page shows around it. Use it for a navigation panel on a phone.

  • variant="ghost" on SheetContent draws no border, fill or shadow, for a Card placed inside. It keeps its size.

Source

"use client";

import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";
import { RiCloseLine } from "@remixicon/react";
import { cn } from "cn";
import * as React from "react";

import { Button } from "@/components/ui/button";

function Sheet({ ...props }: SheetPrimitive.Root.Props) {
  return <SheetPrimitive.Root data-slot="sheet" {...props} />;
}

function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) {
  return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
}

function SheetClose({ ...props }: SheetPrimitive.Close.Props) {
  return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
}

function SheetPortal({ ...props }: SheetPrimitive.Portal.Props) {
  return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;
}

function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) {
  return (
    <SheetPrimitive.Backdrop
      data-slot="sheet-overlay"
      className={cn(
        "fixed inset-0 z-50 bg-[var(--drawer-backdrop,rgb(0_0_0/0.4))] transition-opacity duration-300 ease-out motion-reduce:transition-none data-ending-style:opacity-0 data-starting-style:opacity-0",
        className
      )}
      {...props}
    />
  );
}

function SheetContent({
  className,
  children,
  side = "right",
  showCloseButton = true,
  size = "default",
  overlayClassName,
  variant = "default",
  ...props
}: SheetPrimitive.Popup.Props & {
  /** `ghost` has no border, fill or shadow, for a Card placed inside. It keeps its `size`. */
  variant?: "default" | "ghost";
  side?: "top" | "right" | "bottom" | "left";
  showCloseButton?: boolean;
  /** `flush` fills the edge: no margin and no rounded corners, so nothing shows around the panel. */
  size?: "default" | "flush";
  /** Classes for the backdrop, e.g. `bg-transparent` for a panel that keeps the page visible. */
  overlayClassName?: string;
}) {
  return (
    <SheetPortal>
      <SheetOverlay className={overlayClassName} />
      <SheetPrimitive.Popup
        data-slot="sheet-content"
        data-side={side}
        data-size={size}
        className={cn(
          "fixed z-50 m-2 flex max-h-[calc(100dvh-16px)] flex-col gap-4 overflow-clip rounded-[24px] border border-[var(--surface-strong,var(--border))] bg-[var(--surface-overlay,var(--popover))] py-6 text-sm text-popover-foreground shadow-[shadow:var(--shadow-control,0_1px_2px_0_rgb(0_0_0/0.05))] outline-none transition-[translate,filter,opacity] duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] motion-safe:data-ending-style:blur-[4px] motion-safe:data-starting-style:blur-[4px] motion-reduce:transition-none motion-reduce:data-ending-style:opacity-0 motion-reduce:data-starting-style:opacity-0 sm:m-3 sm:max-h-[calc(100dvh-24px)]",
          "data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:max-h-[85%] motion-safe:data-[side=bottom]:data-ending-style:translate-y-[calc(100%+24px)] motion-safe:data-[side=bottom]:data-starting-style:translate-y-[calc(100%+24px)]",
          "data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:max-h-[85%] motion-safe:data-[side=top]:data-ending-style:-translate-y-[calc(100%+24px)] motion-safe:data-[side=top]:data-starting-style:-translate-y-[calc(100%+24px)]",
          "data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:w-[calc(100%-16px)] data-[side=left]:max-w-[400px] motion-safe:data-[side=left]:data-ending-style:-translate-x-[calc(100%+24px)] motion-safe:data-[side=left]:data-starting-style:-translate-x-[calc(100%+24px)]",
          "data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:w-[calc(100%-16px)] data-[side=right]:max-w-[400px] motion-safe:data-[side=right]:data-ending-style:translate-x-[calc(100%+24px)] motion-safe:data-[side=right]:data-starting-style:translate-x-[calc(100%+24px)]",
          size === "flush" &&
            "m-0 max-h-dvh rounded-none border-0 sm:m-0 sm:max-h-dvh data-[side=left]:max-w-[320px] data-[side=left]:border-r data-[side=right]:max-w-[320px] data-[side=right]:border-l",
          variant === "ghost" &&
            "border-0 bg-transparent shadow-none data-[side=left]:border-r-0 data-[side=right]:border-l-0",
          className
        )}
        {...props}
      >
        {children}
        {showCloseButton && (
          <SheetPrimitive.Close
            data-slot="sheet-close"
            render={
              <Button
                variant="close"
                className="absolute top-6 right-5"
                size="icon-xs"
              />
            }
          >
            <RiCloseLine className="size-6" />
            <span className="sr-only">Close</span>
          </SheetPrimitive.Close>
        )}
      </SheetPrimitive.Popup>
    </SheetPortal>
  );
}

function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="sheet-header"
      className={cn("flex flex-col gap-1 px-6 pr-14", className)}
      {...props}
    />
  );
}

function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
  return (
    <div
      data-slot="sheet-footer"
      className={cn(
        "mt-auto flex flex-col-reverse gap-2 px-6 sm:flex-row sm:items-center sm:justify-end",
        className
      )}
      {...props}
    />
  );
}

function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) {
  return (
    <SheetPrimitive.Title
      data-slot="sheet-title"
      className={cn(
        "text-[18px] leading-[26px] font-medium text-foreground",
        className
      )}
      {...props}
    />
  );
}

function SheetDescription({
  className,
  ...props
}: SheetPrimitive.Description.Props) {
  return (
    <SheetPrimitive.Description
      data-slot="sheet-description"
      className={cn(
        "text-[14px] leading-[20px] text-balance text-muted-foreground",
        className
      )}
      {...props}
    />
  );
}

export {
  Sheet,
  SheetTrigger,
  SheetClose,
  SheetContent,
  SheetHeader,
  SheetFooter,
  SheetTitle,
  SheetDescription,
};