import React from "react"; import { Button } from "@openstatus/ui/src/components/button"; import { Kbd } from "../../kbd"; import { LoadingAnimation } from "../../loading-animation"; interface Props { onSubmit?: () => void; isPending?: boolean; isDirty?: boolean; form?: string; } export function SaveButton({ isPending, isDirty, onSubmit, form }: Props) { React.useEffect(() => { const callback = (event: KeyboardEvent) => { // event.metaKey - pressed Command key on Macs // event.ctrlKey - pressed Control key on Linux or Windows if ((event.metaKey || event.ctrlKey) && event.key === "s") { event.preventDefault(); onSubmit?.(); } }; document.addEventListener("keydown", callback); return () => { document.removeEventListener("keydown", callback); }; // no need to listen to `onSubmit` changes }, [onSubmit]); return (
{isDirty ? (

You have unsaved changes

) : null}
); }