5414
Sa
sat / files
sat / src / components / ui / sheet.tsx
4.5 KB
1"use client"; 2 3import { XIcon } from "lucide-react"; 4import { Dialog as SheetPrimitive } from "radix-ui"; 5import type * as React from "react"; 6import { Button } from "@/components/ui/button"; 7import { cn } from "@/lib/utils"; 8 9function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) { 10 return <SheetPrimitive.Root data-slot="sheet" {...props} />; 11} 12 13function SheetTrigger({ 14 ...props 15}: React.ComponentProps<typeof SheetPrimitive.Trigger>) { 16 return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />; 17} 18 19function SheetClose({ 20 ...props 21}: React.ComponentProps<typeof SheetPrimitive.Close>) { 22 return <SheetPrimitive.Close data-slot="sheet-close" {...props} />; 23} 24 25function SheetPortal({ 26 ...props 27}: React.ComponentProps<typeof SheetPrimitive.Portal>) { 28 return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />; 29} 30 31function SheetOverlay({ 32 className, 33 ...props 34}: React.ComponentProps<typeof SheetPrimitive.Overlay>) { 35 return ( 36 <SheetPrimitive.Overlay 37 data-slot="sheet-overlay" 38 className={cn( 39 "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/80 duration-100 data-ending-style:opacity-0 data-starting-style:opacity-0 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 z-50", 40 className, 41 )} 42 {...props} 43 /> 44 ); 45} 46 47function SheetContent({ 48 className, 49 children, 50 side = "right", 51 showCloseButton = true, 52 ...props 53}: React.ComponentProps<typeof SheetPrimitive.Content> & { 54 side?: "top" | "right" | "bottom" | "left"; 55 showCloseButton?: boolean; 56}) { 57 return ( 58 <SheetPortal> 59 <SheetOverlay /> 60 <SheetPrimitive.Content 61 data-slot="sheet-content" 62 data-side={side} 63 className={cn( 64 "bg-background data-open:animate-in data-closed:animate-out data-[side=right]:data-closed:slide-out-to-right-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=top]:data-closed:slide-out-to-top-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:fade-out-0 data-open:fade-in-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=bottom]:data-open:slide-in-from-bottom-10 fixed z-50 flex flex-col bg-clip-padding text-sm shadow-lg 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 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 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 data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm", 65 className, 66 )} 67 {...props} 68 > 69 {children} 70 {showCloseButton && ( 71 <SheetPrimitive.Close data-slot="sheet-close" asChild> 72 <Button 73 variant="ghost" 74 className="absolute top-4 right-4" 75 size="icon-sm" 76 > 77 <XIcon /> 78 <span className="sr-only">Close</span> 79 </Button> 80 </SheetPrimitive.Close> 81 )} 82 </SheetPrimitive.Content> 83 </SheetPortal> 84 ); 85} 86 87function SheetHeader({ className, ...props }: React.ComponentProps<"div">) { 88 return ( 89 <div 90 data-slot="sheet-header" 91 className={cn("gap-1.5 p-6 flex flex-col", className)} 92 {...props} 93 /> 94 ); 95} 96 97function SheetFooter({ className, ...props }: React.ComponentProps<"div">) { 98 return ( 99 <div 100 data-slot="sheet-footer" 101 className={cn("gap-2 p-6 mt-auto flex flex-col", className)} 102 {...props} 103 /> 104 ); 105} 106 107function SheetTitle({ 108 className, 109 ...props 110}: React.ComponentProps<typeof SheetPrimitive.Title>) { 111 return ( 112 <SheetPrimitive.Title 113 data-slot="sheet-title" 114 className={cn("text-foreground text-base font-medium", className)} 115 {...props} 116 /> 117 ); 118} 119 120function SheetDescription({ 121 className, 122 ...props 123}: React.ComponentProps<typeof SheetPrimitive.Description>) { 124 return ( 125 <SheetPrimitive.Description 126 data-slot="sheet-description" 127 className={cn("text-muted-foreground text-sm", className)} 128 {...props} 129 /> 130 ); 131} 132 133export { 134 Sheet, 135 SheetTrigger, 136 SheetClose, 137 SheetContent, 138 SheetHeader, 139 SheetFooter, 140 SheetTitle, 141 SheetDescription, 142};