2023-01-29 16:44:02 +01:00
|
|
|
// Hooks
|
2022-05-25 18:35:20 +02:00
|
|
|
import { useRouter } from 'next/router'
|
2023-01-29 16:44:02 +01:00
|
|
|
// Components
|
2023-01-28 18:10:29 +01:00
|
|
|
import { Header, ns as headerNs } from 'site/components/header/index.mjs'
|
|
|
|
import { Footer, ns as footerNs } from 'site/components/footer/index.mjs'
|
2023-01-29 16:44:02 +01:00
|
|
|
import { Search, ns as searchNs } from 'site/components/search.mjs'
|
2023-01-28 18:10:29 +01:00
|
|
|
|
|
|
|
export const ns = [...new Set([...headerNs, ...footerNs, ...searchNs])]
|
2022-05-25 18:35:20 +02:00
|
|
|
|
2023-01-29 16:44:02 +01:00
|
|
|
export const LayoutWrapper = ({
|
|
|
|
app,
|
|
|
|
children = [],
|
|
|
|
footer,
|
|
|
|
search,
|
|
|
|
setSearch,
|
|
|
|
noSearch = false,
|
|
|
|
}) => {
|
2022-05-25 18:35:20 +02:00
|
|
|
const startNavigation = () => {
|
|
|
|
app.startLoading()
|
|
|
|
// Force close of menu on mobile if it is open
|
|
|
|
if (app.primaryNavigation) app.setPrimaryNavigation(false)
|
|
|
|
// Force close of search modal if it is open
|
|
|
|
if (search) setSearch(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
router.events?.on('routeChangeStart', startNavigation)
|
|
|
|
router.events?.on('routeChangeComplete', () => app.stopLoading())
|
|
|
|
|
|
|
|
return (
|
2022-12-03 11:25:02 -06:00
|
|
|
<div
|
|
|
|
className={`
|
2022-05-25 18:35:20 +02:00
|
|
|
flex flex-col justify-between
|
|
|
|
min-h-screen
|
|
|
|
bg-base-100
|
2022-12-03 11:25:02 -06:00
|
|
|
`}
|
|
|
|
>
|
2022-05-25 18:35:20 +02:00
|
|
|
<Header app={app} setSearch={setSearch} />
|
|
|
|
<main className="grow">{children}</main>
|
|
|
|
{!noSearch && search && (
|
|
|
|
<>
|
2022-12-03 11:25:02 -06:00
|
|
|
<div
|
|
|
|
className={`
|
2022-05-25 18:35:20 +02:00
|
|
|
fixed w-full max-h-screen bg-base-100 top-0 z-30 pt-0 pb-16 px-8
|
|
|
|
md:rounded-lg md:top-24
|
|
|
|
md:max-w-xl md:m-auto md:inset-x-12
|
|
|
|
md:max-w-2xl
|
|
|
|
lg:max-w-4xl
|
2022-12-03 11:25:02 -06:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<Search app={app} search={search} setSearch={setSearch} />
|
|
|
|
</div>
|
|
|
|
<div className="fixed top-0 left-0 w-full min-h-screen bg-neutral z-20 bg-opacity-70"></div>
|
2022-05-25 18:35:20 +02:00
|
|
|
</>
|
|
|
|
)}
|
2022-12-27 18:16:05 +01:00
|
|
|
{footer && <Footer app={app} />}
|
2022-05-25 18:35:20 +02:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|