11import React from 'react' ;
2+ import { Tooltip as CarbonTooltip } from '@carbon/react' ;
23import { useTranslation } from 'react-i18next' ;
34import { type FormField } from '../../types' ;
4- import Tooltip from '../inputs/tooltip/tooltip.component' ;
55
66import styles from './field-label.scss' ;
7+ import { Information } from '@carbon/react/icons' ;
78
89interface FieldLabelProps {
910 field : FormField ;
@@ -13,7 +14,18 @@ interface FieldLabelProps {
1314 customLabel ?: string ;
1415}
1516
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 } ) => {
1729 const { t } = useTranslation ( ) ;
1830 const labelText = customLabel || t ( field . label ) ;
1931 return (
@@ -24,9 +36,18 @@ const FieldLabel: React.FC<FieldLabelProps> = ({ field, customLabel }) => {
2436 *
2537 </ span >
2638 ) }
27- { field . questionInfo && < Tooltip field = { field } /> }
2839 </ div >
2940 ) ;
3041} ;
3142
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+
3253export default FieldLabel ;
0 commit comments