From 3d678679cf03e644ccbefc260ddfb0b0d0f74f7a Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 29 Apr 2024 16:18:53 +0800 Subject: [PATCH] =?UTF-8?q?nobelium=20=E9=A1=B6=E9=83=A8=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/nobelium/components/Nav.js | 189 ++++++++++++++++++++---------- themes/nobelium/config.js | 4 +- 2 files changed, 126 insertions(+), 67 deletions(-) diff --git a/themes/nobelium/components/Nav.js b/themes/nobelium/components/Nav.js index 38253b43..a30618ed 100644 --- a/themes/nobelium/components/Nav.js +++ b/themes/nobelium/components/Nav.js @@ -1,24 +1,31 @@ -import { useEffect, useRef, useState } from 'react' -import Link from 'next/link' -import { useGlobal } from '@/lib/global' -import CONFIG from '../config' -import { SvgIcon } from './SvgIcon' -import { MenuItemDrop } from './MenuItemDrop' import Collapse from '@/components/Collapse' -import { MenuItemCollapse } from './MenuItemCollapse' import LazyImage from '@/components/LazyImage' +import { siteConfig } from '@/lib/config' +import { useGlobal } from '@/lib/global' +import Link from 'next/link' +import { useEffect, useRef, useState } from 'react' +import CONFIG from '../config' +import { MenuItemCollapse } from './MenuItemCollapse' +import { MenuItemDrop } from './MenuItemDrop' import RandomPostButton from './RandomPostButton' import SearchButton from './SearchButton' -import { siteConfig } from '@/lib/config' - +import { SvgIcon } from './SvgIcon' +/** + * 顶部导航 + */ const Nav = props => { const { navBarTitle, fullWidth, siteInfo } = props - const useSticky = !JSON.parse(siteConfig('NOBELIUM_AUTO_COLLAPSE_NAV_BAR', true)) + const autoCollapseNavBar = siteConfig( + 'NOBELIUM_AUTO_COLLAPSE_NAV_BAR', + true, + CONFIG + ) + const navRef = useRef(null) const sentinalRef = useRef([]) const handler = ([entry]) => { - if (navRef && navRef.current && useSticky) { - if (!entry.isIntersecting && entry !== undefined) { + if (navRef && navRef.current && autoCollapseNavBar) { + if (!entry?.isIntersecting) { navRef.current?.classList.add('sticky-nav-full') } else { navRef.current?.classList.remove('sticky-nav-full') @@ -34,42 +41,46 @@ const Nav = props => { if (sentinalRef.current) obvserver.unobserve(sentinalRef.current) } }, [sentinalRef]) - return <> -
-