|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import * as DialogPrimitive from "@radix-ui/react-dialog"; |
4 | | -import { Cross2Icon } from "@radix-ui/react-icons"; |
| 4 | +import { XIcon } from "lucide-react"; |
5 | 5 | import * as React from "react"; |
6 | 6 |
|
7 | | -import { cn } from "@renderer/lib/utils"; |
| 7 | +import { cn } from "@/lib/utils"; |
8 | 8 |
|
9 | | -const Dialog = DialogPrimitive.Root; |
| 9 | +function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) { |
| 10 | + return <DialogPrimitive.Root data-slot='dialog' {...props} />; |
| 11 | +} |
10 | 12 |
|
11 | | -const DialogTrigger = DialogPrimitive.Trigger; |
| 13 | +function DialogTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>) { |
| 14 | + return <DialogPrimitive.Trigger data-slot='dialog-trigger' {...props} />; |
| 15 | +} |
12 | 16 |
|
13 | | -const DialogPortal = DialogPrimitive.Portal; |
| 17 | +function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) { |
| 18 | + return <DialogPrimitive.Portal data-slot='dialog-portal' {...props} />; |
| 19 | +} |
14 | 20 |
|
15 | | -const DialogClose = DialogPrimitive.Close; |
| 21 | +function DialogClose({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>) { |
| 22 | + return <DialogPrimitive.Close data-slot='dialog-close' {...props} />; |
| 23 | +} |
16 | 24 |
|
17 | | -const DialogOverlay = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Overlay>, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>>( |
18 | | - ({ className, ...props }, ref) => ( |
| 25 | +function DialogOverlay({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Overlay>) { |
| 26 | + return ( |
19 | 27 | <DialogPrimitive.Overlay |
20 | | - ref={ref} |
| 28 | + data-slot='dialog-overlay' |
21 | 29 | className={cn( |
22 | | - "fixed inset-0 z-50 bg-black/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", |
| 30 | + "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", |
23 | 31 | className, |
24 | 32 | )} |
25 | 33 | {...props} |
26 | 34 | /> |
27 | | - ), |
28 | | -); |
29 | | -DialogOverlay.displayName = DialogPrimitive.Overlay.displayName; |
| 35 | + ); |
| 36 | +} |
30 | 37 |
|
31 | | -const DialogContent = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Content>, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>>( |
32 | | - ({ className, children, ...props }, ref) => ( |
33 | | - <DialogPortal> |
| 38 | +function DialogContent({ |
| 39 | + className, |
| 40 | + children, |
| 41 | + showCloseButton = true, |
| 42 | + ...props |
| 43 | +}: React.ComponentProps<typeof DialogPrimitive.Content> & { |
| 44 | + showCloseButton?: boolean; |
| 45 | +}) { |
| 46 | + return ( |
| 47 | + <DialogPortal data-slot='dialog-portal'> |
34 | 48 | <DialogOverlay /> |
35 | 49 | <DialogPrimitive.Content |
36 | | - ref={ref} |
| 50 | + data-slot='dialog-content' |
37 | 51 | className={cn( |
38 | | - "fixed left-[50%] top-[50%] z-50 grid w-full outline-none overflow-y-auto max-h-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background py-6 px-4 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", |
| 52 | + "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", |
39 | 53 | className, |
40 | 54 | )} |
41 | 55 | {...props}> |
42 | 56 | {children} |
43 | | - <DialogPrimitive.Close className='absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground'> |
44 | | - <Cross2Icon className='h-4 w-4' /> |
45 | | - <span className='sr-only'>Close</span> |
46 | | - </DialogPrimitive.Close> |
| 57 | + {showCloseButton && ( |
| 58 | + <DialogPrimitive.Close |
| 59 | + data-slot='dialog-close' |
| 60 | + className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"> |
| 61 | + <XIcon /> |
| 62 | + <span className='sr-only'>Close</span> |
| 63 | + </DialogPrimitive.Close> |
| 64 | + )} |
47 | 65 | </DialogPrimitive.Content> |
48 | 66 | </DialogPortal> |
49 | | - ), |
50 | | -); |
51 | | -DialogContent.displayName = DialogPrimitive.Content.displayName; |
| 67 | + ); |
| 68 | +} |
52 | 69 |
|
53 | | -const DialogHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
54 | | - <div className={cn("flex flex-col space-y-1.5 text-center sm:text-left", className)} {...props} /> |
55 | | -); |
56 | | -DialogHeader.displayName = "DialogHeader"; |
| 70 | +function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { |
| 71 | + return <div data-slot='dialog-header' className={cn("flex flex-col gap-2 text-center sm:text-left", className)} {...props} />; |
| 72 | +} |
57 | 73 |
|
58 | | -const DialogFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => ( |
59 | | - <div className={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...props} /> |
60 | | -); |
61 | | -DialogFooter.displayName = "DialogFooter"; |
| 74 | +function DialogFooter({ className, ...props }: React.ComponentProps<"div">) { |
| 75 | + return <div data-slot='dialog-footer' className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)} {...props} />; |
| 76 | +} |
62 | 77 |
|
63 | | -const DialogTitle = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Title>, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>>( |
64 | | - ({ className, ...props }, ref) => <DialogPrimitive.Title ref={ref} className={cn("text-lg font-semibold leading-none tracking-tight", className)} {...props} />, |
65 | | -); |
66 | | -DialogTitle.displayName = DialogPrimitive.Title.displayName; |
| 78 | +function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) { |
| 79 | + return <DialogPrimitive.Title data-slot='dialog-title' className={cn("text-lg leading-none font-semibold", className)} {...props} />; |
| 80 | +} |
67 | 81 |
|
68 | | -const DialogDescription = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Description>, React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>>( |
69 | | - ({ className, ...props }, ref) => <DialogPrimitive.Description ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />, |
70 | | -); |
71 | | -DialogDescription.displayName = DialogPrimitive.Description.displayName; |
| 82 | +function DialogDescription({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Description>) { |
| 83 | + return <DialogPrimitive.Description data-slot='dialog-description' className={cn("text-muted-foreground text-sm", className)} {...props} />; |
| 84 | +} |
72 | 85 |
|
73 | 86 | export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger }; |
0 commit comments