import React, { useState } from 'react'; import { AutofillDropdown } from './autofill/autofillDropdown'; export interface TextDataEntryInputProps { slug: string; name?: string; id?: string; onChange?: (key: string, val: any) => void; maxLength?: number; disabled?: boolean; placeholder?: string; valueTransform?: (val: string) => string; autofill?: boolean; } export const DataEntryInput: React.FC = props => { const [isEditing, setEditing] = useState(false); const nameAttr = props.name || props.slug; const idAttr = props.id || props.slug; const handleChange = (value: string) => { console.log(value); const transform = props.valueTransform || (x => x); const transformedValue = value === '' ? null : transform(value); props.onChange(props.slug, transformedValue); }; return ( <> handleChange(e.target.value)} onInput={e => setEditing(true)} onFocus={e => setEditing(true)} onBlur={e => setEditing(false)} /> { props.autofill && handleChange(value)} onClose={() => setEditing(false)} fieldName={props.slug} fieldValue={props.value} /> } ); };