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;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .sun-and-moon > .sun {
|
||||
.theme-dark .sun-and-moon > .sun {
|
||||
transform: scale(1.75);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .sun-and-moon > .sun-beams {
|
||||
.theme-dark .sun-and-moon > .sun-beams {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
||||
.theme-dark .sun-and-moon > .moon > circle {
|
||||
transform: translateX(-7px);
|
||||
}
|
||||
|
||||
@supports (cx: 1) {
|
||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
||||
.theme-dark .sun-and-moon > .moon > circle {
|
||||
cx: 17;
|
||||
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-duration: 0.25s;
|
||||
transform: scale(1.75);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .sun-and-moon > .sun-beams {
|
||||
.theme-dark .sun-and-moon > .sun-beams {
|
||||
transition-duration: 0.15s;
|
||||
transform: rotateZ(-25deg);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .sun-and-moon > .moon > circle {
|
||||
.theme-dark .sun-and-moon > .moon > circle {
|
||||
transition-duration: 0.5s;
|
||||
transition-delay: 0.25s;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,13 @@
|
||||
* Apache License: https://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
|
||||
import React, { useEffect } from "react";
|
||||
import { IconButton } from "@mui/material";
|
||||
import SunAndMoonIcon from "./SunAndMoonIcon";
|
||||
import "./index.css";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
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 dispatch = useDispatch();
|
||||
|
||||
@@ -24,20 +23,17 @@ const ThemeSwitch = () => {
|
||||
dispatch(setMode(mode === "light" ? "dark" : "light"));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
document.body.setAttribute("data-theme", mode);
|
||||
}, [mode]);
|
||||
|
||||
return (
|
||||
<IconButton
|
||||
id="theme-toggle"
|
||||
title="Toggles light & dark"
|
||||
className={`theme-${mode}`}
|
||||
aria-label="auto"
|
||||
aria-live="polite"
|
||||
onClick={toggleTheme}
|
||||
sx={{
|
||||
width: 48,
|
||||
height: 48,
|
||||
width,
|
||||
height,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
|
||||
Reference in new issue
Block a user