Last active
January 27, 2021 21:32
-
-
Save horaciosystem/253bdfbbbb524a12282bb57a3ee70290 to your computer and use it in GitHub Desktop.
Sidebar [react, reakit, tailwindcss, postcss, postcss-nested]
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 { | |
useDialogState, | |
Dialog, | |
DialogDisclosure, | |
DialogBackdrop, | |
} from "reakit/Dialog" | |
import styles from "./Layout.module.css" | |
function Layout({ children }) { | |
const dialog = useDialogState({ animated: true }) | |
const { productDomain } = useProduct() | |
Router.events.on("routeChangeComplete", () => dialog.hide()) | |
return ( | |
<> | |
<div> | |
<Header | |
openSidebarButton={ | |
<DialogDisclosure | |
data-test-id="open-sidebar-button" | |
as={Button} | |
theme="primary" | |
size="sm" | |
{...dialog} | |
aria-label="open menu" | |
className="mr-2 md:mr-4 min-w-0 flex-shrink-0" | |
> | |
<MenuIcon className="w-6 md:w-6" /> | |
</DialogDisclosure> | |
} | |
/> | |
{children} | |
<UserModules /> | |
<DialogBackdrop {...dialog} className={styles.sidebarBackdrop}> | |
<Dialog | |
{...dialog} | |
aria-label="Navigation bar" | |
className={`${styles.sidebar} bg-inverse w-65`} | |
preventBodyScroll | |
hideOnClickOutside | |
hideOnEsc | |
tabIndex={0} | |
> | |
<SideNavbar /> | |
</Dialog> | |
</DialogBackdrop> | |
</div> | |
</> | |
) | |
} |
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
.sidebar { | |
position: fixed; | |
left: 0; | |
top: 0; | |
height: 100vh; | |
overflow: auto; | |
z-index: 999; | |
outline: 0; | |
will-change: transform; | |
transition: transform 0.3s ease; | |
transform: translate3d(-100%, 0, 0); | |
&[data-enter] { | |
transform: translate3d(0, 0, 0); | |
} | |
} | |
.sidebarBackdrop { | |
background-color: rgba(0, 0, 0, 0.5); | |
position: fixed; | |
top: 0; | |
right: 0; | |
bottom: 0; | |
left: 0; | |
z-index: 999; | |
&[data-enter] { | |
opacity: 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment