-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.tsx
79 lines (74 loc) · 1.3 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
import React from 'react'
import { RSRP } from './RSRP.js'
import { SignalQualityTriangle } from './SignalQualityTriangle.js'
import { createRoot } from 'react-dom/client'
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
dbm={dbm}
renderBar={({ quality }) => (
<>
<td>
<SignalQualityTriangle
quality={quality}
style={{
color: colorGenerator.next().value,
}}
/>
</td>
<td>-</td>
</>
)}
renderInvalid={() => (
<>
<td>❎</td>
<td>Unexpected value reported!</td>
</>
)}
/>
)
const container = document.querySelector('#root')
if (container !== null) {
const root = createRoot(container)
root.render(
<table>
<thead>
<tr>
<th>dbm</th>
<th>icon</th>
<th>info</th>
</tr>
</thead>
<tbody>
{[
1000, 100, 10, -0, -40, -50, -60, -70, -80, -90, -100, -110, -120,
-130, -140, -150, -200, -1000,
].map((dbm, key) => (
<tr key={key}>
<td>{dbm}</td>
{renderForDBM(dbm)}
</tr>
))}
</tbody>
</table>,
)
}