blob: e9967e6173b2f3f67cba05394b541f16be5b2b6e [file] [log] [blame]
giod0026612025-05-08 13:00:36 +00001"use client";
gio5f2f1002025-03-20 18:38:48 +04002
giod0026612025-05-08 13:00:36 +00003import * as React from "react";
4import * as SheetPrimitive from "@radix-ui/react-dialog";
5import { Cross2Icon } from "@radix-ui/react-icons";
6import { cva, type VariantProps } from "class-variance-authority";
gio5f2f1002025-03-20 18:38:48 +04007
giod0026612025-05-08 13:00:36 +00008import { cn } from "@/lib/utils";
gio5f2f1002025-03-20 18:38:48 +04009
giod0026612025-05-08 13:00:36 +000010const Sheet = SheetPrimitive.Root;
gio5f2f1002025-03-20 18:38:48 +040011
giod0026612025-05-08 13:00:36 +000012const SheetTrigger = SheetPrimitive.Trigger;
gio5f2f1002025-03-20 18:38:48 +040013
giod0026612025-05-08 13:00:36 +000014const SheetClose = SheetPrimitive.Close;
gio5f2f1002025-03-20 18:38:48 +040015
giod0026612025-05-08 13:00:36 +000016const SheetPortal = SheetPrimitive.Portal;
gio5f2f1002025-03-20 18:38:48 +040017
18const SheetOverlay = React.forwardRef<
giod0026612025-05-08 13:00:36 +000019 React.ElementRef<typeof SheetPrimitive.Overlay>,
20 React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
gio5f2f1002025-03-20 18:38:48 +040021>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000022 <SheetPrimitive.Overlay
23 className={cn(
24 "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
25 className,
26 )}
27 {...props}
28 ref={ref}
29 />
30));
31SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
gio5f2f1002025-03-20 18:38:48 +040032
33const sheetVariants = cva(
giod0026612025-05-08 13:00:36 +000034 "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",
35 {
36 variants: {
37 side: {
38 top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
39 bottom: "inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
40 left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
41 right: "inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
42 },
43 },
44 defaultVariants: {
45 side: "right",
46 },
47 },
48);
gio5f2f1002025-03-20 18:38:48 +040049
50interface SheetContentProps
giod0026612025-05-08 13:00:36 +000051 extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
52 VariantProps<typeof sheetVariants> {}
gio5f2f1002025-03-20 18:38:48 +040053
giod0026612025-05-08 13:00:36 +000054const SheetContent = React.forwardRef<React.ElementRef<typeof SheetPrimitive.Content>, SheetContentProps>(
55 ({ side = "right", className, children, ...props }, ref) => (
56 <SheetPortal>
57 <SheetOverlay />
58 <SheetPrimitive.Content ref={ref} className={cn(sheetVariants({ side }), className)} {...props}>
59 <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
60 <Cross2Icon className="h-4 w-4" />
61 <span className="sr-only">Close</span>
62 </SheetPrimitive.Close>
63 {children}
64 </SheetPrimitive.Content>
65 </SheetPortal>
66 ),
67);
68SheetContent.displayName = SheetPrimitive.Content.displayName;
gio5f2f1002025-03-20 18:38:48 +040069
giod0026612025-05-08 13:00:36 +000070const SheetHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
71 <div className={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...props} />
72);
73SheetHeader.displayName = "SheetHeader";
gio5f2f1002025-03-20 18:38:48 +040074
giod0026612025-05-08 13:00:36 +000075const SheetFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
76 <div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} />
77);
78SheetFooter.displayName = "SheetFooter";
gio5f2f1002025-03-20 18:38:48 +040079
80const SheetTitle = React.forwardRef<
giod0026612025-05-08 13:00:36 +000081 React.ElementRef<typeof SheetPrimitive.Title>,
82 React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
gio5f2f1002025-03-20 18:38:48 +040083>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000084 <SheetPrimitive.Title ref={ref} className={cn("text-lg font-semibold text-foreground", className)} {...props} />
85));
86SheetTitle.displayName = SheetPrimitive.Title.displayName;
gio5f2f1002025-03-20 18:38:48 +040087
88const SheetDescription = React.forwardRef<
giod0026612025-05-08 13:00:36 +000089 React.ElementRef<typeof SheetPrimitive.Description>,
90 React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
gio5f2f1002025-03-20 18:38:48 +040091>(({ className, ...props }, ref) => (
giod0026612025-05-08 13:00:36 +000092 <SheetPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
93));
94SheetDescription.displayName = SheetPrimitive.Description.displayName;
gio5f2f1002025-03-20 18:38:48 +040095
96export {
giod0026612025-05-08 13:00:36 +000097 Sheet,
98 SheetPortal,
99 SheetOverlay,
100 SheetTrigger,
101 SheetClose,
102 SheetContent,
103 SheetHeader,
104 SheetFooter,
105 SheetTitle,
106 SheetDescription,
107};