2023-05-16 10:34:13 +02:00
|
|
|
// Hooks
|
2023-06-20 16:52:00 -05:00
|
|
|
import { useContext } from 'react'
|
2023-05-16 10:34:13 +02:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-07-29 18:22:39 +02:00
|
|
|
import { useTheme } from 'shared/hooks/use-theme.mjs'
|
2023-05-16 10:34:13 +02:00
|
|
|
// Context
|
|
|
|
import { ModalContext } from 'shared/context/modal-context.mjs'
|
|
|
|
// Components
|
|
|
|
import {
|
|
|
|
I18nIcon,
|
|
|
|
SearchIcon,
|
|
|
|
ThemeIcon,
|
|
|
|
MenuIcon,
|
|
|
|
DesignIcon,
|
|
|
|
CodeIcon,
|
|
|
|
DocsIcon,
|
|
|
|
WrenchIcon,
|
|
|
|
FreeSewingIcon,
|
2023-05-21 09:41:20 +02:00
|
|
|
HeartIcon,
|
2023-05-16 10:34:13 +02:00
|
|
|
} from 'shared/components/icons.mjs'
|
2023-06-20 16:52:00 -05:00
|
|
|
import { HeaderWrapper } from 'shared/components/wrappers/header.mjs'
|
2023-05-16 10:34:13 +02:00
|
|
|
import { ModalThemePicker, ns as themeNs } from 'shared/components/modal/theme-picker.mjs'
|
|
|
|
import { ModalMenu } from 'site/components/navigation/modal-menu.mjs'
|
2023-07-30 18:25:31 +02:00
|
|
|
import { NavButton, NavSpacer } from 'shared/components/header.mjs'
|
2023-05-16 10:34:13 +02:00
|
|
|
|
2023-07-16 09:51:06 +02:00
|
|
|
export const ns = ['common', 'header', 'sections', ...themeNs]
|
2023-05-16 10:34:13 +02:00
|
|
|
|
2023-07-16 08:25:08 +02:00
|
|
|
const NavIcons = ({ setModal, slug }) => {
|
2023-05-16 10:34:13 +02:00
|
|
|
const { t } = useTranslation(['header'])
|
|
|
|
const iconSize = 'h-6 w-6 lg:h-12 lg:w-12'
|
2023-07-29 18:22:39 +02:00
|
|
|
const { spectrum } = useTheme()
|
2023-05-16 10:34:13 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-07-16 08:25:08 +02:00
|
|
|
<NavButton
|
|
|
|
onClick={() => setModal(<ModalMenu slug={slug} />)}
|
|
|
|
label={t('header:menu')}
|
2023-07-29 18:22:39 +02:00
|
|
|
color={spectrum[0]}
|
2023-07-16 08:25:08 +02:00
|
|
|
>
|
2023-05-16 10:34:13 +02:00
|
|
|
<MenuIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
<NavSpacer />
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/api" label="API Docs" color={spectrum[1]} extraClasses="hidden lg:flex">
|
2023-05-21 09:41:20 +02:00
|
|
|
<DocsIcon className={iconSize} />
|
2023-05-16 10:34:13 +02:00
|
|
|
</NavButton>
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/design" label="Design" color={spectrum[2]} extraClasses="hidden lg:flex">
|
2023-05-16 10:34:13 +02:00
|
|
|
<DesignIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-05-22 20:08:05 +02:00
|
|
|
<NavButton
|
|
|
|
href="/contribute"
|
|
|
|
label="Contribute"
|
2023-07-29 18:22:39 +02:00
|
|
|
color={spectrum[3]}
|
2023-05-22 20:08:05 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
2023-05-21 09:41:20 +02:00
|
|
|
<CodeIcon className={iconSize} />
|
2023-05-16 10:34:13 +02:00
|
|
|
</NavButton>
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/i18n" label="Translate" color={spectrum[4]} extraClasses="hidden lg:flex">
|
2023-05-16 10:34:13 +02:00
|
|
|
<I18nIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
<NavButton
|
2023-05-21 09:41:20 +02:00
|
|
|
href="/infra"
|
2023-05-17 10:59:45 +02:00
|
|
|
label="Infrastrucure"
|
2023-07-29 18:22:39 +02:00
|
|
|
color={spectrum[5]}
|
2023-05-16 10:34:13 +02:00
|
|
|
extraClasses="hidden lg:flex"
|
|
|
|
>
|
|
|
|
<WrenchIcon className={iconSize} stroke={1.5} />
|
|
|
|
</NavButton>
|
2023-05-21 09:41:20 +02:00
|
|
|
<NavSpacer />
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/about" label="About" color={spectrum[6]} extraClasses="hidden lg:flex">
|
2023-05-21 09:41:20 +02:00
|
|
|
<FreeSewingIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/support" label="Support" color={spectrum[7]} extraClasses="hidden lg:flex">
|
2023-05-21 09:41:20 +02:00
|
|
|
<HeartIcon className={iconSize} fill />
|
2023-05-16 10:34:13 +02:00
|
|
|
</NavButton>
|
|
|
|
<NavSpacer />
|
|
|
|
<NavButton
|
|
|
|
onClick={() => setModal(<ModalThemePicker />)}
|
|
|
|
label={t('header:theme')}
|
2023-07-29 18:22:39 +02:00
|
|
|
color={spectrum[8]}
|
2023-05-16 10:34:13 +02:00
|
|
|
>
|
|
|
|
<ThemeIcon className={iconSize} />
|
|
|
|
</NavButton>
|
2023-07-29 18:22:39 +02:00
|
|
|
<NavButton href="/search" label={t('header:search')} color={spectrum[9]}>
|
2023-05-16 10:34:13 +02:00
|
|
|
<SearchIcon className={iconSize} />
|
|
|
|
</NavButton>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-07-16 08:25:08 +02:00
|
|
|
export const Header = ({
|
|
|
|
show = true, // Whether or not to show the header
|
|
|
|
slug, // Slug of the current page
|
|
|
|
}) => {
|
2023-05-16 10:34:13 +02:00
|
|
|
const { setModal } = useContext(ModalContext) || {}
|
|
|
|
|
2023-07-16 08:25:08 +02:00
|
|
|
const headerIcons = <NavIcons {...{ setModal, slug }} />
|
|
|
|
|
|
|
|
return show ? (
|
|
|
|
<HeaderWrapper {...{ show, slug }}>
|
2023-05-16 10:34:13 +02:00
|
|
|
<div className="m-auto md:px-8">
|
|
|
|
<div className="p-0 flex flex-row gap-2 justify-between text-neutral-content items-center">
|
|
|
|
{/* Non-mobile content */}
|
2023-07-15 12:01:02 +02:00
|
|
|
<div className="hidden lg:flex lg:px-2 flex-row items-center justify-between xl:justify-center w-full">
|
2023-07-16 08:25:08 +02:00
|
|
|
{headerIcons}
|
2023-05-16 10:34:13 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* Mobile content */}
|
|
|
|
<div className="flex lg:hidden flex-row items-center justify-between w-full">
|
2023-07-16 08:25:08 +02:00
|
|
|
{headerIcons}
|
2023-05-16 10:34:13 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-20 16:52:00 -05:00
|
|
|
</HeaderWrapper>
|
2023-07-16 08:25:08 +02:00
|
|
|
) : null
|
2023-05-16 10:34:13 +02:00
|
|
|
}
|