alert-dialog.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. const AlertDialog = AlertDialogPrimitive.Root
  7. const AlertDialogTrigger = AlertDialogPrimitive.Trigger
  8. const AlertDialogPortal = AlertDialogPrimitive.Portal
  9. const AlertDialogOverlay = React.forwardRef<
  10. React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
  11. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
  12. >(({ className, ...props }, ref) => (
  13. <AlertDialogPrimitive.Overlay
  14. className={cn(
  15. "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
  16. className
  17. )}
  18. {...props}
  19. ref={ref}
  20. />
  21. ))
  22. AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
  23. const AlertDialogContent = React.forwardRef<
  24. React.ElementRef<typeof AlertDialogPrimitive.Content>,
  25. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
  26. >(({ className, ...props }, ref) => (
  27. <AlertDialogPortal>
  28. <AlertDialogOverlay />
  29. <AlertDialogPrimitive.Content
  30. ref={ref}
  31. className={cn(
  32. "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
  33. className
  34. )}
  35. {...props}
  36. />
  37. </AlertDialogPortal>
  38. ))
  39. AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
  40. const AlertDialogHeader = ({
  41. className,
  42. ...props
  43. }: React.HTMLAttributes<HTMLDivElement>) => (
  44. <div
  45. className={cn(
  46. "flex flex-col space-y-2 text-center sm:text-left",
  47. className
  48. )}
  49. {...props}
  50. />
  51. )
  52. AlertDialogHeader.displayName = "AlertDialogHeader"
  53. const AlertDialogFooter = ({
  54. className,
  55. ...props
  56. }: React.HTMLAttributes<HTMLDivElement>) => (
  57. <div
  58. className={cn(
  59. "flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
  60. className
  61. )}
  62. {...props}
  63. />
  64. )
  65. AlertDialogFooter.displayName = "AlertDialogFooter"
  66. const AlertDialogTitle = React.forwardRef<
  67. React.ElementRef<typeof AlertDialogPrimitive.Title>,
  68. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
  69. >(({ className, ...props }, ref) => (
  70. <AlertDialogPrimitive.Title
  71. ref={ref}
  72. className={cn("text-lg font-semibold", className)}
  73. {...props}
  74. />
  75. ))
  76. AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
  77. const AlertDialogDescription = React.forwardRef<
  78. React.ElementRef<typeof AlertDialogPrimitive.Description>,
  79. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
  80. >(({ className, ...props }, ref) => (
  81. <AlertDialogPrimitive.Description
  82. ref={ref}
  83. className={cn("text-sm text-muted-foreground", className)}
  84. {...props}
  85. />
  86. ))
  87. AlertDialogDescription.displayName =
  88. AlertDialogPrimitive.Description.displayName
  89. const AlertDialogAction = React.forwardRef<
  90. React.ElementRef<typeof AlertDialogPrimitive.Action>,
  91. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
  92. >(({ className, ...props }, ref) => (
  93. <AlertDialogPrimitive.Action
  94. ref={ref}
  95. className={cn(buttonVariants(), className)}
  96. {...props}
  97. />
  98. ))
  99. AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
  100. const AlertDialogCancel = React.forwardRef<
  101. React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
  102. React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
  103. >(({ className, ...props }, ref) => (
  104. <AlertDialogPrimitive.Cancel
  105. ref={ref}
  106. className={cn(
  107. buttonVariants({ variant: "outline" }),
  108. "mt-2 sm:mt-0",
  109. className
  110. )}
  111. {...props}
  112. />
  113. ))
  114. AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
  115. export {
  116. AlertDialog,
  117. AlertDialogPortal,
  118. AlertDialogOverlay,
  119. AlertDialogTrigger,
  120. AlertDialogContent,
  121. AlertDialogHeader,
  122. AlertDialogFooter,
  123. AlertDialogTitle,
  124. AlertDialogDescription,
  125. AlertDialogAction,
  126. AlertDialogCancel,
  127. }