sheet.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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/75 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:duration-150 data-[state=open]:duration-150",
  16. className,
  17. )}
  18. {...props}
  19. ref={ref}
  20. />
  21. ));
  22. SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
  23. const sheetSideVariants = {
  24. left: "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",
  25. right:
  26. "inset-y-0 right-0 h-full w-3/4 max-w-xs data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",
  27. };
  28. const SheetContent = React.forwardRef<
  29. React.ComponentRef<typeof SheetPrimitive.Content>,
  30. React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content> & {
  31. side?: "left" | "right";
  32. overlayClassName?: string;
  33. }
  34. >(({ className, children, side = "left", overlayClassName, ...props }, ref) => (
  35. <SheetPortal>
  36. <SheetOverlay className={overlayClassName} />
  37. <SheetPrimitive.Content
  38. ref={ref}
  39. className={cn(
  40. "fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-150 data-[state=open]:duration-150 data-[state=open]:animate-in data-[state=closed]:animate-out focus:outline-none",
  41. sheetSideVariants[side],
  42. className,
  43. )}
  44. {...props}
  45. >
  46. {children}
  47. </SheetPrimitive.Content>
  48. </SheetPortal>
  49. ));
  50. SheetContent.displayName = SheetPrimitive.Content.displayName;
  51. const SheetTitle = React.forwardRef<
  52. React.ComponentRef<typeof SheetPrimitive.Title>,
  53. React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
  54. >(({ className, ...props }, ref) => (
  55. <SheetPrimitive.Title
  56. ref={ref}
  57. className={cn("text-lg font-semibold text-foreground", className)}
  58. {...props}
  59. />
  60. ));
  61. SheetTitle.displayName = SheetPrimitive.Title.displayName;
  62. export { Sheet, SheetTrigger, SheetClose, SheetContent, SheetTitle };