Last active
February 2, 2024 22:01
-
-
Save ChrisCrossCrash/f803ddde8c54ee4a42c9f573831a0706 to your computer and use it in GitHub Desktop.
A two-panel layout that only displays one panel at a time.
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
import React from 'react' | |
type TwoPanelShiftLayoutProps = { | |
panelLeft: React.ReactNode | |
panelRight: React.ReactNode | |
isShifted?: boolean | |
className?: string | |
style?: React.CSSProperties | |
} | |
/** A two-panel layout that only displays one panel at a time. */ | |
function TwoPanelShiftLayout(props: TwoPanelShiftLayoutProps) { | |
return ( | |
<div | |
style={{ maxWidth: '100vw', overflowX: 'hidden', ...props.style }} | |
className={props.className ?? ''} | |
> | |
<div | |
style={{ | |
display: 'grid', | |
gridTemplateColumns: 'repeat(2, 1fr)', | |
height: '100dvh', | |
width: '200vw', | |
transition: 'transform 1s cubic-bezier(0.215, 0.61, 0.355, 1)', | |
transform: props.isShifted ? 'translateX(-50%)' : 'none', | |
}} | |
> | |
{/* We use `overflow: 'auto'` so that each panel scrolls independently, | |
rather than scrolling down on one panel causing the other panel to | |
scroll down as well. */} | |
<div style={{ overflow: 'auto' }}>{props.panelLeft}</div> | |
<div style={{ overflow: 'auto' }}>{props.panelRight}</div> | |
</div> | |
</div> | |
) | |
} | |
export default TwoPanelShiftLayout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment