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";
|
|
|
|
|
import { ThemeMode } from "reducers/uiReducers/themeReducer";
|
2020-09-22 11:56:11 +00:00
|
|
|
import Switch from "components/ads/RectangularSwitcher";
|
|
|
|
|
import MenuItem from "components/ads/MenuItem";
|
|
|
|
|
import { getThemeDetails } from "selectors/themeSelectors";
|
2020-09-16 11:50:47 +00:00
|
|
|
|
|
|
|
|
export default function ThemeSwitcher(props: { className?: string }) {
|
|
|
|
|
const dispatch = useDispatch();
|
2020-09-22 11:56:11 +00:00
|
|
|
const themeDetails = useSelector(getThemeDetails);
|
|
|
|
|
const [switchedOn, setSwitchOn] = useState(
|
|
|
|
|
themeDetails.mode === ThemeMode.DARK,
|
|
|
|
|
);
|
|
|
|
|
|
2020-09-16 11:50:47 +00:00
|
|
|
return (
|
2020-09-22 11:56:11 +00:00
|
|
|
<MenuItem
|
|
|
|
|
text="Theme"
|
|
|
|
|
label={
|
|
|
|
|
<Switch
|
|
|
|
|
className={props.className}
|
|
|
|
|
value={switchedOn}
|
|
|
|
|
onSwitch={value => {
|
|
|
|
|
setSwitchOn(value);
|
|
|
|
|
dispatch(setThemeMode(value ? ThemeMode.DARK : ThemeMode.LIGHT));
|
|
|
|
|
}}
|
|
|
|
|
></Switch>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2020-09-16 11:50:47 +00:00
|
|
|
);
|
|
|
|
|
}
|