<div x-data="tocDemo()" x-init="init()" @scroll.window="onScroll">
<!-- sidebar offset accounts for the fixed header height via a CSS var,
not a hardcoded top value, so it stays correct if the header
height ever changes -->
<aside class="sticky self-start"
style="top: calc(var(--app-header-h, 0px) + 1rem)">
<nav x-show="sections.length > 1">
<a :href="'#' + s.id"
:class="{ 'sc-toc-link--active': activeIndex === i }"
x-text="s.label"></a>
</nav>
</aside>
</div>
<script>
function tocDemo() {
return {
sections: [
{ id: 'intro', label: 'Introduction' },
{ id: 'install', label: 'Installation' },
{ id: 'usage', label: 'Usage' },
{ id: 'api', label: 'API Reference' },
{ id: 'faq', label: 'FAQ' },
],
activeIndex: 0,
init() {
// Real implementation: IntersectionObserver per section,
// set activeIndex to whichever section crosses the header offset.
},
onScroll(e) {
// Demo-only scroll handler — see preview JS for the simplified
// version used to drive this showcase without IntersectionObserver.
},
};
}
</script>