---
/**
* Mobile product switcher — the docs tab bar's counterpart inside the
* hamburger drawer. Desktop hides it (the horizontal tab bar owns
* navigation there); on mobile the tab bar is hidden and this switcher
* is how you move between hubs.
*
* A disclosure (<details>), not a native <select>, so brand marks and
* the category headings render like the desktop dropdowns. Picking a
* product navigates to that hub's landing page.
*/
import { DOCS_TABS, DOCS_TAB_GROUPS, activeTab, groupTabs } from "../../docs-tabs";
import { TAB_ICONS } from "../../docs-icons";
const current = activeTab(Astro.url.pathname);
// Same taxonomy as the desktop dropdowns (docs-tabs.ts), so a new hub
// lands in the right category on both without a second list to update.
const grouped: { heading?: string; tabs: typeof DOCS_TABS }[] = [
{ tabs: DOCS_TABS.filter((tab) => tab.slot === "start") },
...DOCS_TAB_GROUPS.map((group) => ({ heading: group.label, tabs: groupTabs(group) })),
{ heading: "Meta", tabs: DOCS_TABS.filter((tab) => tab.slot === "end") },
];
---
<details class="alc-switcher">
<summary class="alc-switcher__current">
{
TAB_ICONS[current.label] && (
<svg
class="alc-switcher__icon"
aria-hidden="true"
width="16"
height="16"
viewBox="0 0 24 24"
set:html={TAB_ICONS[current.label]}
/>
)
}
<span>{current.label}</span>
<svg
class="alc-switcher__chevron"
aria-hidden="true"
width="12"
height="12"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m6 9 6 6 6-6" />
</svg>
</summary>
<div class="alc-switcher__panel">
{
grouped.map((group) => (
<>
{group.heading && (
<div class="alc-switcher__heading">{group.heading}</div>
)}
{group.tabs.map((tab) => (
<a
href={tab.href}
class:list={["alc-switcher__item", { "alc-switcher__item--active": tab.label === current.label }]}
aria-current={tab.label === current.label ? "true" : undefined}
>
{TAB_ICONS[tab.label] && (
<svg
class="alc-switcher__icon"
aria-hidden="true"
width="15"
height="15"
viewBox="0 0 24 24"
set:html={TAB_ICONS[tab.label]}
/>
)}
<span>{tab.label}</span>
</a>
))}
</>
))
}
</div>
</details>
<style>
/* Below 72rem only: wider viewports get the header tab bar. */
.alc-switcher {
margin: 0 0 0.75rem;
}
@media (min-width: 72rem) {
.alc-switcher {
display: none;
}
}
.alc-switcher__current {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid var(--alc-hairline-2);
border-radius: 10px;
font-size: var(--sl-text-base);
font-weight: 600;
color: var(--sl-color-white);
cursor: pointer;
user-select: none;
list-style: none;
}
.alc-switcher__current::marker,
.alc-switcher__current::-webkit-details-marker {
display: none;
}
.alc-switcher[open] .alc-switcher__current {
border-color: var(--alc-accent-deep);
}
.alc-switcher__icon {
flex-shrink: 0;
opacity: 0.9;
}
.alc-switcher__chevron {
margin-inline-start: auto;
color: var(--alc-fg-4);
transition: transform var(--alc-dur, 0.2s) var(--alc-ease, ease);
}
.alc-switcher[open] .alc-switcher__chevron {
transform: rotateZ(180deg);
}
.alc-switcher__panel {
margin-top: 6px;
border: 1px solid var(--alc-hairline-2);
border-radius: 12px;
background: var(--alc-bg-elev-1, var(--sl-color-bg-nav));
padding: 6px 0;
overflow: hidden;
}
.alc-switcher__heading {
padding: 8px 14px 3px;
font-size: 10.5px;
font-weight: 600;
letter-spacing: 0.07em;
text-transform: uppercase;
color: var(--alc-fg-4);
border-top: 1px solid var(--alc-hairline);
margin-top: 5px;
}
.alc-switcher__item {
display: flex;
align-items: center;
gap: 10px;
padding: 8px 14px;
font-size: var(--sl-text-sm);
color: var(--alc-fg-2);
text-decoration: none;
}
.alc-switcher__item:hover {
color: var(--alc-accent-deep);
}
.alc-switcher__item--active {
color: var(--alc-accent-deep);
font-weight: 600;
background: color-mix(in srgb, var(--alc-accent-deep) 10%, transparent);
}
</style>