2021-12-11 14:04:05 +01:00
|
|
|
import { useState } from 'react'
|
2021-12-21 20:47:13 +01:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import Link from 'next/link'
|
2021-12-11 14:04:05 +01:00
|
|
|
// Shared components
|
2021-12-21 20:47:13 +01:00
|
|
|
import Logo from 'shared/components/logos/freesewing.js'
|
|
|
|
import PrimaryNavigation from 'shared/components/navigation/primary'
|
|
|
|
import get from 'lodash.get'
|
2021-12-11 14:04:05 +01:00
|
|
|
|
|
|
|
const iconSize= 48
|
|
|
|
|
2021-12-21 20:47:13 +01:00
|
|
|
const PageTitle = ({ app, slug, title }) => {
|
|
|
|
if (title) return <h1>{title}</h1>
|
|
|
|
if (slug) return <h1>{get(app.navigation, slug.split('/')).__title}</h1>
|
2021-12-11 14:04:05 +01:00
|
|
|
|
2021-12-21 20:47:13 +01:00
|
|
|
return <h1>FIXME: This page has no title</h1>
|
|
|
|
}
|
|
|
|
|
|
|
|
const Breadcrumbs = ({ app, slug=false, title }) => {
|
|
|
|
if (!slug) return null
|
|
|
|
const crumbs = []
|
|
|
|
const chunks = slug.split('/')
|
|
|
|
for (const i in chunks) {
|
|
|
|
const page = get(app.navigation, chunks.slice(0,i+1))
|
|
|
|
crumbs.push([page.__linktitle, '/'+chunks.slice(0,i+1).join('/'), (i+1 < chunks.length)])
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className="flex flex-row gap-2 font-bold">
|
|
|
|
<li>
|
|
|
|
<Link href="/">
|
|
|
|
<a title="To the homepage">
|
|
|
|
<Logo size={24} />
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
{crumbs.map(crumb => (
|
|
|
|
<>
|
|
|
|
<li>»</li>
|
|
|
|
<li>
|
|
|
|
{crumb[2]
|
|
|
|
? (
|
|
|
|
<Link href={crumb[1]}>
|
|
|
|
<a title={crumb[0]} className="text-secondary hover:text-secondary-focus">
|
|
|
|
{crumb[0]}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
: crumb[0]
|
|
|
|
}
|
|
|
|
</li>
|
|
|
|
</>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const DefaultLayout = ({ app, title=false, children=[]}) => {
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
const slug = router.asPath.slice(1)
|
2021-12-11 14:04:05 +01:00
|
|
|
const [leftNav, setLeftNav] = useState(false)
|
|
|
|
|
|
|
|
const toggleLeftNav = () => setLeftNav(!leftNav)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={`
|
|
|
|
flex flex-col justify-between
|
|
|
|
min-h-screen
|
|
|
|
bg-base-100
|
2021-12-18 16:26:55 +01:00
|
|
|
lg:py-8
|
2021-12-21 20:47:13 +01:00
|
|
|
`} data-theme={app.theme}>
|
2021-12-11 14:04:05 +01:00
|
|
|
<header className={`
|
|
|
|
bg-primary
|
|
|
|
p-4
|
|
|
|
block
|
|
|
|
sm:hidden
|
|
|
|
`}>
|
|
|
|
header
|
|
|
|
</header>
|
|
|
|
<main className={`
|
|
|
|
grow flex flex-row
|
|
|
|
sm:py-8
|
2021-12-18 16:26:55 +01:00
|
|
|
gap-2
|
2021-12-21 20:47:13 +01:00
|
|
|
lg:gap-16
|
|
|
|
xl:gap-32
|
2021-12-11 14:04:05 +01:00
|
|
|
`}>
|
|
|
|
<aside className={`
|
|
|
|
fixed top-0 right-0
|
2021-12-21 20:47:13 +01:00
|
|
|
${app.primaryMenu ? '' : 'translate-x-[-100%]'} transition-transform
|
2021-12-11 14:04:05 +01:00
|
|
|
sm:relative sm:transform-none
|
2021-12-12 18:58:24 +01:00
|
|
|
h-screen w-screen
|
2021-12-21 20:47:13 +01:00
|
|
|
bg-base-50
|
|
|
|
sm:bg-base-50
|
2021-12-11 14:04:05 +01:00
|
|
|
sm:max-w-[38.2%]
|
2021-12-11 18:19:20 +01:00
|
|
|
sm:flex sm:flex-row-reverse
|
2021-12-21 20:47:13 +01:00
|
|
|
sm:sticky
|
|
|
|
overflow-y-scroll
|
|
|
|
py-4
|
2021-12-11 14:04:05 +01:00
|
|
|
`}>
|
2021-12-21 20:47:13 +01:00
|
|
|
<PrimaryNavigation app={app} active={slug}/>
|
2021-12-11 14:04:05 +01:00
|
|
|
</aside>
|
2021-12-21 20:47:13 +01:00
|
|
|
<section className='max-w-screen-lg lg:pt-8 p-4'>
|
|
|
|
{title && (
|
|
|
|
<>
|
|
|
|
<Breadcrumbs app={app} slug={slug} title={title} />
|
|
|
|
<PageTitle app={app} slug={slug} title={title} />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{children}
|
2021-12-11 14:04:05 +01:00
|
|
|
</section>
|
|
|
|
</main>
|
|
|
|
<footer className="bg-primary p-8">footer</footer>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DefaultLayout
|