52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import * as React from "react"
|
||
import { CircleAlertIcon, CircleCheckIcon } from "lucide-react"
|
||
|
||
import { cn } from "../lib/utils"
|
||
import { Button } from "../ui/button"
|
||
|
||
/**
|
||
* Липкая панель внизу формы: показывает, есть ли несохранённые изменения,
|
||
* и даёт «Сохранить» / «Сбросить». Можно добавить свои действия слева.
|
||
*/
|
||
export function SaveBar({
|
||
dirty,
|
||
onSave,
|
||
onReset,
|
||
saveLabel = "Сохранить",
|
||
error,
|
||
children,
|
||
className,
|
||
}: {
|
||
dirty: boolean
|
||
onSave: () => void
|
||
onReset?: () => void
|
||
saveLabel?: string
|
||
/** Блокирует сохранение и показывается вместо статуса. */
|
||
error?: string | null
|
||
children?: React.ReactNode
|
||
className?: string
|
||
}) {
|
||
return (
|
||
<div className={cn("sticky bottom-0 z-20 flex flex-wrap items-center gap-2 border-t bg-card/95 px-5 py-3 backdrop-blur", className)}>
|
||
{children}
|
||
<span
|
||
className={cn(
|
||
"ml-auto inline-flex items-center gap-1.5 text-xs",
|
||
error ? "text-destructive" : dirty ? "text-warning" : "text-muted-foreground",
|
||
)}
|
||
>
|
||
{error || dirty ? <CircleAlertIcon className="size-3.5" /> : <CircleCheckIcon className="size-3.5" />}
|
||
{error ?? (dirty ? "Есть несохранённые изменения" : "Все изменения сохранены")}
|
||
</span>
|
||
{onReset && (
|
||
<Button variant="ghost" size="sm" disabled={!dirty} onClick={onReset}>
|
||
Сбросить
|
||
</Button>
|
||
)}
|
||
<Button size="sm" disabled={!dirty || Boolean(error)} onClick={onSave}>
|
||
{saveLabel}
|
||
</Button>
|
||
</div>
|
||
)
|
||
}
|