1
0
Fork 0

feat(shared): Use modal menu as main menu

This commit is contained in:
Joost De Cock 2023-04-19 20:56:15 +02:00
parent bd7eaaf9a1
commit 7f8911a49d
2 changed files with 28 additions and 15 deletions

View file

@ -1,6 +1,8 @@
import { useState, useEffect } from 'react'
export const ModalWrapper = ({ export const ModalWrapper = ({
app, app,
children, children = null,
flex = 'row', flex = 'row',
justify = 'center', justify = 'center',
items = 'center', items = 'center',
@ -8,17 +10,27 @@ export const ModalWrapper = ({
bgOpacity = '100 lg:bg-opacity-95', bgOpacity = '100 lg:bg-opacity-95',
bare = false, bare = false,
keepOpenOnClick = false, keepOpenOnClick = false,
}) => ( }) => {
<div const [animate, setAnimate] = useState(true)
className={`fixed top-0 left-0 m-0 p-0 shadow w-full h-screen
useEffect(() => {
if (animate) setAnimate(false)
}, [children, animate])
return (
<div
className={`fixed top-0 left-0 m-0 p-0 shadow w-full h-screen
transform-all duration-100
${animate ? 'opacity-0 -translate-x-full lg:translate-x-0' : 'opacity-100 -translate-x-0'}
bg-${bg} bg-opacity-${bgOpacity} z-50 hover:cursor-pointer bg-${bg} bg-opacity-${bgOpacity} z-50 hover:cursor-pointer
flex flex-${flex} justify-${justify} overflow-auto items-${items}`} flex flex-${flex} justify-${justify} overflow-auto items-${items}`}
onClick={keepOpenOnClick ? null : () => app.updateState('modal', false)} onClick={keepOpenOnClick ? null : () => app.updateState('modal', false)}
> >
{bare ? ( {bare ? (
children children
) : ( ) : (
<div className="bg-base-100 p-4 lg:px-8 lg:rounded-lg lg:shadow-lg">{children}</div> <div className="bg-base-100 p-4 lg:px-8 lg:rounded-lg lg:shadow-lg">{children}</div>
)} )}
</div> </div>
) )
}

View file

@ -9,6 +9,7 @@ import { LayoutWrapper, ns as layoutNs } from 'site/components/wrappers/layout.m
import { DocsLayout, ns as docsNs } from 'site/components/layouts/docs.mjs' import { DocsLayout, ns as docsNs } from 'site/components/layouts/docs.mjs'
import { Feeds } from 'site/components/feeds.mjs' import { Feeds } from 'site/components/feeds.mjs'
import { Spinner } from 'shared/components/spinner.mjs' import { Spinner } from 'shared/components/spinner.mjs'
import { ModalMenu } from 'site/components/navigation/modal-menu.mjs'
export const ns = [...new Set([...layoutNs, ...docsNs])] export const ns = [...new Set([...layoutNs, ...docsNs])]
@ -33,8 +34,8 @@ export const PageWrapper = ({
* Swipe handling for the entire site * Swipe handling for the entire site
*/ */
const swipeHandlers = useSwipeable({ const swipeHandlers = useSwipeable({
onSwipedLeft: () => (app.state?.menu?.main ? app.updateState('menu.main', false) : null), onSwipedLeft: () => app.setModal(false),
onSwipedRight: () => (app.state?.menu?.main ? null : app.updateState('menu.main', true)), onSwipedRight: () => app.setModal(<ModalMenu app={app} />),
trackMouse: true, trackMouse: true,
}) })