alert-dialog.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. "use client"
  2. import * as React from "react"
  3. import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"
  4. import { cn } from "@/lib/utils"
  5. import { buttonVariants } from "@/components/ui/button"
  6. function AlertDialog({
  7. ...props
  8. }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
  9. return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />
  10. }
  11. function AlertDialogTrigger({
  12. ...props
  13. }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
  14. return (
  15. <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
  16. )
  17. }
  18. function AlertDialogPortal({
  19. ...props
  20. }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
  21. return (
  22. <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
  23. )
  24. }
  25. function AlertDialogOverlay({
  26. className,
  27. ...props
  28. }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
  29. return (
  30. <AlertDialogPrimitive.Overlay
  31. data-slot="alert-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 AlertDialogContent({
  41. className,
  42. ...props
  43. }: React.ComponentProps<typeof AlertDialogPrimitive.Content>) {
  44. return (
  45. <AlertDialogPortal>
  46. <AlertDialogOverlay />
  47. <AlertDialogPrimitive.Content
  48. data-slot="alert-dialog-content"
  49. className={cn(
  50. "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",
  51. className
  52. )}
  53. {...props}
  54. />
  55. </AlertDialogPortal>
  56. )
  57. }
  58. function AlertDialogHeader({
  59. className,
  60. ...props
  61. }: React.ComponentProps<"div">) {
  62. return (
  63. <div
  64. data-slot="alert-dialog-header"
  65. className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
  66. {...props}
  67. />
  68. )
  69. }
  70. function AlertDialogFooter({
  71. className,
  72. ...props
  73. }: React.ComponentProps<"div">) {
  74. return (
  75. <div
  76. data-slot="alert-dialog-footer"
  77. className={cn(
  78. "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
  79. className
  80. )}
  81. {...props}
  82. />
  83. )
  84. }
  85. function AlertDialogTitle({
  86. className,
  87. ...props
  88. }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
  89. return (
  90. <AlertDialogPrimitive.Title
  91. data-slot="alert-dialog-title"
  92. className={cn("text-lg font-semibold", className)}
  93. {...props}
  94. />
  95. )
  96. }
  97. function AlertDialogDescription({
  98. className,
  99. ...props
  100. }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
  101. return (
  102. <AlertDialogPrimitive.Description
  103. data-slot="alert-dialog-description"
  104. className={cn("text-muted-foreground text-sm", className)}
  105. {...props}
  106. />
  107. )
  108. }
  109. function AlertDialogAction({
  110. className,
  111. ...props
  112. }: React.ComponentProps<typeof AlertDialogPrimitive.Action>) {
  113. return (
  114. <AlertDialogPrimitive.Action
  115. className={cn(buttonVariants(), className)}
  116. {...props}
  117. />
  118. )
  119. }
  120. function AlertDialogCancel({
  121. className,
  122. ...props
  123. }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>) {
  124. return (
  125. <AlertDialogPrimitive.Cancel
  126. className={cn(buttonVariants({ variant: "outline" }), className)}
  127. {...props}
  128. />
  129. )
  130. }
  131. export {
  132. AlertDialog,
  133. AlertDialogPortal,
  134. AlertDialogOverlay,
  135. AlertDialogTrigger,
  136. AlertDialogContent,
  137. AlertDialogHeader,
  138. AlertDialogFooter,
  139. AlertDialogTitle,
  140. AlertDialogDescription,
  141. AlertDialogAction,
  142. AlertDialogCancel,
  143. }