mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
22 lines
938 B
JavaScript
22 lines
938 B
JavaScript
import { useGlobal } from '@/lib/global'
|
|
import { saveDarkModeToCookies } from '@/themes/theme'
|
|
import { Moon, Sun } from './HeroIcons'
|
|
|
|
const DarkModeButton = (props) => {
|
|
const { isDarkMode, updateDarkMode } = useGlobal()
|
|
// 用户手动设置主题
|
|
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={`${props.className ? props.className : ''} flex justify-center dark:text-gray-200 text-gray-800`}>
|
|
<div id='darkModeButton' className=' hover:scale-110 cursor-pointer transform duration-200 w-5 h-5'> {isDarkMode ? <Sun /> : <Moon />}</div>
|
|
</div>
|
|
}
|
|
export default DarkModeButton
|