1
1
import React from 'react' ;
2
+ import { Tooltip as CarbonTooltip } from '@carbon/react' ;
2
3
import { useTranslation } from 'react-i18next' ;
3
4
import { type FormField } from '../../types' ;
4
- import Tooltip from '../inputs/tooltip/tooltip.component' ;
5
5
6
6
import styles from './field-label.scss' ;
7
+ import { Information } from '@carbon/react/icons' ;
7
8
8
9
interface FieldLabelProps {
9
10
field : FormField ;
@@ -13,7 +14,18 @@ interface FieldLabelProps {
13
14
customLabel ?: string ;
14
15
}
15
16
16
- const FieldLabel : React . FC < FieldLabelProps > = ( { field, customLabel } ) => {
17
+ const Tooltip : React . FC < { field : FormField ; children : React . ReactNode } > = ( { field, children } ) => {
18
+ const { t } = useTranslation ( ) ;
19
+ return (
20
+ < CarbonTooltip align = "top-left" label = { t ( field . questionInfo ) } defaultOpen >
21
+ < span className = { styles . tooltip } >
22
+ { children } < Information className = { styles . tooltipIcon } />
23
+ </ span >
24
+ </ CarbonTooltip >
25
+ ) ;
26
+ } ;
27
+
28
+ const FieldLabelContent : React . FC < FieldLabelProps > = ( { field, customLabel } ) => {
17
29
const { t } = useTranslation ( ) ;
18
30
const labelText = customLabel || t ( field . label ) ;
19
31
return (
@@ -24,9 +36,18 @@ const FieldLabel: React.FC<FieldLabelProps> = ({ field, customLabel }) => {
24
36
*
25
37
</ span >
26
38
) }
27
- { field . questionInfo && < Tooltip field = { field } /> }
28
39
</ div >
29
40
) ;
30
41
} ;
31
42
43
+ const FieldLabel : React . FC < FieldLabelProps > = ( { field, customLabel } ) => {
44
+ return field ?. questionInfo ? (
45
+ < Tooltip field = { field } >
46
+ < FieldLabelContent field = { field } customLabel = { customLabel } />
47
+ </ Tooltip >
48
+ ) : (
49
+ < FieldLabelContent field = { field } customLabel = { customLabel } />
50
+ ) ;
51
+ } ;
52
+
32
53
export default FieldLabel ;
0 commit comments