Compare commits

...

2 Commits

Author SHA1 Message Date
cf437a4c99 Update ThemeButton
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m39s
2024-09-27 21:50:48 +01:00
fd184a5973 Update Card 2024-09-27 21:50:32 +01:00
2 changed files with 5 additions and 16 deletions

View File

@ -89,7 +89,7 @@ Card.Link = function CardLink({href, children}: CardLink) {
Card.Title = function CardTitle({as: Component = 'h2', href, children}: CardTitle) { Card.Title = function CardTitle({as: Component = 'h2', href, children}: CardTitle) {
return ( return (
<Component className="text-base font-semibold tracking-tight text-zinc-800 dark:text-zinc-100"> <Component className="group-hover:text-indigo-500 text-base font-semibold tracking-tight text-zinc-800 dark:text-zinc-100">
{href ? <Card.Link href={href}>{children}</Card.Link> : children} {href ? <Card.Link href={href}>{children}</Card.Link> : children}
</Component> </Component>
) )

View File

@ -7,33 +7,22 @@ import {MoonIcon} from '@/components/icons/MoonIcon'
export function ThemeButton() { export function ThemeButton() {
const [mounted, setMounted] = useState(false) const [mounted, setMounted] = useState(false)
const {theme, setTheme} = useTheme() const {resolvedTheme, setTheme} = useTheme()
let otherTheme = resolvedTheme === 'dark' ? 'light' : 'dark'
useEffect(() => { useEffect(() => {
const timeout = setTimeout(() => setMounted(true), 500) const timeout = setTimeout(() => setMounted(true), 500)
return () => clearTimeout(timeout) return () => clearTimeout(timeout)
}, []) }, [])
function toggleTheme() {
let darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
let isSystemDarkMode = darkModeMediaQuery.matches
let isDarkMode = theme === 'dark'
if (isDarkMode === isSystemDarkMode) {
setTheme('light')
} else {
setTheme('dark')
}
}
if (!mounted) return <ThemeButton.Skeleton/> if (!mounted) return <ThemeButton.Skeleton/>
return ( return (
<button <button
type="button" type="button"
aria-label="Toggle dark mode" aria-label={mounted ? `Switch to ${otherTheme} theme` : 'Toggle theme'}
className="group rounded-full bg-white/90 px-3 py-2 shadow-lg shadow-zinc-800/5 ring-1 ring-zinc-900/5 backdrop-blur transition dark:bg-zinc-800/90 dark:ring-white/10 dark:hover:ring-white/20" className="group rounded-full bg-white/90 px-3 py-2 shadow-lg shadow-zinc-800/5 ring-1 ring-zinc-900/5 backdrop-blur transition dark:bg-zinc-800/90 dark:ring-white/10 dark:hover:ring-white/20"
onClick={() => toggleTheme()} onClick={() => setTheme(otherTheme)}
> >
<SunIcon <SunIcon
className="h-6 w-6 fill-zinc-100 stroke-zinc-500 transition group-hover:fill-zinc-200 group-hover:stroke-zinc-700 dark:hidden [@media(prefers-color-scheme:dark)]:fill-indigo-50 [@media(prefers-color-scheme:dark)]:stroke-indigo-500 [@media(prefers-color-scheme:dark)]:group-hover:fill-indigo-50 [@media(prefers-color-scheme:dark)]:group-hover:stroke-indigo-600"/> className="h-6 w-6 fill-zinc-100 stroke-zinc-500 transition group-hover:fill-zinc-200 group-hover:stroke-zinc-700 dark:hidden [@media(prefers-color-scheme:dark)]:fill-indigo-50 [@media(prefers-color-scheme:dark)]:stroke-indigo-500 [@media(prefers-color-scheme:dark)]:group-hover:fill-indigo-50 [@media(prefers-color-scheme:dark)]:group-hover:stroke-indigo-600"/>