refactor(react/collections/table): deduplicate editing

This commit is contained in:
Elian Doran
2025-09-11 21:51:02 +03:00
parent cb84e4c7b6
commit 62452b61b1
3 changed files with 49 additions and 50 deletions

View File

@@ -242,3 +242,42 @@ function AddNewColumn({ viewConfig, saveConfig }: { viewConfig?: BoardViewData,
</div>
)
}
export function TitleEditor({ currentValue, save, dismiss }: {
currentValue: string,
save: (newValue: string) => void,
dismiss: () => void
}) {
const inputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
inputRef.current?.focus();
inputRef.current?.select();
}, [ inputRef ]);
return (
<FormTextBox
inputRef={inputRef}
currentValue={currentValue}
onKeyDown={(e) => {
if (e.key === "Enter") {
const newValue = e.currentTarget.value;
if (newValue !== currentValue) {
save(newValue);
}
dismiss();
}
if (e.key === "Escape") {
dismiss();
}
}}
onBlur={(newValue) => {
if (newValue !== currentValue) {
save(newValue);
}
dismiss();
}}
/>
)
}