refactor: file preview modal header on mobile

This commit is contained in:
Aman Harwara
2023-01-28 00:33:30 +05:30
parent b3562dca69
commit 0a2b66ec0a
4 changed files with 74 additions and 25 deletions

View File

@@ -5,6 +5,8 @@ import { PopoverAlignment, PopoverSide } from './Types'
import { OppositeSide, checkCollisions, getNonCollidingAlignment, getOverflows } from './Utils/Collisions'
import { getAppRect, getPopoverMaxHeight, getPositionedPopoverRect } from './Utils/Rect'
const percentOf = (percent: number, value: number) => (percent / 100) * value
const getStylesFromRect = (
rect: DOMRect,
options: {
@@ -15,16 +17,18 @@ const getStylesFromRect = (
const { disableMobileFullscreenTakeover = false, maxHeight = 'none' } = options
const canApplyMaxHeight = maxHeight !== 'none' && (!isMobileScreen() || disableMobileFullscreenTakeover)
const shouldApplyMobileWidth = isMobileScreen() && disableMobileFullscreenTakeover
const marginForMobile = percentOf(10, window.innerWidth)
return {
willChange: 'transform',
transform: `translate(${rect.x}px, ${rect.y}px)`,
transform: `translate(${shouldApplyMobileWidth ? marginForMobile / 2 : rect.x}px, ${rect.y}px)`,
visibility: 'visible',
...(canApplyMaxHeight && {
maxHeight: `${maxHeight}px`,
}),
...(disableMobileFullscreenTakeover && {
maxWidth: `${window.innerWidth - rect.x * 2}px`,
...(shouldApplyMobileWidth && {
width: `${window.innerWidth - marginForMobile}px`,
}),
}
}