-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Popup window to be centred on screen (#198)
Co-authored-by: Matt Gowland <[email protected]> Co-authored-by: Sebastian Vittersø <[email protected]>
- Loading branch information
1 parent
7dbd49d
commit 1a5b45e
Showing
4 changed files
with
43 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { TPopupPosition } from './types' | ||
|
||
export function calculatePopupPosition(popupWidth = 600, popupHeight = 600): TPopupPosition { | ||
// Calculate the screen dimensions and position the popup at the center | ||
const screenLeft = window.screenLeft | ||
const screenTop = window.screenTop | ||
const screenWidth = window.innerWidth | ||
const screenHeight = window.innerHeight | ||
|
||
// Calculate the position to center the popup | ||
const defaultLeft = screenLeft + (screenWidth - popupWidth) / 2 | ||
const defaultTop = screenTop + (screenHeight - popupHeight) / 2 | ||
|
||
// Ensure the bottom-right corner does not go off the screen | ||
// Adjust the left and top positions if necessary | ||
const maxLeft = screenLeft + (screenWidth - popupWidth) | ||
const maxTop = screenTop + (screenHeight - popupHeight) | ||
|
||
return { | ||
width: Math.min(popupWidth, screenWidth), | ||
height: Math.min(popupHeight, screenHeight), | ||
left: Math.max(0, Math.min(defaultLeft, maxLeft)), | ||
top: Math.max(0, Math.min(defaultTop, maxTop)), | ||
} | ||
} |
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