suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Patterns19
  • Overview
  • Action Bar
  • Action Menu
  • App Shell
  • Command Palette
  • Confirm
  • Context Actions
  • Date Picker
  • Flyout
  • Modal
  • Navbar
  • Paged List
  • Panel
  • Picker
  • Preview
  • Search Picker
  • Segment Picker
  • Split View
  • Table List
  • Trail

suiss/ui ยท Pattern

Panel

A side panel that renders as a Sheet on desktop and a swipeable Drawer on mobile.

Panel is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelDemo() {

Panel presents secondary content such as forms, filters or details without leaving the page. On desktop it renders a suiss/ui Sheet that slides in from the chosen side. On mobile (below 48rem, via useIsMobile) it switches to a Drawer with a swipe handle, and every subcomponent swaps to its Drawer counterpart.

Use it where a desktop layout calls for a side sheet and a phone calls for a bottom sheet.

Installation

$ pnpm dlx shadcn@latest add @esuiss/panel

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add patterns panel
  1. Add the cn helper.

  2. Add the pieces it builds on: Drawer, Sheet, use-mobile.

  3. Copy and paste the following code into your project.

components/patterns/panel.tsx
"use client"

import * as React from "react"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import {
  Sheet,
  SheetClose,
  1. Update the import paths to match your project setup.

Usage

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
<div className="flex min-h-svh items-center justify-center">
  <Panel>
    <PanelTrigger render={<Button variant="outline" />}>
      Edit profile
    </PanelTrigger>
    <PanelContent>
      <PanelHeader>
        <PanelTitle>Edit profile</PanelTitle>
        <PanelDescription>
          Update your details and save when you are done.
        </PanelDescription>
      </PanelHeader>
      <PanelBody className="grid gap-2">
        <Label htmlFor="panel-name">Name</Label>
        <Input id="panel-name" defaultValue="Jordan Lee" />
      </PanelBody>
      <PanelFooter>
        <Button>Save changes</Button>
        <PanelClose render={<Button variant="secondary" />}>Cancel</PanelClose>
      </PanelFooter>
    </PanelContent>
  </Panel>
</div>
<div className="flex min-h-svh items-center justify-center">
  <Panel>
    <PanelTrigger asChild>
      <Button variant="outline">Edit profile</Button>
    </PanelTrigger>
    <PanelContent>
      <PanelHeader>
        <PanelTitle>Edit profile</PanelTitle>
        <PanelDescription>
          Update your details and save when you are done.
        </PanelDescription>
      </PanelHeader>
      <PanelBody className="grid gap-2">
        <Label htmlFor="panel-name">Name</Label>
        <Input id="panel-name" defaultValue="Jordan Lee" />
      </PanelBody>
      <PanelFooter>
        <Button>Save changes</Button>
        <PanelClose asChild>
          <Button variant="secondary">Cancel</Button>
        </PanelClose>
      </PanelFooter>
    </PanelContent>
  </Panel>
</div>

Composition

Use the following composition to build a Panel:

Panel
โ”œโ”€โ”€ PanelTrigger
โ””โ”€โ”€ PanelContent
    โ”œโ”€โ”€ PanelHeader
    โ”‚   โ”œโ”€โ”€ PanelTitle
    โ”‚   โ””โ”€โ”€ PanelDescription
    โ”œโ”€โ”€ PanelBody
    โ””โ”€โ”€ PanelFooter
        โ””โ”€โ”€ PanelClose

Examples

By default

Set defaultOpen to start open. The panel closes from the close button.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelOpenByDefault() {

Sides

Set side on PanelContent to open the desktop sheet from the top, right, bottom or left. It is ignored on mobile.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelSides() {

With close label

Set closeLabel to replace the close icon with a Done text button.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelWithCloseLabel() {

Without close button

Set showCloseButton to false to hide the built-in close button, and close from a Cancel button in PanelClose instead.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelWithoutCloseButton() {

Floating

Set floating to inset the mobile drawer from the screen edges. It has no effect on desktop.

import {
  Panel,
  PanelBody,
  PanelClose,
  PanelContent,
  PanelDescription,
  PanelFooter,
  PanelHeader,
  PanelTitle,
  PanelTrigger,
} from "@/components/patterns/panel"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function PanelFloating() {

Accessibility

  • The content is a dialog named by PanelTitle and described by PanelDescription.
  • Escape closes the panel and returns focus to the trigger.
  • The built-in close button is named Close, or by closeLabel when set.

API Reference

Panel

The root that chooses Sheet or Drawer and holds the open state.

PropTypeDefault
openboolean-
defaultOpenboolean-
onOpenChange(open: boolean) => void-
floatingboolean-
childrenReact.ReactNode-

Open state is uncontrolled by default; use defaultOpen for an initial state, or open with onOpenChange to control it. Compose PanelTrigger and PanelContent inside Panel; all parts must be used inside it, or they throw. The presentation follows the viewport at render time, so a panel open while the viewport crosses 48rem re-renders in the other presentation.

PanelTrigger

The button that opens the panel.

PropTypeDefault
renderReact.ReactElement-
PropTypeDefault
asChildbooleanfalse

Also accepts the props of SheetTrigger.

Also accepts className, children, id and aria-label.

PanelContent

The popup surface, with an optional close button.

PropTypeDefault
side"top" | "right" | "bottom" | "left""right"
showCloseButtonbooleantrue
closeLabelstring-

Also accepts the props of React.HTMLAttributes<HTMLElement>.

Also accepts className, style, children, id and aria-label.

PanelHeader

Groups the title and description.

Also accepts the props of React.ComponentProps<"div">.

PanelTitle

The panel's heading, which names the dialog.

Also accepts the props of React.HTMLAttributes<HTMLHeadingElement>.

Also accepts className, children and id.

PanelDescription

Supporting text that describes the dialog.

Also accepts the props of React.HTMLAttributes<HTMLParagraphElement>.

Also accepts className, children and id.

PanelBody

The padded main content area.

Also accepts the props of React.ComponentProps<"div">.

Put scrollable or form content here. Its padding matches each presentation.

PanelFooter

Holds the panel's actions.

Also accepts the props of React.ComponentProps<"div">.

PanelClose

A button that closes the panel.

PropTypeDefault
renderReact.ReactElement-
PropTypeDefault
asChildbooleanfalse

Also accepts the props of SheetClose.

Also accepts className, children, id and aria-label.

Use the render prop on PanelTrigger and PanelClose to render them as a suiss/ui Button.

Set asChild on PanelTrigger and PanelClose to render a suiss/ui Button in their place.

Each part sets a data-slot, such as panel-content or panel-close, for styling.

NextPickerPreviousPaged List

On this page

  1. 01Installation
  2. 02Usage
  3. 03Composition
  4. 04Examples
    • By default
    • Sides
    • With close label
    • Without close button
    • Floating
  5. 05Accessibility
  6. 06API Reference
    • Panel
    • PanelTrigger
    • PanelContent
    • PanelHeader
    • PanelTitle
    • PanelDescription
    • PanelBody
    • PanelFooter
    • PanelClose