diff options
Diffstat (limited to 'examples/docs/src/components/LeftSidebar/LeftSidebar.astro')
-rw-r--r-- | examples/docs/src/components/LeftSidebar/LeftSidebar.astro | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/examples/docs/src/components/LeftSidebar/LeftSidebar.astro b/examples/docs/src/components/LeftSidebar/LeftSidebar.astro new file mode 100644 index 000000000..96bd36fba --- /dev/null +++ b/examples/docs/src/components/LeftSidebar/LeftSidebar.astro @@ -0,0 +1,109 @@ +--- +import { SIDEBAR } from '../../config.ts'; +import { getLanguageFromURL } from '../util.ts'; +const {currentPage} = Astro.props; +const currentPageMatch = currentPage.slice(1); +const langCode = getLanguageFromURL(currentPage); +// SIDEBAR is a flat array. Group it by sections to properly render. +const sidebarSections = SIDEBAR[langCode].reduce((col, item) => { + if (item.header) { + col.push({...item, children: []}); + } else { + col[col.length-1].children.push(item); + } + return col; +}, []); + +--- + +<nav aria-labelledby="grid-left"> + <ul class="nav-groups"> + {sidebarSections.map(section => ( + <li> + <div class="nav-group"> + <h2 class="nav-group-title">{section.text}</h2> + <ul> + {section.children.map(child => ( + <li class="nav-link"><a href={`${Astro.site.pathname}${child.link}`} aria-current={`${currentPageMatch === child.link ? 'page' : 'false'}`}>{child.text}</a></li> + ))} + </ul> + </div> + </li> + ))} + </ul> +</nav> + +<script> + window.addEventListener('DOMContentLoaded', (event) => { + var target = document.querySelector('[aria-current="page"]'); + if (target && (target.offsetTop > (window.innerHeight - 100))) { + document.querySelector('.nav-groups').scrollTop = target.offsetTop; + } + }); +</script> + +<style> + nav { + width: 100%; + margin-right: 1rem; + } + .nav-groups { + height: 100%; + padding: 2rem 0; + overflow-x: visible; + overflow-y: auto; + max-height: 100vh; + } + + .nav-groups > li + li { + margin-top: 2rem; + } + + .nav-groups > :first-child { + padding-top: var(--doc-padding); + } + + .nav-groups > :last-child { + padding-bottom: 2rem; + margin-bottom: var(--theme-navbar-height); + } + + .nav-group-title { + font-size: 1.0rem; + font-weight: 700; + padding: 0.1rem 1rem; + text-transform: uppercase; + margin-bottom: 0.5rem; + } + + .nav-link a { + font-size: 1.0rem; + margin: 1px; + padding: 0.3rem 1rem; + font: inherit; + color: inherit; + text-decoration: none; + display: block; + } + .nav-link a:hover, + .nav-link a:focus { + background-color: var(--theme-bg-hover); + } + + .nav-link a[aria-current="page"] { + color: var(--theme-text-accent); + background-color: var(--theme-bg-accent); + font-weight: 600; + } + + :global(:root.theme-dark) .nav-link a[aria-current="page"] { + color: hsla(var(--color-base-white), 100%, 1); + } + + @media (min-width: 50em) { + .nav-groups { + padding: 0; + } + } + +</style> |