Skip to content

Instantly share code, notes, and snippets.

@scwood
Created October 20, 2021 01:30
Show Gist options
  • Save scwood/efd8583765dc876586423202468e032e to your computer and use it in GitHub Desktop.
Save scwood/efd8583765dc876586423202468e032e to your computer and use it in GitHub Desktop.
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