|
| 1 | +import * as React from "react"; |
| 2 | +import * as SheetPrimitive from "@radix-ui/react-dialog"; |
| 3 | +import { XIcon } from "lucide-react"; |
| 4 | + |
| 5 | +import { cn } from "@/lib/utils"; |
| 6 | + |
| 7 | +function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) { |
| 8 | + return <SheetPrimitive.Root data-slot="sheet" {...props} />; |
| 9 | +} |
| 10 | + |
| 11 | +function SheetTrigger({ ...props }: React.ComponentProps<typeof SheetPrimitive.Trigger>) { |
| 12 | + return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />; |
| 13 | +} |
| 14 | + |
| 15 | +function SheetClose({ ...props }: React.ComponentProps<typeof SheetPrimitive.Close>) { |
| 16 | + return <SheetPrimitive.Close data-slot="sheet-close" {...props} />; |
| 17 | +} |
| 18 | + |
| 19 | +function SheetPortal({ ...props }: React.ComponentProps<typeof SheetPrimitive.Portal>) { |
| 20 | + return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />; |
| 21 | +} |
| 22 | + |
| 23 | +function SheetOverlay({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Overlay>) { |
| 24 | + return ( |
| 25 | + <SheetPrimitive.Overlay |
| 26 | + data-slot="sheet-overlay" |
| 27 | + className={cn( |
| 28 | + "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50", |
| 29 | + className, |
| 30 | + )} |
| 31 | + {...props} |
| 32 | + /> |
| 33 | + ); |
| 34 | +} |
| 35 | + |
| 36 | +function SheetContent({ |
| 37 | + className, |
| 38 | + children, |
| 39 | + side = "right", |
| 40 | + ...props |
| 41 | +}: React.ComponentProps<typeof SheetPrimitive.Content> & { |
| 42 | + side?: "top" | "right" | "bottom" | "left"; |
| 43 | +}) { |
| 44 | + return ( |
| 45 | + <SheetPortal> |
| 46 | + <SheetOverlay /> |
| 47 | + <SheetPrimitive.Content |
| 48 | + data-slot="sheet-content" |
| 49 | + className={cn( |
| 50 | + "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500", |
| 51 | + side === "right" && |
| 52 | + "data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm", |
| 53 | + side === "left" && |
| 54 | + "data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm", |
| 55 | + side === "top" && |
| 56 | + "data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b", |
| 57 | + side === "bottom" && |
| 58 | + "data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t", |
| 59 | + className, |
| 60 | + )} |
| 61 | + {...props} |
| 62 | + > |
| 63 | + {children} |
| 64 | + <SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"> |
| 65 | + <XIcon className="size-4" /> |
| 66 | + <span className="sr-only">Close</span> |
| 67 | + </SheetPrimitive.Close> |
| 68 | + </SheetPrimitive.Content> |
| 69 | + </SheetPortal> |
| 70 | + ); |
| 71 | +} |
| 72 | + |
| 73 | +function SheetHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 74 | + return <div data-slot="sheet-header" className={cn("flex flex-col gap-1.5 p-4", className)} {...props} />; |
| 75 | +} |
| 76 | + |
| 77 | +function SheetFooter({ className, ...props }: React.ComponentProps<"div">) { |
| 78 | + return <div data-slot="sheet-footer" className={cn("mt-auto flex flex-col gap-2 p-4", className)} {...props} />; |
| 79 | +} |
| 80 | + |
| 81 | +function SheetTitle({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Title>) { |
| 82 | + return ( |
| 83 | + <SheetPrimitive.Title |
| 84 | + data-slot="sheet-title" |
| 85 | + className={cn("text-foreground font-semibold", className)} |
| 86 | + {...props} |
| 87 | + /> |
| 88 | + ); |
| 89 | +} |
| 90 | + |
| 91 | +function SheetDescription({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Description>) { |
| 92 | + return ( |
| 93 | + <SheetPrimitive.Description |
| 94 | + data-slot="sheet-description" |
| 95 | + className={cn("text-muted-foreground text-sm", className)} |
| 96 | + {...props} |
| 97 | + /> |
| 98 | + ); |
| 99 | +} |
| 100 | + |
| 101 | +export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetHeader, SheetFooter, SheetTitle, SheetDescription }; |
0 commit comments