alert-dialog.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. 'use client';
  2. import * as React from 'react';
  3. import { AlertDialog as AlertDialogPrimitive } from 'radix-ui';
  4. import { cn } from '@/lib/utils';
  5. import { Button } from '@/components/ui/button';
  6. function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
  7. return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
  8. }
  9. function AlertDialogTrigger({
  10. ...props
  11. }: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
  12. return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />;
  13. }
  14. function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
  15. return <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />;
  16. }
  17. function AlertDialogOverlay({
  18. className,
  19. ...props
  20. }: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
  21. return (
  22. <AlertDialogPrimitive.Overlay
  23. data-slot="alert-dialog-overlay"
  24. className={cn(
  25. '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 z-50',
  26. className,
  27. )}
  28. {...props}
  29. />
  30. );
  31. }
  32. function AlertDialogContent({
  33. className,
  34. size = 'default',
  35. container,
  36. ...props
  37. }: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
  38. size?: 'default' | 'sm';
  39. container?: HTMLElement | null;
  40. }) {
  41. return (
  42. <AlertDialogPortal container={container}>
  43. <AlertDialogOverlay />
  44. <AlertDialogPrimitive.Content
  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-background ring-foreground/10 gap-6 rounded-xl p-6 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-lg 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({ className, ...props }: React.ComponentProps<'div'>) {
  57. return (
  58. <div
  59. data-slot="alert-dialog-header"
  60. className={cn(
  61. '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-6 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]',
  62. className,
  63. )}
  64. {...props}
  65. />
  66. );
  67. }
  68. function AlertDialogFooter({ className, ...props }: React.ComponentProps<'div'>) {
  69. return (
  70. <div
  71. data-slot="alert-dialog-footer"
  72. className={cn(
  73. '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',
  74. className,
  75. )}
  76. {...props}
  77. />
  78. );
  79. }
  80. function AlertDialogMedia({ className, ...props }: React.ComponentProps<'div'>) {
  81. return (
  82. <div
  83. data-slot="alert-dialog-media"
  84. className={cn(
  85. "bg-muted mb-2 inline-flex size-16 items-center justify-center rounded-md sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-8",
  86. className,
  87. )}
  88. {...props}
  89. />
  90. );
  91. }
  92. function AlertDialogTitle({
  93. className,
  94. ...props
  95. }: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
  96. return (
  97. <AlertDialogPrimitive.Title
  98. data-slot="alert-dialog-title"
  99. className={cn(
  100. 'text-lg font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2',
  101. className,
  102. )}
  103. {...props}
  104. />
  105. );
  106. }
  107. function AlertDialogDescription({
  108. className,
  109. ...props
  110. }: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
  111. return (
  112. <AlertDialogPrimitive.Description
  113. data-slot="alert-dialog-description"
  114. className={cn(
  115. 'text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3',
  116. className,
  117. )}
  118. {...props}
  119. />
  120. );
  121. }
  122. function AlertDialogAction({
  123. className,
  124. variant = 'default',
  125. size = 'default',
  126. ...props
  127. }: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
  128. Pick<React.ComponentProps<typeof Button>, 'variant' | 'size'>) {
  129. return (
  130. <Button variant={variant} size={size} asChild>
  131. <AlertDialogPrimitive.Action
  132. data-slot="alert-dialog-action"
  133. className={cn(className)}
  134. {...props}
  135. />
  136. </Button>
  137. );
  138. }
  139. function AlertDialogCancel({
  140. className,
  141. variant = 'outline',
  142. size = 'default',
  143. ...props
  144. }: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
  145. Pick<React.ComponentProps<typeof Button>, 'variant' | 'size'>) {
  146. return (
  147. <Button variant={variant} size={size} asChild>
  148. <AlertDialogPrimitive.Cancel
  149. data-slot="alert-dialog-cancel"
  150. className={cn(className)}
  151. {...props}
  152. />
  153. </Button>
  154. );
  155. }
  156. export {
  157. AlertDialog,
  158. AlertDialogAction,
  159. AlertDialogCancel,
  160. AlertDialogContent,
  161. AlertDialogDescription,
  162. AlertDialogFooter,
  163. AlertDialogHeader,
  164. AlertDialogMedia,
  165. AlertDialogOverlay,
  166. AlertDialogPortal,
  167. AlertDialogTitle,
  168. AlertDialogTrigger,
  169. };