Skip to content

Commit

Permalink
Add smooth scroll and fix styles on in page nav
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Dec 10, 2024
1 parent 60f66ad commit a440d03
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/frontend/components/field--objectives.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ interface FieldObjectiveProps {


export function FieldObjectives({fieldObjectives} : FieldObjectiveProps) {
console.log(fieldObjectives)
return (
<div>
<h2 className="font-sans-2xl margin-bottom-1" id="objectives">
Expand Down
23 changes: 19 additions & 4 deletions src/frontend/components/usa--in-page-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import * as React from "react";
import { useState, useEffect } from "react";
import Link from 'next/link'
import { FieldLogo } from './field--logo';

// TODO: Add scrollTo code for long pages when using in page navigation.

export function USAInPageNav({links, logo, logoAbove = true}) {
const [currentLink, setCurrentLink] = useState(links[0].href);
// const [scrollTarget, setScrollTarget] = useState(links[0].href);
// useEffect(() => {
// if (currentLink !== scrollTarget) {
// setScrollTarget(currentLink);
// let id = currentLink;
// if (id.charAt(0) === "#") {
// id = id.substring(1);
// }
// document.getElementById(id).scrollIntoView({behavior: "smooth"})
// }
// }, [currentLink, scrollTarget])

return (
<aside
className="usa-in-page-nav"
Expand All @@ -24,12 +38,13 @@ export function USAInPageNav({links, logo, logoAbove = true}) {
<ul className="usa-in-page-nav__list">
{links.map((link) => (
<li key={link.href} className={`usa-in-page-nav__item${link.primary ? " usa-in-page-nav__item--primary" : ""}`}>
<a
<Link
href={link.href}
className="usa-in-page-nav__link"
onClick={() => setCurrentLink(link.href)}
className={`usa-in-page-nav__link ${link.href === currentLink ? "usa-current" : ""}`}
>
{link.label}
</a>
</Link>
</li>
))}
</ul>
Expand Down
11 changes: 11 additions & 0 deletions src/frontend/styles/components/usa--in-page-nav.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
html {
scroll-behavior: smooth;
}

.usa-in-page-nav__item {
font-weight: 400 !important;
}

.usa-in-page-nav__item--primary {
font-weight: 700 !important;
}
3 changes: 2 additions & 1 deletion src/frontend/styles/project-styles.scss
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import "./components/field--goal-type.scss";
@import "./components/field--goal-type.scss";
@import "./components/usa--in-page-nav.scss";

0 comments on commit a440d03

Please sign in to comment.