Files
emdash-patch-imageupload/packages/admin/src/components/SaveButton.tsx
kunthawat 2d1be52177 Emdash source with visual editor image upload fix
Fixes:
1. media.ts: wrap placeholder generation in try-catch
2. toolbar.ts: check r.ok, display error message in popover
2026-05-03 10:44:54 +07:00

48 lines
1.3 KiB
TypeScript

/**
* Save Button with inline feedback
*
* Shows state based on whether there are unsaved changes:
* - "Saved" when clean (no unsaved changes)
* - "Save" when dirty (has unsaved changes)
* - "Saving..." while saving
*/
import { Button, Loader } from "@cloudflare/kumo";
import { useLingui } from "@lingui/react/macro";
import { FloppyDisk, Check } from "@phosphor-icons/react";
import type { ComponentProps } from "react";
import * as React from "react";
import { cn } from "../lib/utils";
export interface SaveButtonProps extends Omit<ComponentProps<typeof Button>, "children" | "shape"> {
/** Whether there are unsaved changes */
isDirty: boolean;
/** Whether currently saving */
isSaving: boolean;
}
/**
* Button that reflects save state
*/
export function SaveButton({ isDirty, isSaving, className, disabled, ...props }: SaveButtonProps) {
const { t } = useLingui();
const isSaved = !isDirty && !isSaving;
return (
<Button
className={cn("min-w-[100px] transition-all", className)}
disabled={disabled || isSaving || isSaved}
variant={isSaved ? "secondary" : "primary"}
icon={isSaving ? <Loader size="sm" /> : isSaved ? <Check /> : <FloppyDisk />}
aria-live="polite"
aria-busy={isSaving}
{...props}
>
{isSaving ? t`Saving...` : isSaved ? t`Saved` : t`Save`}
</Button>
);
}
export default SaveButton;