alert-dialog.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 'use client';
  2. import * as React from 'react';
  3. import { AlertDialog as AlertDialogPrimitive } from '@base-ui/react/alert-dialog';
  4. import { cn } from '@/lib/utils';
  5. import { Button } from '@/components/ui/button';
  6. function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) {
  7. return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
  8. }
  9. function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props) {
  10. return (
  11. <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />
  12. );
  13. }
  14. function AlertDialogPortal({ ...props }: AlertDialogPrimitive.Portal.Props) {
  15. return (
  16. <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />
  17. );
  18. }
  19. function AlertDialogOverlay({
  20. className,
  21. ...props
  22. }: AlertDialogPrimitive.Backdrop.Props) {
  23. return (
  24. <AlertDialogPrimitive.Backdrop
  25. data-slot="alert-dialog-overlay"
  26. className={cn(
  27. 'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 isolate z-50',
  28. className,
  29. )}
  30. {...props}
  31. />
  32. );
  33. }
  34. function AlertDialogContent({
  35. className,
  36. size = 'default',
  37. ...props
  38. }: AlertDialogPrimitive.Popup.Props & {
  39. size?: 'default' | 'sm';
  40. }) {
  41. return (
  42. <AlertDialogPortal>
  43. <AlertDialogOverlay />
  44. <AlertDialogPrimitive.Popup
  45. data-slot="alert-dialog-content"
  46. data-size={size}
  47. className={cn(
  48. 'data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-popover text-popover-foreground ring-foreground/10 gap-4 rounded-xl p-4 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none',
  49. className,
  50. )}
  51. {...props}
  52. />
  53. </AlertDialogPortal>
  54. );
  55. }
  56. function AlertDialogHeader({
  57. className,
  58. ...props
  59. }: React.ComponentProps<'div'>) {
  60. return (
  61. <div
  62. data-slot="alert-dialog-header"
  63. className={cn(
  64. 'grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]',
  65. className,
  66. )}
  67. {...props}
  68. />
  69. );
  70. }
  71. function AlertDialogFooter({
  72. className,
  73. ...props
  74. }: React.ComponentProps<'div'>) {
  75. return (
  76. <div
  77. data-slot="alert-dialog-footer"
  78. className={cn(
  79. 'bg-muted/50 -mx-4 -mb-4 rounded-b-xl border-t p-4 flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end',
  80. className,
  81. )}
  82. {...props}
  83. />
  84. );
  85. }
  86. function AlertDialogMedia({
  87. className,
  88. ...props
  89. }: React.ComponentProps<'div'>) {
  90. return (
  91. <div
  92. data-slot="alert-dialog-media"
  93. className={cn(
  94. "bg-muted mb-2 inline-flex size-10 items-center justify-center rounded-md sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6",
  95. className,
  96. )}
  97. {...props}
  98. />
  99. );
  100. }
  101. function AlertDialogTitle({
  102. className,
  103. ...props
  104. }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
  105. return (
  106. <AlertDialogPrimitive.Title
  107. data-slot="alert-dialog-title"
  108. className={cn(
  109. 'text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2 cn-font-heading',
  110. className,
  111. )}
  112. {...props}
  113. />
  114. );
  115. }
  116. function AlertDialogDescription({
  117. className,
  118. ...props
  119. }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
  120. return (
  121. <AlertDialogPrimitive.Description
  122. data-slot="alert-dialog-description"
  123. className={cn(
  124. 'text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3',
  125. className,
  126. )}
  127. {...props}
  128. />
  129. );
  130. }
  131. function AlertDialogAction({
  132. className,
  133. ...props
  134. }: React.ComponentProps<typeof Button>) {
  135. return (
  136. <Button
  137. data-slot="alert-dialog-action"
  138. className={cn(className)}
  139. {...props}
  140. />
  141. );
  142. }
  143. function AlertDialogCancel({
  144. className,
  145. variant = 'outline',
  146. size = 'default',
  147. ...props
  148. }: AlertDialogPrimitive.Close.Props &
  149. Pick<React.ComponentProps<typeof Button>, 'variant' | 'size'>) {
  150. return (
  151. <AlertDialogPrimitive.Close
  152. data-slot="alert-dialog-cancel"
  153. className={cn(className)}
  154. render={<Button variant={variant} size={size} />}
  155. {...props}
  156. />
  157. );
  158. }
  159. export {
  160. AlertDialog,
  161. AlertDialogAction,
  162. AlertDialogCancel,
  163. AlertDialogContent,
  164. AlertDialogDescription,
  165. AlertDialogFooter,
  166. AlertDialogHeader,
  167. AlertDialogMedia,
  168. AlertDialogOverlay,
  169. AlertDialogPortal,
  170. AlertDialogTitle,
  171. AlertDialogTrigger,
  172. };