import { useState, ReactNode, cloneElement } from "react"; import { Input } from "@/components/ui/input"; interface EditableTextProps { children: ReactNode; onChange: (newText: string) => void; } export default function EditableText({ children, onChange, }: EditableTextProps) { const [isEditing, setIsEditing] = useState(false); const child = Array.isArray(children) ? children[0] : children; const text = child?.props.children || ""; const handleBlur = () => { setIsEditing(false); }; const handleChange = (e: React.ChangeEvent) => { onChange(e.target.value); }; return (
setIsEditing(true)}> {isEditing ? ( ) : ( cloneElement(child, {}, text) )}
); }