شیت
پنلی که از لبهٔ صفحه برای کشوهای ناوبری، فیلترها و فرمهای ویرایش کشیده میشود — با جلوهی نئوبروتالیستی حاشیهها و سایهها.
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"Sheet یک دیالوگ مهارشده به لبهٔ صفحه است نه مرکز — همان overlay، تلهٔ فوکوس و رفتار dismiss، با placement متفاوت. بر پایهٔ Base UI Dialog ساخته شده و با دستور پخت نئوبروتالیستی استایل شده: حاشیههای ضخیم، سایههای سخت و تایپوگرافی پررنگ.
برای این موارد از آن استفاده کنید:
- ناوبری موبایل — drawer همبرگری که از کنار میلغزد.
- پنل سبد و جزئیات — سبد خرید، خلاصهٔ سفارش یا جزئیات ردیف بدون ترک صفحه.
- فرم ویرایش — یک رکورد را در پنل کناری بهروز کنید در حالی که جدول در دید میماند.
نصب#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/sheet.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/sheet.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/sheet.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/sheet.json
وابستگیهای زیر را نصب کنید:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
کد زیر را کپی کرده و در پروژهٔ خود جایگذاری کنید.
"use client"
import * as React from "react"
import { XIcon } from "lucide-react"
import { Dialog as SheetPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
return <SheetPrimitive.Root data-slot="sheet" {...props} />
}
function SheetTrigger({
...props
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
}
function SheetClose({
...props
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
}
function SheetPortal({
...props
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
}
function SheetOverlay({
className,
...props
}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
return (
<SheetPrimitive.Overlay
data-slot="sheet-overlay"
className={cn(
"fixed inset-0 z-50 bg-foreground/20 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
className
)}
{...props}
/>
)
}
function SheetContent({
className,
children,
side = "right",
showCloseButton = true,
...props
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
side?: "top" | "right" | "bottom" | "left"
showCloseButton?: boolean
}) {
return (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
data-slot="sheet-content"
data-side={side}
className={cn(
"fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-md transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t-2 data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r-2 data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l-2 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b-2 data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10",
className
)}
{...props}
>
{children}
{showCloseButton && (
<SheetPrimitive.Close data-slot="sheet-close" asChild>
<Button
variant="ghost"
className="absolute top-3 right-3"
size="icon-sm"
>
<XIcon />
<span className="sr-only">Close</span>
</Button>
</SheetPrimitive.Close>
)}
</SheetPrimitive.Content>
</SheetPortal>
)
}
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sheet-header"
className={cn("flex flex-col gap-0.5 p-4", className)}
{...props}
/>
)
}
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="sheet-footer"
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
{...props}
/>
)
}
function SheetTitle({
className,
...props
}: React.ComponentProps<typeof SheetPrimitive.Title>) {
return (
<SheetPrimitive.Title
data-slot="sheet-title"
className={cn(
"font-head text-base font-medium text-foreground",
className
)}
{...props}
/>
)
}
function SheetDescription({
className,
...props
}: React.ComponentProps<typeof SheetPrimitive.Description>) {
return (
<SheetPrimitive.Description
data-slot="sheet-description"
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
)
}
export {
Sheet,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
}
مسیرهای import را مطابق با پیکربندی پروژهٔ خود بهروزرسانی کنید.
استفاده#
import {
Sheet,
SheetClose,
SheetContent,
SheetDescription,
SheetFooter,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "@/components/ui/sheet"<Sheet>
<SheetTrigger>Open</SheetTrigger>
<SheetContent>
<SheetHeader>
<SheetTitle>Are you absolutely sure?</SheetTitle>
<SheetDescription>This action cannot be undone.</SheetDescription>
</SheetHeader>
</SheetContent>
</Sheet>ترکیب#
برای ساخت یک Sheet، از ترکیب زیر استفاده کنید:
Sheet
├── SheetTrigger
└── SheetContent
├── SheetHeader
│ ├── SheetTitle
│ └── SheetDescription
└── SheetFooterنمونهها#
سمت#
برای تعیین لبهای از صفحه که sheet از آن ظاهر میشود، از ویژگی side روی SheetContent استفاده کنید. مقادیر عبارتاند از top، right، bottom یا left.
import { Button } from "@/components/ui/button"
import {
Sheet,بدون دکمهٔ بستن#
برای پنهان کردن دکمهٔ بستن، از showCloseButton={false} روی SheetContent استفاده کنید.
import { Button } from "@/components/ui/button"
import {
Sheet,RTL#
برای فعالسازی پشتیبانی RTL در Neobrutalism، راهنمای پیکربندی RTL را ببینید.
"use client"
import {دسترسیپذیری#
Sheet از الگوی WAI-ARIA Dialog (Modal) پیروی میکند: پنل role="dialog" با aria-modal رندر میکند، فوکوس هنگام باز شدن وارد میشود و آنجا گیر میافتد، و SheetTitle / SheetDescription به aria-labelledby / aria-describedby وصلاند — همیشه یک SheetTitle رندر کنید، در صورت نیاز بهصورت visually hidden.
تعاملات صفحهکلید:
| کلید | عمل |
|---|---|
Space / Enter | باز کردن sheet وقتی تریگر فوکوس دارد |
Tab / Shift + Tab | حرکت فوکوس بین عناصر focusable داخل sheet (تلهٔ فوکوس) |
Esc | بستن sheet و بازگرداندن فوکوس به تریگر |
مرجع API#
مستندات Base UI Dialog را ببینید.