46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Button } from "@/components/ui/button"
|
|
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"
|
|
|
|
type ConfirmDialogProps = {
|
|
open: boolean
|
|
title: string
|
|
description?: string
|
|
confirmText?: string
|
|
cancelText?: string
|
|
destructive?: boolean
|
|
pending?: boolean
|
|
onOpenChange: (open: boolean) => void
|
|
onConfirm: () => void
|
|
}
|
|
|
|
export function ConfirmDialog({
|
|
open,
|
|
title,
|
|
description,
|
|
confirmText = "确认",
|
|
cancelText = "取消",
|
|
destructive = false,
|
|
pending = false,
|
|
onOpenChange,
|
|
onConfirm,
|
|
}: ConfirmDialogProps) {
|
|
return (
|
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
</DialogHeader>
|
|
{description && <div className="text-sm text-muted-foreground">{description}</div>}
|
|
<DialogFooter>
|
|
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={pending}>
|
|
{cancelText}
|
|
</Button>
|
|
<Button type="button" variant={destructive ? "destructive" : "default"} onClick={onConfirm} disabled={pending}>
|
|
{pending ? "处理中..." : confirmText}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|