feat: removed useEffect in toggling theme
This commit is contained in:
1 parent
acefedd6e7
commit
7c5c3507d8
2 files changed
+12
-16
No files matched your search
@@ -6,20 +6,20 @@
|
|||||||
stroke-width: 2px;
|
stroke-width: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .sun {
|
.theme-dark .sun-and-moon > .sun {
|
||||||
transform: scale(1.75);
|
transform: scale(1.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .sun-beams {
|
.theme-dark .sun-and-moon > .sun-beams {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
.theme-dark .sun-and-moon > .moon > circle {
|
||||||
transform: translateX(-7px);
|
transform: translateX(-7px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@supports (cx: 1) {
|
@supports (cx: 1) {
|
||||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
.theme-dark .sun-and-moon > .moon > circle {
|
||||||
cx: 17;
|
cx: 17;
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
}
|
}
|
||||||
@@ -46,18 +46,18 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .sun {
|
.theme-dark .sun-and-moon > .sun {
|
||||||
transition-timing-function: var(--ease-3);
|
transition-timing-function: var(--ease-3);
|
||||||
transition-duration: 0.25s;
|
transition-duration: 0.25s;
|
||||||
transform: scale(1.75);
|
transform: scale(1.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .sun-beams {
|
.theme-dark .sun-and-moon > .sun-beams {
|
||||||
transition-duration: 0.15s;
|
transition-duration: 0.15s;
|
||||||
transform: rotateZ(-25deg);
|
transform: rotateZ(-25deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
.theme-dark .sun-and-moon > .moon > circle {
|
||||||
transition-duration: 0.5s;
|
transition-duration: 0.5s;
|
||||||
transition-delay: 0.25s;
|
transition-delay: 0.25s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,13 @@
|
|||||||
* Apache License: https://www.apache.org/licenses/LICENSE-2.0
|
* Apache License: https://www.apache.org/licenses/LICENSE-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useEffect } from "react";
|
|
||||||
import { IconButton } from "@mui/material";
|
import { IconButton } from "@mui/material";
|
||||||
import SunAndMoonIcon from "./SunAndMoonIcon";
|
import SunAndMoonIcon from "./SunAndMoonIcon";
|
||||||
import "./index.css";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { setMode } from "../../Features/UI/uiSlice";
|
import { setMode } from "../../Features/UI/uiSlice";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
const ThemeSwitch = () => {
|
const ThemeSwitch = ({ width = 48, height = 48 }) => {
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
const mode = useSelector((state) => state.ui.mode);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
@@ -24,20 +23,17 @@ const ThemeSwitch = () => {
|
|||||||
dispatch(setMode(mode === "light" ? "dark" : "light"));
|
dispatch(setMode(mode === "light" ? "dark" : "light"));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
document.body.setAttribute("data-theme", mode);
|
|
||||||
}, [mode]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
id="theme-toggle"
|
id="theme-toggle"
|
||||||
title="Toggles light & dark"
|
title="Toggles light & dark"
|
||||||
|
className={`theme-${mode}`}
|
||||||
aria-label="auto"
|
aria-label="auto"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
onClick={toggleTheme}
|
onClick={toggleTheme}
|
||||||
sx={{
|
sx={{
|
||||||
width: 48,
|
width,
|
||||||
height: 48,
|
height,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
|
|||||||
Reference in new issue
Block a user