dialog.tsx 3.9 KB

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