// Hooks import { useState, useEffect, useContext } from 'react' import { useTranslation } from 'next-i18next' // Context import { ModalContext } from 'shared/context/modal-context.mjs' import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { HelpIcon, I18nIcon, SearchIcon, ThemeIcon, MenuIcon, DesignIcon, CommunityIcon, CodeIcon, DocsIcon, WrenchIcon, FreeSewingIcon, } from 'shared/components/icons.mjs' import { Ribbon } from 'shared/components/ribbon.mjs' import Link from 'next/link' import { ModalThemePicker, ns as themeNs } from 'shared/components/modal/theme-picker.mjs' import { ModalMenu } from 'site/components/navigation/modal-menu.mjs' import { NavButton, NavSpacer, colors } from 'shared/components/workbench/header.mjs' export const ns = ['header', 'sections', ...themeNs] /* * for all developers * for pattern designers and coders * for infrastructure coders * for writers * for translators * how to work as a team * about freesewing * */ const NavIcons = ({ setModal, setSearch }) => { const { t } = useTranslation(['header']) const iconSize = 'h-6 w-6 lg:h-12 lg:w-12' return ( <> setModal()} label={t('header:menu')} color={colors[0]}> setModal()} label={t('header:theme')} color={colors[7]} > setSearch(true)} label={t('header:search')} color={colors[8]}> ) } export const Header = ({ setSearch }) => { const { setModal } = useContext(ModalContext) || {} const { loading } = useContext(LoadingContext) const [prevScrollPos, setPrevScrollPos] = useState(0) const [show, setShow] = useState(true) useEffect(() => { if (typeof window !== 'undefined') { const handleScroll = () => { const curScrollPos = typeof window !== 'undefined' ? window.pageYOffset : 0 if (curScrollPos >= prevScrollPos) { if (show && curScrollPos > 20) setShow(false) } else setShow(true) setPrevScrollPos(curScrollPos) } window.addEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleScroll) } }, [prevScrollPos, show]) return (
{/* Non-mobile content */}
{/* Mobile content */}
) }