infoalloggi-monorepo/apps/infoalloggi/src/components/confirm.tsx
2025-08-04 17:45:44 +02:00

63 lines
1.6 KiB
TypeScript

import { cn } from "~/lib/utils";
import {
AlertDialog,
AlertDialogTrigger,
AlertDialogContent,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogCancel,
AlertDialogAction,
} from "~/components/ui/alert-dialog";
import { buttonVariants } from "~/components/ui/button";
import type { ReactNode } from "react";
export const Confirm = ({
children,
title,
description,
onConfirm,
onCancel,
open,
setOpen,
onlyHedless,
cancelText,
confirmText,
}: {
children: ReactNode;
title: string;
description: string;
onConfirm: () => void;
onCancel?: () => void;
open?: boolean;
setOpen?: (open: boolean) => void;
onlyHedless?: boolean;
cancelText?: string;
confirmText?: string;
}) => {
return (
<AlertDialog open={open} onOpenChange={setOpen}>
{onlyHedless ? null : (
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
)}
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
<AlertDialogDescription>{description}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel onClick={() => onCancel && onCancel()}>
{cancelText || "Annulla"}
</AlertDialogCancel>
<AlertDialogAction
className={cn(buttonVariants({ variant: "destructive" }))}
onClick={() => onConfirm()}
>
{confirmText || "Conferma"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};