-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
137 lines (120 loc) · 4.04 KB
/
index.html
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="root"></div>
</body>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
function Minutes2Hours() {
const [amount, setAmount] = React.useState(0);
const [invert, setInvert] = React.useState(false);
const onChange = (event) => {
setAmount(event.target.value);
}
const onInvert = () => {
reset();
setInvert((current) => !current);
}
const reset = () => {
setAmount(0);
}
return (
<div>
<h3>Minues To Hours</h3>
<div>
<label htmlFor="minutes">Minutes</label>
<input
id="minutes"
value={invert ? amount * 60 : amount}
placeholder="Minutes"
type="number"
onChange={onChange}
disabled={invert}
/>
</div>
<div>
<label htmlFor="hours">Hours</label>
<input
id="hours"
value={invert ? amount : Math.round(amount / 60)}
placeholder="Hours"
type="number"
onChange={onChange}
disabled={!invert}
/>
<button onClick={reset}>Reset</button>
<button onClick={onInvert}>Invert</button>
</div>
</div>
);
}
function Km2Miles() {
const [amount, setAmount] = React.useState(0);
const [invert, setInvert] = React.useState(false);
function onReset() {
setAmount(0);
}
function onChanged(event) {
setAmount(event.target.value);
}
function onClicked() {
onReset();
setInvert((current) => !current);
}
return (
<div>
<h3>Km To Miles</h3>
<div>
<label htmlFor="km">km</label>
<input
id="km"
type="number"
placeholder="KM"
value={invert ? amount * 1.609 : amount}
onChange={onChanged}
disabled={invert}
/>
</div>
<div>
<label htmlFor="miles">miles</label>
<input
id="miles"
type="number"
placeHolder="Miles"
value={invert ? amount : amount / 1.609}
onChange={onChanged}
disabled={!invert}
/>
</div>
<button onClick={onReset}>Reset</button>
<button onClick={onClicked}>Invert</button>
</div>
);
}
function App() {
const [index, setIndex] = React.useState("0");
function onSelect(event) {
setIndex(event.target.value);
}
return (
<div>
<h1>Super Converter</h1>
<select value={index} onChange={onSelect}>
<option value="0">Minutes & Hours</option>
<option value="1">Km To Miles</option>
</select>
<hr />
{index === "0" ? <Minutes2Hours /> : null}
{index === "1" ? <Km2Miles /> : null}
</div>
);
}
const root = document.getElementById("root");
ReactDOM.render(<App />, root);
</script>
</html>