Skip to content

WIP: add dark theme btn #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const navbarLogo = {
arrow: {
Svg: require("@site/static/img/Arrow.svg").default,
},
theme: {
Svg: require("@site/static/img/theme.svg").default,
},
};

const navbarContent = {
Expand Down Expand Up @@ -110,6 +113,7 @@ const mobileViewContent = {

function Navbar() {
const [isMobile, setIsMobile] = useState(false);
const [darkTheme, setDarkTheme] = useState(false);
useEffect(() => {
window.addEventListener("resize", () => {
window.innerWidth > 680 ? setIsMobile(false) : setIsMobile(!isMobile);
Expand Down Expand Up @@ -164,6 +168,21 @@ function Navbar() {
</a>
</button>
</li>
<li
className={styles.navbar_theme_button}
onClick={() => {
setDarkTheme(!darkTheme);
const el = document.querySelector(
`[data-theme="${darkTheme ? "dark" : "light"}"]`
);
el.setAttribute(
"data-theme",
`${darkTheme ? "light" : "dark"}`
);
}}
>
<navbarLogo.theme.Svg role="img" />
</li>
</ul>
</nav>
</section>
Expand Down
7 changes: 7 additions & 0 deletions src/theme/Navbar/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,10 @@
.navbar_contri_designs {
border-top: 1px solid white;
}

.navbar_theme_button {
cursor: pointer;
width: 2rem;
padding: 1rem 0 1rem 1rem;
filter: brightness(0) invert(1);
}
1 change: 1 addition & 0 deletions static/img/theme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.