sheet.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use client";
  2. import * as React from "react";
  3. import * as SheetPrimitive from "@radix-ui/react-dialog";
  4. import { cn } from "@/lib/utils";
  5. const Sheet = SheetPrimitive.Root;
  6. const SheetTrigger = SheetPrimitive.Trigger;
  7. const SheetClose = SheetPrimitive.Close;
  8. const SheetPortal = SheetPrimitive.Portal;
  9. const SheetOverlay = React.forwardRef<
  10. React.ComponentRef<typeof SheetPrimitive.Overlay>,
  11. React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
  12. >(({ className, ...props }, ref) => (
  13. <SheetPrimitive.Overlay
  14. className={cn(
  15. "fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
  16. className,
  17. )}
  18. {...props}
  19. ref={ref}
  20. />
  21. ));
  22. SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
  23. const SheetContent = React.forwardRef<
  24. React.ComponentRef<typeof SheetPrimitive.Content>,
  25. React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>
  26. >(({ className, children, ...props }, ref) => (
  27. <SheetPortal>
  28. <SheetOverlay />
  29. <SheetPrimitive.Content
  30. ref={ref}
  31. className={cn(
  32. "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",
  33. "inset-y-0 left-0 h-full w-3/4 max-w-xs border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",
  34. className,
  35. )}
  36. {...props}
  37. >
  38. {children}
  39. </SheetPrimitive.Content>
  40. </SheetPortal>
  41. ));
  42. SheetContent.displayName = SheetPrimitive.Content.displayName;
  43. const SheetTitle = React.forwardRef<
  44. React.ComponentRef<typeof SheetPrimitive.Title>,
  45. React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
  46. >(({ className, ...props }, ref) => (
  47. <SheetPrimitive.Title
  48. ref={ref}
  49. className={cn("text-lg font-semibold text-foreground", className)}
  50. {...props}
  51. />
  52. ));
  53. SheetTitle.displayName = SheetPrimitive.Title.displayName;
  54. export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetTitle };