dialog.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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({
  7. ...props
  8. }) {
  9. return <DialogPrimitive.Root data-slot="dialog" {...props} />;
  10. }
  11. function DialogTrigger({
  12. ...props
  13. }) {
  14. return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
  15. }
  16. function DialogPortal({
  17. ...props
  18. }) {
  19. return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
  20. }
  21. function DialogClose({
  22. ...props
  23. }) {
  24. return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
  25. }
  26. function DialogOverlay({
  27. className,
  28. ...props
  29. }) {
  30. return (
  31. <DialogPrimitive.Overlay
  32. data-slot="dialog-overlay"
  33. className={cn(
  34. "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",
  35. className
  36. )}
  37. {...props} />
  38. );
  39. }
  40. function DialogContent({
  41. className,
  42. children,
  43. showCloseButton = true,
  44. ...props
  45. }) {
  46. return (
  47. <DialogPortal data-slot="dialog-portal">
  48. <DialogOverlay />
  49. <DialogPrimitive.Content
  50. data-slot="dialog-content"
  51. className={cn(
  52. "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",
  53. className
  54. )}
  55. {...props}>
  56. {children}
  57. {showCloseButton && (
  58. <DialogPrimitive.Close
  59. data-slot="dialog-close"
  60. 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">
  61. <XIcon />
  62. <span className="sr-only">Close</span>
  63. </DialogPrimitive.Close>
  64. )}
  65. </DialogPrimitive.Content>
  66. </DialogPortal>
  67. );
  68. }
  69. function DialogHeader({
  70. className,
  71. ...props
  72. }) {
  73. return (
  74. <div
  75. data-slot="dialog-header"
  76. className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
  77. {...props} />
  78. );
  79. }
  80. function DialogFooter({
  81. className,
  82. ...props
  83. }) {
  84. return (
  85. <div
  86. data-slot="dialog-footer"
  87. className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)}
  88. {...props} />
  89. );
  90. }
  91. function DialogTitle({
  92. className,
  93. ...props
  94. }) {
  95. return (
  96. <DialogPrimitive.Title
  97. data-slot="dialog-title"
  98. className={cn("text-lg leading-none font-semibold", className)}
  99. {...props} />
  100. );
  101. }
  102. function DialogDescription({
  103. className,
  104. ...props
  105. }) {
  106. return (
  107. <DialogPrimitive.Description
  108. data-slot="dialog-description"
  109. className={cn("text-muted-foreground text-sm", className)}
  110. {...props} />
  111. );
  112. }
  113. export {
  114. Dialog,
  115. DialogClose,
  116. DialogContent,
  117. DialogDescription,
  118. DialogFooter,
  119. DialogHeader,
  120. DialogOverlay,
  121. DialogPortal,
  122. DialogTitle,
  123. DialogTrigger,
  124. }