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

72 lines
1.9 KiB
TypeScript
Raw Normal View History

2019-08-14 16:54:31 -04:00
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { DataTitleCopyable } from './data-title';
2019-10-17 08:15:48 -04:00
interface BaseDataEntryProps {
slug: string;
title: string;
tooltip?: string;
disabled?: boolean;
copy: any; // CopyProps clashes with propTypes
mode: 'view' | 'edit' | 'multi-edit';
onChange: (key: string, value: any) => void;
}
interface DataEntryProps extends BaseDataEntryProps {
value: string;
maxLength?: number;
placeholder?: string;
}
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}
2019-10-17 08:15:48 -04:00
onChange={e =>
2019-10-17 11:15:28 -04:00
props.onChange(
props.slug,
e.target.value === '' ?
null :
e.target.value
)
2019-10-17 08:15:48 -04:00
}
/>
2019-08-14 16:54:31 -04:00
</Fragment>
);
}
DataEntry.propTypes = {
title: PropTypes.string,
slug: PropTypes.string,
tooltip: PropTypes.string,
disabled: PropTypes.bool,
value: PropTypes.any,
placeholder: PropTypes.string,
maxLength: PropTypes.number,
onChange: PropTypes.func,
2019-08-14 16:54:31 -04:00
copy: PropTypes.shape({
copying: PropTypes.bool,
copyingKey: PropTypes.func,
toggleCopyAttribute: PropTypes.func
})
}
export default DataEntry;
2019-10-17 08:15:48 -04:00
export {
BaseDataEntryProps
};