import React, { SFC, ComponentType } from 'react'; import PropTypes from 'prop-types'; import get from 'lodash/get'; import { withStyles, WithStyles, createStyles } from '@material-ui/core/styles'; import classnames from 'classnames'; import sanitizeRestProps from './sanitizeRestProps'; import { FieldProps, InjectedFieldProps, fieldPropTypes } from './types'; const styles = createStyles({ root: { display: 'inline-block' }, }); interface Props extends FieldProps { src?: string; title?: string; target?: string; } export const FileField: SFC< Props & InjectedFieldProps & WithStyles > = ({ classes, className, record, source, title, src, target, ...rest }) => { const sourceValue = get(record, source); if (!sourceValue) { return (
); } if (Array.isArray(sourceValue)) { return ( ); } const titleValue = get(record, title) || title; return (
{titleValue}
); }; const EnhancedFileField = withStyles(styles)(FileField) as ComponentType; EnhancedFileField.defaultProps = { addLabel: true, }; EnhancedFileField.propTypes = { ...fieldPropTypes, src: PropTypes.string, title: PropTypes.string, target: PropTypes.string, }; EnhancedFileField.displayName = 'EnhancedFileField'; export default EnhancedFileField;