Skip to content

Commit a254a09

Browse files
committed
Make the whole label as tooltip trigger
1 parent d4cf6dc commit a254a09

File tree

4 files changed

+33
-34
lines changed

4 files changed

+33
-34
lines changed

src/components/field-label/field-label.component.tsx

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
2+
import { Tooltip as CarbonTooltip } from '@carbon/react';
23
import { useTranslation } from 'react-i18next';
34
import { type FormField } from '../../types';
4-
import Tooltip from '../inputs/tooltip/tooltip.component';
55

66
import styles from './field-label.scss';
7+
import { Information } from '@carbon/react/icons';
78

89
interface 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+
3253
export default FieldLabel;

src/components/field-label/field-label.scss

+9
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@
99
display: flex;
1010
align-items: center;
1111
}
12+
13+
.tooltip {
14+
display: flex;
15+
align-items: center;
16+
}
17+
18+
.tooltipIcon {
19+
margin-left: 0.25rem;
20+
}

src/components/inputs/tooltip/tooltip.component.tsx

-23
This file was deleted.

src/components/inputs/tooltip/tooltip.scss

-8
This file was deleted.

0 commit comments

Comments
 (0)