Skip to content

Commit

Permalink
chore: fix dark-mode switch on mobile devices (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
1502shivam-singh authored Oct 13, 2021
1 parent 8cdabe2 commit 42610de
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
8 changes: 5 additions & 3 deletions website/src/css/customTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ a:hover {
}

.add-margin {
margin: 30px 0;
margin: 30px 0 0 0;
}

.homeCanvas{
Expand Down Expand Up @@ -1244,8 +1244,10 @@ a:hover {
}
}

.react-toggle {
display: none;
@media only screen and (min-width: 768px) {
.react-toggle {
display: none;
}
}

.bottom-pos {
Expand Down
19 changes: 18 additions & 1 deletion website/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useLayoutEffect } from "react";
import React, { useState, useEffect, useLayoutEffect } from "react";
import useThemeContext from '@theme/hooks/useThemeContext';
import Layout from "@theme/Layout";

import HeroSection from "./sections/heroSection";
Expand All @@ -24,6 +25,21 @@ const useWindowSize = () => {
return size;
}

const ThemeResetComponent = () => {
const {isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext();

useEffect(() => {
const children = document.querySelector(".navbar__items--right").childElementCount;
document.querySelector(".navbar__items--right").childNodes[children-2].style.display = "none";

if(isDarkTheme) {
setLightTheme(true);
}
}, [])

return (null);
};

const Index = () => {

const [screenWidth, screenHeight] = useWindowSize();
Expand All @@ -39,6 +55,7 @@ const Index = () => {
<HomeEventsSection />
<EndCTA />
<EventPosterCard />
<ThemeResetComponent/>
</Layout>
);
};
Expand Down
10 changes: 8 additions & 2 deletions website/src/theme/DocPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ function DocPageContent({
const [hiddenSidebar, setHiddenSidebar] = useState(false);

useEffect(() => {
document.querySelector(".react-toggle").style.display = "block";
const children = document.querySelector(".navbar__items--right").childElementCount;
if(window.innerWidth > 745) {
document.querySelector(".navbar__items--right").childNodes[children-2].style.display = "block";
}
else {
document.querySelector(".navbar__items--right").childNodes[children-2].style.display = "none";
}
const currentPage = currentDocRoute.path.split("/")[2] || "";
switch (currentPage) {
case "general":
Expand Down Expand Up @@ -77,7 +83,7 @@ function DocPageContent({
break;
}
return () => {
document.querySelector(".react-toggle").style.display = "none";
document.querySelector(".navbar__items--right").childNodes[children-2].style.display = "none"
}
}, []);

Expand Down

0 comments on commit 42610de

Please sign in to comment.