mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix: theme button (#1394)
This commit is contained in:
@@ -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 (
|
||||
<StyledThemeModeSwitch
|
||||
data-testid="change-theme-container"
|
||||
onMouseEnter={() => {
|
||||
setIsHover(true);
|
||||
if (!firstTrigger) {
|
||||
setFirstTrigger(true);
|
||||
}
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
setIsHover(false);
|
||||
@@ -22,9 +18,8 @@ export const ThemeModeSwitch = () => {
|
||||
>
|
||||
<StyledSwitchItem
|
||||
data-testid="change-theme-light"
|
||||
active={theme === 'light'}
|
||||
active={resolvedTheme === 'light'}
|
||||
isHover={isHover}
|
||||
firstTrigger={firstTrigger}
|
||||
onClick={() => {
|
||||
setTheme('light');
|
||||
}}
|
||||
@@ -33,9 +28,8 @@ export const ThemeModeSwitch = () => {
|
||||
</StyledSwitchItem>
|
||||
<StyledSwitchItem
|
||||
data-testid="change-theme-dark"
|
||||
active={theme === 'dark'}
|
||||
active={resolvedTheme === 'dark'}
|
||||
isHover={isHover}
|
||||
firstTrigger={firstTrigger}
|
||||
onClick={() => {
|
||||
setTheme('dark');
|
||||
}}
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user