blob: 245b07bb1e6e2f156dc2d5b02e2dc264fb4a1891 (
plain)
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
|
import styled from 'styled-components';
import { TransitionGroup, CSSTransition } from 'react-transition-group';
const Dot = styled.div`
background: ${props => props.theme.red};
color: white;
border-radius: 50%;
padding: 5px;
margin-left: 1rem;
font-weight: 100;
font-feature-settings: 'tnum';
font-variant-numeric: tabular-nums;
`;
const AnimationStyles = styled.span`
position: relative;
.count {
display: block;
position: relative;
transition: all 0.4s;
backface-visibility: hidden;
}
.count-enter {
transform: rotateX(0.5turn);
}
.count-enter-active {
transform: rotateX(0);
}
.count-exit {
top: 0;
position: absolute;
transform: rotateX(0);
}
.count-exit-active {
transform: rotateX(0.5turn);
}
`;
const CartCount = ({ count }) => (
<AnimationStyles>
<TransitionGroup>
<CSSTransition className="count" classNames="count" key={count} timeout={{ enter: 2000, exit: 2000 }}>
<Dot>{count}</Dot>
</CSSTransition>
</TransitionGroup>
</AnimationStyles>
);
export default CartCount;
|