summaryrefslogtreecommitdiffstats
path: root/frontend/components/ChaChing.js
blob: 5874c2768a2e1184df1548fb9f6498cd4e61a83b (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
53
54
55
56
import TransitionGroup from 'react-transition-group/TransitionGroup';
import Transition from 'react-transition-group/Transition';
import styled from 'styled-components';

const CartCount = styled.div`
  padding: 10px;
  transition: all 0.5s;
  display: inline-block;
  background: white;
  background: linear-gradient(to bottom, #eeeeee 0%, #eeeeee 100%);
  transform: translateY(100%);
  z-index: 1;
  position: relative;
  &.cart-entering {
    background: green;
    transform: translateY(100%);
  }
  &.cart-entered {
    transform: translateY(0);
  }
  &.cart-exiting {
    position: absolute;
    z-index: 0;
    left: 0;
    transform: translateY(-100%);
  }
`;

const ChaChingStyles = styled.div`
  position: relative;
  display: inline-block;
  overflow: hidden;
`;

const ChaChing = ({ amount }) => (
  <ChaChingStyles>
    <TransitionGroup>
      <Transition
        in
        timeout={{
          enter: 0,
          exit: 500,
        }}
        key={amount}
      >
        {status => (
          <CartCount className={`cart-${status}`} key={`count-${amount}`}>
            {amount}
          </CartCount>
        )}
      </Transition>
    </TransitionGroup>
  </ChaChingStyles>
);

export default ChaChing;