infoalloggi-monorepo/apps/infoalloggi/src/components/ui/dialog.tsx

142 lines
3.7 KiB
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import { XIcon } from "lucide-react";
import { Dialog as DialogPrimitive } from "radix-ui";
import type * as React from "react";
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
import { cn } from "~/lib/utils";
2025-08-04 17:45:44 +02:00
function Dialog({
2025-08-28 18:27:07 +02:00
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
2025-08-28 18:27:07 +02:00
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
2025-08-04 17:45:44 +02:00
}
function DialogTrigger({
2025-08-28 18:27:07 +02:00
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
2025-08-28 18:27:07 +02:00
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
2025-08-04 17:45:44 +02:00
}
function DialogPortal({
2025-08-28 18:27:07 +02:00
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
2025-08-28 18:27:07 +02:00
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
2025-08-04 17:45:44 +02:00
}
function DialogClose({
2025-08-28 18:27:07 +02:00
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
2025-08-28 18:27:07 +02:00
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
2025-08-04 17:45:44 +02:00
}
function DialogOverlay({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
2025-08-28 18:27:07 +02:00
return (
<DialogPrimitive.Overlay
className={cn(
2025-10-10 16:18:43 +02:00
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=open]:animate-in",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-overlay"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function DialogContent({
2025-08-28 18:27:07 +02:00
className,
children,
showCloseButton = true,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
2025-08-28 18:27:07 +02:00
showCloseButton?: boolean;
2025-08-04 17:45:44 +02:00
}) {
2025-08-28 18:27:07 +02:00
return (
<DialogPortal data-slot="dialog-portal">
<DialogOverlay />
<DialogPrimitive.Content
className={cn(
2025-10-10 16:18:43 +02:00
"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 bg-background p-6 shadow-lg duration-200 data-[state=closed]:animate-out data-[state=open]:animate-in sm:max-w-lg",
2025-08-28 18:27:07 +02:00
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-content"
2025-08-28 18:27:07 +02:00
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
2025-10-10 16:18:43 +02:00
className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden 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 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
2025-08-29 16:18:32 +02:00
data-slot="dialog-close"
2025-08-28 18:27:07 +02:00
>
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
);
2025-08-04 17:45:44 +02:00
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
2025-08-28 18:27:07 +02:00
return (
<div
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-header"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
2025-08-28 18:27:07 +02:00
return (
<div
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className,
)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-footer"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function DialogTitle({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
2025-08-28 18:27:07 +02:00
return (
<DialogPrimitive.Title
2025-10-10 16:18:43 +02:00
className={cn("font-semibold text-lg leading-none", className)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-title"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
function DialogDescription({
2025-08-28 18:27:07 +02:00
className,
...props
2025-08-04 17:45:44 +02:00
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
2025-08-28 18:27:07 +02:00
return (
<DialogPrimitive.Description
className={cn("text-muted-foreground text-sm", className)}
2025-08-29 16:18:32 +02:00
data-slot="dialog-description"
2025-08-28 18:27:07 +02:00
{...props}
/>
);
2025-08-04 17:45:44 +02:00
}
export {
2025-08-28 18:27:07 +02:00
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
};