-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathAnimatedIconCrossfade.tsx
More file actions
65 lines (60 loc) · 1.59 KB
/
AnimatedIconCrossfade.tsx
File metadata and controls
65 lines (60 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { styled } from '@linaria/react';
import { motion } from 'framer-motion';
import { useContext } from 'react';
import { type IconComponent } from 'twenty-ui/display';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
type AnimatedIconCrossfadeProps = {
isToggled: boolean;
DefaultIcon: IconComponent;
ToggledIcon: IconComponent;
};
const StyledContainer = styled.div`
height: calc(${themeCssVariables.icon.size.sm} * 1px);
overflow: hidden;
position: relative;
width: calc(${themeCssVariables.icon.size.sm} * 1px);
`;
const StyledLayer = styled(motion.div)`
align-items: center;
display: flex;
inset: 0;
justify-content: center;
position: absolute;
`;
export const AnimatedIconCrossfade = ({
isToggled,
DefaultIcon,
ToggledIcon,
}: AnimatedIconCrossfadeProps) => {
const { theme } = useContext(ThemeContext);
return (
<StyledContainer>
<StyledLayer
initial={false}
animate={{
opacity: isToggled ? 0 : 1,
scale: isToggled ? 0.85 : 1,
}}
transition={{
duration: theme.animation.duration.fast,
ease: 'easeInOut',
}}
>
<DefaultIcon size={theme.icon.size.sm} />
</StyledLayer>
<StyledLayer
initial={false}
animate={{
opacity: isToggled ? 1 : 0,
scale: isToggled ? 1 : 0.85,
}}
transition={{
duration: theme.animation.duration.fast,
ease: 'easeInOut',
}}
>
<ToggledIcon size={theme.icon.size.sm} />
</StyledLayer>
</StyledContainer>
);
};