colouring-montreal/app/src/frontend/building/data-components/data-entry-input.tsx

31 lines
974 B
TypeScript
Raw Normal View History

2020-01-06 11:21:44 -05:00
import React from 'react';
export interface TextDataEntryInputProps {
slug: string;
maxLength?: number;
disabled?: boolean;
placeholder?: string;
valueTransform?: (val: string) => string;
onChange?: (key: string, val: any) => void;
}
export const TextDataEntryInput: React.FC<TextDataEntryInputProps & {value?: string}> = props => {
return (
<input className="form-control" type="text"
id={props.slug}
name={props.slug}
value={props.value || ''}
maxLength={props.maxLength}
disabled={props.disabled}
placeholder={props.placeholder}
onChange={e => {
const transform = props.valueTransform || (x => x);
const val = e.target.value === '' ?
null :
transform(e.target.value);
props.onChange(props.slug, val);
}}
/>
);
};