Files
chorus-services/modules/dashboard/components/ThemeToggle.tsx
tony 2e1bb2e55e Major update to chorus.services platform
- Extensive updates to system configuration and deployment
- Enhanced documentation and architecture improvements
- Updated dependencies and build configurations
- Improved service integrations and workflows

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-17 22:01:07 +10:00

49 lines
1.4 KiB
TypeScript

'use client'
import { useState, useEffect } from 'react'
import { Sun, Moon } from 'lucide-react'
export default function ThemeToggle() {
const [isDark, setIsDark] = useState(false)
useEffect(() => {
// Check if user has a saved preference, otherwise default to light mode
const savedTheme = localStorage.getItem('theme')
const prefersDark = savedTheme === 'dark'
setIsDark(prefersDark)
if (prefersDark) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
}, [])
const toggleTheme = () => {
const newTheme = !isDark
setIsDark(newTheme)
if (newTheme) {
document.documentElement.classList.add('dark')
localStorage.setItem('theme', 'dark')
} else {
document.documentElement.classList.remove('dark')
localStorage.setItem('theme', 'light')
}
}
return (
<button
onClick={toggleTheme}
className="fixed top-chorus-lg right-chorus-lg z-50 p-chorus-md bg-white dark:bg-carbon-900 border border-sand-300 dark:border-carbon-600 rounded-lg shadow-lg hover:shadow-xl transition-all duration-300 ease-out hover:scale-105 active:scale-95"
aria-label={isDark ? 'Switch to light mode' : 'Switch to dark mode'}
>
{isDark ? (
<Sun className="h-5 w-5 text-sand-600 dark:text-sand-400" />
) : (
<Moon className="h-5 w-5 text-carbon-600" />
)}
</button>
)
}