import logo from "./logo.png"; import lightDark from "./light-dark.webp"; import { Outlet, Link } from "react-router-dom"; import "./Header.css"; import Ender from "../Footer/Ender"; import { useEffect, useState } from "react"; /** * @param {null} nothing - Takes in nothing * @returns {JSX.Element} JSX - HTML tags and JS functionality * @description The top header part of the page includes the naviagtion * @author Brock * @todo add appropriate links */ export default function Header() { const [bannerInfo, setBannerInfo] = useState({ titleText: "UCalgary Baja", subtitleText: "Hello", imgUrl: "https://picsum.photos/200", imgAlt: "Lorem picsum", }); useEffect(() => { HeaderBannerHeight(); }); /** * @param {null} nothing - Takes in nothing * @returns {CSSStyleRule} CSS - changes page to darkmode * @description inverts all of the colors of body without touching the pictures * @author Brock */ const switchDarkMode = () => { const body = document.getElementById("root"); const logoCss = document.getElementById("logo"); body.classList.toggle("darkmode"); logoCss.classList.toggle("logoAfterDark"); }; /** * @param {null} nothing - Takes in nothing * @returns {CSSStyleRule} CSS - makes it compliant with bowser preferances * @description checks for what the browser prefers * @author Brock */ document.addEventListener("DOMContentLoaded", () => { const prefersDarkMode = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; if (prefersDarkMode) { switchDarkMode(); } }); /** * @param {null} nothing - This takes in nothing * @returns {null} nothing - This returns nothing * @description This makes it so that the banner will always be 100% of the page at the top * @author Brock */ const HeaderBannerHeight = () => { if (bannerInfo.titleText === "" && bannerInfo.imgUrl === "") { // return early to avoid error when no banner is desired return; } const headerTop = document.getElementsByTagName("header")[0]; const headerTopStyle = getComputedStyle(headerTop); const headerTopInnerHeight = headerTop.offsetHeight; // 2 is used to align bottom of div with img const headerTopMarginTop = parseFloat(headerTopStyle.marginTop) * 2; const headerTopMarginHeight = parseFloat(headerTopStyle.marginBottom); const headerTopTotalHeight = headerTopInnerHeight + headerTopMarginHeight + headerTopMarginTop; const HomeBannerTop = document.getElementById("BannerHeader"); // 1svh is to gget the div close enough to the image HomeBannerTop.style.height = `calc(100svh + -${headerTopTotalHeight}px)`; }; return ( <>
{bannerInfo.titleText === "" && bannerInfo.imgUrl === "" ? ( <> ) : (
{bannerInfo.imgAlt}

{bannerInfo.titleText}

{bannerInfo.subtitleText}

)} ); } // used like this //