1"use client"
2
3import * as React from "react"
4import { cn } from "@/lib/utils"
5import { Dialog as DialogPrimitive } from "radix-ui"
6
7import { Button } from "@/components/ui/button"
8import { X } from "@phosphor-icons/react"
9
10function Dialog({
11 ...props
12}: React.ComponentProps<typeof DialogPrimitive.Root>) {
13 return <DialogPrimitive.Root data-slot="dialog" {...props} />
14}
15
16function DialogTrigger({
17 ...props
18}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
19 return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
20}
21
22function DialogPortal({
23 ...props
24}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
25 return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
26}
27
28function DialogClose({
29 ...props
30}: React.ComponentProps<typeof DialogPrimitive.Close>) {
31 return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
32}
33
34function DialogOverlay({
35 className,
36 ...props
37}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
38 return (
39 <DialogPrimitive.Overlay
40 data-slot="dialog-overlay"
41 className={cn(
42 "fixed inset-0 isolate z-50 bg-ink/60 duration-[120ms] data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
43 className
44 )}
45 {...props}
46 />
47 )
48}
49
50function DialogContent({
51 className,
52 children,
53 showCloseButton = true,
54 ...props
55}: React.ComponentProps<typeof DialogPrimitive.Content> & {
56 showCloseButton?: boolean
57}) {
58 return (
59 <DialogPortal>
60 <DialogOverlay />
61 <DialogPrimitive.Content
62 data-slot="dialog-content"
63 className={cn(
64 "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-panel border-3 border-ink bg-paper p-4 text-sm text-ink shadow-hard-lg duration-[120ms] outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
65 className
66 )}
67 {...props}
68 >
69 {children}
70 {showCloseButton && (
71 <DialogPrimitive.Close data-slot="dialog-close" asChild>
72 <Button
73 variant="ghost"
74 className="absolute top-2 right-2"
75 size="icon"
76 >
77 <X weight="bold" className="size-5" />
78 <span className="sr-only">Tutup</span>
79 </Button>
80 </DialogPrimitive.Close>
81 )}
82 </DialogPrimitive.Content>
83 </DialogPortal>
84 )
85}
86
87function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
88 return (
89 <div
90 data-slot="dialog-header"
91 className={cn("flex flex-col gap-2", className)}
92 {...props}
93 />
94 )
95}
96
97function DialogFooter({
98 className,
99 showCloseButton = false,
100 children,
101 ...props
102}: React.ComponentProps<"div"> & {
103 showCloseButton?: boolean
104}) {
105 return (
106 <div
107 data-slot="dialog-footer"
108 className={cn(
109 "-mx-4 -mb-4 flex flex-col-reverse gap-3 rounded-b-panel border-t-3 border-ink bg-cream p-4 sm:flex-row sm:justify-end",
110 className
111 )}
112 {...props}
113 >
114 {children}
115 {showCloseButton && (
116 <DialogPrimitive.Close asChild>
117 <Button variant="neutral">Tutup</Button>
118 </DialogPrimitive.Close>
119 )}
120 </div>
121 )
122}
123
124function DialogTitle({
125 className,
126 ...props
127}: React.ComponentProps<typeof DialogPrimitive.Title>) {
128 return (
129 <DialogPrimitive.Title
130 data-slot="dialog-title"
131 className={cn("font-display text-lg font-extrabold", className)}
132 {...props}
133 />
134 )
135}
136
137function DialogDescription({
138 className,
139 ...props
140}: React.ComponentProps<typeof DialogPrimitive.Description>) {
141 return (
142 <DialogPrimitive.Description
143 data-slot="dialog-description"
144 className={cn(
145 "text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
146 className
147 )}
148 {...props}
149 />
150 )
151}
152
153export {
154 Dialog,
155 DialogClose,
156 DialogContent,
157 DialogDescription,
158 DialogFooter,
159 DialogHeader,
160 DialogOverlay,
161 DialogPortal,
162 DialogTitle,
163 DialogTrigger,
164}
165