From 43a6cd49a4ca62dacce391037f1eaf573d280c9b Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 18 Jul 2023 11:19:01 +0800 Subject: [PATCH] theme-heo --- components/DarkModeButton.js | 19 ++++++++- themes/gitbook/components/FloatTocButton.js | 5 ++- themes/heo/components/ArticleAdjacent.js | 4 +- themes/heo/components/FloatTocButton.js | 45 +++++++++++++++++++++ themes/heo/components/Hero.js | 2 +- themes/heo/components/SlideOver.js | 43 ++++++++++++++------ themes/heo/components/TocDrawer.js | 42 ------------------- themes/heo/index.js | 8 ++-- 8 files changed, 106 insertions(+), 62 deletions(-) create mode 100644 themes/heo/components/FloatTocButton.js delete mode 100644 themes/heo/components/TocDrawer.js diff --git a/components/DarkModeButton.js b/components/DarkModeButton.js index b41b6c00..aaeed000 100644 --- a/components/DarkModeButton.js +++ b/components/DarkModeButton.js @@ -1,9 +1,26 @@ import { useGlobal } from '@/lib/global' import { saveDarkModeToCookies } from '@/themes/theme' import { Moon, Sun } from './HeroIcons' +import { useImperativeHandle } from 'react' +/** + * 深色模式按钮 + */ const DarkModeButton = (props) => { + const { cRef, className } = props const { isDarkMode, updateDarkMode } = useGlobal() + + /** + * 对外暴露方法 + */ + useImperativeHandle(cRef, () => { + return { + handleChangeDarkMode: () => { + handleChangeDarkMode() + } + } + }) + // 用户手动设置主题 const handleChangeDarkMode = () => { const newStatus = !isDarkMode @@ -14,7 +31,7 @@ const DarkModeButton = (props) => { htmlElement.classList?.add(newStatus ? 'dark' : 'light') } - return
+ return
{isDarkMode ? : }
} diff --git a/themes/gitbook/components/FloatTocButton.js b/themes/gitbook/components/FloatTocButton.js index 3b6c5933..4215f447 100644 --- a/themes/gitbook/components/FloatTocButton.js +++ b/themes/gitbook/components/FloatTocButton.js @@ -1,5 +1,8 @@ import { useGitBookGlobal } from '@/themes/gitbook' +/** + * 移动端悬浮目录按钮 + */ export default function FloatTocButton () { const { tocVisible, changeTocVisible } = useGitBookGlobal() @@ -14,7 +17,7 @@ export default function FloatTocButton () { } >
diff --git a/themes/heo/components/ArticleAdjacent.js b/themes/heo/components/ArticleAdjacent.js index bebc7e69..ebfb0a3e 100644 --- a/themes/heo/components/ArticleAdjacent.js +++ b/themes/heo/components/ArticleAdjacent.js @@ -67,10 +67,10 @@ export default function ArticleAdjacent({ prev, next }) { {/* 桌面端 */} -
+
下一篇

diff --git a/themes/heo/components/FloatTocButton.js b/themes/heo/components/FloatTocButton.js new file mode 100644 index 00000000..bbded092 --- /dev/null +++ b/themes/heo/components/FloatTocButton.js @@ -0,0 +1,45 @@ +import { useState } from 'react' +import Catalog from './Catalog' + +/** + * 移动端悬浮目录按钮 + */ +export default function FloatTocButton(props) { + const [tocVisible, changeTocVisible] = useState(false) + + const { post } = props + + const toggleToc = () => { + changeTocVisible(!tocVisible) + } + + // 没有目录就隐藏该按钮 + if (!post || !post.toc || post.toc.length < 1) { + return <> + } + + return (
+ {/* 按钮 */} +
+
+ + {/* 目录Modal */} +
+ {/* 侧边菜单 */} +
+ {post && <> +
+ +
+ + } +
+
+ {/* 背景蒙版 */} +
+
) +} diff --git a/themes/heo/components/Hero.js b/themes/heo/components/Hero.js index d34530c2..b6979531 100644 --- a/themes/heo/components/Hero.js +++ b/themes/heo/components/Hero.js @@ -180,7 +180,7 @@ function TopGroup(props) {
{/* eslint-disable-next-line */} -
{p?.title}
+
{p?.title}
{/* hover 悬浮的 ‘荐’ 字 */}
荐 diff --git a/themes/heo/components/SlideOver.js b/themes/heo/components/SlideOver.js index cc4a4772..fdd20bf4 100644 --- a/themes/heo/components/SlideOver.js +++ b/themes/heo/components/SlideOver.js @@ -1,5 +1,5 @@ -import { Fragment, useImperativeHandle, useState } from 'react' +import { Fragment, useImperativeHandle, useRef, useState } from 'react' import { Dialog, Transition } from '@headlessui/react' import DarkModeButton from '@/components/DarkModeButton' import Link from 'next/link' @@ -13,8 +13,8 @@ export default function SlideOver(props) { const [open, setOpen] = useState(false) /** - * 函数组件暴露方法useImperativeHandle - */ + * 函数组件暴露方法useImperativeHandle + */ useImperativeHandle(cRef, () => ({ toggleSlideOvers: toggleSlideOvers })) @@ -77,25 +77,22 @@ export default function SlideOver(props) {
功能
-
显示模式
+ {/* 切换深色模式 */} +
博客
- + {/* 导航按钮 */}
- - 主页 - - - 关于 - +
标签
- +
@@ -109,3 +106,25 @@ export default function SlideOver(props) { ) } + +/** + * 一个包含图标的按钮 + */ +function DarkModeBlockButton() { + const darkModeRef = useRef() + function handleChangeDarkMode() { + darkModeRef?.current?.handleChangeDarkMode() + } + return +} + +/** + * 一个简单的按钮 + */ +function Button({ title, url }) { + return + {title} + +} diff --git a/themes/heo/components/TocDrawer.js b/themes/heo/components/TocDrawer.js deleted file mode 100644 index 13fad1a9..00000000 --- a/themes/heo/components/TocDrawer.js +++ /dev/null @@ -1,42 +0,0 @@ -import Catalog from './Catalog' -import React, { useImperativeHandle, useState } from 'react' - -/** - * 目录抽屉栏 - * @param toc - * @param post - * @returns {JSX.Element} - * @constructor - */ -const TocDrawer = ({ post, cRef }) => { - // 暴露给父组件 通过cRef.current.handleMenuClick 调用 - useImperativeHandle(cRef, () => { - return { - handleSwitchVisible: () => switchVisible() - } - }) - const [showDrawer, switchShowDrawer] = useState(false) - const switchVisible = () => { - switchShowDrawer(!showDrawer) - } - return <> -
- {/* 侧边菜单 */} -
- {post && <> -
- -
- - } -
-
- {/* 背景蒙版 */} -
- -} -export default TocDrawer diff --git a/themes/heo/index.js b/themes/heo/index.js index 68ef8a94..1a8f46e0 100644 --- a/themes/heo/index.js +++ b/themes/heo/index.js @@ -30,6 +30,7 @@ import { Style } from './style' import { NoticeBar } from './components/NoticeBar' import { HashTag } from '@/components/HeroIcons' import LatestPostsGroup from './components/LatestPostsGroup' +import FloatTocButton from './components/FloatTocButton' /** * 基础布局 采用上中下布局,移动端使用顶部侧边导航栏 @@ -56,7 +57,7 @@ const LayoutBase = props => { {headerSlot} {/* 主区块 */} -
+
@@ -243,14 +244,14 @@ const LayoutSlug = props => { return ( -
+
{lock && } {!lock &&
{/* Notion文章主体 */} -
+
{post && }
@@ -277,6 +278,7 @@ const LayoutSlug = props => {
}
+
)