-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zemian Deng
committed
May 23, 2022
1 parent
0161994
commit 2a72df5
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |