File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -6,14 +6,15 @@ import { useTheme } from 'next-themes';
66import { useEffect , useRef , useState } from 'react' ;
77import { ThemeSwitcher } from 'theme-toggle-animation' ;
88import { Toaster } from './ui/sonner' ;
9- const DURATION = 300 ;
9+ const DURATION = 500 ;
1010// 创建 ThemeSwitcher 实例
1111const themeSwitcher = new ThemeSwitcher ( {
1212 customHtmlStyles : true ,
1313 transition : 'circle' ,
1414 duration : DURATION
1515} ) ;
1616export function ThemeToggle ( ) {
17+ const eventRef = useRef < AnyIfEmpty > ( null ) ;
1718 const [ mounted , setMounted ] = useState ( false ) ;
1819 const { theme, setTheme } : AnyIfEmpty = useTheme ( ) ;
1920 const toggleRef = useRef < AnyIfEmpty > ( null ) ;
@@ -55,19 +56,19 @@ export function ThemeToggle() {
5556 if ( ! mounted ) {
5657 return null ;
5758 }
58- const handleThemeChange = ( event : React . MouseEvent & AnyIfEmpty ) => {
59+ const handleThemeChange = ( ) => {
5960 const newTheme = theme === 'dark' ? 'light' : 'dark' ;
60- themeSwitcher . toggleTheme ( event ) ;
61+ themeSwitcher . toggleTheme ( eventRef . current ) ;
6162 setTimeout ( ( ) => {
6263 setTheme ( newTheme ) ;
63- } , DURATION ) ;
64+ } ) ;
6465 } ;
6566 return (
6667 < div className = "flex items-center space-x-2" >
6768 < Switch
6869 ref = { toggleRef }
6970 id = "theme-toggle"
70- // onClick={handleThemeChange }
71+ onClick = { ( event ) => ( eventRef . current = event ) }
7172 checked = { theme === 'dark' }
7273 onCheckedChange = { handleThemeChange }
7374 className = "w-16 h-8 px-1"
You can’t perform that action at this time.
0 commit comments