-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
TextField.tsx
49 lines (41 loc) · 1.42 KB
/
TextField.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as React from 'react';
import { FC, memo, ElementType } from 'react';
import get from 'lodash/get';
import Typography, { TypographyProps } from '@material-ui/core/Typography';
import sanitizeFieldRestProps from './sanitizeFieldRestProps';
import { PublicFieldProps, InjectedFieldProps, fieldPropTypes } from './types';
const TextField: FC<TextFieldProps> = memo<TextFieldProps>(
({ className, source, record = {}, emptyText, ...rest }) => {
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>
);
}
);
// what? TypeScript loses the displayName if we don't set it explicitly
TextField.displayName = 'TextField';
TextField.defaultProps = {
addLabel: true,
};
TextField.propTypes = {
// @ts-ignore
...Typography.propTypes,
...fieldPropTypes,
};
export interface TextFieldProps
extends PublicFieldProps,
InjectedFieldProps,
TypographyProps {
// TypographyProps do not expose the component props, see https://github.com/mui-org/material-ui/issues/19512
component?: ElementType<any>;
}
export default TextField;