Sheet
A panel that slides in from the edge of the viewport with an overlay.
source cached 2026-10-19
ui/sheet.tsx
"use client";
import { Dialog as SheetPrimitive } from "@base-ui/react/dialog";
import { XIcon } from "blode-icons-react";
import * as React from "react";
import { cn } from "@/lib/utils";
const Sheet = ({ ...props }: SheetPrimitive.Root.Props) => (
<SheetPrimitive.Root data-slot="sheet" {...props} />
);
const SheetTrigger = ({
asChild,
children,
...props
}: SheetPrimitive.Trigger.Props & {
asChild?: boolean;
}) => {
if (asChild && React.isValidElement(children)) {
return <SheetPrimitive.Trigger data-slot="sheet-trigger" render={children} {...props} />;
}
return (
<SheetPrimitive.Trigger data-slot="sheet-trigger" {...props}>
{children}
</SheetPrimitive.Trigger>
);
};
const SheetClose = ({
asChild,
children,
...props
}: SheetPrimitive.Close.Props & {
asChild?: boolean;
}) => {
if (asChild && React.isValidElement(children)) {
return <SheetPrimitive.Close data-slot="sheet-close" render={children} {...props} />;
}
return (
<SheetPrimitive.Close data-slot="sheet-close" {...props}>
{children}
</SheetPrimitive.Close>
);
};
const SheetPortal = ({ ...props }: SheetPrimitive.Portal.Props) => (
<SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
);
const SheetOverlay = ({ className, ...props }: SheetPrimitive.Backdrop.Props) => (
<SheetPrimitive.Backdrop
className={cn(
"data-closed:fade-out-0 data-open:fade-in-0 fixed inset-0 z-50 bg-overlay backdrop-blur-[10px] data-closed:animate-out data-open:animate-in data-closed:duration-300 data-open:duration-500 motion-reduce:transition-none",
className,
)}
data-slot="sheet-overlay"
{...props}
/>
);
const SheetContent = ({
className,
children,
side = "right",
showCloseButton = true,
...props
}: SheetPrimitive.Popup.Props & {
side?: "top" | "right" | "bottom" | "left";
showCloseButton?: boolean;
}) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Popup
className={cn(
"fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-closed:animate-out data-open:animate-in data-closed:duration-300 data-open:duration-500",
side === "right" &&
"data-[side=right]:data-closed:slide-out-to-right data-[side=right]:data-open:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm",
side === "left" &&
"data-[side=left]:data-closed:slide-out-to-left data-[side=left]:data-open:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",
side === "top" &&
"data-[side=top]:data-closed:slide-out-to-top data-[side=top]:data-open:slide-in-from-top inset-x-0 top-0 h-auto border-b",
side === "bottom" &&
"data-[side=bottom]:data-closed:slide-out-to-bottom data-[side=bottom]:data-open:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t",
className,
)}
data-side={side}
data-slot="sheet-content"
{...props}
>
{children}
{showCloseButton && (
<SheetPrimitive.Close className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<XIcon className="size-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
)}
</SheetPrimitive.Popup>
</SheetPortal>
);
const SheetHeader = ({ className, ...props }: React.ComponentProps<"div">) => (
<div className={cn("flex flex-col gap-1.5 p-4", className)} data-slot="sheet-header" {...props} />
);
const SheetFooter = ({ className, ...props }: React.ComponentProps<"div">) => (
<div
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
data-slot="sheet-footer"
{...props}
/>
);
const SheetTitle = ({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Title>) => (
<SheetPrimitive.Title
className={cn("font-semibold text-foreground", className)}
data-slot="sheet-title"
{...props}
/>
);
const SheetDescription = ({
className,
...props
}: React.ComponentProps<typeof SheetPrimitive.Description>) => (
<SheetPrimitive.Description
className={cn("text-muted-foreground text-sm", className)}
data-slot="sheet-description"
{...props}
/>
);
export {
Sheet,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
};
No selection tags yet — empty means no evidence, not lack of support.
DependenciesBundle weight · light
- ui-primitives
- @base-ui/react