1
1
import React , { useState , useEffect } from "react"
2
- import styled from "@emotion/styled"
3
2
import { useIntl } from "react-intl"
4
3
import axios from "axios"
5
4
import { kebabCase } from "lodash"
6
5
import { AreaChart , ResponsiveContainer , Area , XAxis } from "recharts"
7
6
8
- import { Grid , Icon , VStack , Box as ChakraBox } from "@chakra-ui/react"
7
+ import { VStack , Grid , Box , Icon , Button , Text } from "@chakra-ui/react"
9
8
import { MdInfoOutline } from "react-icons/md"
10
9
11
10
import Translation from "./Translation"
12
11
import Tooltip from "./Tooltip"
13
12
import Link from "./Link"
14
- // import Icon from "./Icon"
15
13
import StatErrorMessage from "./StatErrorMessage"
16
14
import StatLoadingMessage from "./StatLoadingMessage"
17
15
@@ -26,106 +24,6 @@ import { GATSBY_FUNCTIONS_PATH } from "../constants"
26
24
import { Lang } from "../utils/languages"
27
25
import { Direction } from "../types"
28
26
29
- const Value = styled . span `
30
- position: absolute;
31
- bottom: 8%;
32
- font-size: min(4.4vw, 4rem);
33
- font-weight: 600;
34
- margin-top: 0rem;
35
- margin-bottom: 1rem;
36
- color: ${ ( { theme } ) => theme . colors . text } ;
37
- flex-wrap: wrap;
38
- text-overflow: ellipsis;
39
- @media (max-width: ${ ( { theme } ) => theme . breakpoints . l } ) {
40
- font-size: max(8.8vw, 48px);
41
- }
42
- `
43
-
44
- const Title = styled . p `
45
- font-size: 1.25rem;
46
- margin-bottom: 0.5rem;
47
- color: ${ ( { theme } ) => theme . colors . text } ;
48
- text-transform: uppercase;
49
- font-family: ${ ( props ) => props . theme . fonts . monospace } ;
50
- `
51
-
52
- const Box = styled . div `
53
- position: relative;
54
- color: ${ ( { theme } ) => theme . colors . text } ;
55
- height: 20rem;
56
- background: ${ ( { theme, color = "" } ) => theme . colors [ color ] } ;
57
- display: flex;
58
- flex-direction: column;
59
- justify-content: space-between;
60
- align-items: flex-start;
61
- border: 1px solid ${ ( { theme } ) => theme . colors . color } ;
62
- padding: 1.5rem;
63
- @media (max-width: ${ ( { theme } ) => theme . breakpoints . l } ) {
64
- border-left: 0px solid #000000;
65
- border-right: 0px solid #000000;
66
- margin-top: -1px;
67
- padding: 1rem;
68
- padding-top: 2rem;
69
- }
70
- `
71
-
72
- const StatRow = styled . div `
73
- display: flex;
74
- flex-direction: column;
75
- `
76
-
77
- // const StyledIcon = styled(Icon)`
78
- // fill: ${({ theme }) => theme.colors.text };
79
- // margin-right: 0.5rem;
80
- // @media (max-width: ${({ theme }) => theme.breakpoints.l}) {
81
- // }
82
- // &:hover,
83
- // &:active,
84
- // &:focus {
85
- // fill: ${({ theme }) => theme.colors.primary };
86
- // }
87
- // `
88
-
89
- const Lines = styled . div `
90
- position: absolute;
91
- left: 0;
92
- bottom: 0;
93
- width: 100%;
94
- height: 65%;
95
- `
96
-
97
- const ButtonContainer = styled . div < { dir ?: Direction } > `
98
- position: absolute;
99
- ${ ( { dir } ) => ( dir === "rtl" ? "left" : "right" ) } : 20px;
100
- bottom: 20px;
101
- font-family: ${ ( props ) => props . theme . fonts . monospace } ;
102
- `
103
-
104
- const Button = styled . button < { color : string } > `
105
- background: ${ ( props ) => props . theme . colors . background } ;
106
- font-family: ${ ( props ) => props . theme . fonts . monospace } ;
107
- font-size: 1.25rem;
108
- color: ${ ( { theme } ) => theme . colors . text } ;
109
- padding: 2px 15px;
110
- border-radius: 1px;
111
- border: 1px solid ${ ( { theme, color } ) => theme . colors [ color ] } ;
112
- cursor: pointer;
113
-
114
- &:disabled {
115
- cursor: default;
116
- opacity: 0.7;
117
- }
118
- `
119
-
120
- const ButtonToggle = styled ( Button ) < { active : boolean } > `
121
- ${ ( { active, theme } ) =>
122
- active &&
123
- `
124
- background-color: ${ theme . colors . homeBoxPurple } ;
125
- opacity: 1;
126
- ` }
127
- `
128
-
129
27
const ranges = [ "30d" , "90d" ] as const
130
28
131
29
interface State {
@@ -158,20 +56,21 @@ const GridItem: React.FC<IGridItemProps> = ({ metric, dir }) => {
158
56
< StatLoadingMessage />
159
57
) : (
160
58
< VStack >
161
- < ChakraBox >
59
+ < Box >
162
60
{ state . value } { " " }
163
61
< Tooltip content = { tooltipContent ( metric ) } >
164
62
< Icon
165
63
as = { MdInfoOutline }
166
64
width = "24px"
167
65
height = "24px"
66
+ fill = "text"
67
+ mr = "0.5rem"
168
68
_hover = { { fill : "primary" } }
169
69
_active = { { fill : "primary" } }
170
70
_focus = { { fill : "primary" } }
171
- mr = "0.5rem"
172
71
> </ Icon >
173
72
</ Tooltip >
174
- </ ChakraBox >
73
+ </ Box >
175
74
</ VStack >
176
75
)
177
76
@@ -228,18 +127,90 @@ const GridItem: React.FC<IGridItemProps> = ({ metric, dir }) => {
228
127
)
229
128
230
129
return (
231
- < Box >
130
+ < Box
131
+ position = "relative"
132
+ color = "text"
133
+ height = "20rem"
134
+ background = { "" }
135
+ display = "flex"
136
+ flexDirection = "column"
137
+ justifyContent = "space-between"
138
+ alignItems = "flex-start"
139
+ borderX = { {
140
+ base : "0px solid #000000" ,
141
+ lg : "1px solid" ,
142
+ } }
143
+ borderY = "1px solid"
144
+ marginTop = { {
145
+ base : "-1px" ,
146
+ lg : "0" ,
147
+ } }
148
+ padding = { {
149
+ base : "1rem" ,
150
+ lg : "1.5rem" ,
151
+ } }
152
+ paddingTop = { {
153
+ base : "2rem" ,
154
+ lg : "0" ,
155
+ } }
156
+ >
232
157
< div >
233
- < Title > { title } </ Title >
158
+ < Text
159
+ fontSize = "1.25rem"
160
+ mb = "0.5rem"
161
+ color = "text"
162
+ textTransform = "uppercase"
163
+ fontFamily = "monospace"
164
+ >
165
+ { title }
166
+ </ Text >
234
167
< p > { description } </ p >
235
168
</ div >
236
169
{ ! state . hasError && ! isLoading && (
237
170
< >
238
- < Lines > { chart } </ Lines >
239
- < ButtonContainer dir = { dir } > { buttonContainer } </ ButtonContainer >
171
+ < Box
172
+ position = "absolute"
173
+ left = { 0 }
174
+ bottom = { 0 }
175
+ width = "100%"
176
+ height = "65%"
177
+ >
178
+ { chart }
179
+ </ Box >
180
+ { dir === "rtl" ? (
181
+ < Box
182
+ position = "absolute"
183
+ bottom = "20px"
184
+ fontFamily = "monospace"
185
+ left = "20px"
186
+ >
187
+ { buttonContainer }
188
+ </ Box >
189
+ ) : (
190
+ < Box
191
+ position = "absolute"
192
+ bottom = "20px"
193
+ fontFamily = "monospace"
194
+ right = "20px"
195
+ >
196
+ { buttonContainer }
197
+ </ Box >
198
+ ) }
240
199
</ >
241
200
) }
242
- < Value > { value } </ Value >
201
+ < Text
202
+ position = "absolute"
203
+ bottom = "8%"
204
+ fontSize = { { base : "max(8.8vw, 48px)" , lg : "min(4.4vw, 4rem)" } }
205
+ fontWeight = { 600 }
206
+ marginTop = "0rem"
207
+ marginBottom = "1rem"
208
+ color = "text"
209
+ flexWrap = "wrap"
210
+ textOverflow = "ellipsis"
211
+ >
212
+ { value }
213
+ </ Text >
243
214
</ Box >
244
215
)
245
216
}
@@ -259,16 +230,29 @@ interface IRangeSelectorProps {
259
230
const RangeSelector : React . FC < IRangeSelectorProps > = ( { state, setState } ) => (
260
231
< div >
261
232
{ ranges . map ( ( range , idx ) => (
262
- < ButtonToggle
263
- active = { state === range }
264
- onClick = { ( ) => {
265
- setState ( ranges [ idx ] )
266
- } }
233
+ < Button
234
+ onClick = { ( ) => setState ( ranges [ idx ] ) }
267
235
key = { idx }
268
236
color = { "" }
237
+ background = "background"
238
+ fontFamily = "monospace"
239
+ fontSize = "1.25rem"
240
+ padding = "2px 15px"
241
+ borderRadius = "1px"
242
+ border = "1px solid"
243
+ cursor = "pointer"
244
+ _focus = { { outline : "none" } }
245
+ _hover = { { color : "" } }
246
+ _active = { { color : "" } }
247
+ _disabled = { {
248
+ cursor : "default" ,
249
+ opacity : "0.7" ,
250
+ } }
251
+ size = "sm"
252
+ backgroundColor = { state === ranges [ idx ] ? "homeBoxPurple" : "" }
269
253
>
270
254
{ range }
271
- </ ButtonToggle >
255
+ </ Button >
272
256
) ) }
273
257
</ div >
274
258
)
@@ -566,7 +550,7 @@ const StatsBoxGrid: React.FC<IProps> = () => {
566
550
gridTemplateColumns = "repeat(2, 1fr)"
567
551
margin = { {
568
552
base : "0" ,
569
- md : "2rem 0 0" ,
553
+ sm : "2rem 0 0" ,
570
554
lg : "2rem 2rem 0" ,
571
555
} }
572
556
borderRadius = "2px"
0 commit comments