Skip to content

Commit f9844d3

Browse files
authored
refactor(tooltip): use showWarningIfFirstOccurence to handle tooltip warnings (#314)
1 parent 0088113 commit f9844d3

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/common/warnings.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export enum SDSWarningTypes {
33
ChipDeprecated = "chipDeprecated",
44
MenuSelectDeprecated = "menuSelectDeprecated",
55
ButtonIconMediumSize = "buttonIconMediumSize",
6+
TooltipSubtitle = "tooltipSubtitle",
7+
TooltipWidth = "tooltipWidth",
8+
TooltipInverted = "tooltipInverted",
69
}
710

811
const SDS_WARNINGS = {
@@ -24,6 +27,20 @@ const SDS_WARNINGS = {
2427
hasWarned: false,
2528
message: "Warning: A medium size ButtonIcon can only be of type tertiary!",
2629
},
30+
[SDSWarningTypes.TooltipSubtitle]: {
31+
hasWarned: false,
32+
message:
33+
"Warning: The 'subtitle' text is only available for dark tooltips!",
34+
},
35+
[SDSWarningTypes.TooltipWidth]: {
36+
hasWarned: false,
37+
message: "Warning: The 'wide' width is only available for light tooltips!",
38+
},
39+
[SDSWarningTypes.TooltipInverted]: {
40+
hasWarned: false,
41+
message:
42+
"Warning: Tooltips using the inverted prop will be deprecated. Please use sdsStyle: 'dark' | 'light' instead!",
43+
},
2744
};
2845

2946
export const showWarningIfFirstOccurence = (warningType: SDSWarningTypes) => {

src/core/Tooltip/index.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
} from "@mui/material";
66
import { useTheme } from "@mui/material/styles";
77
import React, { forwardRef } from "react";
8+
import {
9+
SDSWarningTypes,
10+
showWarningIfFirstOccurence,
11+
} from "src/common/warnings";
812
import {
913
arrowCss,
1014
StyledPopper,
@@ -43,24 +47,15 @@ const Tooltip = forwardRef(function Tooltip(
4347
const { children } = rest;
4448

4549
if (inverted) {
46-
// eslint-disable-next-line no-console
47-
console.warn(
48-
"Warning: Tooltips using the inverted prop will be deprecated. Please use sdsStyle: 'dark' | 'light' instead."
49-
);
50+
showWarningIfFirstOccurence(SDSWarningTypes.TooltipInverted);
5051
}
5152

5253
if (width === "wide" && sdsStyle === "dark") {
53-
// eslint-disable-next-line no-console
54-
console.warn(
55-
"Warning: The 'wide' width is only available for light tooltips."
56-
);
54+
showWarningIfFirstOccurence(SDSWarningTypes.TooltipWidth);
5755
}
5856

5957
if (subtitle && sdsStyle === "light") {
60-
// eslint-disable-next-line no-console
61-
console.warn(
62-
"Warning: The 'subtitle' text is only available for dark tooltips."
63-
);
58+
showWarningIfFirstOccurence(SDSWarningTypes.TooltipSubtitle);
6459
}
6560

6661
const theme = useTheme();

0 commit comments

Comments
 (0)