Merge pull request #4473 from freesewing/joost
fix(dev): Make slug available in header for modal menu
This commit is contained in:
commit
9f655f71e1
4 changed files with 44 additions and 33 deletions
|
@ -23,13 +23,17 @@ import { NavButton, NavSpacer, colors } from 'shared/components/header.mjs'
|
||||||
|
|
||||||
export const ns = ['header', 'sections', ...themeNs]
|
export const ns = ['header', 'sections', ...themeNs]
|
||||||
|
|
||||||
const NavIcons = ({ setModal }) => {
|
const NavIcons = ({ setModal, slug }) => {
|
||||||
const { t } = useTranslation(['header'])
|
const { t } = useTranslation(['header'])
|
||||||
const iconSize = 'h-6 w-6 lg:h-12 lg:w-12'
|
const iconSize = 'h-6 w-6 lg:h-12 lg:w-12'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<NavButton onClick={() => setModal(<ModalMenu />)} label={t('header:menu')} color={colors[0]}>
|
<NavButton
|
||||||
|
onClick={() => setModal(<ModalMenu slug={slug} />)}
|
||||||
|
label={t('header:menu')}
|
||||||
|
color={colors[0]}
|
||||||
|
>
|
||||||
<MenuIcon className={iconSize} />
|
<MenuIcon className={iconSize} />
|
||||||
</NavButton>
|
</NavButton>
|
||||||
<NavSpacer />
|
<NavSpacer />
|
||||||
|
@ -80,24 +84,29 @@ const NavIcons = ({ setModal }) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Header = (props) => {
|
export const Header = ({
|
||||||
|
show = true, // Whether or not to show the header
|
||||||
|
slug, // Slug of the current page
|
||||||
|
}) => {
|
||||||
const { setModal } = useContext(ModalContext) || {}
|
const { setModal } = useContext(ModalContext) || {}
|
||||||
|
|
||||||
return (
|
const headerIcons = <NavIcons {...{ setModal, slug }} />
|
||||||
<HeaderWrapper {...props}>
|
|
||||||
|
return show ? (
|
||||||
|
<HeaderWrapper {...{ show, slug }}>
|
||||||
<div className="m-auto md:px-8">
|
<div className="m-auto md:px-8">
|
||||||
<div className="p-0 flex flex-row gap-2 justify-between text-neutral-content items-center">
|
<div className="p-0 flex flex-row gap-2 justify-between text-neutral-content items-center">
|
||||||
{/* Non-mobile content */}
|
{/* Non-mobile content */}
|
||||||
<div className="hidden lg:flex lg:px-2 flex-row items-center justify-between xl:justify-center w-full">
|
<div className="hidden lg:flex lg:px-2 flex-row items-center justify-between xl:justify-center w-full">
|
||||||
<NavIcons setModal={setModal} />
|
{headerIcons}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mobile content */}
|
{/* Mobile content */}
|
||||||
<div className="flex lg:hidden flex-row items-center justify-between w-full">
|
<div className="flex lg:hidden flex-row items-center justify-between w-full">
|
||||||
<NavIcons setModal={setModal} />
|
{headerIcons}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</HeaderWrapper>
|
</HeaderWrapper>
|
||||||
)
|
) : null
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
// Dependencies
|
|
||||||
import { useContext } from 'react'
|
|
||||||
// Hooks
|
// Hooks
|
||||||
import { useNavigation } from 'site/hooks/use-navigation.mjs'
|
import { useNavigation } from 'site/hooks/use-navigation.mjs'
|
||||||
// Contenxt
|
|
||||||
import { NavigationContext } from 'shared/context/navigation-context.mjs'
|
|
||||||
// Components
|
// Components
|
||||||
import { SectionsMenu, ns as sectionsNs } from 'site/components/navigation/sections-menu.mjs'
|
import { SectionsMenu, ns as sectionsNs } from 'site/components/navigation/sections-menu.mjs'
|
||||||
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
|
import { ModalWrapper } from 'shared/components/wrappers/modal.mjs'
|
||||||
|
@ -14,8 +10,7 @@ import { NavLinks, Breadcrumbs } from 'shared/components/navigation/sitenav.mjs'
|
||||||
|
|
||||||
export const ns = nsMerge(sectionsNs)
|
export const ns = nsMerge(sectionsNs)
|
||||||
|
|
||||||
export const ModalMenu = () => {
|
export const ModalMenu = ({ slug }) => {
|
||||||
const { slug } = useContext(NavigationContext)
|
|
||||||
const { siteNav } = useNavigation()
|
const { siteNav } = useNavigation()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -132,6 +132,10 @@ const MainLink = ({
|
||||||
* @param siteNav {object} - The site navigation object as returned by the useNavigation hook
|
* @param siteNav {object} - The site navigation object as returned by the useNavigation hook
|
||||||
*/
|
*/
|
||||||
export const Breadcrumbs = ({ slug, siteNav }) => {
|
export const Breadcrumbs = ({ slug, siteNav }) => {
|
||||||
|
if (!slug) {
|
||||||
|
console.log('No slug passed to Breadcrumbs')
|
||||||
|
return null
|
||||||
|
}
|
||||||
// Start with the home crumb
|
// Start with the home crumb
|
||||||
const crumbs = [
|
const crumbs = [
|
||||||
<li className="inline" key={0}>
|
<li className="inline" key={0}>
|
||||||
|
@ -144,25 +148,27 @@ export const Breadcrumbs = ({ slug, siteNav }) => {
|
||||||
const chunks = slug.split('/')
|
const chunks = slug.split('/')
|
||||||
for (let i = 1; i <= chunks.length; i++) {
|
for (let i = 1; i <= chunks.length; i++) {
|
||||||
const page = get(siteNav, chunks.slice(0, i))
|
const page = get(siteNav, chunks.slice(0, i))
|
||||||
crumbs.push(
|
if (page) {
|
||||||
<li className="pl-1" key={`${i}s`}>
|
crumbs.push(
|
||||||
<RightIcon className="w-4 h-4 opacity-50" stroke={3} />
|
<li className="pl-1" key={`${i}s`}>
|
||||||
</li>,
|
<RightIcon className="w-4 h-4 opacity-50" stroke={3} />
|
||||||
i === chunks.length ? (
|
</li>,
|
||||||
<li className="pl-1" key={i}>
|
i === chunks.length ? (
|
||||||
<span className="font-medium">{page.t}</span>
|
<li className="pl-1" key={i}>
|
||||||
</li>
|
<span className="font-medium">{page.t}</span>
|
||||||
) : (
|
</li>
|
||||||
<li key={i}>
|
) : (
|
||||||
<PageLink
|
<li key={i}>
|
||||||
href={`/${page.s}`}
|
<PageLink
|
||||||
title={page.t}
|
href={`/${page.s}`}
|
||||||
className="text-secondary-focus font-medium pl-1"
|
title={page.t}
|
||||||
txt={page.t}
|
className="text-secondary-focus font-medium pl-1"
|
||||||
/>
|
txt={page.t}
|
||||||
</li>
|
/>
|
||||||
|
</li>
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ul className="flex flex-row flex-wrap items-center">{crumbs}</ul>
|
return <ul className="flex flex-row flex-wrap items-center">{crumbs}</ul>
|
||||||
|
|
|
@ -13,6 +13,7 @@ export const LayoutWrapper = ({
|
||||||
noSearch = false,
|
noSearch = false,
|
||||||
header = false,
|
header = false,
|
||||||
footer = true,
|
footer = true,
|
||||||
|
slug,
|
||||||
}) => {
|
}) => {
|
||||||
const ChosenHeader = header ? header : Header
|
const ChosenHeader = header ? header : Header
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ export const LayoutWrapper = ({
|
||||||
<Head>
|
<Head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
</Head>
|
</Head>
|
||||||
<ChosenHeader show={showHeader} />
|
<ChosenHeader show={showHeader} slug={slug} />
|
||||||
|
|
||||||
<main
|
<main
|
||||||
className={`grow transition-margin duration-300 ease-in-out lg:group-[.header-shown]/layout:mt-24 lg:mt-4
|
className={`grow transition-margin duration-300 ease-in-out lg:group-[.header-shown]/layout:mt-24 lg:mt-4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue