This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.tsx
100 lines (95 loc) · 1.39 KB
/
demo.tsx
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React from 'react'
import ReactDOM from 'react-dom'
import { RSRP } from './RSRP'
import { RSRPBar } from './RSRPBar'
import { dbmToRSRP } from './dbmToRSRP'
const colors = [
'#03a8a0',
'#039c4b',
'#66d313',
'#fedf17',
'#ff0984',
'#21409a',
'#04adff',
'#e48873',
'#f16623',
'#f44546',
]
const color = function*() {
let i = 0
while (true) {
yield colors[i]
i = (i + 1) % colors.length
}
}
const colorGenerator = color()
const renderForDBM = (dbm: number) => (
<RSRP
rsrp={dbmToRSRP(dbm)}
renderBar={({ quality }) =>
quality === 0 ? (
<>
<td>
<RSRPBar quality={0} />
</td>
<td>Not known or not detectable</td>
</>
) : (
<>
<td>
<RSRPBar
quality={quality}
style={{
color: colorGenerator.next().value,
}}
/>
</td>
<td>-</td>
</>
)
}
renderInvalid={() => (
<>
<td>❎</td>
<td>Unexpected value reported!</td>
</>
)}
/>
)
ReactDOM.render(
<table>
<thead>
<tr>
<th>dbm</th>
<th>icon</th>
<th>info</th>
</tr>
</thead>
<tbody>
{[
1000,
100,
10,
-0,
-70,
-75,
-80,
-85,
-90,
-95,
-100,
-105,
-110,
-140,
-150,
-1000,
].map((dbm, key) => (
<tr key={key}>
<td>{dbm}</td>
{renderForDBM(dbm)}
</tr>
))}
</tbody>
</table>,
document.querySelector('#root'),
)