Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复heo暗黑模式下,右侧最新文章列表背景仍为白色bug,并且在上部导航栏添加暗黑模式切换按钮 #1303

Merged
merged 5 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions themes/heo/components/DarkModeButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useGlobal } from '@/lib/global'
import { saveDarkModeToCookies } from '@/themes/theme'
import { Moon, Sun } from '@/components/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
saveDarkModeToCookies(newStatus)
updateDarkMode(newStatus)
const htmlElement = document.getElementsByTagName('html')[0]
htmlElement.classList?.remove(newStatus ? 'light' : 'dark')
htmlElement.classList?.add(newStatus ? 'dark' : 'light')
}

return <div onClick={handleChangeDarkMode} className={`${className || ''} cursor-pointer hover: scale-100 hover:bg-black hover:bg-opacity-10 rounded-full w-10 h-10 flex justify-center items-center duration-200 transition-all`}>
<div id='darkModeButton' className=' cursor-pointer hover: scale-50 w-10 h-10 '> {isDarkMode ? <Sun /> : <Moon />}</div>
</div>
}
export default DarkModeButton
2 changes: 2 additions & 0 deletions themes/heo/components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Logo from './Logo'
import throttle from 'lodash.throttle'
import RandomPostButton from './RandomPostButton'
import SearchButton from './SearchButton'
import DarkModeButton from './DarkModeButton'
import SlideOver from './SlideOver'
import ReadingProgress from './ReadingProgress'
import { MenuListTop } from './MenuListTop'
Expand Down Expand Up @@ -145,6 +146,7 @@ const NavBar = props => {
<div className='flex flex-shrink-0 justify-center items-center space-x-1'>
<RandomPostButton {...props} />
<SearchButton />
{!JSON.parse(BLOG.THEME_SWITCH) && <DarkModeButton {...props} />}
<ReadingProgress />

{/* 移动端菜单按钮 */}
Expand Down
2 changes: 1 addition & 1 deletion themes/heo/components/SideRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function SideRight(props) {
<TouchMeCard />

{/* 最新文章列表 */}
<div className={'border dark:border-gray-700 rounded-xl lg:p-6 p-4 hidden lg:block bg-white'}>
<div className={'border dark:border-gray-700 dark:bg-[#1e1e1e] dark:text-white rounded-xl lg:p-6 p-4 hidden lg:block bg-white'}>
<LatestPostsGroupMini {...props} />
</div>

Expand Down
Loading