diff --git a/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/index.tsx b/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/index.tsx index 84f34af751..cea6fbeeb5 100644 --- a/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/index.tsx +++ b/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/index.tsx @@ -4,17 +4,13 @@ import { useState } from 'react'; import { MoonIcon, SunIcon } from './Icons'; import { StyledSwitchItem, StyledThemeModeSwitch } from './style'; export const ThemeModeSwitch = () => { - const { theme, setTheme } = useTheme(); + const { setTheme, resolvedTheme } = useTheme(); const [isHover, setIsHover] = useState(false); - const [firstTrigger, setFirstTrigger] = useState(false); return ( { setIsHover(true); - if (!firstTrigger) { - setFirstTrigger(true); - } }} onMouseLeave={() => { setIsHover(false); @@ -22,9 +18,8 @@ export const ThemeModeSwitch = () => { > { setTheme('light'); }} @@ -33,9 +28,8 @@ export const ThemeModeSwitch = () => { { setTheme('dark'); }} diff --git a/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/style.ts b/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/style.ts index 0cdd5db5ff..7598f58072 100644 --- a/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/style.ts +++ b/apps/web/src/components/blocksuite/header/header-right-items/theme-mode-switch/style.ts @@ -15,8 +15,7 @@ export const StyledThemeModeSwitch = styled('div')({ export const StyledSwitchItem = styled('div')<{ active: boolean; isHover: boolean; - firstTrigger: boolean; -}>(({ active, isHover, firstTrigger, theme }) => { +}>(({ active, isHover, theme }) => { const activeRaiseAnimate = toString( spring({ top: '0' }, { top: '-100%' }, { preset: 'gentle' }) ); @@ -34,26 +33,22 @@ export const StyledSwitchItem = styled('div')<{ ? { color: theme.colors.iconColor, top: '0', - animation: firstTrigger - ? css` - ${keyframes`${ - isHover ? activeRaiseAnimate : activeDeclineAnimate - }`} ${ANIMATE_DURATION}ms forwards - ` - : 'unset', + animation: css` + ${keyframes`${ + isHover ? activeRaiseAnimate : activeDeclineAnimate + }`} ${ANIMATE_DURATION}ms forwards + `, animationDirection: isHover ? 'normal' : 'alternate', } : { top: '100%', color: theme.colors.primaryColor, backgroundColor: theme.colors.hoverBackground, - animation: firstTrigger - ? css` - ${keyframes`${ - isHover ? raiseAnimate : declineAnimate - }`} ${ANIMATE_DURATION}ms forwards - ` - : 'unset', + animation: css` + ${keyframes`${ + isHover ? raiseAnimate : declineAnimate + }`} ${ANIMATE_DURATION}ms forwards + `, animationDirection: isHover ? 'normal' : 'alternate', }; return css`