AstroCol/src/components/WikiEntry.astro

51 lines
1.3 KiB
Plaintext
Raw Normal View History

2024-11-08 09:56:44 +00:00
---
import WikiPageEntry from "../types/WikiPageEntry";
const { entry } = Astro.props as { entry: WikiPageEntry };
---
<li>
2025-02-09 19:56:20 +00:00
{entry.children.length > 0 && <a class="dropdown-arrow" href="#">▶</a>}<a class={Astro.url.pathname === entry.url ? "active" : ""} href={entry.url}>{entry.title}</a>
2024-11-08 09:56:44 +00:00
{entry.children.length > 0 && (
2025-02-09 19:56:20 +00:00
<ul style="display: none;">
2024-11-08 09:56:44 +00:00
{entry.children.map((child: WikiPageEntry) => <Astro.self entry={child} />)}
</ul>
)}
</li>
<style>
a {
2025-02-09 19:56:20 +00:00
color: green;
}
a:hover {
2024-11-08 09:56:44 +00:00
color: lime;
}
li {
list-style-type: none;
}
2025-02-09 19:56:20 +00:00
.dropdown-arrow {
color: green;
margin-right: 0.5rem;
text-decoration: none;
}
.active {
color: lime;
text-decoration: none;
}
</style>
<script>
const dropdownArrows: NodeListOf<HTMLElement> = document.querySelectorAll('.dropdown-arrow');
dropdownArrows.forEach((arrow) => {
arrow.addEventListener('click', (event) => {
event.preventDefault();
const ul = (event.target as HTMLElement)?.parentElement?.querySelector('ul');
if(!ul) return;
arrow.textContent = ul.style.display === 'none' ? '▼' : '▶';
arrow.style.color = ul.style.display === 'none' ? 'lime' : 'green';
ul.style.display = ul.style.display === 'none' ? 'block' : 'none';
});
});
</script>