diff --git a/package.json b/package.json index a14b0f2..2e371c6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-template", + "name": "dev-lab", "private": true, "version": "0.0.0", "type": "module", diff --git a/src/page/bmi-calculator/index.tsx b/src/page/bmi-calculator/index.tsx new file mode 100644 index 0000000..ea82ebc --- /dev/null +++ b/src/page/bmi-calculator/index.tsx @@ -0,0 +1,170 @@ +import { useState } from "react" +import { useTranslation } from "react-i18next" + +/** + * Home page component that displays the BMI calculator. + */ +export default function BmiCalculator() { + const { t } = useTranslation() + + const [weight, setWeight] = useState("") + const [height, setHeight] = useState("") + const [bmi, setBmi] = useState(null) + const [bmiCategory, setBmiCategory] = useState("") + + const calculateBMI = () => { + const weightNum = parseFloat(weight) + const heightNum = parseFloat(height) / 100 // Convert cm to meters + + if (weightNum > 0 && heightNum > 0) { + const bmiValue = weightNum / (heightNum * heightNum) + setBmi(parseFloat(bmiValue.toFixed(1))) + + // Determine BMI category + if (bmiValue < 18.5) { + setBmiCategory("underweight") + } else if (bmiValue < 25) { + setBmiCategory("normal") + } else if (bmiValue < 30) { + setBmiCategory("overweight") + } else { + setBmiCategory("obese") + } + } + } + + const resetCalculator = () => { + setWeight("") + setHeight("") + setBmi(null) + setBmiCategory("") + } + + const getBmiColour = () => { + switch (bmiCategory) { + case "underweight": + return "text-blue-600" + case "normal": + return "text-green-600" + case "overweight": + return "text-yellow-600" + case "obese": + return "text-red-600" + default: + return "text-gray-600" + } + } + + return ( +
+
+ {/* Header */} +
+

{t("bmi.title")}

+

{t("bmi.description")}

+
+ + {/* Calculator Form */} +
+
+ {/* Weight Input */} +
+ +
+ setWeight(e.target.value)} + placeholder={t("bmi.weight.placeholder")} + className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-base" + min="1" + max="500" + /> + kg +
+
+ + {/* Height Input */} +
+ +
+ setHeight(e.target.value)} + placeholder={t("bmi.height.placeholder")} + className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent text-base" + min="50" + max="300" + /> + cm +
+
+
+ + {/* Action Buttons */} +
+ + +
+
+ + {/* BMI Result */} + {bmi !== null && ( +
+
+

+ {t("bmi.result.title")} +

+
{bmi}
+
+ {t(`bmi.category.${bmiCategory}`)} +
+
+ {t(`bmi.advice.${bmiCategory}`)} +
+
+ + {/* BMI Scale */} +
+

{t("bmi.scale.title")}

+
+
+ {t("bmi.category.underweight")} + < 18.5 +
+
+ {t("bmi.category.normal")} + 18.5 - 24.9 +
+
+ + {t("bmi.category.overweight")} + + 25.0 - 29.9 +
+
+ {t("bmi.category.obese")} + ≥ 30.0 +
+
+
+
+ )} +
+
+ ) +} diff --git a/src/page/home/index.tsx b/src/page/home/index.tsx index 55884a3..0f480f0 100644 --- a/src/page/home/index.tsx +++ b/src/page/home/index.tsx @@ -28,6 +28,18 @@ export default function Home() { +
+

Get Started

+

+ BMI Calculator. +

+ + Open BMI Calculator + +
+ {/* Features */}
diff --git a/src/page/json-viewer/index.tsx b/src/page/json-viewer/index.tsx index 479dbeb..571015d 100644 --- a/src/page/json-viewer/index.tsx +++ b/src/page/json-viewer/index.tsx @@ -78,7 +78,7 @@ export default function JsonViewer() {
- JSON Source +