infoalloggi-monorepo/apps/infoalloggi/src/components/confirm.tsx
2025-08-29 16:18:32 +02:00

63 lines
1.5 KiB
TypeScript

import type { ReactNode } from "react";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "~/components/ui/alert-dialog";
import { buttonVariants } from "~/components/ui/button";
import { cn } from "~/lib/utils";
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 onOpenChange={setOpen} open={open}>
{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>
);
};