Skip to content

Commit 10b815a

Browse files
fix: move map function to TooltipPlacement.ts back
1 parent 84db441 commit 10b815a

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/components/Tooltip/Tooltip.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { Placement } from '@popperjs/core/lib/enums';
66
import { variant } from 'styled-system';
77
import { Colors, MediaQueries } from '../../essentials';
88
import { get } from '../../utils/themeGet';
9-
import { deprecatedProperty } from '../../utils/deprecatedProperty';
109
import { Text } from '../Text/Text';
11-
import { TooltipPlacement, TOOLTIP_TO_POPPER_PLACEMENT_MAP } from './TooltipPlacement';
10+
import { mapPlacementWithDeprecationWarning, TooltipPlacement } from './TooltipPlacement';
1211

1312
const fadeAnimation = keyframes`
1413
from {
@@ -137,14 +136,6 @@ interface TooltipProps {
137136
alwaysVisible?: boolean;
138137
}
139138

140-
// TODO: Find the right place
141-
const mapWithDeprecationWarning = (placement: TooltipPlacement | Placement): Placement => {
142-
const mappedPlacement = TOOLTIP_TO_POPPER_PLACEMENT_MAP[placement as TooltipPlacement];
143-
if (mappedPlacement)
144-
deprecatedProperty('Tooltip', placement, `Value '${placement}' for placement`, mappedPlacement);
145-
return mappedPlacement ?? (placement as Placement);
146-
};
147-
148139
const Tooltip: React.FC<TooltipProps> = ({
149140
content,
150141
children,
@@ -165,7 +156,7 @@ const Tooltip: React.FC<TooltipProps> = ({
165156
* without introduce any breaking changes to the Tooltip component.
166157
* TODO: Remove in the next major release.
167158
*/
168-
const mappedPlacement = mapWithDeprecationWarning(placement);
159+
const mappedPlacement = mapPlacementWithDeprecationWarning(placement);
169160

170161
const { styles, attributes } = usePopper(triggerReference, contentReference, {
171162
placement: mappedPlacement,

src/components/Tooltip/TooltipPlacement.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Placement } from '@popperjs/core';
2+
import { deprecatedProperty } from '../../utils/deprecatedProperty';
23

34
export type TooltipPlacement =
45
| 'bottom-left'
@@ -10,7 +11,7 @@ export type TooltipPlacement =
1011
| 'center-left'
1112
| 'center-right';
1213

13-
export const TOOLTIP_TO_POPPER_PLACEMENT_MAP: { [key in TooltipPlacement]: Placement } = {
14+
const TOOLTIP_TO_POPPER_PLACEMENT_MAP: { [key in TooltipPlacement]: Placement } = {
1415
'bottom-left': 'bottom-start',
1516
'bottom-center': 'bottom',
1617
'bottom-right': 'bottom-end',
@@ -20,3 +21,10 @@ export const TOOLTIP_TO_POPPER_PLACEMENT_MAP: { [key in TooltipPlacement]: Place
2021
'center-left': 'left',
2122
'center-right': 'right'
2223
};
24+
25+
export const mapPlacementWithDeprecationWarning = (placement: TooltipPlacement | Placement): Placement => {
26+
const mappedPlacement = TOOLTIP_TO_POPPER_PLACEMENT_MAP[placement as TooltipPlacement];
27+
if (mappedPlacement)
28+
deprecatedProperty('Tooltip', placement, `Value '${placement}' for placement`, mappedPlacement);
29+
return mappedPlacement ?? (placement as Placement);
30+
};

0 commit comments

Comments
 (0)