update (#253)
This commit is contained in:
1 parent
dd9058b798
commit
9f5f721bd0
5 files changed
+159
-72
No files matched your search
@@ -1,22 +0,0 @@
|
||||
import { Button, ButtonProps } from "@/ui/Button"
|
||||
import { HiOutlineMenuAlt4, HiOutlineX } from "react-icons/hi"
|
||||
|
||||
export type MenuToggleProps = Omit<ButtonProps, "theme"> & {
|
||||
open: boolean
|
||||
}
|
||||
|
||||
export const MenuToggle: React.FC<MenuToggleProps> = ({ open, ...props }) => {
|
||||
const icon = open ? (
|
||||
<HiOutlineX size={24} />
|
||||
) : (
|
||||
<HiOutlineMenuAlt4 size={24} />
|
||||
)
|
||||
return (
|
||||
<Button
|
||||
{...props}
|
||||
theme={"icon"}
|
||||
>
|
||||
{icon}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -8,14 +8,15 @@ import { AccessibilityButton } from "../AccessibilityButton"
|
||||
import { Spacer } from "../Spacer"
|
||||
|
||||
export type DesktopNavigationProps = {
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ style }) => {
|
||||
export function DesktopNavigation({ style, className }: DesktopNavigationProps) {
|
||||
const menu = useContext(MenuContext)
|
||||
|
||||
return (
|
||||
<Box wrap gap={"var(--size-s)"} style={style}>
|
||||
<Box wrap className={className} gap={"var(--size-s)"} style={style}>
|
||||
<Link href="/">
|
||||
<HudozkaLogo />
|
||||
</Link>
|
||||
@@ -29,3 +30,4 @@ export const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ style }) =
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,61 +1,62 @@
|
||||
import { MenuToggle } from "../MenuToggle"
|
||||
import s from "./nav.module.css"
|
||||
|
||||
import { Menu } from "../Menu"
|
||||
import { Overlay } from "@/ui/Overlay"
|
||||
import { useCallback, useContext } from "react"
|
||||
import { useCallback, useContext, useEffect, useRef } from "react"
|
||||
import { MenuContext } from "@/context/MenuContext"
|
||||
import { Box } from "@/ui/Box"
|
||||
import { Spacer } from "../Spacer"
|
||||
import { useToggle } from "@/hooks/useToggle"
|
||||
import HudozkaLogo from "../HudozkaLogo"
|
||||
import { HudozkaTitle } from "../HudozkaTitle"
|
||||
import Link from "next/link"
|
||||
import { useRouter } from "next/router"
|
||||
import { HiOutlineMenuAlt4, HiOutlineX } from "react-icons/hi"
|
||||
|
||||
export type MobileNavigationProps = {
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export const MobileNavigation: React.FC<MobileNavigationProps> = ({ style }) => {
|
||||
const [open, toggleOpen] = useToggle(false)
|
||||
const handleToggle = useCallback(() => toggleOpen(), [toggleOpen])
|
||||
export function MobileNavigation({ className, style }: MobileNavigationProps) {
|
||||
const menu = useContext(MenuContext)
|
||||
const detailsRef = useRef<HTMLDetailsElement>(null)
|
||||
const router = useRouter()
|
||||
|
||||
const close = useCallback(() => {
|
||||
if (detailsRef.current) {
|
||||
detailsRef.current.open = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
router.events.on("routeChangeStart", close)
|
||||
return () => {
|
||||
router.events.off("routeChangeStart", close)
|
||||
}
|
||||
}, [router.events, close])
|
||||
|
||||
return (
|
||||
<>
|
||||
<Overlay
|
||||
show={open}
|
||||
onClickOverlay={toggleOpen}
|
||||
// duration={250}
|
||||
duration={0}
|
||||
>
|
||||
<Box style={{
|
||||
padding: "var(--size-s)",
|
||||
}}>
|
||||
<Spacer />
|
||||
<MenuToggle
|
||||
open={open}
|
||||
onClick={handleToggle}
|
||||
/>
|
||||
</Box>
|
||||
<Box style={{
|
||||
justifyContent: "center",
|
||||
}}>
|
||||
<Menu vertical
|
||||
items={menu}
|
||||
/>
|
||||
</Box>
|
||||
</Overlay>
|
||||
|
||||
<nav className={className}>
|
||||
<Box wrap gap={"var(--size-s)"} style={style}>
|
||||
<Link href="/">
|
||||
<HudozkaLogo />
|
||||
</Link>
|
||||
<HudozkaTitle compact />
|
||||
<Spacer />
|
||||
<MenuToggle
|
||||
open={open}
|
||||
onClick={handleToggle}
|
||||
/>
|
||||
<details className={s.details} ref={detailsRef}>
|
||||
<summary className={s.toggle}>
|
||||
<HiOutlineMenuAlt4 className={s.iconOpen} size={24} />
|
||||
<HiOutlineX className={s.iconClose} size={24} />
|
||||
</summary>
|
||||
<div className={s.panel}>
|
||||
<div className={s.panelClose}>
|
||||
<button className={s.toggle} onClick={close}>
|
||||
<HiOutlineX size={24} />
|
||||
</button>
|
||||
</div>
|
||||
<Menu vertical items={menu} onItemClick={close} />
|
||||
</div>
|
||||
</details>
|
||||
</Box>
|
||||
</>
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMobile } from "src/hooks/useMobile"
|
||||
import s from "./nav.module.css"
|
||||
import { DesktopNavigation } from "./DesktopNavigation"
|
||||
import { MobileNavigation } from "./MobileNavigation"
|
||||
|
||||
@@ -6,16 +6,15 @@ export type NavigationProps = {
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export const Navigation: React.FC<NavigationProps> = ({ style }) => {
|
||||
const mobile = useMobile()
|
||||
|
||||
if (mobile) {
|
||||
return (
|
||||
<MobileNavigation style={style} />
|
||||
)
|
||||
}
|
||||
|
||||
export function Navigation({ style }: NavigationProps) {
|
||||
return (
|
||||
<DesktopNavigation style={style} />
|
||||
<>
|
||||
<div className={s.desktop}>
|
||||
<DesktopNavigation style={style} />
|
||||
</div>
|
||||
<div className={s.mobile}>
|
||||
<MobileNavigation style={style} />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* Responsive switching */
|
||||
|
||||
.desktop {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.mobile {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 31.25em) {
|
||||
.desktop {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobile menu: details/summary toggle */
|
||||
|
||||
.details {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.details summary {
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.details summary::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: var(--size-xs);
|
||||
border: 1px solid rgba(0, 0, 0, 0);
|
||||
border-radius: var(--size-s);
|
||||
background-color: var(--color-back);
|
||||
color: var(--color-text);
|
||||
cursor: pointer;
|
||||
transition: box-shadow 200ms ease-in, background-color 200ms ease-in;
|
||||
}
|
||||
|
||||
.toggle:hover {
|
||||
border-color: rgba(0, 0, 0, 0);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.toggle:hover {
|
||||
background-color: var(--color-back-active);
|
||||
}
|
||||
}
|
||||
|
||||
/* Icon swap */
|
||||
|
||||
.iconClose {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.details[open] .iconOpen {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.details[open] .iconClose {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* Fullscreen overlay panel */
|
||||
|
||||
.panel {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000000;
|
||||
overflow-y: auto;
|
||||
background-color: var(--color-back-main);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.panelClose {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
padding: var(--size-s);
|
||||
}
|
||||
|
||||
/* Body scroll lock when menu is open */
|
||||
|
||||
:global(body):has(.details[open]) {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Reduced motion */
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.toggle {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user