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.
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
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Composition
Use the following composition to build a Panel:
Examples
By default
Set defaultOpen to start open. The panel closes from the close button.
Sides
Set side on PanelContent to open the desktop sheet from the top, right, bottom or left. It is ignored on mobile.
With close label
Set closeLabel to replace the close icon with a Done text button.
Without close button
Set showCloseButton to false to hide the built-in close button, and close from a Cancel button in PanelClose instead.
Floating
Set floating to inset the mobile drawer from the screen edges. It has no effect on desktop.
Accessibility
- The content is a
dialognamed byPanelTitleand described byPanelDescription. - Escape closes the panel and returns focus to the trigger.
- The built-in close button is named Close, or by
closeLabelwhen set.
API Reference
Panel
The root that chooses Sheet or Drawer and holds the open state.
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
defaultOpen | boolean | - |
onOpenChange | (open: boolean) => void | - |
floating | boolean | - |
children | React.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.
| Prop | Type | Default |
|---|---|---|
render | React.ReactElement | - |
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
Also accepts the props of SheetTrigger.
Also accepts className, children, id and aria-label.
PanelContent
The popup surface, with an optional close button.
| Prop | Type | Default |
|---|---|---|
side | "top" | "right" | "bottom" | "left" | "right" |
showCloseButton | boolean | true |
closeLabel | string | - |
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.
| Prop | Type | Default |
|---|---|---|
render | React.ReactElement | - |
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
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.