-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from mongodb/brooke/mobile
Adds basic mobile responsiveness
- Loading branch information
Showing
14 changed files
with
479 additions
and
254 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
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,122 @@ | ||
'use client'; | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { css, keyframes } from '@emotion/css'; | ||
// @ts-expect-error | ||
import XIcon from '@leafygreen-ui/icon/dist/XWithCircle'; | ||
import IconButton from '@leafygreen-ui/icon-button'; | ||
import { color, spacing, transitionDuration } from '@leafygreen-ui/tokens'; | ||
import { useDarkMode } from '@leafygreen-ui/leafygreen-provider'; | ||
|
||
const slideIn = keyframes` | ||
from { | ||
transform: translateX(-100%); | ||
} | ||
to { | ||
transform: translateX(0); | ||
} | ||
`; | ||
|
||
const slideOut = keyframes` | ||
from { | ||
transform: translateX(0); | ||
} | ||
to { | ||
transform: translateX(-100%); | ||
} | ||
`; | ||
|
||
const fadeIn = keyframes` | ||
from { | ||
opacity: 0; | ||
} | ||
to { | ||
opacity: 1; | ||
} | ||
`; | ||
|
||
const fadeOut = keyframes` | ||
from { | ||
opacity: 1; | ||
} | ||
to { | ||
opacity: 0.5; | ||
} | ||
`; | ||
|
||
export const Drawer = ({ | ||
isOpen, | ||
onClose, | ||
children, | ||
}: { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
children: React.ReactNode; | ||
}) => { | ||
const { theme } = useDarkMode(); | ||
const [firstMount, setFirstMount] = useState(false); | ||
|
||
useEffect(() => { | ||
if (isOpen && !firstMount) { | ||
setFirstMount(true); | ||
} | ||
}, [isOpen, firstMount]); | ||
|
||
if (!firstMount) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<div | ||
onClick={onClose} | ||
className={css` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: rgba(0, 0, 0, 0.75); | ||
z-index: ${isOpen ? 1 : 0}; | ||
opacity: ${isOpen ? 1 : 0}; | ||
animation: ${isOpen ? fadeIn : fadeOut} | ||
${transitionDuration.slowest}ms backwards; | ||
`} | ||
/> | ||
|
||
<div | ||
className={css` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 60%; | ||
height: 100%; | ||
background-color: ${color[theme].background.secondary.default}; | ||
color: white; | ||
overflow: hidden; | ||
animation: ${isOpen ? slideIn : slideOut} | ||
${transitionDuration.slowest}ms forwards; | ||
z-index: 2; | ||
padding-bottom: ${spacing[400]}px; | ||
overflow-y: scroll; | ||
`} | ||
> | ||
<IconButton | ||
aria-label="Close Menu" | ||
size="large" | ||
onClick={onClose} | ||
className={css` | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
/* z-index: 5; */ | ||
padding: ${spacing[600]}px; | ||
`} | ||
> | ||
<XIcon size="large" /> | ||
</IconButton> | ||
{children} | ||
</div> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.