Sheet
A modal panel that slides in from an edge of the screen. Use it for details, filters, and editors that need more room than a dialog but should keep the page behind in view. Focus stays inside until it closes. On a touch screen, swipe it back toward its edge to close it.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/sheet.jsonCopies Sheet and the components it uses (Button) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/sheet. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/react @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Button.
Copy and paste the following code into your project.
'use client'; import { createContext, useContext, useLayoutEffect, useState, type Dispatch, type SetStateAction } from 'react'; import { Drawer as SheetPrimitive } from '@base-ui/react/drawer'; import { mergeProps } from '@base-ui/react/merge-props'; import { useRender } from '@base-ui/react/use-render'; import { CloseIcon } from '@/lib/sprout/icons/close-icon'; import { cn, stateClassName } from '@/lib/sprout/classes'; import { Button } from '@/components/ui/button'; export const sheetSideNames = ['top', 'right', 'bottom', 'left'] as const; export const sheetSizeNames = ['default', 'lg', 'xl', 'full'] as const; export const sheetTitleSizeNames = ['default', 'lg'] as const; export type SheetSide = (typeof sheetSideNames)[number]; export type SheetSize = (typeof sheetSizeNames)[number]; export type SheetTitleSize = (typeof sheetTitleSizeNames)[number]; const swipeDirections = { top: 'up', right: 'right', bottom: 'down', left: 'left', } as const satisfies Record<SheetSide, SheetPrimitive.Root.Props['swipeDirection']>; const SheetSideContext = createContext<Dispatch<SetStateAction<SheetSide>> | null>(null); export type SheetProps = Omit< SheetPrimitive.Root.Props, 'swipeDirection' | 'snapPoints' | 'snapPoint' | 'defaultSnapPoint' | 'onSnapPointChange' | 'snapToSequentialPoints' >; export function Sheet(props: SheetProps) { const [side, setSide] = useState<SheetSide>('right'); return ( <SheetSideContext.Provider value={setSide}> <SheetPrimitive.Root data-slot="sheet" {...props} swipeDirection={swipeDirections[side]} /> </SheetSideContext.Provider> ); } export type SheetTriggerProps = SheetPrimitive.Trigger.Props; export function SheetTrigger(props: SheetTriggerProps) { return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />; } export type SheetCloseProps = SheetPrimitive.Close.Props; export function SheetClose(props: SheetCloseProps) { return <SheetPrimitive.Close data-slot="sheet-close" {...props} />; } export type SheetPortalProps = SheetPrimitive.Portal.Props; export function SheetPortal(props: SheetPortalProps) { return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />; } export type SheetOverlayProps = SheetPrimitive.Backdrop.Props; export function SheetOverlay({ className, ...props }: SheetOverlayProps) { return ( <SheetPrimitive.Backdrop data-slot="sheet-overlay" {...props} className={stateClassName<SheetPrimitive.Backdrop.State>('sprout-sheet-overlay', className)} /> ); } export interface SheetContentProps extends SheetPrimitive.Popup.Props { side?: SheetSide; size?: SheetSize; showCloseButton?: boolean; closeLabel?: string; keepMounted?: boolean; container?: SheetPrimitive.Portal.Props['container']; showSwipeHandle?: boolean; } export function SheetContent({ className, children, side = 'right', size = 'default', showCloseButton = true, closeLabel = 'Close', keepMounted = false, container, showSwipeHandle = false, ...props }: SheetContentProps) { const setSide = useContext(SheetSideContext); useLayoutEffect(() => setSide?.(side), [setSide, side]); return ( <SheetPortal keepMounted={keepMounted} container={container}> <SheetOverlay /> <SheetPrimitive.Viewport data-slot="sheet-viewport" className="sprout-sheet-viewport"> <SheetPrimitive.Popup data-slot="sheet-content" data-side={side} data-size={size} {...props} className={stateClassName<SheetPrimitive.Popup.State>('sprout-sheet-content', className)} > {showSwipeHandle && ( <div data-slot="sheet-swipe-handle" aria-hidden="true" className="sprout-sheet-swipe-handle" /> )} <SheetPrimitive.Content className="sprout-sheet-inner">{children}</SheetPrimitive.Content> {showCloseButton && ( <SheetPrimitive.Close data-slot="sheet-close" className="sprout-sheet-close" aria-label={closeLabel} render={<Button variant="ghost" size="icon-sm" />} > <CloseIcon size="md" aria-hidden="true" /> </SheetPrimitive.Close> )} </SheetPrimitive.Popup> </SheetPrimitive.Viewport> </SheetPortal> ); } type PartSlot = 'sheet-header' | 'sheet-body' | 'sheet-footer'; export interface SheetPartState extends Record<string, unknown> { slot: PartSlot; } export type SheetPartProps = useRender.ComponentProps<'div', SheetPartState>; function part(slot: PartSlot, base: string) { return function SheetPart({ className, render, ref, ...props }: SheetPartProps) { return useRender({ defaultTagName: 'div', ref, render, props: mergeProps<'div'>({ 'data-slot': slot, className: cn(base, className) } as object, props), state: { slot }, }); }; } export const SheetHeader = part('sheet-header', 'sprout-sheet-header'); export const SheetBody = part('sheet-body', 'sprout-sheet-body'); export const SheetFooter = part('sheet-footer', 'sprout-sheet-footer'); export interface SheetTitleProps extends SheetPrimitive.Title.Props { size?: SheetTitleSize; } export function SheetTitle({ className, size = 'default', ...props }: SheetTitleProps) { return ( <SheetPrimitive.Title data-slot="sheet-title" data-size={size} {...props} className={stateClassName<SheetPrimitive.Title.State>('sprout-sheet-title', className)} /> ); } export type SheetDescriptionProps = SheetPrimitive.Description.Props; export function SheetDescription({ className, ...props }: SheetDescriptionProps) { return ( <SheetPrimitive.Description data-slot="sheet-description" {...props} className={stateClassName<SheetPrimitive.Description.State>('sprout-sheet-description', className)} /> ); }And the files it imports:
lib/sprout/icons/close-icon.tsxlib/sprout/icons/create-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-sheet-overlay { z-index: 50; isolation: isolate; background: var(--sprout-overlay); opacity: calc(1 - var(--drawer-swipe-progress, 0)); position: fixed; inset: 0; } .sprout-sheet-viewport { z-index: 50; pointer-events: none; position: fixed; inset: 0; } .sprout-sheet-content { z-index: 50; box-sizing: border-box; background: var(--sprout-surface); min-width: 0; color: var(--sprout-text); box-shadow: var(--sprout-shadow-overlay); font-family: inherit; font-size: var(--sprout-text-sm); overscroll-behavior: contain; overflow-wrap: break-word; pointer-events: auto; outline: none; flex-direction: column; line-height: 1.25rem; display: flex; position: fixed; overflow: hidden auto; } .sprout-sheet-content:is([data-side="left"], [data-side="right"]) { transform: translate3d(var(--drawer-swipe-movement-x, 0px), 0, 0); } .sprout-sheet-content:is([data-side="top"], [data-side="bottom"]) { transform: translate3d(0, var(--drawer-swipe-movement-y, 0px), 0); } .sprout-sheet-content[data-swiping] { user-select: none; } .sprout-sheet-inner { display: contents; } .sprout-sheet-overlay[hidden], .sprout-sheet-content[hidden] { display: none; } :is(.sprout-sheet-content:is([data-side="left"], [data-side="right"])) { width: 75%; height: 100dvh; top: 0; bottom: 0; } .sprout-sheet-content[data-side="right"] { border-left: 1px solid var(--sprout-line); right: 0; } .sprout-sheet-content[data-side="left"] { border-right: 1px solid var(--sprout-line); left: 0; } .sprout-sheet-content:is([data-side="left"], [data-side="right"]):is([data-size="lg"], [data-size="xl"]) { width: 100%; } :is(.sprout-sheet-content:is([data-side="top"], [data-side="bottom"])) { max-height: 85dvh; left: 0; right: 0; } .sprout-sheet-content[data-side="top"] { border-bottom: 1px solid var(--sprout-line); padding-top: env(safe-area-inset-top); border-end-end-radius: var(--sprout-radius-panel); border-end-start-radius: var(--sprout-radius-panel); top: 0; } .sprout-sheet-content[data-side="bottom"] { border-top: 1px solid var(--sprout-line); padding-bottom: env(safe-area-inset-bottom); border-start-start-radius: var(--sprout-radius-panel); border-start-end-radius: var(--sprout-radius-panel); bottom: 0; } .sprout-sheet-content[data-size="full"] { width: 100%; max-width: none; height: 100dvh; max-height: none; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); box-shadow: none; border: 0; border-radius: 0; inset: 0; } .sprout-sheet-header { flex-direction: column; gap: 2px; min-width: 0; padding: 16px; display: flex; } .sprout-sheet-content:has( > .sprout-sheet-close) > .sprout-sheet-inner > .sprout-sheet-header { padding-inline-end: 48px; } .sprout-sheet-title { min-width: 0; font-size: var(--sprout-text-base); letter-spacing: -.005em; overflow-wrap: anywhere; margin: 0; font-weight: 550; line-height: 1.375rem; } .sprout-sheet-title[data-size="lg"] { letter-spacing: -.015em; font-size: 1.25rem; font-weight: 600; line-height: 1.75rem; } .sprout-sheet-title[tabindex="-1"]:focus { outline: none; } .sprout-sheet-title[tabindex="-1"]:focus-visible { outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: 0; border-radius: 2px; } .sprout-sheet-description { min-width: 0; color: var(--sprout-muted); font-size: var(--sprout-text-sm); text-wrap: pretty; margin: 0; line-height: 1.25rem; } .sprout-sheet-body { overscroll-behavior: contain; flex-direction: column; flex: auto; gap: 16px; min-width: 0; min-height: 0; padding: 0 16px 24px; display: flex; overflow-y: auto; } .sprout-sheet-footer { flex-direction: column; gap: 8px; margin-top: auto; padding: 16px; display: flex; } .sprout-sheet-swipe-handle { z-index: 1; cursor: grab; touch-action: none; flex-shrink: 0; justify-content: center; align-items: center; display: flex; position: relative; } .sprout-sheet-swipe-handle:active { cursor: grabbing; } .sprout-sheet-swipe-handle:after { content: ""; background: var(--sprout-input); border-radius: 999px; } @media (hover: hover) { .sprout-sheet-swipe-handle:hover:after { background: var(--sprout-border); } } .sprout-sheet-content:is([data-side="top"], [data-side="bottom"]) > .sprout-sheet-swipe-handle { height: 20px; } .sprout-sheet-content:is([data-side="top"], [data-side="bottom"]) > .sprout-sheet-swipe-handle:after { width: 3rem; height: 4px; } .sprout-sheet-content[data-side="bottom"] > .sprout-sheet-swipe-handle { margin-bottom: -12px; } .sprout-sheet-content[data-side="top"] > .sprout-sheet-swipe-handle { order: 1; margin-top: -12px; } .sprout-sheet-content:is([data-side="left"], [data-side="right"]) > .sprout-sheet-swipe-handle { z-index: 1; width: 16px; position: absolute; top: 0; bottom: 0; } .sprout-sheet-content:is([data-side="left"], [data-side="right"]) > .sprout-sheet-swipe-handle:after { width: 4px; height: 3rem; } .sprout-sheet-content[data-side="right"] > .sprout-sheet-swipe-handle { left: 0; } .sprout-sheet-content[data-side="left"] > .sprout-sheet-swipe-handle { right: 0; } .sprout-sheet-close { position: absolute; top: 12px; right: 12px; } .sprout-sheet-content[data-size="full"] > .sprout-sheet-close { top: calc(12px + env(safe-area-inset-top)); } @media (width >= 40rem) { .sprout-sheet-content:is([data-side="left"], [data-side="right"]) { max-width: 24rem; } .sprout-sheet-content:is([data-side="left"], [data-side="right"])[data-size="lg"] { max-width: 32rem; } .sprout-sheet-content:is([data-side="left"], [data-side="right"])[data-size="xl"] { max-width: 42rem; } .sprout-sheet-content[data-size="full"] { max-width: none; } .sprout-sheet-content:is([data-side="top"], [data-side="bottom"]) > .sprout-sheet-inner > .sprout-sheet-footer { flex-flow: wrap; justify-content: flex-end; } } @media (prefers-reduced-motion: no-preference) { .sprout-sheet-overlay { transition: opacity var(--sprout-motion-normal) var(--sprout-motion-ease); } .sprout-sheet-overlay[data-starting-style], .sprout-sheet-overlay[data-ending-style] { opacity: 0; } .sprout-sheet-content { transition: opacity var(--sprout-motion-normal) var(--sprout-motion-ease), translate var(--sprout-motion-normal) var(--sprout-motion-ease), transform var(--sprout-motion-normal) var(--sprout-motion-ease); } .sprout-sheet-overlay[data-swiping], .sprout-sheet-content[data-swiping] { transition-duration: 0s; } .sprout-sheet-content[data-ending-style], .sprout-sheet-overlay[data-ending-style] { transition-duration: var(--sprout-motion-fast); } .sprout-sheet-content[data-starting-style], .sprout-sheet-content[data-ending-style] { opacity: 0; } .sprout-sheet-content[data-side="right"]:is([data-starting-style], [data-ending-style]) { translate: 2.5rem; } .sprout-sheet-content[data-side="left"]:is([data-starting-style], [data-ending-style]) { translate: -2.5rem; } .sprout-sheet-content[data-side="bottom"]:is([data-starting-style], [data-ending-style]) { translate: 0 2.5rem; } .sprout-sheet-content[data-side="top"]:is([data-starting-style], [data-ending-style]) { translate: 0 -2.5rem; } .sprout-sheet-content[data-swipe-dismiss][data-ending-style] { opacity: 1; transition-duration: calc(var(--drawer-swipe-strength, 1) * var(--sprout-motion-normal)); } .sprout-sheet-content[data-swipe-dismiss][data-side="right"][data-ending-style] { translate: 100%; } .sprout-sheet-content[data-swipe-dismiss][data-side="left"][data-ending-style] { translate: -100%; } .sprout-sheet-content[data-swipe-dismiss][data-side="bottom"][data-ending-style] { translate: 0 100%; } .sprout-sheet-content[data-swipe-dismiss][data-side="top"][data-ending-style] { translate: 0 -100%; } .sprout-sheet-inner > :is(.sprout-sheet-header, .sprout-sheet-body, .sprout-sheet-footer) { animation: sprout-sheet-section-in var(--sprout-motion-normal) var(--sprout-motion-ease) both; } .sprout-sheet-inner > .sprout-sheet-header { animation-delay: 30ms; } .sprout-sheet-inner > .sprout-sheet-body { animation-delay: 60ms; } .sprout-sheet-inner > .sprout-sheet-footer { animation-delay: 90ms; } } @keyframes sprout-sheet-section-in { from { opacity: 0; translate: 0 4px; } } }Import it from
@/components/ui/sheet. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/sheet.
Usage
import { Button } from "@tulipfarm/sprout/button";
import {
Sheet,
SheetBody,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@tulipfarm/sprout/sheet";
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger render={<Button variant="outline" size="sm" />}>
<Filter aria-hidden="true" />
Filters (2)
</SheetTrigger>
<SheetContent side="bottom">
<SheetHeader>
<SheetTitle>Filter and sort</SheetTitle>
<SheetDescription>Results update as you choose.</SheetDescription>
</SheetHeader>
<SheetBody>…</SheetBody>
<SheetFooter>
<Button onClick={() => setOpen(false)}>Show results</Button>
<Button variant="ghost" size="sm" onClick={clear}>Clear filters</Button>
</SheetFooter>
</SheetContent>
</Sheet>Sheet works controlled with open and onOpenChange, or uncontrolled with a SheetTrigger. To keep it open while a save runs or while a second sheet is on top, ignore the change in onOpenChange and hide the corner button with showCloseButton={!saving}.
Sides
side is "right" (default), "left","top", or "bottom". Top and bottom sheets span the width, grow with their content up to 85% of the height, and lay out footer actions in a row from 640px.
Sides
Each side as Cloud opens it. Escape, the overlay, or a close button dismisses the sheet; nothing is saved.
Sizes
size sets the width of left and right sheets: "default" (24rem), "lg" (32rem), or "xl" (42rem). "full" covers the viewport from any side and respects safe areas. SheetTitle size="lg" is the larger title for product-style detail sheets.
Sizes
default 24rem, lg 32rem, xl 42rem, and full screen. Below 640px side sheets take 75% of the width, and lg and xl take all of it.
Swipe to close
Every sheet follows a touch swipe toward its side. A right sheet swipes right and a bottom sheet swipes down. Let go past half the panel, or flick it, and the sheet closes. A shorter swipe springs back. Scrolling a long body scrolls first and swipes only from the edge.
A mouse or pen drags the sheet only from the handle or empty panel space. Drags on text, fields, and buttons select and click as usual, so desktop forms are safe. showSwipeHandle adds a grab bar on the edge facing the page. It is off by default. Turn it on for bottom sheets on phones, where people expect it.
<Sheet>
<SheetTrigger render={<Button variant="outline" />}>Stock filters</SheetTrigger>
<SheetContent side="bottom" showSwipeHandle>
<SheetHeader>
<SheetTitle>Stock filters</SheetTitle>
<SheetDescription>Swipe down or press Show results to close.</SheetDescription>
</SheetHeader>
<SheetBody>…</SheetBody>
<SheetFooter>
<SheetClose render={<Button />}>Show results</SheetClose>
</SheetFooter>
</SheetContent>
</Sheet>Swipe to close
Swipe toward the edge on a touch screen. A short swipe springs back.
Cloud patterns
Put a custom bar and your own scroll region directly in SheetContent, or use SheetBody, which scrolls between the header and footer. initialFocus can target a title with tabIndex={-1}, finalFocus can return focus to a trigger ref, and keepMounted keeps drafts while the sheet is closed. A dialog or a second sheet can open on top.
Cloud patterns
Compositions from TulipFarm Cloud with sample data. Nothing leaves this page.
States
Show a skeleton with role="status" while data loads, an errorStatePanel with a retry, and a short sentence when nothing needs attention.
States
Loading, error, empty, and a list with a nested editor. The status sheet stays open while the editor on top is open.
API
Sheet, SheetTrigger, SheetPortal,SheetClose, SheetOverlay, SheetTitle, and SheetDescription wrap the Base UI drawer parts and take their props, including render. SheetHeader, SheetBody, and SheetFooter render a div and accept render, so a body can be the form. Sheet leaves out swipeDirection and snap points. The side on SheetContent sets the swipe direction.
SheetContent takes side, size, showCloseButton, closeLabel, keepMounted, container, showSwipeHandle, and every Base UI popup prop such as initialFocus and finalFocus. It sets data-slot="sheet-content" (overridable), data-side, and data-size. Its corner button has data-slot="sheet-close", so you can move it with a className selector. SheetTitle takes size ("default" or "lg").
Accessibility
The panel has role="dialog" and is named by SheetTitle. Every sheet needs a title, even if it is hidden with sr-only. Tab and Shift+Tab stay inside, and Escape or a click on the overlay closes it unless you ignore the change.
Opening slides 2.5rem and fades over 180ms. Closing takes 120ms. A swipe moves the panel with the finger, and the overlay fades as it goes. Motion turns off when reduced motion is requested. The swipe still works. The handle is hidden from assistive tech, so keep a close button or a footer action in every sheet.
Theme tokens
Sheets use --sprout-overlay, --sprout-surface, --sprout-line, --sprout-text, --sprout-muted, --sprout-shadow-overlay, and --sprout-radius-panel. They need no brand color, so they look the same with the neutral and TulipFarm themes in light and dark mode.