Manuel Bustillo 38ca2c3409
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 3m6s
Add copyright notice / copyright_notice (pull_request) Successful in 5m9s
Playwright Tests / test (pull_request) Successful in 8m52s
Allow inline editing of guest name
2024-11-11 08:01:45 +01:00

34 lines
984 B
TypeScript

/* Copyright (C) 2024 Manuel Bustillo*/
import React, { useState } from 'react';
export default function InlineTextField({ initialValue, onChange }: { initialValue: string, onChange: (value: string) => void }) {
const [editing, setEditing] = useState(false);
const [value, setValue] = useState(initialValue);
const renderText = () => <span onClick={() => setEditing(true)}>{value}</span>
const onConfirm = () => {
onChange(value);
setEditing(false);
}
function renderForm() {
return (
<div className="flex flex-row">
<input
type="text"
value={value}
className="px-2 py-0 h-5 max-w-48"
onChange={(e) => setValue(e.target.value)}
onBlur={onConfirm}
autoFocus
/>
</div>
)
}
return (
editing ? (renderForm()) : (renderText())
);
}