forked from marmelab/react-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldTitle.tsx
47 lines (39 loc) · 1.07 KB
/
FieldTitle.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
import * as React from 'react';
import { FunctionComponent, ReactElement, memo } from 'react';
import useTranslate from '../i18n/useTranslate';
import getFieldLabelTranslationArgs from './getFieldLabelTranslationArgs';
interface Props {
isRequired?: boolean;
resource?: string;
source?: string;
label?: string | ReactElement | false;
}
export const FieldTitle: FunctionComponent<Props> = ({
resource,
source,
label,
isRequired,
}) => {
const translate = useTranslate();
if (label === false || label === '') {
return null;
}
if (label && typeof label !== 'string') {
return label;
}
return (
<span>
{translate(
...getFieldLabelTranslationArgs({
label: label as string,
resource,
source,
})
)}
{isRequired && ' *'}
</span>
);
};
// What? TypeScript loses the displayName if we don't set it explicitly
FieldTitle.displayName = 'FieldTitle';
export default memo(FieldTitle);