|
| 1 | +--- |
| 2 | +import AstrolightSiteTitle from '@astrojs/starlight/components/SiteTitle.astro' |
| 3 | +import type { Props } from '@astrojs/starlight/props' |
| 4 | +
|
| 5 | +const menuItems = [ |
| 6 | + { name: 'Docs', href: '/introduction' }, |
| 7 | + { name: 'Performance', href: '/performance' }, |
| 8 | + { name: 'Playground', href: '/playground' }, |
| 9 | +] |
| 10 | +
|
| 11 | +function pathsMatch(lhs: string, rhs: string): boolean { |
| 12 | + return rhs.includes(lhs) |
| 13 | +} |
| 14 | +--- |
| 15 | + |
| 16 | +<div> |
| 17 | + <AstrolightSiteTitle {...Astro.props} /> |
| 18 | + |
| 19 | + <div class="separator"></div> |
| 20 | + |
| 21 | + <div class="menu-items"> |
| 22 | + { |
| 23 | + menuItems.map((menuItem) => ( |
| 24 | + <a |
| 25 | + href={menuItem.href} |
| 26 | + aria-current={ |
| 27 | + pathsMatch(encodeURI(menuItem.href), Astro.url.pathname) && "page" |
| 28 | + } |
| 29 | + > |
| 30 | + <span>{menuItem.name}</span> |
| 31 | + </a> |
| 32 | + )) |
| 33 | + } |
| 34 | + </div> |
| 35 | +</div> |
| 36 | + |
| 37 | +<style> |
| 38 | + div { |
| 39 | + display: flex; |
| 40 | + gap: var(--sl-content-pad-x); |
| 41 | + align-items: center; |
| 42 | + } |
| 43 | + |
| 44 | + .separator { |
| 45 | + content: ""; |
| 46 | + height: 1.5rem; |
| 47 | + border-inline-end: 1px solid var(--sl-color-gray-4); |
| 48 | + } |
| 49 | + |
| 50 | + div a { |
| 51 | + text-decoration: none; |
| 52 | + color: var(--sl-color-white); |
| 53 | + font-size: var(--sl-text-base); |
| 54 | + font-weight: 500; |
| 55 | + } |
| 56 | + |
| 57 | + div a:hover { |
| 58 | + text-decoration: underline; |
| 59 | + color: var(--sl-color-text-accent); |
| 60 | + } |
| 61 | + |
| 62 | + [aria-current="page"], |
| 63 | + [aria-current="page"]:hover, |
| 64 | + [aria-current="page"]:focus { |
| 65 | + color: var(--sl-color-text-accent); |
| 66 | + } |
| 67 | + |
| 68 | + @media (min-width: 50rem) { |
| 69 | + .menu-items { |
| 70 | + display: flex; |
| 71 | + } |
| 72 | + .separator { |
| 73 | + display: block; |
| 74 | + } |
| 75 | + } |
| 76 | +</style> |
0 commit comments