forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfirmRemove.tsx
More file actions
62 lines (56 loc) · 1.28 KB
/
Copy pathConfirmRemove.tsx
File metadata and controls
62 lines (56 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// src/components/ui/ConfirmRemove.tsx
"use client"
import { useState } from "react"
import { Button } from "@/components/ui/Button"
interface ConfirmRemoveProps {
onConfirm: () => void
label?: string
confirmLabel?: string
variant?: "danger" | "ghost"
className?: string
/** Disables buttons and shows busyLabel while processing */
busy?: boolean
busyLabel?: string
}
function ConfirmRemove({
onConfirm,
label = "Remove",
confirmLabel = "Confirm Remove",
variant = "danger",
className,
busy,
busyLabel,
}: ConfirmRemoveProps) {
const [confirming, setConfirming] = useState(false)
if (confirming) {
return (
<div className="flex items-center gap-2">
<Button
size="sm"
variant="danger"
onClick={onConfirm}
disabled={busy}
text={busy && busyLabel ? busyLabel : confirmLabel}
/>
<Button
size="sm"
variant="ghost"
onClick={() => setConfirming(false)}
disabled={busy}
text="Cancel"
/>
</div>
)
}
return (
<Button
size="sm"
variant={variant}
className={className}
onClick={() => setConfirming(true)}
text={label}
/>
)
}
export type { ConfirmRemoveProps }
export { ConfirmRemove }