Skip to content

Commit

Permalink
Fix typescript isses
Browse files Browse the repository at this point in the history
  • Loading branch information
huijing committed Dec 7, 2023
1 parent bbb7464 commit 26e9c2a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
base: "/developers",
integrations: [
starlight({
title: "Interledger Protocol (ILP)",
title: "Interledger",
description: "Enable seamless exchange of value across payment networks.",
customCss: [
"./node_modules/@interledger/docs-design-system/src/styles/green-theme.css",
Expand Down
33 changes: 21 additions & 12 deletions src/components/pages/FoundationHeader.astro
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,8 @@ a.switch-link:hover {
</style>

<script>
// Site navigation CSS classes
const siteLinksWrapper = document.querySelector("[data-nav-wrapper]");
const wideNavMinWidth = window.matchMedia("(min-width: 1060px)");
handleNavDisplayStyles(wideNavMinWidth);
wideNavMinWidth.addEventListener("change", handleNavDisplayStyles);

const siteNavToggle = document.getElementById("siteNavToggle");
Expand All @@ -361,23 +359,33 @@ if (document.contains(siteNavToggle)) {

function handleMobileNavToggle() {
siteLinksWrapper?.classList.toggle("offscreen");
if (siteLinksWrapper.getAttribute("class").includes("offscreen")) {
if (siteLinksWrapper?.getAttribute("class")?.includes("offscreen")) {
menuIcon?.classList.remove("open");
} else {
menuIcon?.classList.add("open");
}
}

function handleNavDisplayStyles(event: MediaQueryList) {
function handleNavDisplayStyles(event: MediaQueryListEvent) {
if (event.matches) {
siteLinksWrapper?.classList.remove("offscreen");
} else {
if (siteLinksWrapper) {
flashPrevention(siteLinksWrapper);
}
siteLinksWrapper?.classList.add("offscreen");
}
}

function flashPrevention(element: Element) {
element.setAttribute("style", "display:none");
setTimeout(() => {
element.removeAttribute("style");
}, 10);
}

// Site sub-navigation toggle
const siteNav = document.querySelector(".site-nav__links");
const siteNav = document.querySelector(".site-nav__links") as HTMLInputElement;

if (document.contains(siteNav)) {
const subLinks = document.querySelectorAll(".has-submenu > a");
Expand All @@ -386,25 +394,25 @@ if (document.contains(siteNav)) {
subLink.setAttribute("aria-expanded", "false");

subLink.addEventListener("click", function (event) {
const clickedSubLink = event.target;
const clickedSubLink = event.target as Element;
const allSubLinks = Array.from(subLinks);
const notClickedLinks = allSubLinks.filter(function (otherLink) {
return otherLink !== clickedSubLink;
});
notClickedLinks.forEach((link) => {
link.setAttribute("aria-expanded", "false");
});
if (clickedSubLink.getAttribute("aria-expanded") === "true") {
clickedSubLink.setAttribute("aria-expanded", "false");
if (clickedSubLink?.getAttribute("aria-expanded") === "true") {
clickedSubLink?.setAttribute("aria-expanded", "false");
} else {
clickedSubLink.setAttribute("aria-expanded", "true");
clickedSubLink?.setAttribute("aria-expanded", "true");
}
event.preventDefault();
return false;
});
});

siteNav.addEventListener("keydown", function (event) {
siteNav?.addEventListener("keydown", function (event) {
if (event.key === "Escape") {
resetSubMenus();
}
Expand All @@ -423,10 +431,11 @@ if (document.contains(siteNav)) {
}
}

function isClickOutside(event: MouseEvent, nodeList: Iterable<unknown> | ArrayLike<unknown>) {
function isClickOutside(event: MouseEvent, nodeList: NodeListOf<Element>) {
let clickedInsideTarget = false;
const eventTarget = event.target as Element;
Array.from(nodeList).forEach(function (element) {
if (element.contains(event.target)) {
if (element.contains(eventTarget)) {
clickedInsideTarget = true;
}
});
Expand Down
4 changes: 0 additions & 4 deletions src/layouts/HomeLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ const { title, description } = Astro.props;
flex-direction: column;
min-height: 100%;
min-width: 360px;
color: var(--color-text);
font-family: "Titillium", Arial, sans-serif;
background-image: var(--gradient);
background-repeat: no-repeat;
background-attachment: fixed;
}

/* Background swirl */
Expand Down

0 comments on commit 26e9c2a

Please sign in to comment.