-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
182 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/styles/utils/generators/TooltipStyleUtils/computeHorizontalShift/index.native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type ComputeHorizontalShift from './types'; | ||
|
||
const computeHorizontalShift: ComputeHorizontalShift = () => 0; | ||
|
||
export default computeHorizontalShift; |
42 changes: 42 additions & 0 deletions
42
src/styles/utils/generators/TooltipStyleUtils/computeHorizontalShift/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import roundToNearestMultipleOfFour from '@libs/roundToNearestMultipleOfFour'; | ||
import variables from '@styles/variables'; | ||
import type ComputeHorizontalShift from './types'; | ||
|
||
/** This defines the proximity with the edge of the window in which tooltips should not be displayed. | ||
* If a tooltip is too close to the edge of the screen, we'll shift it towards the center. */ | ||
const GUTTER_WIDTH = variables.gutterWidth; | ||
|
||
/** | ||
* Compute the amount the tooltip needs to be horizontally shifted in order to keep it from displaying in the gutters. | ||
* | ||
* @param windowWidth - The width of the window. | ||
* @param xOffset - The distance between the left edge of the window | ||
* and the left edge of the wrapped component. | ||
* @param componentWidth - The width of the wrapped component. | ||
* @param tooltipWidth - The width of the tooltip itself. | ||
* @param [manualShiftHorizontal] - Any additional amount to manually shift the tooltip to the left or right. | ||
* A positive value shifts it to the right, | ||
* and a negative value shifts it to the left. | ||
*/ | ||
const computeHorizontalShift: ComputeHorizontalShift = (windowWidth, xOffset, componentWidth, tooltipWidth, manualShiftHorizontal) => { | ||
// First find the left and right edges of the tooltip (by default, it is centered on the component). | ||
const componentCenter = xOffset + componentWidth / 2 + manualShiftHorizontal; | ||
const tooltipLeftEdge = componentCenter - tooltipWidth / 2; | ||
const tooltipRightEdge = componentCenter + tooltipWidth / 2; | ||
|
||
if (tooltipLeftEdge < GUTTER_WIDTH) { | ||
// Tooltip is in left gutter, shift right by a multiple of four. | ||
return roundToNearestMultipleOfFour(GUTTER_WIDTH - tooltipLeftEdge); | ||
} | ||
|
||
if (tooltipRightEdge > windowWidth - GUTTER_WIDTH) { | ||
// Tooltip is in right gutter, shift left by a multiple of four. | ||
return roundToNearestMultipleOfFour(windowWidth - GUTTER_WIDTH - tooltipRightEdge); | ||
} | ||
|
||
// Tooltip is not in the gutter, so no need to shift it horizontally | ||
return 0; | ||
}; | ||
|
||
export {GUTTER_WIDTH}; | ||
export default computeHorizontalShift; |
3 changes: 3 additions & 0 deletions
3
src/styles/utils/generators/TooltipStyleUtils/computeHorizontalShift/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type ComputeHorizontalShift = (windowWidth: number, xOffset: number, componentWidth: number, tooltipWidth: number, manualShiftHorizontal: number) => number; | ||
|
||
export default ComputeHorizontalShift; |
179 changes: 0 additions & 179 deletions
179
src/styles/utils/generators/TooltipStyleUtils/index.native.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.