forked from jordanlambrecht/tracker-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveDiscardBar.tsx
More file actions
71 lines (65 loc) · 1.71 KB
/
Copy pathSaveDiscardBar.tsx
File metadata and controls
71 lines (65 loc) · 1.71 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
63
64
65
66
67
68
69
70
71
// src/components/ui/SaveDiscardBar.tsx
import clsx from "clsx"
import { Button } from "@/components/ui/Button"
interface SaveDiscardBarProps {
dirty: boolean
saving: boolean
onSave?: () => void
onDiscard?: () => void
error?: string | null
success?: string | null
saveLabel?: string
savingLabel?: string
className?: string
justify?: "start" | "end"
showDivider?: boolean
saveDisabled?: boolean
}
function SaveDiscardBar({
dirty,
saving,
onSave,
onDiscard,
error,
success,
saveLabel = "Save Changes",
savingLabel = "Saving...",
className,
justify = "start",
showDivider = true,
saveDisabled = false,
}: SaveDiscardBarProps) {
if (!dirty && !error && !success) return null
const content = (
<>
{error && (
<p className="text-xs font-sans text-danger" role="alert">
{error}
</p>
)}
{success && <p className="text-xs font-sans text-success">{success}</p>}
{dirty && (
<>
{showDivider && <div className="border-t border-border" />}
<div className={clsx("flex items-center gap-3", justify === "end" && "justify-end")}>
<Button size="sm" onClick={onSave} disabled={saving || saveDisabled || !onSave}>
{saving ? savingLabel : saveLabel}
</Button>
{onDiscard && (
<Button
size="sm"
variant="ghost"
onClick={onDiscard}
disabled={saving}
text="Discard"
/>
)}
</div>
</>
)}
</>
)
return className ? <div className={className}>{content}</div> : content
}
export type { SaveDiscardBarProps }
export { SaveDiscardBar }