1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Revert <Tooltip> changes

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-11-16 11:17:16 -05:00
parent 98367158c0
commit 30f44c13ef

View File

@ -112,21 +112,26 @@ export class Tooltip extends React.Component<TooltipProps> {
@boundMethod @boundMethod
refreshPosition() { refreshPosition() {
const { preferredPositions = [] } = this.props; const { preferredPositions } = this.props;
const { elem, targetElem } = this; const { elem, targetElem } = this;
// Start with the preferred positions let positions = new Set<TooltipPosition>([
const positions = new Set([preferredPositions].flat()); TooltipPosition.RIGHT,
TooltipPosition.BOTTOM,
TooltipPosition.TOP,
TooltipPosition.LEFT,
TooltipPosition.TOP_RIGHT,
TooltipPosition.TOP_LEFT,
TooltipPosition.BOTTOM_RIGHT,
TooltipPosition.BOTTOM_LEFT,
]);
// Then add the default ordering, these won't override the above if (preferredPositions) {
positions.add(TooltipPosition.RIGHT); positions = new Set([
positions.add(TooltipPosition.BOTTOM); ...[preferredPositions].flat(),
positions.add(TooltipPosition.TOP); ...positions,
positions.add(TooltipPosition.LEFT); ]);
positions.add(TooltipPosition.TOP_RIGHT); }
positions.add(TooltipPosition.TOP_LEFT);
positions.add(TooltipPosition.BOTTOM_RIGHT);
positions.add(TooltipPosition.BOTTOM_LEFT);
// reset position first and get all possible client-rect area for tooltip element // reset position first and get all possible client-rect area for tooltip element
this.setPosition({ left: 0, top: 0 }); this.setPosition({ left: 0, top: 0 });
@ -173,35 +178,35 @@ export class Tooltip extends React.Component<TooltipProps> {
const bottomCenter = targetBounds.bottom + offset; const bottomCenter = targetBounds.bottom + offset;
switch (position) { switch (position) {
case TooltipPosition.TOP: case "top":
left = horizontalCenter; left = horizontalCenter;
top = topCenter; top = topCenter;
break; break;
case TooltipPosition.BOTTOM: case "bottom":
left = horizontalCenter; left = horizontalCenter;
top = bottomCenter; top = bottomCenter;
break; break;
case TooltipPosition.LEFT: case "left":
top = verticalCenter; top = verticalCenter;
left = targetBounds.left - tooltipBounds.width - offset; left = targetBounds.left - tooltipBounds.width - offset;
break; break;
case TooltipPosition.RIGHT: case "right":
top = verticalCenter; top = verticalCenter;
left = targetBounds.right + offset; left = targetBounds.right + offset;
break; break;
case TooltipPosition.TOP_LEFT: case "top_left":
left = targetBounds.left; left = targetBounds.left;
top = topCenter; top = topCenter;
break; break;
case TooltipPosition.TOP_RIGHT: case "top_right":
left = targetBounds.right - tooltipBounds.width; left = targetBounds.right - tooltipBounds.width;
top = topCenter; top = topCenter;
break; break;
case TooltipPosition.BOTTOM_LEFT: case "bottom_left":
top = bottomCenter; top = bottomCenter;
left = targetBounds.left; left = targetBounds.left;
break; break;
case TooltipPosition.BOTTOM_RIGHT: case "bottom_right":
top = bottomCenter; top = bottomCenter;
left = targetBounds.right - tooltipBounds.width; left = targetBounds.right - tooltipBounds.width;
break; break;