@@ -2,6 +2,8 @@ import React, {useEffect} from 'react'
2
2
import './ExpChart.css'
3
3
import logo from '../ExpChart/assets/expenses-chart-component-main/images/logo.svg'
4
4
import data from '../ExpChart/assets/expenses-chart-component-main/data.json'
5
+ import { motion } from 'framer-motion'
6
+ import { basicFadeUp2Profile , basicFadeUpProfile } from './animation'
5
7
6
8
const ExpChart = ( ) => {
7
9
@@ -23,14 +25,44 @@ const ExpChart = () => {
23
25
document . getElementById ( highest ) . classList . add ( 'expChart-graph-data-vis-highest' )
24
26
}
25
27
28
+
29
+
30
+
26
31
useEffect ( ( ) => {
27
32
addStyle ( )
33
+
34
+ // ANIMATE COUNTER
35
+ setTimeout ( ( ) => {
36
+
37
+ const counters = document . querySelectorAll ( '.expChart-graph-stats-left-total' ) ;
38
+ const speed = 700 ;
39
+
40
+ counters . forEach ( counter => {
41
+ const animate = ( ) => {
42
+ const value = + counter . getAttribute ( 'counter' ) ;
43
+ const data = + counter . innerText ;
44
+
45
+ const time = value / speed ;
46
+ if ( data < value ) {
47
+ counter . innerText = Math . ceil ( data + time ) ;
48
+ setTimeout ( animate , 1 ) ;
49
+ } else {
50
+ counter . innerText = `$${ value } ` ;
51
+ }
52
+
53
+ }
54
+
55
+ animate ( ) ;
56
+ } ) ;
57
+
58
+ } , 1200 )
59
+
28
60
} , [ ] )
29
61
30
62
return (
31
63
< div className = 'expChart df' >
32
64
< main className = "expChart-container" >
33
- < header className = "expChart-header" >
65
+ < motion . header { ... basicFadeUpProfile } className = "expChart-header" >
34
66
< div className = "expChart-balance-info" >
35
67
< h4 className = "expChart-balance-info-title" >
36
68
My balance
@@ -40,17 +72,24 @@ const ExpChart = () => {
40
72
</ p >
41
73
</ div >
42
74
< img src = { logo } alt = "" className = "expChart-logo" />
43
- </ header >
44
- < section className = "expChart-graph" >
75
+ </ motion . header >
76
+ < motion . section { ... basicFadeUp2Profile } className = "expChart-graph" >
45
77
< h1 className = "expChart-graph-title" >
46
78
Spending - Last 7 days
47
79
</ h1 >
48
80
< ul className = "expChart-graph-data-container" >
49
81
{ data . map ( ( item , index ) => (
50
82
< li className = "expChart-graph-data-info" >
51
- < div className = "expChart-graph-data-vis" key = { index } id = { index } style = { { height :`${ ( Math . floor ( item . amount ) * 3 ) } px` } } >
83
+ < motion . div
84
+ initial = { { height :'0px' } }
85
+ animate = { { height :( Math . floor ( item . amount ) * 3 ) ,
86
+ transition :{ duration : .2 ,
87
+ ease :[ 0.25 , 0.46 , 0.45 , 0.94 ] ,
88
+ delay : 1.2 + ( 0.15 * index )
89
+ } } }
90
+ className = "expChart-graph-data-vis" key = { index } id = { index } style = { { height :`${ ( Math . floor ( item . amount ) * 3 ) } px` } } >
52
91
< span > ${ item . amount } </ span >
53
- </ div >
92
+ </ motion . div >
54
93
< div className = "expChart-graph-data-day" >
55
94
{ item . day }
56
95
</ div >
@@ -62,8 +101,8 @@ const ExpChart = () => {
62
101
< div className = "expChart-graph-stats-left-desc" >
63
102
Total this month
64
103
</ div >
65
- < div className = "expChart-graph-stats-left-total" >
66
- $478.33
104
+ < div className = "expChart-graph-stats-left-total" counter = "478.33" >
105
+ { /* $478.33 */ }
67
106
</ div >
68
107
</ div >
69
108
< div className = "expChart-graph-stats-right" >
@@ -75,7 +114,7 @@ const ExpChart = () => {
75
114
</ div >
76
115
</ div >
77
116
</ div >
78
- </ section >
117
+ </ motion . section >
79
118
</ main >
80
119
</ div >
81
120
)
0 commit comments