mirror of
https://github.com/fccview/cronmaster.git
synced 2026-02-07 04:21:42 -05:00
34 lines
938 B
TypeScript
34 lines
938 B
TypeScript
'use client'
|
|
|
|
import { useTheme } from 'next-themes';
|
|
import { useEffect, useState } from 'react';
|
|
import { SunIcon, MoonIcon } from '@phosphor-icons/react';
|
|
|
|
export const ThemeToggle = () => {
|
|
const [mounted, setMounted] = useState(false);
|
|
const { theme, setTheme } = useTheme();
|
|
|
|
useEffect(() => {
|
|
setMounted(true);
|
|
}, []);
|
|
|
|
if (!mounted) return null;
|
|
|
|
const isDark = theme === 'dark';
|
|
|
|
return (
|
|
<button
|
|
onClick={() => setTheme(isDark ? 'light' : 'dark')}
|
|
className="p-2 ascii-border bg-background0 hover:bg-background1 transition-colors"
|
|
aria-label={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
|
|
title={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
|
|
>
|
|
{isDark ? (
|
|
<SunIcon size={20} weight="regular" className="text-foreground" />
|
|
) : (
|
|
<MoonIcon size={20} weight="regular" className="text-foreground" />
|
|
)}
|
|
</button>
|
|
);
|
|
};
|