Created
October 20, 2021 01:30
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
export interface TemperatureUnitToggleProps { | |
selectedUnit: TemperatureUnit; | |
onChange: (temperatureUnit: TemperatureUnit) => void; | |
} | |
/** | |
* A toggle component to swap between Celsius and Fahrenheit | |
*/ | |
export const TemperatureUnitToggle: FunctionComponent<TemperatureUnitToggleProps> = ({ selectedUnit, onChange }) => { | |
const isCelsiusSelected = selectedUnit === TemperatureUnit.Celsius; | |
return ( | |
<button | |
className={styles.toggleButton} | |
onClick={() => onChange(isCelsiusSelected ? TemperatureUnit.Fahrenheit : TemperatureUnit.Celsius)} | |
> | |
<span | |
className={classNames(styles.celsius, { | |
[dashboardStyles.semiBold]: isCelsiusSelected, | |
[styles.deemphasized]: !isCelsiusSelected, | |
})} | |
> | |
°C | |
</span> | |
<span | |
className={classNames({ | |
[dashboardStyles.semiBold]: !isCelsiusSelected, | |
[styles.deemphasized]: isCelsiusSelected, | |
})} | |
> | |
°F | |
</span> | |
</button> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment