summaryrefslogtreecommitdiffstats
path: root/components/ChaChing.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2017-09-21 15:39:12 -0400
committerWes Bos <wesbos@gmail.com>2017-09-21 15:39:12 -0400
commit3b45dd7b593825721ec9ee9f6a49c732601b1ae0 (patch)
treea2e8e73d6b6b6bc32eda2bb79af817397e4304f5 /components/ChaChing.js
parent1450e579c67e3d969cb099dfe6c1cefd1e313fb5 (diff)
Cha Ching
Diffstat (limited to 'components/ChaChing.js')
-rw-r--r--components/ChaChing.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/components/ChaChing.js b/components/ChaChing.js
new file mode 100644
index 0000000..5874c27
--- /dev/null
+++ b/components/ChaChing.js
@@ -0,0 +1,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;