-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow virtuoso to resize dynamically, ref #5242
- Loading branch information
1 parent
773421b
commit ab6dd7b
Showing
9 changed files
with
165 additions
and
98 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
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
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
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,36 @@ | ||
import type React from 'react'; | ||
|
||
import { Box } from 'leather-styles/jsx'; | ||
|
||
import { useViewportMinWidth } from '@app/common/hooks/use-media-query'; | ||
|
||
interface VirtuosoWrapper { | ||
children: React.ReactNode; | ||
hasFooter?: boolean; | ||
} | ||
|
||
function vhToPixels(vh: string) { | ||
const numericHeight = +vh.replace('vh', ''); | ||
return (numericHeight * window.innerHeight) / 100; | ||
} | ||
|
||
export function VirtuosoWrapper({ children, hasFooter }: VirtuosoWrapper) { | ||
const isAtLeastMd = useViewportMinWidth('md'); | ||
const virtualHeight = isAtLeastMd ? '70vh' : '100vh'; | ||
const headerHeight = 75; | ||
const footerHeight = hasFooter ? 125 : 0; | ||
const heightOffset = headerHeight + footerHeight; | ||
const height = vhToPixels(virtualHeight) - heightOffset; | ||
|
||
return ( | ||
<Box | ||
style={{ | ||
height: height, | ||
overflow: 'hidden', | ||
marginBottom: hasFooter ? '100px' : '10px', | ||
}} | ||
> | ||
{children} | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.