import * as React from 'react' ; import { memo , FC , ElementType } from 'react' ; import get from 'lodash/get' ; import Typography , { TypographyProps } from '@material-ui/core/Typography' ; import { useRecordContext } from 'ra-core' ; import sanitizeFieldRestProps from './sanitizeFieldRestProps' ; import { PublicFieldProps , InjectedFieldProps , fieldPropTypes } from './types' ; const TextField = memo ( props => { const { className , source , emptyText , ... rest } = props ; const record = useRecordContext ( props ) ; const value = get ( record , source ) ; return ( < Typography component = "span" variant = "body2" className = { className } { ... sanitizeFieldRestProps ( rest ) } > { value != null && typeof value !== 'string' ? JSON . stringify ( value ) : value || emptyText } < /Typography>); } ) ; TextField . displayName = 'TextField' ; TextField . defaultProps = { addLabel : true , } ; TextField . propTypes = { ... Typography . propTypes , ... fieldPropTypes , } ; export interface TextFieldProps extends PublicFieldProps , InjectedFieldProps , TypographyProps { component ? : ElementType < any > ; } export default TextField ;