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

57 lines
1.8 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
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;
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;
copy?: CopyProps; // CopyProps clashes with propTypes
2019-10-17 12:38:44 -04:00
mode?: 'view' | 'edit' | 'multi-edit';
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 {
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}
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}
name={props.slug + props.slugModifier ?? ''}
2020-01-06 11:21:44 -05:00
value={props.value}
onChange={props.onChange}
disabled={props.mode === 'view' || props.disabled}
2020-01-06 11:21:44 -05:00
maxLength={props.maxLength}
placeholder={props.placeholder}
isUrl={props.isUrl}
required={props.required}
2020-01-06 11:21:44 -05:00
valueTransform={props.valueTransform}
/>
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
};