-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: overhaul styling for tool pages
Signed-off-by: tylerslaton <[email protected]>
- Loading branch information
1 parent
ef64df0
commit 10bb7a6
Showing
3 changed files
with
19 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,19 @@ | ||
<template> | ||
<div class="sidebar"> | ||
<div v-for="group in headerGroups" :key="group.id" class="mb-4 overflow-auto"> | ||
<a :href="`#${group.id}`">{{ group.text || "root" }}</a> | ||
<button @click="toggleGroup(group)" class="px-4 py-2 text-xs font-thin cursor-pointer"> | ||
{{ group.isOpen ? '▼' : '►' }} | ||
</button> | ||
|
||
<div class="ml-4" v-show="group.isOpen"> | ||
<div v-for="header in group.headers" :key="header.id" class="m-2"> | ||
<a :href="`#${header.id}`">{{ header.text }}</a> | ||
</div> | ||
</div> | ||
<div class="sidebar text-gray-600"> | ||
<div v-for="header in headers" :key="header.id" class="mb-4 overflow-auto"> | ||
<a :href="`#${header.id}`">{{ header.innerHTML || "root" }}</a> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, onMounted } from 'vue'; | ||
const headerGroups = ref([]); | ||
const headers = ref([]); | ||
onMounted(() => { | ||
fetchHeaders(); | ||
achors(); | ||
}); | ||
const fetchHeaders = () => { | ||
const headers = Array.from(document.querySelectorAll('h2, h4')); | ||
const groups = []; | ||
for (let i = 0; i < headers.length; i++) { | ||
const header = headers[i]; | ||
if (header.tagName === 'H2') { | ||
const group = { | ||
id: header.id, | ||
text: header.textContent, | ||
headers: [], | ||
isOpen: false | ||
}; | ||
groups.push(group); | ||
} else if (header.tagName === 'H4' && groups.length > 0) { | ||
const group = groups[groups.length - 1]; | ||
group.headers.push({ | ||
id: header.id, | ||
text: header.textContent | ||
}); | ||
} | ||
} | ||
headerGroups.value = groups; | ||
} | ||
const achors = () => { | ||
const navbarHeight = document.querySelector('.navbar').offsetHeight; | ||
const anchors = document.querySelectorAll('.sidebar a'); | ||
anchors.forEach(anchor => { | ||
anchor.addEventListener('click', (event) => { | ||
event.preventDefault(); | ||
const targetId = anchor.getAttribute('href').substring(1); | ||
const targetElement = document.getElementById(targetId); | ||
const offsetTop = targetElement.offsetTop - navbarHeight; | ||
window.scrollTo({ | ||
top: offsetTop, | ||
behavior: 'smooth' | ||
}); | ||
}); | ||
}); | ||
} | ||
const toggleGroup = (group) => { | ||
group.isOpen = !group.isOpen; | ||
} | ||
const fetchHeaders = () => headers.value = Array.from(document.querySelectorAll('h2')); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters