2019-08-14 16:54:31 -04:00
|
|
|
import React, { Fragment } from 'react';
|
|
|
|
|
2019-11-05 15:13:10 -05:00
|
|
|
import { CopyProps } from '../data-containers/category-view-props';
|
2019-08-14 16:54:31 -04:00
|
|
|
|
2020-01-06 14:48:47 -05:00
|
|
|
import { DataEntryInput, TextDataEntryInputProps } from './data-entry-input';
|
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;
|
2021-03-11 14:06:25 -05:00
|
|
|
slugModifier?: string | number; // string used with slug with array items (ensures the form labels link to the input for the correct item)
|
2019-10-17 08:15:48 -04:00
|
|
|
title: string;
|
|
|
|
tooltip?: string;
|
|
|
|
disabled?: boolean;
|
2019-11-05 15:13:10 -05:00
|
|
|
copy?: CopyProps; // CopyProps clashes with propTypes
|
2019-10-17 12:38:44 -04:00
|
|
|
mode?: 'view' | 'edit' | 'multi-edit';
|
2021-03-11 14:00:49 -05:00
|
|
|
isUrl?: boolean;
|
|
|
|
required?: boolean;
|
2019-10-17 12:38:44 -04:00
|
|
|
onChange?: (key: string, value: any) => void;
|
2019-10-17 08:15:48 -04:00
|
|
|
}
|
|
|
|
|
2020-01-06 11:21:44 -05:00
|
|
|
interface DataEntryProps extends BaseDataEntryProps, TextDataEntryInputProps {
|
2019-11-05 15:13:10 -05:00
|
|
|
value?: string;
|
2019-10-17 08:15:48 -04:00
|
|
|
}
|
|
|
|
|
2020-01-06 11:21:44 -05:00
|
|
|
const DataEntry: React.FC<DataEntryProps> = (props) => {
|
2019-08-14 16:54:31 -04:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<DataTitleCopyable
|
|
|
|
slug={props.slug}
|
2021-03-11 14:06:25 -05:00
|
|
|
slugModifier={props.slugModifier}
|
2019-08-14 16:54:31 -04:00
|
|
|
title={props.title}
|
|
|
|
tooltip={props.tooltip}
|
2019-11-22 14:30:03 -05:00
|
|
|
disabled={props.disabled || props.value == undefined || props.value == ''}
|
2019-08-14 16:54:31 -04:00
|
|
|
copy={props.copy}
|
|
|
|
/>
|
2020-01-06 14:48:47 -05:00
|
|
|
<DataEntryInput
|
2020-01-06 11:21:44 -05:00
|
|
|
slug={props.slug}
|
2021-03-11 14:06:25 -05:00
|
|
|
name={props.slug + props.slugModifier ?? ''}
|
2020-01-06 11:21:44 -05:00
|
|
|
value={props.value}
|
|
|
|
onChange={props.onChange}
|
2019-08-23 12:35:17 -04:00
|
|
|
disabled={props.mode === 'view' || props.disabled}
|
2020-08-04 10:54:49 -04:00
|
|
|
|
2020-01-06 11:21:44 -05:00
|
|
|
maxLength={props.maxLength}
|
2019-08-23 12:35:17 -04:00
|
|
|
placeholder={props.placeholder}
|
2021-03-11 14:00:49 -05:00
|
|
|
isUrl={props.isUrl}
|
|
|
|
required={props.required}
|
2020-01-06 11:21:44 -05:00
|
|
|
valueTransform={props.valueTransform}
|
2019-08-23 12:35:17 -04:00
|
|
|
/>
|
2019-08-14 16:54:31 -04:00
|
|
|
</Fragment>
|
|
|
|
);
|
2019-11-07 03:13:30 -05:00
|
|
|
};
|
2019-08-14 16:54:31 -04:00
|
|
|
|
|
|
|
export default DataEntry;
|
2019-10-17 08:15:48 -04:00
|
|
|
export {
|
|
|
|
BaseDataEntryProps
|
|
|
|
};
|