-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wb-lyb830048
committed
Jan 11, 2024
1 parent
fe91fac
commit e5e60f9
Showing
6 changed files
with
341 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
--- | ||
import MobileNavbarSublist from "./MobileNavbarSublist.astro"; | ||
import dataSource from '@components/common/Header/navbar.ts'; | ||
import { docsItems } from '@components/common/Header/DocsMenu.astro'; | ||
import { communityItems } from '@components/common/Header/CommunityMenu.astro'; | ||
const sublist = []; | ||
for (let i = 0; i < dataSource.length; i++) { | ||
const item = dataSource[i]; | ||
let _item = {}; | ||
if (item.slot) { | ||
_item = { type: 'group', label: item.label, entries: [], collapsed: true }; | ||
} else { | ||
_item = { type: 'link', label: item.label, href: item.route, isCurrent: false } | ||
} | ||
sublist.push(_item); | ||
} | ||
(() => { | ||
const [docs, , community, ] = sublist; | ||
const docsEntries = []; | ||
const communityEntries = []; | ||
for (let i = 0; i < docsItems.length; i++) { | ||
const item = docsItems[i]; | ||
docsEntries.push({ type: 'link', label: item.label, href: item.link, isCurrent: false }) | ||
} | ||
for (let i = 0; i < communityItems.length; i++) { | ||
const item = communityItems[i]; | ||
if (item.children) { | ||
const _item = { type: 'group', label: item.label, entries: [], collapsed: false, class: 'large-weight text-13px' }; | ||
for (let j = 0; j < item.children.length; j++) { | ||
const child = item.children[j]; | ||
_item.entries.push({ type: 'link', label: child.label, href: child.link, isCurrent: false }); | ||
} | ||
communityEntries.push(_item); | ||
} else { | ||
communityEntries.push({ type: 'link', label: item.label, href: item.link, isCurrent: false }); | ||
} | ||
} | ||
docs.entries = docsEntries; | ||
community.entries = communityEntries; | ||
})() | ||
--- | ||
|
||
|
||
<div class={`mobile-navbar ${Astro.props.class}`}> | ||
<mobile-menu-button> | ||
<button | ||
aria-expanded="false" | ||
aria-label='menu-button' | ||
aria-controls="starlight__sidebar" | ||
class="sl-flex" | ||
> | ||
<svg | ||
viewBox="0 0 1024 1024" | ||
version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
p-id="6304" | ||
width="24" | ||
height="24" | ||
> | ||
<path | ||
d="M192.037 287.953h640.124c17.673 0 32-14.327 32-32s-14.327-32-32-32H192.037c-17.673 0-32 14.327-32 32s14.327 32 32 32zM832.161 479.169H438.553c-17.673 0-32 14.327-32 32s14.327 32 32 32h393.608c17.673 0 32-14.327 32-32s-14.327-32-32-32zM832.161 735.802H192.037c-17.673 0-32 14.327-32 32s14.327 32 32 32h640.124c17.673 0 32-14.327 32-32s-14.327-32-32-32zM319.028 351.594l-160 160 160 160z" | ||
fill="#f4f4f6" | ||
p-id="6305" | ||
> | ||
</path> | ||
</svg> | ||
</button> | ||
</mobile-menu-button> | ||
|
||
<div class="navbar-pane bg-gray-14"> | ||
<div class="navbar-content flex"> | ||
<MobileNavbarSublist sublist={sublist} /> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
<script> | ||
class MobileMenuButton extends HTMLElement { | ||
menuButton = this.querySelector('button')!; | ||
|
||
constructor() { | ||
super(); | ||
this.menuButton.addEventListener('click', () => this.toggleExpanded()); | ||
|
||
const parentNav = this.closest('nav'); | ||
if (parentNav) { | ||
parentNav.addEventListener('keyup', (e) => this.closeOnEscape(e)); | ||
} | ||
} | ||
|
||
setExpanded(expanded: boolean) { | ||
this.setAttribute('aria-expanded', String(expanded)); | ||
document.body.toggleAttribute('data-mobile-menu-expanded', expanded); | ||
} | ||
|
||
toggleExpanded() { | ||
document.body.classList.toggle('overflow-hidden'); | ||
this.setExpanded(this.getAttribute('aria-expanded') !== 'true'); | ||
} | ||
|
||
closeOnEscape(e: KeyboardEvent) { | ||
if (e.code === 'Escape') { | ||
this.setExpanded(false); | ||
this.menuButton.focus(); | ||
} | ||
} | ||
} | ||
|
||
customElements.define('mobile-menu-button', MobileMenuButton); | ||
</script> | ||
|
||
|
||
<style> | ||
.mobile-navbar button { | ||
border: 0; | ||
display: flex; | ||
align-items: center; | ||
width: 2rem; | ||
height: 2rem; | ||
background-color: theme('colors.gray.14'); | ||
cursor: pointer; | ||
} | ||
|
||
.mobile-navbar .navbar-pane { | ||
visibility: var(--sl-sidebar-visibility, hidden); | ||
position: fixed; | ||
z-index: 5; | ||
inset-block: 0; | ||
inset-inline-start: 0; | ||
/* padding-top: 4rem; */ | ||
margin-top: 4rem; | ||
width: 100%; | ||
overflow-y: auto; | ||
} | ||
|
||
:global([aria-expanded='true']) ~ .navbar-pane { | ||
--sl-sidebar-visibility: visible; | ||
} | ||
|
||
.mobile-navbar .navbar-content { | ||
height: 100%; | ||
min-height: max-content; | ||
padding: 1rem 1rem 0; | ||
flex-direction: column; | ||
} | ||
|
||
|
||
</style> |
Oops, something went wrong.