返回 AiToEarn
alert-dialog.tsx
根目录 / project / aitoearn-web / src / components / ui / alert-dialog.tsx
1 'use client'
2
3 import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog'
4 import * as React from 'react'
5
6 import { buttonVariants } from '@/components/ui/button'
7 import { cn } from '@/utils/className'
8
9 const AlertDialog = AlertDialogPrimitive.Root
10
11 const AlertDialogTrigger = AlertDialogPrimitive.Trigger
12
13 const AlertDialogPortal = AlertDialogPrimitive.Portal
14
15 const AlertDialogOverlay = React.forwardRef<
16 React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
17 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
18 >(({ className, ...props }, ref) => (
19 <AlertDialogPrimitive.Overlay
20 className={cn(
21 'fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
22 className,
23 )}
24 {...props}
25 ref={ref}
26 />
27 ))
28 AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName
29
30 interface AlertDialogContentProps extends React.ComponentPropsWithoutRef<
31 typeof AlertDialogPrimitive.Content
32 > {
33 overlayStyle?: React.CSSProperties
34 overlayClassName?: string
35 }
36
37 const AlertDialogContent = React.forwardRef<
38 React.ElementRef<typeof AlertDialogPrimitive.Content>,
39 AlertDialogContentProps
40 >(({ className, overlayStyle, overlayClassName, ...props }, ref) => (
41 <AlertDialogPortal>
42 <AlertDialogOverlay className={overlayClassName} style={overlayStyle} />
43 <AlertDialogPrimitive.Content
44 ref={ref}
45 className={cn(
46 'fixed left-[50%] top-[50%] z-50 grid w-[calc(100%-32px)] sm:w-full max-w-lg min-h-[200px] sm:min-h-0 translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-5 sm:p-6 shadow-2xl 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%] rounded-xl',
47 className,
48 )}
49 {...props}
50 />
51 </AlertDialogPortal>
52 ))
53 AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName
54
55 function AlertDialogHeader({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
56 return (
57 <div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} />
58 )
59 }
60 AlertDialogHeader.displayName = 'AlertDialogHeader'
61
62 function AlertDialogFooter({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
63 return (
64 <div
65 className={cn('flex flex-row gap-2 [&>button]:flex-1 sm:[&>button]:flex-initial sm:justify-end [&>button]:min-h-[44px] sm:[&>button]:min-h-[36px]', className)}
66 {...props}
67 />
68 )
69 }
70 AlertDialogFooter.displayName = 'AlertDialogFooter'
71
72 const AlertDialogTitle = React.forwardRef<
73 React.ElementRef<typeof AlertDialogPrimitive.Title>,
74 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
75 >(({ className, ...props }, ref) => (
76 <AlertDialogPrimitive.Title
77 ref={ref}
78 className={cn('text-lg font-semibold', className)}
79 {...props}
80 />
81 ))
82 AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName
83
84 const AlertDialogDescription = React.forwardRef<
85 React.ElementRef<typeof AlertDialogPrimitive.Description>,
86 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
87 >(({ className, ...props }, ref) => (
88 <AlertDialogPrimitive.Description
89 ref={ref}
90 className={cn('text-sm text-muted-foreground', className)}
91 {...props}
92 />
93 ))
94 AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName
95
96 const AlertDialogAction = React.forwardRef<
97 React.ElementRef<typeof AlertDialogPrimitive.Action>,
98 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
99 >(({ className, ...props }, ref) => (
100 <AlertDialogPrimitive.Action ref={ref} className={cn(buttonVariants(), className)} {...props} />
101 ))
102 AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName
103
104 const AlertDialogCancel = React.forwardRef<
105 React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
106 React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
107 >(({ className, ...props }, ref) => (
108 <AlertDialogPrimitive.Cancel
109 ref={ref}
110 className={cn(buttonVariants({ variant: 'outline' }), className)}
111 {...props}
112 />
113 ))
114 AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName
115
116 export {
117 AlertDialog,
118 AlertDialogAction,
119 AlertDialogCancel,
120 AlertDialogContent,
121 AlertDialogDescription,
122 AlertDialogFooter,
123 AlertDialogHeader,
124 AlertDialogOverlay,
125 AlertDialogPortal,
126 AlertDialogTitle,
127 AlertDialogTrigger,
128 }
129
129 lines Plain Text