create SwitchBox comp

This commit is contained in:
madarsbiss 2021-09-21 19:31:30 +03:00
parent 3ec5ec415e
commit 56268d2392
4 changed files with 36 additions and 26 deletions

24
components/SwitchBox.js Normal file
View File

@ -0,0 +1,24 @@
import styles from "./SwitchBox.module.css";
const SwitchBox = ({ onClick, systemUsed }) => {
return (
<div className={styles.wrapper}>
<p
className={styles.switch}
style={{ color: systemUsed == "metric" ? "green" : "black" }}
onClick={onClick}
>
Metric System
</p>
<p
className={styles.switch}
style={{ color: systemUsed == "metric" ? "black" : "green" }}
onClick={onClick}
>
Imperial System
</p>
</div>
);
};
export default SwitchBox;

View File

@ -0,0 +1,9 @@
.wrapper {
text-align: right;
}
.switch {
margin: 0 10px;
cursor: pointer;
display: inline;
}

View File

@ -2,6 +2,8 @@ import { useState, useEffect } from "react";
import Image from "next/image"; import Image from "next/image";
import Metrics from "../components/Metrics"; import Metrics from "../components/Metrics";
import SwitchBox from "../components/SwitchBox";
import { convertTime, ctoF, timeToAMPM } from "../services/converters"; import { convertTime, ctoF, timeToAMPM } from "../services/converters";
import { isPM } from "../services/utils"; import { isPM } from "../services/utils";
@ -126,22 +128,7 @@ const App = () => {
</div> </div>
<Metrics styles={styles} data={weatherData} systemUsed={systemUsed} /> <Metrics styles={styles} data={weatherData} systemUsed={systemUsed} />
<div className={styles.switchBox}> <SwitchBox onClick={changeSystem} systemUsed={systemUsed} />
<p
className={styles.switch}
style={{ color: systemUsed == "metric" ? "green" : "black" }}
onClick={changeSystem}
>
Metric System
</p>
<p
className={styles.switch}
style={{ color: systemUsed == "metric" ? "black" : "green" }}
onClick={changeSystem}
>
Imperial System
</p>
</div>
</div> </div>
</div> </div>
) : weatherData && weatherData.message ? ( ) : weatherData && weatherData.message ? (

View File

@ -78,16 +78,6 @@
font-size: 18px; font-size: 18px;
} }
.switchBox {
text-align: right;
}
.switch {
margin: 0 10px;
cursor: pointer;
display: inline;
}
.errScr { .errScr {
text-align: center; text-align: center;
height: 100vh; height: 100vh;