From 9f5f721bd0fd55e1c8f266d7036949279272c0b0 Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sun, 8 Feb 2026 15:13:03 +0700 Subject: [PATCH] update (#253) --- src/components/MenuToggle/index.tsx | 22 ---- .../Navigation/DesktopNavigation.tsx | 6 +- .../Navigation/MobileNavigation.tsx | 75 ++++++------ src/components/Navigation/index.tsx | 21 ++-- src/components/Navigation/nav.module.css | 107 ++++++++++++++++++ 5 files changed, 159 insertions(+), 72 deletions(-) delete mode 100644 src/components/MenuToggle/index.tsx create mode 100644 src/components/Navigation/nav.module.css diff --git a/src/components/MenuToggle/index.tsx b/src/components/MenuToggle/index.tsx deleted file mode 100644 index a05725ba..00000000 --- a/src/components/MenuToggle/index.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Button, ButtonProps } from "@/ui/Button" -import { HiOutlineMenuAlt4, HiOutlineX } from "react-icons/hi" - -export type MenuToggleProps = Omit & { - open: boolean -} - -export const MenuToggle: React.FC = ({ open, ...props }) => { - const icon = open ? ( - - ) : ( - - ) - return ( - - ) -} diff --git a/src/components/Navigation/DesktopNavigation.tsx b/src/components/Navigation/DesktopNavigation.tsx index 9d23313e..ca1d2753 100644 --- a/src/components/Navigation/DesktopNavigation.tsx +++ b/src/components/Navigation/DesktopNavigation.tsx @@ -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 = ({ style }) => { +export function DesktopNavigation({ style, className }: DesktopNavigationProps) { const menu = useContext(MenuContext) return ( - + @@ -29,3 +30,4 @@ export const DesktopNavigation: React.FC = ({ style }) = ) } + diff --git a/src/components/Navigation/MobileNavigation.tsx b/src/components/Navigation/MobileNavigation.tsx index 77fc1f66..40e7e6ac 100644 --- a/src/components/Navigation/MobileNavigation.tsx +++ b/src/components/Navigation/MobileNavigation.tsx @@ -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 = ({ style }) => { - const [open, toggleOpen] = useToggle(false) - const handleToggle = useCallback(() => toggleOpen(), [toggleOpen]) +export function MobileNavigation({ className, style }: MobileNavigationProps) { const menu = useContext(MenuContext) + const detailsRef = useRef(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 ( - <> - - - - - - - - - - + ) } diff --git a/src/components/Navigation/index.tsx b/src/components/Navigation/index.tsx index b8583063..3a4948a4 100644 --- a/src/components/Navigation/index.tsx +++ b/src/components/Navigation/index.tsx @@ -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 = ({ style }) => { - const mobile = useMobile() - - if (mobile) { - return ( - - ) - } - +export function Navigation({ style }: NavigationProps) { return ( - + <> +
+ +
+
+ +
+ ) } diff --git a/src/components/Navigation/nav.module.css b/src/components/Navigation/nav.module.css new file mode 100644 index 00000000..41b57ee5 --- /dev/null +++ b/src/components/Navigation/nav.module.css @@ -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; + } +}