-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
4c9c167
commit 1a970b6
Showing
12 changed files
with
150 additions
and
111 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,36 @@ | ||
import { token } from 'leather-styles/tokens'; | ||
|
||
import { pxStringToNumber } from '@shared/utils/px-string-to-number'; | ||
|
||
import { useViewportMinWidth } from '@app/common/hooks/use-media-query'; | ||
import { useHasLedgerKeys } from '@app/store/ledger/ledger.selectors'; | ||
import { getHeightOffset } from '@app/ui/components/containers/dialog/dialog'; | ||
|
||
// virtuosoHeight = calc(InteractiveItem height - negative margin) | ||
// calc(72px - 24px) = 58 | ||
export const virtuosoHeight = 58; | ||
|
||
type VirtuosoVariants = 'footer' | 'no-footer' | 'popup'; | ||
|
||
export function useGetVirtuosoHeight(accountNum: number, variant: VirtuosoVariants) { | ||
const isAtleastBreakpointMd = useViewportMinWidth('md'); | ||
|
||
const isLedger = useHasLedgerKeys(); | ||
const offset = getHeightOffset(true, !isLedger); | ||
|
||
// TODO rename dialogHeight as actionPopupHeight in monorepo | ||
const actionPopupHeight = token('sizes.dialogHeight'); | ||
// handles resizing of a full size browser - non popup | ||
const isNarrowLargeWindow = | ||
window.innerHeight > pxStringToNumber(actionPopupHeight) && !isAtleastBreakpointMd; | ||
|
||
if (accountNum > 10) { | ||
if (variant === 'popup') return '50vh'; | ||
if (isNarrowLargeWindow) { | ||
return variant === 'footer' ? '85vh' : '95vh'; | ||
} | ||
return variant === 'footer' ? '70vh' : '85vh'; | ||
} | ||
const visibleAccounts = virtuosoHeight * accountNum; | ||
return visibleAccounts + offset; | ||
} |
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,23 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
import { BreakpointToken, token } from 'leather-styles/tokens'; | ||
|
||
function useMediaQuery(query: string) { | ||
const [matches, setMatches] = useState(false); | ||
|
||
useEffect(() => { | ||
const media = window.matchMedia(query); | ||
if (media.matches !== matches) { | ||
setMatches(media.matches); | ||
} | ||
const listener = () => setMatches(media.matches); | ||
window.addEventListener('resize', listener); | ||
return () => window.removeEventListener('resize', listener); | ||
}, [matches, query]); | ||
|
||
return matches; | ||
} | ||
|
||
export function useViewportMinWidth(viewport: BreakpointToken) { | ||
return useMediaQuery(`(min-width: ${token(`breakpoints.${viewport}`)})`); | ||
} |
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
Oops, something went wrong.