import "./TextInput.scss"; import React, { useState } from "react"; import { focusNearestParent } from "../utils"; import "./ProjectName.scss"; type Props = { value: string; onChange: (value: string) => void; label: string; isNameEditable: boolean; }; export const ProjectName = (props: Props) => { const [fileName, setFileName] = useState(props.value); const handleBlur = (event: any) => { focusNearestParent(event.target); const value = event.target.value; if (value !== props.value) { props.onChange(value); } }; const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === "Enter") { event.preventDefault(); if (event.nativeEvent.isComposing || event.keyCode === 229) { return; } event.currentTarget.blur(); } }; return (
{props.isNameEditable ? ( setFileName(event.target.value)} /> ) : ( {props.value} )}
); };