Skip to content

Commit

Permalink
Add TemperatureConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemian Deng committed May 23, 2022
1 parent 0161994 commit 2a72df5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/gui/TemperatureConverter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { h } from "preact";
import { useState } from "preact/hooks";

import "ojs/ojinputtext";

export function TemperatureConverter () {
const [celsius, setCelsius] = useState(0);
const [fahrenheit, setFahrenheit] = useState(32);
const onCelsiusChanged = (event: CustomEvent) => {
const newValue = event.detail.value;
setCelsius(newValue);
const newF = newValue * (9 / 5) + 32;
setFahrenheit(newF);
}
const onFahrenheitChanged = (event: CustomEvent) => {
const newValue = event.detail.value;
setFahrenheit(newValue);
const newC = (newValue - 32) * (5 / 9);
setCelsius(newC);
}
const CelsiusInputText = () =>
<oj-input-text value={celsius} onvalueChanged={onCelsiusChanged}></oj-input-text>;
const FahrenheitInputText = () =>
<oj-input-text value={fahrenheit} onvalueChanged={onFahrenheitChanged}></oj-input-text>;

return (
<div class="oj-sm-width-1/3">
<p>Enter value the press Tab</p>
<p>Celsius:</p>
<CelsiusInputText></CelsiusInputText>

<p>Fahrenheit:</p>
<FahrenheitInputText></FahrenheitInputText>
</div>
);
}

0 comments on commit 2a72df5

Please sign in to comment.