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;
|
2019-10-17 12:38:44 -04:00
|
|
|
copy?: any; // CopyProps clashes with propTypes
|
|
|
|
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;
|
|
|
|
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}
|
|
|
|
/>
|
2019-08-23 12:35:17 -04:00
|
|
|
<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-23 12:35:17 -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,
|
2019-08-23 12:35:17 -04:00
|
|
|
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
|
|
|
|
};
|