Skip to content

Commit

Permalink
Honors portfolio 33 (#54)
Browse files Browse the repository at this point in the history
* Attempt using react-chrono

* Primary elements

* Styled

* Smooth scrolling

* Scroll to top button
  • Loading branch information
kjy5 authored Jun 14, 2022
1 parent 672322a commit 3c3fb56
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 83 deletions.
362 changes: 281 additions & 81 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"photoswipe-dynamic-caption-plugin": "^1.1.1",
"prop-types": "^15.8.1",
"react": "^18.1.0",
"react-chrono": "^1.16.2",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"three": "^0.141.0"
Expand Down
6 changes: 5 additions & 1 deletion src/components/Artifacts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export default function Artifacts(props) {
if (artifact.year !== curYear) {
curYear = artifact.year;
output.push(
<div className="Artifacts__year-header" key={`year_${curYear}`} />
<div
className="Artifacts__year-header"
key={`year_${curYear}`}
id={`year_${curYear}`}
/>
);
}

Expand Down
95 changes: 95 additions & 0 deletions src/components/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import "../styles/NavBar.css";

import React, { useEffect } from "react";

/**
* @description NavBar component
* @returns {JSX.Element} JSX elements for the NavBar
*/
export default function NavBar() {
useEffect(() => {
const scrollToTopButton = document.querySelector("#scroll_to_top_button");

window.onscroll = () => {
if (window.scrollY > 350) {
scrollToTopButton.classList.add("show");
} else {
scrollToTopButton.classList.remove("show");
}
};
});

/**
* @description Function to scroll to the top of the page
* @type {(function(): void)|*}
*/
const scrollToTop = React.useCallback(() => {
window.scrollTo(0, 0);
}, []);

/**
* @description Convert year number to string
* @returns {string} Year string
*/
const yearToString = (year) => {
switch (year) {
case 0:
return "Freshman";
case 1:
return "Sophomore";
case 2:
return "Junior";
case 3:
return "Senior";
default:
return "Graduate";
}
};

/**
* @description Year nav bar item
* @param year {number} Year number
* @param disabled {boolean} Whether the year is disabled
* @returns {JSX.Element} JSX element for the year nav bar item
*/
const navYearElement = (year, disabled) => {
return (
<div className={`NavYear ${disabled && "disabled"}`} key={year}>
<h2 className="NavYear__title">{yearToString(year)}</h2>
<a href={`#year_${year}_quarter_0`} className="NavYear__quarter">
Fall
</a>
<a href={`#year_${year}_quarter_1`} className="NavYear__quarter">
Winter
</a>
<a href={`#year_${year}_quarter_2`} className="NavYear__quarter">
Spring
</a>
</div>
);
};

const output = [];
output.push(navYearElement(0, false));
for (let i = 1; i < 4; i++) {
output.push(navYearElement(i, true));
}
return (
<div className="NavBar">
{/* Nav items */}
{output}

{/* Scroll to top button */}
<button
className="NavBar__back-to-top"
id="scroll_to_top_button"
onClick={scrollToTop}
onKeyDown={scrollToTop}
tabIndex="0"
type="button"
>
&#8613;
</button>
</div>
);
}
2 changes: 2 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Artifacts from "./components/Artifacts";
import { createRoot } from "react-dom/client";
import Graphics from "./scripts/graphics"; // skipcq: JS-0249
import InProgress from "./components/InProgress"; // skipcq: JS-0249
import NavBar from "./components/NavBar";
import React from "react";

getContent().then((contentData) => {
Expand All @@ -26,6 +27,7 @@ getContent().then((contentData) => {
<React.StrictMode>
<div id="top" />
<InProgress />
<NavBar />
<Artifacts contentData={contentData} />
</React.StrictMode>
}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/ArtifactCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

.ArtifactCard:hover {
background-color: #2c3e50;
background-color: rgba(81, 115, 148, 0.6);
border-radius: 15px;
}

Expand Down
69 changes: 69 additions & 0 deletions src/styles/NavBar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.NavBar {
background: rgba(100, 100, 100, 0.15);
padding-bottom: 1.5em;
padding-left: 1em;
padding-right: 1em;

border-radius: 15px;

display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-gap: 20px;
}

.NavYear {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-areas: "title title title";
grid-gap: 5px;
}

.NavYear__title {
color: white;
text-align: center;
grid-area: title;
}

.disabled {
pointer-events: none;
opacity: 0.5;
}

.NavYear__quarter {
color: white;
text-decoration: none;
text-align: center;
font-size: larger;
background: rgba(81, 115, 148, 0.3);
padding: 0.5em;
margin-top: -0.5em;
border-radius: 15px;
}

.NavYear__quarter:hover {
background: rgba(81, 115, 148, 0.7);
}

.NavBar__back-to-top {
display: none;
position: fixed;
bottom: 30px;
left: 30px;
z-index: 10;
border: none;
outline: none;
background: rgba(81, 115, 148, 0.3);
color: white;
padding: 15px;
border-radius: 15px;
font-size: 30px;
cursor: pointer;
}

.NavBar__back-to-top:hover {
background: rgba(81, 115, 148, 0.7);
}

.show {
display: block;
}
4 changes: 4 additions & 0 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

html {
scroll-behavior: smooth;
}

0 comments on commit 3c3fb56

Please sign in to comment.