Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3517897
D4915.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D4915.diff
View Options
diff --git a/web/chat/tooltip-utils.js b/web/chat/tooltip-utils.js
--- a/web/chat/tooltip-utils.js
+++ b/web/chat/tooltip-utils.js
@@ -1,5 +1,6 @@
// @flow
+import invariant from 'invariant';
import * as React from 'react';
import { calculateMaxTextWidth } from '../utils/text-utils';
@@ -178,6 +179,98 @@
}
return defaultPosition;
}
+
+type GetMessageActionTooltipStyleParams = {
+ +sourcePositionInfo: PositionInfo,
+ +tooltipSize: TooltipSize,
+ +tooltipPosition: TooltipPosition,
+};
+
+function getMessageActionTooltipStyle({
+ sourcePositionInfo,
+ tooltipSize,
+ tooltipPosition,
+}: GetMessageActionTooltipStyleParams): TooltipPositionStyle {
+ if (tooltipPosition === tooltipPositions.RIGHT_TOP) {
+ return {
+ xCoord: sourcePositionInfo.right,
+ yCoord: sourcePositionInfo.top,
+ horizontalPosition: 'right',
+ verticalPosition: 'bottom',
+ alignment: 'left',
+ };
+ } else if (tooltipPosition === tooltipPositions.LEFT_TOP) {
+ return {
+ xCoord: sourcePositionInfo.left,
+ yCoord: sourcePositionInfo.top,
+ horizontalPosition: 'left',
+ verticalPosition: 'bottom',
+ alignment: 'right',
+ };
+ } else if (tooltipPosition === tooltipPositions.RIGHT_BOTTOM) {
+ return {
+ xCoord: sourcePositionInfo.right,
+ yCoord: sourcePositionInfo.bottom,
+ horizontalPosition: 'right',
+ verticalPosition: 'top',
+ alignment: 'left',
+ };
+ } else if (tooltipPosition === tooltipPositions.LEFT_BOTTOM) {
+ return {
+ xCoord: sourcePositionInfo.left,
+ yCoord: sourcePositionInfo.bottom,
+ horizontalPosition: 'left',
+ verticalPosition: 'top',
+ alignment: 'right',
+ };
+ } else if (tooltipPosition === tooltipPositions.LEFT) {
+ return {
+ xCoord: sourcePositionInfo.left,
+ yCoord:
+ sourcePositionInfo.top +
+ sourcePositionInfo.height / 2 -
+ tooltipSize.height / 2,
+ horizontalPosition: 'left',
+ verticalPosition: 'bottom',
+ alignment: 'right',
+ };
+ } else if (tooltipPosition === tooltipPositions.RIGHT) {
+ return {
+ xCoord: sourcePositionInfo.right,
+ yCoord:
+ sourcePositionInfo.top +
+ sourcePositionInfo.height / 2 -
+ tooltipSize.height / 2,
+ horizontalPosition: 'right',
+ verticalPosition: 'bottom',
+ alignment: 'left',
+ };
+ } else if (tooltipPosition === tooltipPositions.TOP) {
+ return {
+ xCoord:
+ sourcePositionInfo.left +
+ sourcePositionInfo.width / 2 -
+ tooltipSize.width / 2,
+ yCoord: sourcePositionInfo.top,
+ horizontalPosition: 'right',
+ verticalPosition: 'top',
+ alignment: 'center',
+ };
+ } else if (tooltipPosition === tooltipPositions.BOTTOM) {
+ return {
+ xCoord:
+ sourcePositionInfo.left +
+ sourcePositionInfo.width / 2 -
+ tooltipSize.width / 2,
+ yCoord: sourcePositionInfo.bottom,
+ horizontalPosition: 'right',
+ verticalPosition: 'bottom',
+ alignment: 'center',
+ };
+ }
+ invariant(false, `Unexpected tooltip position value: ${tooltipPosition}`);
+}
+
type CalculateTooltipSizeArgs = {
+tooltipLabels: $ReadOnlyArray<string>,
+timestamp: string,
@@ -212,4 +305,9 @@
};
}
-export { findTooltipPosition, calculateTooltipSize, sizeOfTooltipArrow };
+export {
+ findTooltipPosition,
+ calculateTooltipSize,
+ getMessageActionTooltipStyle,
+ sizeOfTooltipArrow,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 6:33 PM (19 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2695817
Default Alt Text
D4915.diff (3 KB)
Attached To
Mode
D4915: [web] Introduce `getMessageActionTooltipStyle` util function
Attached
Detach File
Event Timeline
Log In to Comment