Files
openclawdoc/components/ThemeToggle.tsx
2026-02-28 23:01:30 +08:00

30 lines
806 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useTheme } from './ThemeProvider';
import { useEffect, useState } from 'react';
export function ThemeToggle() {
const { theme, toggleTheme } = useTheme();
const [mounted, setMounted] = useState(false);
// Avoid hydration mismatch by only rendering icon after mount
useEffect(() => {
setMounted(true);
}, []);
if (!mounted) {
return <button className="theme-toggle" style={{ visibility: 'hidden' }}></button>;
}
return (
<button
onClick={toggleTheme}
className="theme-toggle"
title={theme === 'light' ? '切换到深色模式' : '切换到亮色模式'}
aria-label="Toggle theme"
>
{theme === 'light' ? '🌙' : '☀️'}
</button>
);
}