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

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-08-14 16:54:31 -04:00
import React, { Fragment } from 'react';
import { CopyProps } from '../data-containers/category-view-props';
2019-08-14 16:54:31 -04:00
2019-11-07 02:39:26 -05:00
import { DataTitleCopyable } from './data-title';
2019-10-17 08:15:48 -04:00
interface BaseDataEntryProps {
slug: string;
title: string;
tooltip?: string;
disabled?: boolean;
copy?: CopyProps; // CopyProps clashes with propTypes
2019-10-17 12:38:44 -04:00
mode?: 'view' | 'edit' | 'multi-edit';
onChange?: (key: string, value: any) => void;
2019-10-17 08:15:48 -04:00
}
interface DataEntryProps extends BaseDataEntryProps {
value?: string;
2019-10-17 08:15:48 -04:00
maxLength?: number;
placeholder?: string;
valueTransform?: (string) => string
2019-10-17 08:15:48 -04:00
}
const DataEntry: React.FunctionComponent<DataEntryProps> = (props) => {
2019-08-14 16:54:31 -04:00
return (
<Fragment>
<DataTitleCopyable
slug={props.slug}
title={props.title}
tooltip={props.tooltip}
disabled={props.disabled}
copy={props.copy}
/>
<input className="form-control" type="text"
id={props.slug}
name={props.slug}
value={props.value || ''}
maxLength={props.maxLength}
disabled={props.mode === 'view' || 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);
}}
/>
2019-08-14 16:54:31 -04:00
</Fragment>
);
}
export default DataEntry;
2019-10-17 08:15:48 -04:00
export {
BaseDataEntryProps
};