|
|
@@ -1,9 +1,55 @@
|
|
|
-import React from "react";
|
|
|
+import { TextField, Typography } from "@mui/material";
|
|
|
+import React, { useState } from "react";
|
|
|
|
|
|
function WeightConverter() {
|
|
|
- console.debug("WeightConverter rerender!");
|
|
|
+ const [kg, setKg] = useState<number>(0);
|
|
|
+ const weight_kg = kg;
|
|
|
+ const weight_g = kg * 1000;
|
|
|
+ const weight_lbs = kg * 2.20462;
|
|
|
|
|
|
- return <div>WeightConverter</div>;
|
|
|
+ console.debug("WeightConverter rerender! kg: " + kg);
|
|
|
+
|
|
|
+ function update_kg(val: string) {
|
|
|
+ const numval = Number(val);
|
|
|
+ if (isNaN(numval)) return;
|
|
|
+ setKg(numval);
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateG(val: string) {
|
|
|
+ const numval = Number(val);
|
|
|
+ if (isNaN(numval)) return;
|
|
|
+ setKg(numval / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ function update_lbs(val: string) {
|
|
|
+ const numval = Number(val);
|
|
|
+ if (isNaN(numval)) return;
|
|
|
+ setKg(numval / 2.20462);
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Typography variant="h4">WeightConverter</Typography>
|
|
|
+ <TextField
|
|
|
+ label="kg"
|
|
|
+ helperText="Weight in kg"
|
|
|
+ value={weight_kg}
|
|
|
+ onChange={(e) => update_kg(e.target.value)}
|
|
|
+ />
|
|
|
+ <TextField
|
|
|
+ label="g"
|
|
|
+ helperText="Weight in g"
|
|
|
+ value={weight_g}
|
|
|
+ onChange={(e) => updateG(e.target.value)}
|
|
|
+ />
|
|
|
+ <TextField
|
|
|
+ label="lbs"
|
|
|
+ helperText="Weight in lbs"
|
|
|
+ value={weight_lbs}
|
|
|
+ onChange={(e) => update_lbs(e.target.value)}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
export default WeightConverter;
|