diff --git a/src/components/header/Header.tsx b/src/components/header/Header.tsx index c2bb93a..15ef3e0 100644 --- a/src/components/header/Header.tsx +++ b/src/components/header/Header.tsx @@ -16,7 +16,7 @@ const header = tv({ base: 'fixed z-20 flex w-full translate-y-0 justify-between bg-background-light px-6 py-2 transition duration-300 dark:bg-background sm:px-12 sm:py-4', variants: { mobileMenu: { - true: 'bg-opacity-0', + true: 'bg-opacity-0 dark:bg-opacity-0', false: 'bg-opacity-90 shadow-xl dark:bg-opacity-70', }, }, diff --git a/src/components/theme-switch/ThemeSwitch.tsx b/src/components/theme-switch/ThemeSwitch.tsx index f5e6ad8..2d86dd7 100644 --- a/src/components/theme-switch/ThemeSwitch.tsx +++ b/src/components/theme-switch/ThemeSwitch.tsx @@ -1,4 +1,4 @@ -import React, { FC, useEffect } from 'react' +import React, { FC, useEffect, useState } from 'react' import { HiOutlineMoon, HiSun } from 'react-icons/hi' import { tv } from 'tailwind-variants' import { useLocalStorage } from 'usehooks-ts' @@ -9,6 +9,17 @@ const themeIcon = tv({ const ThemeSwitch: FC = () => { const [theme, setTheme] = useLocalStorage('theme', 'dark') + const [isLight, setIsLight] = useState(theme === 'light') + const [mounted, setMounted] = useState(false) + + useEffect(() => { + setIsLight(theme === 'light') + }, [theme]) + + // Trick to avoid hydration mismatch on SVG tags + useEffect(() => { + setMounted(true) + }, []) useEffect(() => { document.body.classList.remove('light', 'dark') @@ -16,7 +27,11 @@ const ThemeSwitch: FC = () => { }, [theme]) const handleThemeChange = () => { - setTheme(theme === 'light' ? 'dark' : 'light') + setTheme(isLight ? 'dark' : 'light') + } + + if (!mounted) { + return null } return ( diff --git a/tailwind.config.ts b/tailwind.config.ts index d1cac16..901ef6c 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -4,6 +4,9 @@ import colors from 'tailwindcss/colors' export default { darkMode: 'class', content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'], + future: { + hoverOnlyWhenSupported: true, + }, theme: { rotate: { '-180': '-180deg',