-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1303 from jxpeng98/back-ground-bug
修复heo暗黑模式下,右侧最新文章列表背景仍为白色bug,并且在上部导航栏添加暗黑模式切换按钮
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -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 |
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