@@ -2,106 +2,100 @@ import React from 'react'
2
2
import clsx from 'clsx'
3
3
import PropTypes from 'prop-types'
4
4
import { makeStyles } from '@material-ui/core/styles'
5
- import { Paper , Grid , Typography } from '@material-ui/core'
5
+ import { Paper , Box , Grid , Typography } from '@material-ui/core'
6
6
import { Line } from 'react-chartjs-2'
7
7
8
- import { subscriptionsTrendChart } from './data'
8
+ import { generateTrendChartData } from './data'
9
+
10
+ const numbers = [
11
+ {
12
+ name : 'Monthly Revenue' ,
13
+ value : '24350$' ,
14
+ change : '+13%' ,
15
+ trend : 'positive' ,
16
+ chart : generateTrendChartData ( {
17
+ name : 'Monthly Revenue' ,
18
+ from : Math . round ( 24350 / 1.13 ) ,
19
+ to : 24350 ,
20
+ length : 15 ,
21
+ } ) ,
22
+ } ,
23
+ {
24
+ name : 'Total Users' ,
25
+ value : 48205 ,
26
+ change : '+10%' ,
27
+ trend : 'positive' ,
28
+ chart : generateTrendChartData ( {
29
+ name : 'Total Users' ,
30
+ from : Math . round ( 48205 / 1.1 ) ,
31
+ to : 48205 ,
32
+ } ) ,
33
+ } ,
34
+ {
35
+ name : 'Subscriptions' ,
36
+ value : 139 ,
37
+ change : '-5%' ,
38
+ trend : 'negative' ,
39
+ chart : generateTrendChartData ( {
40
+ name : 'Subscriptions' ,
41
+ from : 139 ,
42
+ to : Math . round ( 139 / 1.05 ) ,
43
+ length : 15 ,
44
+ } ) ,
45
+ } ,
46
+ {
47
+ name : 'Monthly Churn' ,
48
+ value : 13 ,
49
+ change : '-10%' ,
50
+ trend : 'positive' ,
51
+ chart : generateTrendChartData ( {
52
+ name : 'Monthly Churn' ,
53
+ from : 13 ,
54
+ to : Math . random ( 13 / 1.1 ) ,
55
+ length : 15 ,
56
+ } ) ,
57
+ } ,
58
+ ]
9
59
10
60
const KeyNumbers = props => {
11
61
const classes = useStyles ( )
12
62
13
63
return (
14
64
< >
15
- < Grid item xs = { 6 } sm = { 3 } >
16
- < Paper className = { classes . paper } >
17
- < Grid container spacing = { 0 } >
18
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
19
- < Typography variant = "body2" > Subscriptions</ Typography >
20
- < Typography variant = "body1" className = { classes . value } >
21
- 139 < sup className = { clsx ( classes . valueChange , classes . positive ) } > +5%</ sup >
22
- </ Typography >
23
- </ Grid >
24
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
25
- < div className = { classes . chartContainer } >
26
- < div className = { classes . chart } >
27
- < Line
28
- data = { subscriptionsTrendChart . data }
29
- options = { subscriptionsTrendChart . options }
30
- />
31
- </ div >
32
- </ div >
33
- </ Grid >
34
- </ Grid >
35
- </ Paper >
36
- </ Grid >
37
- < Grid item xs = { 6 } sm = { 3 } >
38
- < Paper className = { classes . paper } >
39
- < Grid container spacing = { 0 } >
40
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
41
- < Typography variant = "body2" > Monthly Revenue</ Typography >
42
- < Typography variant = "body1" className = { classes . value } >
43
- 24350${ ' ' }
44
- < sup className = { clsx ( classes . valueChange , classes . positive ) } > +13%</ sup >
45
- </ Typography >
46
- </ Grid >
47
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
48
- < div className = { classes . chartContainer } >
49
- < div className = { classes . chart } >
50
- < Line
51
- data = { subscriptionsTrendChart . data }
52
- options = { subscriptionsTrendChart . options }
53
- />
54
- </ div >
55
- </ div >
65
+ { numbers . map ( ( { name, value, change, trend, chart } ) => (
66
+ < Grid item xs = { 12 } sm = { 6 } md = { 3 } key = { name } >
67
+ < Paper className = { classes . paper } >
68
+ < Grid container spacing = { 0 } >
69
+ < Grid item xs = { 6 } sm = { 6 } md = { 12 } lg = { 6 } >
70
+ < Box p = { 2 } >
71
+ < Typography variant = "body2" className = { classes . name } >
72
+ { name }
73
+ </ Typography >
74
+ < Typography variant = "body1" className = { classes . value } >
75
+ { value } { ' ' }
76
+ < sup
77
+ className = { clsx (
78
+ classes . valueChange ,
79
+ trend === 'positive' && classes . positive ,
80
+ trend === 'negative' && classes . negative ,
81
+ ) }
82
+ >
83
+ { change }
84
+ </ sup >
85
+ </ Typography >
86
+ </ Box >
87
+ </ Grid >
88
+ < Grid item xs = { 6 } sm = { 6 } md = { 12 } lg = { 6 } >
89
+ < Box height = "100%" position = "relative" minHeight = { 70 } >
90
+ < div className = { classes . chartContainer } >
91
+ < Line data = { chart . data } options = { chart . options } />
92
+ </ div >
93
+ </ Box >
94
+ </ Grid >
56
95
</ Grid >
57
- </ Grid >
58
- </ Paper >
59
- </ Grid >
60
- < Grid item xs = { 6 } sm = { 3 } >
61
- < Paper className = { classes . paper } >
62
- < Grid container spacing = { 0 } >
63
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
64
- < Typography variant = "body2" > Monthly Churn</ Typography >
65
- < Typography variant = "body1" className = { classes . value } >
66
- 13 < sup className = { clsx ( classes . valueChange , classes . negative ) } > +10%</ sup >
67
- </ Typography >
68
- </ Grid >
69
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
70
- < div className = { classes . chartContainer } >
71
- < div className = { classes . chart } >
72
- < Line
73
- data = { subscriptionsTrendChart . data }
74
- options = { subscriptionsTrendChart . options }
75
- />
76
- </ div >
77
- </ div >
78
- </ Grid >
79
- </ Grid >
80
- </ Paper >
81
- </ Grid >
82
- < Grid item xs = { 6 } sm = { 3 } >
83
- < Paper className = { classes . paper } >
84
- < Grid container spacing = { 0 } >
85
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
86
- < Typography variant = "body2" > Total Users</ Typography >
87
- < Typography variant = "body1" className = { classes . value } >
88
- 48205{ ' ' }
89
- < sup className = { clsx ( classes . valueChange , classes . positive ) } > +30%</ sup >
90
- </ Typography >
91
- </ Grid >
92
- < Grid item xs = { 6 } md = { 12 } lg = { 6 } >
93
- < div className = { classes . chartContainer } >
94
- < div className = { classes . chart } >
95
- < Line
96
- data = { subscriptionsTrendChart . data }
97
- options = { subscriptionsTrendChart . options }
98
- />
99
- </ div >
100
- </ div >
101
- </ Grid >
102
- </ Grid >
103
- </ Paper >
104
- </ Grid >
96
+ </ Paper >
97
+ </ Grid >
98
+ ) ) }
105
99
</ >
106
100
)
107
101
}
@@ -113,13 +107,19 @@ const useStyles = makeStyles(theme => ({
113
107
flexGrow : 1 ,
114
108
} ,
115
109
paper : {
116
- padding : theme . spacing ( 2 ) ,
110
+ // padding: theme.spacing(2),
117
111
textAlign : 'left' ,
118
112
color : theme . palette . text . secondary ,
119
113
height : '100%' ,
120
114
} ,
115
+ name : {
116
+ whiteSpace : 'nowrap' ,
117
+ overflow : 'hidden' ,
118
+ textOverflow : 'ellipsis' ,
119
+ } ,
121
120
value : {
122
121
fontWeight : 'bold' ,
122
+ whiteSpace : 'nowrap' ,
123
123
} ,
124
124
valueChange : { } ,
125
125
negative : {
@@ -129,11 +129,6 @@ const useStyles = makeStyles(theme => ({
129
129
color : theme . palette . text . positive ,
130
130
} ,
131
131
chartContainer : {
132
- width : '100%' ,
133
- position : 'relative' ,
134
- paddingBottom : '25%' ,
135
- } ,
136
- chart : {
137
132
position : 'absolute' ,
138
133
width : '100%' ,
139
134
height : '100%' ,
0 commit comments