2020-09-22 11:56:11 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
2020-09-16 11:50:47 +00:00
|
|
|
import { setThemeMode } from "actions/themeActions";
|
2020-09-22 11:56:11 +00:00
|
|
|
import Switch from "components/ads/RectangularSwitcher";
|
|
|
|
|
import MenuItem from "components/ads/MenuItem";
|
2021-02-11 12:54:00 +00:00
|
|
|
import { getCurrentThemeMode, ThemeMode } from "selectors/themeSelectors";
|
2020-09-16 11:50:47 +00:00
|
|
|
|
|
|
|
|
export default function ThemeSwitcher(props: { className?: string }) {
|
|
|
|
|
const dispatch = useDispatch();
|
2021-02-11 12:54:00 +00:00
|
|
|
const themeMode = useSelector(getCurrentThemeMode);
|
|
|
|
|
const [switchedOn, setSwitchOn] = useState(themeMode === ThemeMode.DARK);
|
2020-09-22 11:56:11 +00:00
|
|
|
|
2020-09-16 11:50:47 +00:00
|
|
|
return (
|
2020-09-22 11:56:11 +00:00
|
|
|
<MenuItem
|
|
|
|
|
label={
|
|
|
|
|
<Switch
|
|
|
|
|
className={props.className}
|
2020-12-24 04:32:25 +00:00
|
|
|
onSwitch={(value) => {
|
2020-09-22 11:56:11 +00:00
|
|
|
setSwitchOn(value);
|
|
|
|
|
dispatch(setThemeMode(value ? ThemeMode.DARK : ThemeMode.LIGHT));
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
value={switchedOn}
|
2021-02-11 12:54:00 +00:00
|
|
|
/>
|
2020-09-22 11:56:11 +00:00
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
text="Theme"
|
2020-09-22 11:56:11 +00:00
|
|
|
/>
|
2020-09-16 11:50:47 +00:00
|
|
|
);
|
|
|
|
|
}
|