Skip to content

Commit 8ba2aaa

Browse files
committed
Refactor
1 parent b62f2d9 commit 8ba2aaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ const Tooltip: React.FC<{ field: FormField; children: React.ReactNode }> = ({ fi
1818
const { t } = useTranslation();
1919
return (
2020
<CarbonTooltip align="top-left" label={t(field.questionInfo)} defaultOpen>
21-
<span className={styles.tooltip}>
22-
{children} <Information className={styles.tooltipIcon} />
23-
</span>
21+
{children}
2422
</CarbonTooltip>
2523
);
2624
};
2725

28-
const FieldLabelContent: React.FC<FieldLabelProps> = ({ field, customLabel }) => {
26+
interface FieldLabelContentProps extends FieldLabelProps {
27+
hasTooltip: boolean;
28+
}
29+
30+
const FieldLabelContent: React.FC<FieldLabelContentProps> = ({ field, customLabel, hasTooltip }) => {
2931
const { t } = useTranslation();
3032
const labelText = customLabel || t(field.label);
3133
return (
@@ -36,17 +38,19 @@ const FieldLabelContent: React.FC<FieldLabelProps> = ({ field, customLabel }) =>
3638
*
3739
</span>
3840
)}
41+
{hasTooltip && <Information size={20} aria-hidden="true" className={styles.tooltipIcon} />}
3942
</div>
4043
);
4144
};
4245

4346
const FieldLabel: React.FC<FieldLabelProps> = ({ field, customLabel }) => {
44-
return field?.questionInfo ? (
47+
const hasTooltip = Boolean(field.questionInfo);
48+
return hasTooltip ? (
4549
<Tooltip field={field}>
46-
<FieldLabelContent field={field} customLabel={customLabel} />
50+
<FieldLabelContent field={field} customLabel={customLabel} hasTooltip={hasTooltip} />
4751
</Tooltip>
4852
) : (
49-
<FieldLabelContent field={field} customLabel={customLabel} />
53+
<FieldLabelContent field={field} customLabel={customLabel} hasTooltip={hasTooltip} />
5054
);
5155
};
5256

0 commit comments

Comments
 (0)