mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 22:05:40 +00:00
Ryan Freeman
cf437a4c99
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m39s
42 lines
1.9 KiB
TypeScript
42 lines
1.9 KiB
TypeScript
'use client'
|
|
|
|
import {useEffect, useState} from 'react'
|
|
import {useTheme} from 'next-themes'
|
|
import {SunIcon} from '@/components/icons/SunIcon'
|
|
import {MoonIcon} from '@/components/icons/MoonIcon'
|
|
|
|
export function ThemeButton() {
|
|
const [mounted, setMounted] = useState(false)
|
|
const {resolvedTheme, setTheme} = useTheme()
|
|
let otherTheme = resolvedTheme === 'dark' ? 'light' : 'dark'
|
|
|
|
useEffect(() => {
|
|
const timeout = setTimeout(() => setMounted(true), 500)
|
|
return () => clearTimeout(timeout)
|
|
}, [])
|
|
|
|
if (!mounted) return <ThemeButton.Skeleton/>
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
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"
|
|
onClick={() => setTheme(otherTheme)}
|
|
>
|
|
<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"/>
|
|
<MoonIcon
|
|
className="hidden h-6 w-6 fill-zinc-700 stroke-zinc-500 transition dark:block [@media(prefers-color-scheme:dark)]:group-hover:stroke-zinc-400 [@media_not_(prefers-color-scheme:dark)]:fill-indigo-400/10 [@media_not_(prefers-color-scheme:dark)]:stroke-indigo-500"/>
|
|
</button>
|
|
)
|
|
}
|
|
|
|
ThemeButton.Skeleton = function ThemeButtonSkeleton() {
|
|
return (
|
|
<div
|
|
className="animate-pulse rounded-full bg-zinc-100 px-3 py-2 backdrop-blur transition dark:bg-zinc-800/90">
|
|
<div className="h-6 w-6"/>
|
|
</div>
|
|
)
|
|
} |