Skip to content

Commit

Permalink
Update: Calender component, And Doc Toc.
Browse files Browse the repository at this point in the history
  • Loading branch information
moshiur01 committed Oct 18, 2024
1 parent f7a1765 commit 41e3f11
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
43 changes: 42 additions & 1 deletion components/TableOfContent.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
<script lang="ts" setup>
import { ref } from "vue";
import { onMounted, ref } from "vue";
const { toc } = useContent();
const activeLink = ref("");
const setActiveLink = (id: string) => {
activeLink.value = id;
};
//handle current active link
const updateActiveLinkOnScroll = () => {
// in doc the heading element is h2
const headingElements = Array.from(
document?.querySelectorAll<HTMLHeadingElement>("h2[id]"),
);
const scrollTop =
document?.documentElement.scrollTop || document?.body.scrollTop;
headingElements?.forEach((anchor) => {
// get anchor tag under the h2 element
const link = document?.querySelector<HTMLAnchorElement>(
`h2[id="${anchor.id}"] a`,
);
if (link) {
link?.classList.remove("active-link");
}
});
// Activate the first matching anchor as scroll
for (let i = headingElements?.length; i >= 0; i--) {
const singleHeading = headingElements[i];
if (scrollTop > singleHeading?.offsetTop - 75) {
const link = document?.querySelector<HTMLAnchorElement>(
`h2[id="${singleHeading.id}"] a`,
);
if (link) {
setActiveLink(singleHeading.id);
link.classList.add("active-link");
break;
}
}
}
};
onMounted(() => {
document.addEventListener("scroll", updateActiveLinkOnScroll);
});
</script>

<template>
Expand Down
4 changes: 0 additions & 4 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export default defineNuxtConfig({
Inter: {
wght: "100..900",
},
// SpaceMono: {
// subsets: "latin",
// wght: ["400"],
// },
},
},
postcss: {
Expand Down
1 change: 1 addition & 0 deletions src/components/Calender/Calendar.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable vue/require-default-prop -->
<script lang="ts" setup>
import {
CalendarRoot,
Expand Down

0 comments on commit 41e3f11

Please sign in to comment.