hi-frontend/packages/ui/src/composed/confirm-button.tsx
speakeloudest 644b20ebef
Some checks are pending
Build and Release / Build (push) Waiting to run
工单组件
2026-05-01 17:09:24 +03:00

54 lines
1.3 KiB
TypeScript

"use client";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@workspace/ui/components/alert-dialog";
import type React from "react";
import type { ReactNode } from "react";
interface ConfirmationButtonProps {
trigger: ReactNode;
title: string;
description: ReactNode;
onConfirm: () => void | Promise<void>;
cancelText?: string;
confirmText?: string;
}
export const ConfirmButton: React.FC<ConfirmationButtonProps> = ({
trigger,
title,
description,
onConfirm,
cancelText = "Cancel",
confirmText = "Confirm",
}) => (
<AlertDialog>
<AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{title}</AlertDialogTitle>
<AlertDialogDescription asChild>
{typeof description === "string" ? (
<span>{description}</span>
) : (
<div>{description}</div>
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{cancelText}</AlertDialogCancel>
<AlertDialogAction onClick={onConfirm}>{confirmText}</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);