-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
73 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,70 @@ | ||
import React, {useRef} from "react"; | ||
import React, {useEffect, useRef} from "react"; | ||
import {categoryStore} from "@/providers/category"; | ||
import {NavLink} from "@@/exports"; | ||
import {history, NavLink, useMatch} from "@@/exports"; | ||
import {motion} from "framer-motion"; | ||
|
||
type Type = { | ||
onClick?: () => void | ||
} | ||
const MyDocMenuElement: React.FC<Type> = ({onClick}) => { | ||
const docs = categoryStore((state) => state.data?.ideaDocs) ?? []; | ||
const ref = useRef<HTMLDetailsElement>(null); | ||
const match = useMatch('/idea/:title') | ||
const docTitle = match ? match.params.title : undefined; | ||
|
||
const closeMenu = () => { | ||
if (ref.current) { | ||
ref.current.removeAttribute("open") | ||
} | ||
} | ||
|
||
|
||
useEffect(() => { | ||
const unListen = history.listen(() => { | ||
closeMenu() | ||
}); | ||
|
||
return () => { | ||
unListen(); | ||
}; | ||
}, [history]); | ||
|
||
if (docs.length === 0) { | ||
return <></> | ||
} | ||
return <> | ||
<li> | ||
<details ref={ref}> | ||
<summary>学习笔记</summary> | ||
<ul > | ||
{ | ||
docs.map((doc) => (<li onClick={()=>{ | ||
//关闭弹窗 | ||
if (ref.current) { | ||
ref.current.removeAttribute("open") | ||
} | ||
onClick?.() | ||
}} className={''}><NavLink to={`/idea/${doc}`}>{doc}</NavLink></li>)) | ||
} | ||
</ul> | ||
</details> | ||
</li> | ||
</> | ||
|
||
|
||
const GetShowTitle = () => { | ||
if (docTitle) { | ||
return docTitle | ||
} | ||
return "笔记" | ||
} | ||
|
||
const title = GetShowTitle() | ||
|
||
return (<li className={match ? 'active' : ''}> | ||
<details ref={ref}> | ||
<summary> | ||
<motion.p | ||
key={title} // 使用 key 来触发动画 | ||
initial={{opacity: 0, y: 10}} // 初始状态:透明且稍微向下 | ||
animate={{opacity: 1, y: 0}} // 动画到:完全显示且位置恢复 | ||
exit={{opacity: 0, y: -5}} // 离开时的动画:透明且向上 | ||
transition={{duration: 0.5}} // 过渡时间 | ||
>{title}</motion.p> | ||
</summary> | ||
<ul className={'w-52'}> | ||
{ | ||
docs.map((doc) => (<li onClick={() => { | ||
closeMenu() | ||
onClick?.() | ||
}} className={''}><NavLink to={`/idea/${doc}`}>{doc}</NavLink></li>)) | ||
} | ||
</ul> | ||
</details> | ||
</li>) | ||
|
||
} | ||
|
||
export default MyDocMenuElement; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters