/** Small modal dialogs of the Keymap page: keymap name (Duplicate / Rename) and confirmations. */ import { useId, useState } from "react"; import { Dialog, Input, T } from "@/ui"; import { validateKeymapName, type CustomKeymaps } from "./model"; import styles from "./Keymap.module.css"; export function KeymapNameDialog({ title, initial, customs, ownId, onCancel, onSubmit, }: { title: string; initial: string; customs: CustomKeymaps; ownId?: string; onCancel: () => void; onSubmit: (name: string) => void; }) { const [name, setName] = useState(initial); const id = useId(); const error = validateKeymapName(name, customs, ownId); const submit = () => !error && onSubmit(name.trim()); return (
setName(e.target.value)} onFocus={(e) => e.currentTarget.select()} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); submit(); } }} />
{error && name.trim() !== "" &&
{error}
}
); }