mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
折叠菜单
This commit is contained in:
@@ -58,17 +58,20 @@ const Collapse = props => {
|
||||
clearTimeout(clearTime)
|
||||
}
|
||||
|
||||
const updateHeight = () => {
|
||||
collapseRef.current.style.height = 'auto'
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
const element = collapseRef.current
|
||||
if (props.isOpen) {
|
||||
expandSection(element)
|
||||
expandSection(collapseRef.current)
|
||||
} else {
|
||||
collapseSection(element)
|
||||
collapseSection(collapseRef.current)
|
||||
}
|
||||
}, [props.isOpen])
|
||||
|
||||
return (
|
||||
<div ref={collapseRef} style={type === 'vertical' ? { height: '0px' } : { width: '0px' }} className={'overflow-hidden duration-200 ' + props.className }>
|
||||
<div ref={collapseRef} onClick={updateHeight} style={type === 'vertical' ? { height: '0px' } : { width: '0px' }} className={'overflow-hidden duration-200 ' + props.className }>
|
||||
{props.children}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
properties.slug = properties.slug ?? properties.id
|
||||
} else if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_menu || properties.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) {
|
||||
// 菜单路径为空、作为可展开菜单使用
|
||||
properties.to = properties.slug ?? '#'
|
||||
properties.to = properties.slug ?? null
|
||||
properties.name = properties.title ?? ''
|
||||
}
|
||||
|
||||
|
||||
@@ -23,19 +23,23 @@ export const CollapseMenu = ({ link }) => {
|
||||
|
||||
return <>
|
||||
<div className='w-full px-8 py-3 text-left border-b' onClick={toggleShow} >
|
||||
<Link
|
||||
{!hasSubMenu && <Link
|
||||
href={link?.to}
|
||||
onClick={hasSubMenu ? toggleOpenSubMenu : null}
|
||||
className="font-sans flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1">
|
||||
className="font-extralight flex justify-between pl-2 pr-4 dark:text-gray-200 no-underline tracking-widest pb-1">
|
||||
<span className='text-blue-400 hover:text-red-400 transition-all items-center duration-200'>{link?.name}</span>
|
||||
{hasSubMenu && <i className='px-2 fa fa-plus text-gray-400'></i>}
|
||||
</Link>
|
||||
</Link>}
|
||||
{hasSubMenu && <div
|
||||
onClick={hasSubMenu ? toggleOpenSubMenu : null}
|
||||
className="font-extralight flex justify-between pl-2 pr-4 cursor-pointer dark:text-gray-200 no-underline tracking-widest pb-1">
|
||||
<span className='text-blue-400 hover:text-red-400 transition-all items-center duration-200'>{link?.name}</span>
|
||||
<i className='px-2 fa fa-plus text-gray-400'></i>
|
||||
</div>}
|
||||
</div>
|
||||
|
||||
{/* 折叠子菜单 */}
|
||||
{hasSubMenu && <Collapse isOpen={isOpen}>
|
||||
{link.subMenus.map(sLink => {
|
||||
return <div key={sLink.id} className='text-left px-10 justify-start text-blue-400 bg-gray-100 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 border-b dark:border-gray-800 py-3 pr-6'>
|
||||
return <div key={sLink.id} className='font-extralight text-left px-10 justify-start text-blue-400 bg-gray-50 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 border-b dark:border-gray-800 py-3 pr-6'>
|
||||
<Link href={sLink.to}>
|
||||
<span className='text-xs'>{sLink.title}</span>
|
||||
</Link>
|
||||
|
||||
@@ -7,23 +7,31 @@ export const DropMenu = ({ link }) => {
|
||||
|
||||
return <div onMouseOver={() => changeShow(true)} onMouseOut={() => changeShow(false)} >
|
||||
|
||||
{!hasSubMenu &&
|
||||
<Link
|
||||
href={link?.to}
|
||||
className="font-sans menu-link pl-2 pr-4 text-gray-700 dark:text-gray-200 no-underline tracking-widest pb-1">
|
||||
{link?.name}
|
||||
{hasSubMenu && <i className='px-2 fa fa-angle-down'></i>}
|
||||
</Link>
|
||||
</Link>}
|
||||
|
||||
{/* 子菜单 */}
|
||||
{hasSubMenu && <ul className={`${show ? 'visible opacity-100' : 'invisible opacity-0'} border-gray-100 bg-white dark:bg-black dark:border-gray-800 transition-all duration-300 z-20 top-12 absolute block border drop-shadow-lg `}>
|
||||
{link.subMenus.map(sLink => {
|
||||
return <li key={sLink.id} className=' text-blue-400 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 border-b dark:border-gray-800 py-3 pr-6 pl-2'>
|
||||
<Link href={sLink.to}>
|
||||
<span className='text-xs'>{sLink.title}</span>
|
||||
</Link>
|
||||
</li>
|
||||
})}
|
||||
</ul>}
|
||||
{hasSubMenu && <>
|
||||
<div className='cursor-pointer font-sans menu-link pl-2 pr-4 text-gray-700 dark:text-gray-200 no-underline tracking-widest pb-1'>
|
||||
{link?.name}
|
||||
<i className='px-2 fa fa-angle-down'></i>
|
||||
</div>
|
||||
</>}
|
||||
|
||||
{/* 子菜单 */}
|
||||
{hasSubMenu && <ul className={`${show ? 'visible opacity-100' : 'invisible opacity-0'} border-gray-100 bg-white dark:bg-black dark:border-gray-800 transition-all duration-300 z-20 top-12 absolute block border drop-shadow-lg `}>
|
||||
{link.subMenus.map(sLink => {
|
||||
return <li key={sLink.id} className=' text-blue-400 hover:bg-gray-50 dark:hover:bg-gray-900 tracking-widest transition-all duration-200 border-b dark:border-gray-800 py-3 pr-6 pl-2'>
|
||||
<Link href={sLink.to}>
|
||||
<span className='text-xs'>{sLink.title}</span>
|
||||
</Link>
|
||||
</li>
|
||||
})}
|
||||
</ul>}
|
||||
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import Collapse from '@/components/Collapse'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useEffect, useState } from 'react'
|
||||
import CONFIG_SIMPLE from '../config_simple'
|
||||
import { CollapseMenu } from './CollapseMenu'
|
||||
import { DropMenu } from './DropMenu'
|
||||
@@ -13,10 +14,17 @@ import { DropMenu } from './DropMenu'
|
||||
*/
|
||||
export const NavBarMenu = ({ customNav, customMenu }) => {
|
||||
const { locale } = useGlobal()
|
||||
const [isOpen, changeIsOpen] = useState(true)
|
||||
const [isOpen, changeIsOpen] = useState(false)
|
||||
const toggleIsOpen = () => {
|
||||
changeIsOpen(!isOpen)
|
||||
}
|
||||
const closeMenu = (e) => {
|
||||
changeIsOpen(false)
|
||||
}
|
||||
const router = useRouter()
|
||||
useEffect(() => {
|
||||
router.events.on('routeChangeComplete', closeMenu)
|
||||
})
|
||||
|
||||
let links = [
|
||||
{ icon: 'fas fa-search', name: locale.NAV.SEARCH, to: '/search', show: CONFIG_SIMPLE.MENU_SEARCH },
|
||||
@@ -49,10 +57,10 @@ export const NavBarMenu = ({ customNav, customMenu }) => {
|
||||
<div id='nav-menu-mobile' className='flex md:hidden my-auto justify-start'>
|
||||
<div onClick={toggleIsOpen} className='cursor-pointer hover:text-red-400 transition-all duration-200'>
|
||||
<i className='fa fa-bars mr-3' />
|
||||
<span>{isOpen ? 'CLOSE' : 'MENU'}</span>
|
||||
<span>{!isOpen ? 'MENU' : 'CLOSE'}</span>
|
||||
</div>
|
||||
|
||||
<Collapse className='absolute w-full top-12 left-0 border-b' isOpen={isOpen}>
|
||||
<Collapse className='absolute w-full top-12 left-0' isOpen={isOpen}>
|
||||
<div id='menu-wrap' className='bg-white border'>
|
||||
{links?.map(link => {
|
||||
if (link?.show) {
|
||||
|
||||
@@ -3,7 +3,7 @@ const CONFIG_SIMPLE = {
|
||||
LOGO_IMG: '/Logo.webp',
|
||||
TOP_BAR: true, // 显示顶栏
|
||||
TOP_BAR_CONTENT: process.env.NEXT_PUBLIC_THEME_SIMPLE_TOP_TIPS || '',
|
||||
LOGO_DESCRIPTION: process.env.NEXT_PUBLIC_THEME_SIMPLE_LOGO_DESCRIPTION || '<div>程序员<br/>互联网爱好者/人文历史<br/>创业财富</div>',
|
||||
LOGO_DESCRIPTION: process.env.NEXT_PUBLIC_THEME_SIMPLE_LOGO_DESCRIPTION || '<div>编程爱好者<br/>阅读分享<br/>自由职业者</div>',
|
||||
|
||||
AUTHOR_LINK: process.env.NEXT_PUBLIC_AUTHOR_LINK || '#',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user