-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_conversion.html
85 lines (85 loc) · 2.57 KB
/
unit_conversion.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
<!DOCTYPE html>
<html>
<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">
const MinutesToHours = () => {
const [amount, setAmount] = React.useState(0);
const [flipped, setFlipped] = React.useState(true);
const onChange = (event) => {
setAmount(event.target.value);
};
const reset = () => {
setAmount(0);
};
const onFlip = () => {
reset();
setFlipped((current) => !current);
};
return (
<div>
<h3>Time Converter</h3>
<div>
<input
value={flipped ? amount : amount * 60}
id='amount'
placeholder='Minutes'
type='number'
onChange={onChange}
disabled={!flipped}
style={{
"text-align": "right",
}}
/>
<label htmlFor='amount'>Minutes</label>
</div>
<div>
<input
value={flipped ? amount / 60 : amount}
id='hours'
placeholder='Hours'
type='number'
onChange={onChange}
disabled={flipped}
style={{
"text-align": "right",
}}
/>
<label htmlFor='hours'>Hours</label>
</div>
<button onClick={reset}>Reset</button>
<button onClick={onFlip}>{flipped ? "Hours to Minutes" : "Minutes to Hours"}</button>
</div>
);
};
const KmToMiles = () => {
return <h3>km To miles</h3>;
};
const App = () => {
const [index, setIndex] = React.useState("xx");
const onSelect = (event) => {
setIndex(event.target.value);
};
return (
<div>
<h1>SuperConverter</h1>
<select value={index} onChange={onSelect}>
<option value='xx'>Select Units</option>
<option value='0'>Minutes & Hours</option>
<option value='1'>Km & Miles</option>
</select>
<hr />
{index === "xx" ? "Please select your units" : null}
{index === "0" ? <MinutesToHours /> : null}
{index === "1" ? <KmToMiles /> : null}
</div>
);
};
const root = document.querySelector("#root");
ReactDOM.render(<App />, root);
</script>
</html>