infoalloggi-monorepo/apps/infoalloggi/src/components/confirm.tsx

64 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import type { ReactNode } from "react";
2025-08-04 17:45:44 +02:00
import {
2025-08-28 18:27:07 +02:00
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
2025-08-04 17:45:44 +02:00
} from "~/components/ui/alert-dialog";
import { buttonVariants } from "~/components/ui/button";
2025-08-28 18:27:07 +02:00
import { cn } from "~/lib/utils";
2025-08-04 17:45:44 +02:00
export const Confirm = ({
2025-08-28 18:27:07 +02:00
children,
title,
description,
onConfirm,
onCancel,
open,
setOpen,
onlyHedless,
cancelText,
confirmText,
2025-08-04 17:45:44 +02:00
}: {
2025-08-28 18:27:07 +02:00
children: ReactNode;
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
title: string;
description: string;
onConfirm: () => void;
onCancel?: () => void;
open?: boolean;
setOpen?: (open: boolean) => void;
onlyHedless?: boolean;
cancelText?: string;
confirmText?: string;
2025-08-04 17:45:44 +02:00
}) => {
2025-08-28 18:27:07 +02:00
return (
2025-08-29 16:18:32 +02:00
<AlertDialog onOpenChange={setOpen} open={open}>
2025-08-28 18:27:07 +02:00
{onlyHedless ? null : (
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
)}
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
<AlertDialogDescription>{description}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => onCancel?.()}>
{cancelText || "Annulla"}
</AlertDialogCancel>
<AlertDialogAction
className={cn(buttonVariants({ variant: "destructive" }))}
onClick={() => onConfirm()}
>
{confirmText || "Conferma"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
2025-08-04 17:45:44 +02:00
};