dialog.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use client";
  2. import * as React from "react";
  3. import * as DialogPrimitive from "@radix-ui/react-dialog";
  4. import { XIcon } from "lucide-react";
  5. import { cn } from "@/lib/utils";
  6. function Dialog({ ...props }) {
  7. return <DialogPrimitive.Root data-slot="dialog" {...props} />;
  8. }
  9. function DialogTrigger({ ...props }) {
  10. return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
  11. }
  12. function DialogPortal({ ...props }) {
  13. return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
  14. }
  15. function DialogClose({ ...props }) {
  16. return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
  17. }
  18. function DialogOverlay({ className, ...props }) {
  19. return (
  20. <DialogPrimitive.Overlay
  21. data-slot="dialog-overlay"
  22. className={cn(
  23. "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",
  24. className,
  25. )}
  26. {...props}
  27. />
  28. );
  29. }
  30. function DialogContent({
  31. className,
  32. children,
  33. showCloseButton = true,
  34. ...props
  35. }) {
  36. return (
  37. <DialogPortal data-slot="dialog-portal">
  38. <DialogOverlay />
  39. <DialogPrimitive.Content
  40. data-slot="dialog-content"
  41. className={cn(
  42. "bg-background 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]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
  43. className,
  44. )}
  45. {...props}
  46. >
  47. {children}
  48. {showCloseButton && (
  49. <DialogPrimitive.Close
  50. data-slot="dialog-close"
  51. className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground 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 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
  52. >
  53. <XIcon />
  54. <span className="sr-only">Schließen</span>
  55. </DialogPrimitive.Close>
  56. )}
  57. </DialogPrimitive.Content>
  58. </DialogPortal>
  59. );
  60. }
  61. function DialogHeader({ className, ...props }) {
  62. return (
  63. <div
  64. data-slot="dialog-header"
  65. className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
  66. {...props}
  67. />
  68. );
  69. }
  70. function DialogFooter({ className, ...props }) {
  71. return (
  72. <div
  73. data-slot="dialog-footer"
  74. className={cn(
  75. "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
  76. className,
  77. )}
  78. {...props}
  79. />
  80. );
  81. }
  82. function DialogTitle({ className, ...props }) {
  83. return (
  84. <DialogPrimitive.Title
  85. data-slot="dialog-title"
  86. className={cn("text-lg leading-none font-semibold", className)}
  87. {...props}
  88. />
  89. );
  90. }
  91. function DialogDescription({ className, ...props }) {
  92. return (
  93. <DialogPrimitive.Description
  94. data-slot="dialog-description"
  95. className={cn("text-muted-foreground text-sm", className)}
  96. {...props}
  97. />
  98. );
  99. }
  100. export {
  101. Dialog,
  102. DialogClose,
  103. DialogContent,
  104. DialogDescription,
  105. DialogFooter,
  106. DialogHeader,
  107. DialogOverlay,
  108. DialogPortal,
  109. DialogTitle,
  110. DialogTrigger,
  111. };