PromucFlow_constructor/app/client/src/pages/common/ThemeSwitcher.tsx
Satish Gandham 7f7f6f666b
Development: Add eslint rules for code consistency (#4083)
Co-authored-by: Satish Gandham <satish@appsmith.com>
Co-authored-by: Abhinav Jha <abhinav@appsmith.com>
2021-04-28 15:58:39 +05:30

29 lines
897 B
TypeScript

import React, { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { setThemeMode } from "actions/themeActions";
import Switch from "components/ads/RectangularSwitcher";
import MenuItem from "components/ads/MenuItem";
import { getCurrentThemeMode, ThemeMode } from "selectors/themeSelectors";
export default function ThemeSwitcher(props: { className?: string }) {
const dispatch = useDispatch();
const themeMode = useSelector(getCurrentThemeMode);
const [switchedOn, setSwitchOn] = useState(themeMode === ThemeMode.DARK);
return (
<MenuItem
label={
<Switch
className={props.className}
onSwitch={(value) => {
setSwitchOn(value);
dispatch(setThemeMode(value ? ThemeMode.DARK : ThemeMode.LIGHT));
}}
value={switchedOn}
/>
}
text="Theme"
/>
);
}