mirror of
https://github.com/UofCBaja/BajaUofCWebsite.git
synced 2025-06-16 05:44:17 -06:00
added header: added dark mode css and togglable dark/light mode and checks for browser preferance
This commit is contained in:
parent
9280dcee83
commit
58f2ad739c
@ -29,8 +29,12 @@ nav a {
|
||||
|
||||
nav a li {
|
||||
background-color: none;
|
||||
padding: 1rem;
|
||||
padding-top: 0px;
|
||||
padding: 0.5rem;
|
||||
border: solid 1px gray;
|
||||
}
|
||||
|
||||
nav a li:hover {
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
nav ul {
|
||||
@ -58,4 +62,38 @@ nav ul {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* not sure what these two are for */
|
||||
header div {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
header div button {
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
height: 4rem;
|
||||
width: 4rem;
|
||||
align-items: center;
|
||||
background-color: inherit;
|
||||
border: solid 2px gray;
|
||||
border-radius: 1rem;
|
||||
}
|
||||
|
||||
header div button img {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* for dark mode */
|
||||
|
||||
.darkmode {
|
||||
filter: invert(95%) hue-rotate(180deg);
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#root.darkmode #logo.logoAfterDark {
|
||||
filter: hue-rotate(180deg);
|
||||
}
|
||||
|
||||
#root.darkmode #darkModeToggle {
|
||||
filter: hue-rotate(180deg);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import logo from "./logo.png";
|
||||
import lightDark from "./light-dark.webp";
|
||||
import { Outlet, Link } from "react-router-dom";
|
||||
import "./Header.css";
|
||||
|
||||
@ -7,12 +8,42 @@ import "./Header.css";
|
||||
* @returns {JSX.Element} JSX - HTML tags and JS functionality
|
||||
* @description The top header part of the page includes the naviagtion
|
||||
* @author Brock <darkicewolf50@gmail.com>
|
||||
* @todo convert any dropdowns and use <Link> just like <a> https://github.com/Akshpreet02/EventSphere
|
||||
* @todo final css
|
||||
*/
|
||||
const Header = () => {
|
||||
/**
|
||||
* @param {null} null - Takes in nothing
|
||||
* @returns {CSSStyleRule} CSS - changes page to darkmode
|
||||
* @description inverts all of the colors of body without touching the pictures
|
||||
* @author Brock <darkicewolf50@gmail.com>
|
||||
*/
|
||||
const switchDarkMode = () => {
|
||||
const body = document.getElementById("root");
|
||||
const logoCss = document.getElementById("logo");
|
||||
|
||||
body.classList.toggle("darkmode");
|
||||
logoCss.classList.toggle("logoAfterDark");
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {null} null - Takes in nothing
|
||||
* @returns {CSSStyleRule} CSS - makes it compliant with bowser preferances
|
||||
* @description checks for what the browser prefers
|
||||
* @author Brock <darkicewolf50@gmail.com>
|
||||
*/
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const prefersDarkMode =
|
||||
window.matchMedia &&
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
if (prefersDarkMode) {
|
||||
switchDarkMode();
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<header>
|
||||
<div>
|
||||
<Link to={"/"}>
|
||||
<figure>
|
||||
<img
|
||||
@ -25,7 +56,14 @@ const Header = () => {
|
||||
</figcaption>
|
||||
</figure>
|
||||
</Link>
|
||||
|
||||
<button onClick={switchDarkMode}>
|
||||
<img
|
||||
id="darkModeToggle"
|
||||
src={lightDark}
|
||||
alt="Light/Dark Toggle Symbol"
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
<nav>
|
||||
<ul>
|
||||
<Link to={"/"}>
|
||||
|
BIN
src/Header/light-dark.webp
Normal file
BIN
src/Header/light-dark.webp
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
@ -1,13 +1,19 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
||||
monospace;
|
||||
}
|
||||
|
||||
#root.darkmode img,
|
||||
#root.darkmode video,
|
||||
#root.darkmode iframe {
|
||||
filter: invert(95%) hue-rotate(180deg);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user