2023-04-25 17:33:34 +02:00
|
|
|
// Hooks
|
|
|
|
import { useState, useEffect, useContext } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
// Context
|
|
|
|
import { ModalContext } from 'shared/context/modal-context.mjs'
|
2023-04-28 21:23:06 +02:00
|
|
|
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
2023-04-25 17:33:34 +02:00
|
|
|
// Components
|
2023-04-07 17:10:54 +02:00
|
|
|
import {
|
|
|
|
DesignIcon,
|
|
|
|
DocsIcon,
|
|
|
|
MenuIcon,
|
|
|
|
SearchIcon,
|
|
|
|
ShowcaseIcon,
|
|
|
|
UserIcon,
|
|
|
|
ThemeIcon,
|
|
|
|
I18nIcon,
|
2023-04-30 21:24:35 +02:00
|
|
|
MeasureIcon,
|
|
|
|
PageIcon,
|
2023-05-18 13:56:50 +02:00
|
|
|
PlusIcon,
|
2023-04-07 17:10:54 +02:00
|
|
|
} from 'shared/components/icons.mjs'
|
2023-01-29 16:44:02 +01:00
|
|
|
import { Ribbon } from 'shared/components/ribbon.mjs'
|
2023-04-19 20:11:52 +02:00
|
|
|
import { ModalThemePicker, ns as themeNs } from 'shared/components/modal/theme-picker.mjs'
|
|
|
|
import { ModalLocalePicker, ns as localeNs } from 'shared/components/modal/locale-picker.mjs'
|
2023-04-09 15:57:25 +02:00
|
|
|
import { ModalMenu } from 'site/components/navigation/modal-menu.mjs'
|
2022-01-02 17:16:15 +01:00
|
|
|
|
2023-05-18 13:56:50 +02:00
|
|
|
import { NavButton, NavSpacer, colors } from 'shared/components/header.mjs'
|
2023-04-07 17:10:54 +02:00
|
|
|
|
2023-05-08 19:28:03 +02:00
|
|
|
export const ns = ['header', 'sections', ...themeNs, ...localeNs]
|
2023-04-09 15:57:25 +02:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
const NavIcons = ({ setModal, setSearch }) => {
|
2023-04-07 17:10:54 +02:00
|
|
|
const { t } = useTranslation(['header'])
|
|
|
|
const iconSize = 'h-6 w-6 lg:h-12 lg:w-12'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-05-08 19:28:03 +02:00
|
|
|
<NavButton onClick={() => setModal(<ModalMenu />)} label={t('header:menu')} color={colors[0]}>
|
2023-04-07 17:10:54 +02:00
|
|
|
<MenuIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
<NavSpacer />
|
2023-05-08 19:28:03 +02:00
|
|
|
<NavButton href="/designs" label={t('header:designs')} color={colors[1]}>
|
2023-04-07 17:10:54 +02:00
|
|
|
<DesignIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
<NavButton
|
2023-04-30 21:24:35 +02:00
|
|
|
href="/patterns"
|
|
|
|
label={t('header:patterns')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[2]}
|
2023-04-07 17:10:54 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
2023-04-30 21:24:35 +02:00
|
|
|
<PageIcon className={iconSize} />
|
2023-04-07 17:10:54 +02:00
|
|
|
</NavButton>
|
2023-04-09 15:57:25 +02:00
|
|
|
<NavButton
|
2023-04-30 21:24:35 +02:00
|
|
|
href="/sets"
|
|
|
|
label={t('header:sets')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[3]}
|
2023-04-09 15:57:25 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
2023-04-30 21:24:35 +02:00
|
|
|
<MeasureIcon className={iconSize} />
|
2023-04-07 17:10:54 +02:00
|
|
|
</NavButton>
|
2023-04-09 15:57:25 +02:00
|
|
|
<NavButton
|
2023-04-30 21:24:35 +02:00
|
|
|
href="/showcase"
|
|
|
|
label={t('header:showcase')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[4]}
|
2023-04-09 15:57:25 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
2023-04-30 21:24:35 +02:00
|
|
|
<ShowcaseIcon className={iconSize} />
|
2023-04-07 17:10:54 +02:00
|
|
|
</NavButton>
|
|
|
|
<NavButton
|
2023-04-30 21:24:35 +02:00
|
|
|
href="/docs"
|
|
|
|
label={t('header:docs')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[5]}
|
2023-04-07 17:10:54 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
2023-04-30 21:24:35 +02:00
|
|
|
<DocsIcon className={iconSize} />
|
2023-04-07 17:10:54 +02:00
|
|
|
</NavButton>
|
|
|
|
<NavSpacer />
|
|
|
|
<NavButton
|
2023-04-28 21:23:06 +02:00
|
|
|
onClick={() => setModal(<ModalThemePicker />)}
|
2023-04-07 17:10:54 +02:00
|
|
|
label={t('header:theme')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[6]}
|
2023-04-07 17:10:54 +02:00
|
|
|
>
|
|
|
|
<ThemeIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-04-07 17:33:45 +02:00
|
|
|
<NavButton
|
2023-04-28 21:23:06 +02:00
|
|
|
onClick={() => setModal(<ModalLocalePicker />)}
|
2023-04-07 17:33:45 +02:00
|
|
|
label={t('header:language')}
|
2023-05-08 19:28:03 +02:00
|
|
|
color={colors[7]}
|
2023-04-07 17:33:45 +02:00
|
|
|
>
|
2023-04-07 17:10:54 +02:00
|
|
|
<I18nIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-05-08 19:28:03 +02:00
|
|
|
<NavButton onClick={() => setSearch(true)} label={t('header:search')} color={colors[8]}>
|
2023-04-07 17:10:54 +02:00
|
|
|
<SearchIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
<NavSpacer />
|
2023-05-08 19:28:03 +02:00
|
|
|
<NavButton href="/account" label={t('header:account')} color={colors[9]}>
|
2023-04-07 17:10:54 +02:00
|
|
|
<UserIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-05-18 13:56:50 +02:00
|
|
|
<NavButton href="/new" label={t('header:new')} color={colors[10]}>
|
|
|
|
<PlusIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-04-07 17:10:54 +02:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2023-01-28 18:10:29 +01:00
|
|
|
|
2023-04-28 21:23:06 +02:00
|
|
|
export const Header = ({ setSearch }) => {
|
2023-04-25 17:33:34 +02:00
|
|
|
const { setModal } = useContext(ModalContext)
|
2023-04-28 21:23:06 +02:00
|
|
|
const { loading } = useContext(LoadingContext)
|
2022-01-02 17:16:15 +01:00
|
|
|
const [prevScrollPos, setPrevScrollPos] = useState(0)
|
|
|
|
const [show, setShow] = useState(true)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (typeof window !== 'undefined') {
|
2022-01-20 09:07:38 +01:00
|
|
|
const handleScroll = () => {
|
2022-11-23 21:42:22 +01:00
|
|
|
const curScrollPos = typeof window !== 'undefined' ? window.pageYOffset : 0
|
2022-01-20 09:07:38 +01:00
|
|
|
if (curScrollPos >= prevScrollPos) {
|
|
|
|
if (show && curScrollPos > 20) setShow(false)
|
2022-11-23 21:42:22 +01:00
|
|
|
} else setShow(true)
|
2022-01-20 09:07:38 +01:00
|
|
|
setPrevScrollPos(curScrollPos)
|
|
|
|
}
|
2022-01-02 17:16:15 +01:00
|
|
|
window.addEventListener('scroll', handleScroll)
|
|
|
|
return () => window.removeEventListener('scroll', handleScroll)
|
|
|
|
}
|
2022-01-20 09:07:38 +01:00
|
|
|
}, [prevScrollPos, show])
|
2022-01-02 17:16:15 +01:00
|
|
|
|
|
|
|
return (
|
2022-11-23 21:42:22 +01:00
|
|
|
<header
|
|
|
|
className={`
|
|
|
|
fixed bottom-0 lg:bottom-auto lg:top-0 left-0
|
|
|
|
bg-neutral
|
|
|
|
w-full
|
|
|
|
z-30
|
|
|
|
transition-transform
|
2023-04-28 21:23:06 +02:00
|
|
|
${show || loading ? '' : 'fixed bottom-0 lg:top-0 left-0 translate-y-36 lg:-translate-y-36'}
|
2022-11-23 21:42:22 +01:00
|
|
|
drop-shadow-xl
|
|
|
|
`}
|
|
|
|
>
|
2022-12-24 18:16:09 +01:00
|
|
|
<div className="m-auto md:px-8">
|
|
|
|
<div className="p-0 flex flex-row gap-2 justify-between text-neutral-content items-center">
|
2023-04-07 17:10:54 +02:00
|
|
|
{/* Non-mobile content */}
|
2023-06-09 19:11:45 +02:00
|
|
|
<div className="hidden lg:flex lg:flex-row lg:justify-between items-center xl:justify-center w-full">
|
2023-04-28 21:23:06 +02:00
|
|
|
<NavIcons setModal={setModal} setSearch={setSearch} />
|
2022-11-23 21:42:22 +01:00
|
|
|
</div>
|
2023-04-07 17:10:54 +02:00
|
|
|
|
|
|
|
{/* Mobile content */}
|
|
|
|
<div className="flex lg:hidden flex-row items-center justify-between w-full">
|
2023-04-28 21:23:06 +02:00
|
|
|
<NavIcons setModal={setModal} setSearch={setSearch} />
|
2022-01-02 17:16:15 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-23 21:42:22 +01:00
|
|
|
</div>
|
2023-04-28 21:23:06 +02:00
|
|
|
<Ribbon />
|
2022-11-23 21:42:22 +01:00
|
|
|
</header>
|
2022-01-02 17:16:15 +01:00
|
|
|
)
|
|
|
|
}
|