|
| 1 | +--- |
| 2 | +import Default from '@astrojs/starlight/components/SocialIcons.astro'; |
| 3 | +const base = import.meta.env.BASE_URL; |
| 4 | +--- |
| 5 | + |
| 6 | +<nav class="custom-header-links" aria-label="Primary navigation"> |
| 7 | + <a href={`${base}introduction/overview/`} class="header-link">Overview</a> |
| 8 | + <a href={`${base}getting-started/quick-start/`} class="header-link">Quick Start</a> |
| 9 | + <a href={`${base}reference/cli/`} class="header-link">CLI</a> |
| 10 | + <a href={`${base}guides/ui/`} class="header-link">UI</a> |
| 11 | + <a href={`${base}faq/`} class="header-link">FAQ</a> |
| 12 | +</nav> |
| 13 | + |
| 14 | +<!-- Hamburger menu for narrow viewports where full nav would overflow --> |
| 15 | +<div class="tablet-nav-wrapper"> |
| 16 | + <button class="hamburger-btn" aria-label="Toggle navigation menu" aria-expanded="false" aria-controls="tablet-nav-dropdown"> |
| 17 | + <span class="hamburger-icon" aria-hidden="true"></span> |
| 18 | + </button> |
| 19 | + <nav class="tablet-dropdown" id="tablet-nav-dropdown" aria-label="Primary navigation" hidden> |
| 20 | + <a href={`${base}introduction/overview/`} class="dropdown-link">Overview</a> |
| 21 | + <a href={`${base}getting-started/quick-start/`} class="dropdown-link">Quick Start</a> |
| 22 | + <a href={`${base}reference/cli/`} class="dropdown-link">CLI</a> |
| 23 | + <a href={`${base}guides/ui/`} class="dropdown-link">UI</a> |
| 24 | + <a href={`${base}faq/`} class="dropdown-link">FAQ</a> |
| 25 | + </nav> |
| 26 | +</div> |
| 27 | + |
| 28 | +<Default {...Astro.props} /> |
| 29 | + |
| 30 | +<style> |
| 31 | + .custom-header-links { |
| 32 | + display: flex; |
| 33 | + align-items: center; |
| 34 | + gap: 1rem; |
| 35 | + margin-right: 1rem; |
| 36 | + } |
| 37 | + |
| 38 | + .header-link { |
| 39 | + color: var(--sl-color-text); |
| 40 | + text-decoration: none; |
| 41 | + font-size: 0.875rem; |
| 42 | + font-weight: 500; |
| 43 | + padding: 0.25rem 0.75rem; |
| 44 | + border-radius: 4px; |
| 45 | + transition: color 0.15s ease, background-color 0.15s ease; |
| 46 | + white-space: nowrap; |
| 47 | + } |
| 48 | + |
| 49 | + .header-link:hover { |
| 50 | + color: var(--sl-color-text-accent); |
| 51 | + background-color: rgba(110, 118, 129, 0.1); |
| 52 | + } |
| 53 | + |
| 54 | + /* Tablet navigation — hidden by default; shown via global CSS at narrow widths */ |
| 55 | + .tablet-nav-wrapper { |
| 56 | + display: none; |
| 57 | + position: relative; |
| 58 | + margin-right: 0.5rem; |
| 59 | + } |
| 60 | + |
| 61 | + .hamburger-btn { |
| 62 | + background: none; |
| 63 | + border: none; |
| 64 | + cursor: pointer; |
| 65 | + padding: 0.5rem; |
| 66 | + color: var(--sl-color-text); |
| 67 | + border-radius: 4px; |
| 68 | + min-height: 44px; |
| 69 | + min-width: 44px; |
| 70 | + display: inline-flex; |
| 71 | + align-items: center; |
| 72 | + justify-content: center; |
| 73 | + } |
| 74 | + |
| 75 | + .hamburger-btn:hover { |
| 76 | + background-color: rgba(110, 118, 129, 0.1); |
| 77 | + } |
| 78 | + |
| 79 | + .hamburger-icon { |
| 80 | + display: block; |
| 81 | + width: 20px; |
| 82 | + height: 2px; |
| 83 | + background: currentColor; |
| 84 | + position: relative; |
| 85 | + } |
| 86 | + |
| 87 | + .hamburger-icon::before, |
| 88 | + .hamburger-icon::after { |
| 89 | + content: ''; |
| 90 | + display: block; |
| 91 | + width: 20px; |
| 92 | + height: 2px; |
| 93 | + background: currentColor; |
| 94 | + position: absolute; |
| 95 | + left: 0; |
| 96 | + } |
| 97 | + |
| 98 | + .hamburger-icon::before { top: -6px; } |
| 99 | + .hamburger-icon::after { top: 6px; } |
| 100 | + |
| 101 | + .tablet-dropdown { |
| 102 | + position: absolute; |
| 103 | + top: calc(100% + 0.5rem); |
| 104 | + right: 0; |
| 105 | + background: var(--sl-color-bg-nav, #161b22); |
| 106 | + border: 1px solid rgba(48, 54, 61, 0.8); |
| 107 | + border-radius: 8px; |
| 108 | + padding: 0.5rem 0; |
| 109 | + min-width: 180px; |
| 110 | + z-index: 100; |
| 111 | + box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); |
| 112 | + } |
| 113 | + |
| 114 | + .dropdown-link { |
| 115 | + display: block; |
| 116 | + padding: 0.625rem 1rem; |
| 117 | + color: var(--sl-color-text); |
| 118 | + text-decoration: none; |
| 119 | + font-size: 0.875rem; |
| 120 | + font-weight: 500; |
| 121 | + transition: background-color 0.15s ease; |
| 122 | + } |
| 123 | + |
| 124 | + .dropdown-link:hover { |
| 125 | + background-color: rgba(110, 118, 129, 0.1); |
| 126 | + color: var(--sl-color-text-accent); |
| 127 | + } |
| 128 | +</style> |
| 129 | + |
| 130 | +<script> |
| 131 | + let hamburgerAbort: AbortController | undefined; |
| 132 | + |
| 133 | + function initHamburgerMenu() { |
| 134 | + hamburgerAbort?.abort(); |
| 135 | + hamburgerAbort = new AbortController(); |
| 136 | + const { signal } = hamburgerAbort; |
| 137 | + |
| 138 | + const hamburgerBtn = document.querySelector<HTMLButtonElement>('.hamburger-btn'); |
| 139 | + const tabletDropdown = document.querySelector<HTMLElement>('.tablet-dropdown'); |
| 140 | + |
| 141 | + if (!hamburgerBtn || !tabletDropdown) return; |
| 142 | + |
| 143 | + hamburgerBtn.addEventListener('click', (e) => { |
| 144 | + e.stopPropagation(); |
| 145 | + const isOpen = hamburgerBtn.getAttribute('aria-expanded') === 'true'; |
| 146 | + hamburgerBtn.setAttribute('aria-expanded', String(!isOpen)); |
| 147 | + tabletDropdown.hidden = isOpen; |
| 148 | + if (!isOpen) { |
| 149 | + const firstLink = tabletDropdown.querySelector<HTMLAnchorElement>('.dropdown-link'); |
| 150 | + firstLink?.focus(); |
| 151 | + } |
| 152 | + }, { signal }); |
| 153 | + |
| 154 | + document.addEventListener('click', (e) => { |
| 155 | + if (!hamburgerBtn.contains(e.target as Node) && !tabletDropdown.contains(e.target as Node)) { |
| 156 | + hamburgerBtn.setAttribute('aria-expanded', 'false'); |
| 157 | + tabletDropdown.hidden = true; |
| 158 | + } |
| 159 | + }, { signal }); |
| 160 | + |
| 161 | + document.addEventListener('keydown', (e) => { |
| 162 | + if (e.key === 'Escape' && hamburgerBtn.getAttribute('aria-expanded') === 'true') { |
| 163 | + hamburgerBtn.setAttribute('aria-expanded', 'false'); |
| 164 | + tabletDropdown.hidden = true; |
| 165 | + hamburgerBtn.focus(); |
| 166 | + } |
| 167 | + }, { signal }); |
| 168 | + } |
| 169 | + |
| 170 | + initHamburgerMenu(); |
| 171 | + document.addEventListener('astro:page-load', initHamburgerMenu); |
| 172 | +</script> |
0 commit comments