| 1 |
--- |
| 2 |
import type {ContentFolder, ContentFile} from '../lib/content'; |
| 3 |
|
| 4 |
interface Props { |
| 5 |
folder: ContentFolder; |
| 6 |
} |
| 7 |
|
| 8 |
const {folder} = Astro.props; |
| 9 |
const currentUrl = Astro.url.pathname; |
| 10 |
const isAnchorNav = folder.folders[0]?.files[0]?.url?.startsWith('#'); |
| 11 |
|
| 12 |
const isReference = folder.folder === 'reference'; |
| 13 |
const isPatterns = folder.folder === 'patterns'; |
| 14 |
|
| 15 |
const linkClasses = 'sidebar-link flex items-center gap-2.5 px-3 py-2 text-sm rounded-lg text-neutral-600 dark:text-neutral-400 interact:bg-neutral-100 dark:interact:bg-neutral-850 interact:text-black dark:interact:text-neutral-200 aria-[current]:bg-neutral-150 dark:aria-[current]:bg-neutral-800 aria-[current]:text-black dark:aria-[current]:text-neutral-50 aria-[current]:font-semibold'; |
| 16 |
--- |
| 17 |
|
| 18 |
<aside id="sidebar" class="fixed top-(--header-height) inset-x-0 isolate z-30 group/sidebar"> |
| 19 |
|
| 20 |
<nav id="sidebar-nav" aria-label="Sidebar Navigation" class=" |
| 21 |
bg-neutral-25 dark:bg-neutral-920 overflow-y-auto border-neutral-200 dark:border-neutral-850 transition |
| 22 |
px-3 sm:px-5 lg:px-6 |
| 23 |
pb-10 |
| 24 |
max-lg:absolute max-lg:top-full max-lg:inset-x-0 max-lg:z-30 |
| 25 |
max-lg:h-[calc(100lvh-var(--header-height))] |
| 26 |
max-lg:overscroll-contain |
| 27 |
max-lg:opacity-0 max-lg:pointer-events-none max-lg:duration-200 |
| 28 |
[html:has(#sidebar-toggle-mobile:checked)_&]:opacity-100 [html:has(#sidebar-toggle-mobile:checked)_&]:pointer-events-auto |
| 29 |
lg:fixed lg:top-(--header-height) lg:left-0 lg:bottom-0 lg:w-[320px] lg:border-r |
| 30 |
"> |
| 31 |
|
| 32 |
<div class="h-7 shrink-0"></div> |
| 33 |
|
| 34 |
<div class="flex items-center justify-between gap-2 px-0.5 mb-6"> |
| 35 |
<h2 class="font-sans text-xs font-medium uppercase tracking-widest text-neutral-600 dark:text-neutral-400"> |
| 36 |
{folder.frontmatter.title} |
| 37 |
</h2> |
| 38 |
</div> |
| 39 |
|
| 40 |
<div _={isAnchorNav ? `install Scrollspy` : undefined}> |
| 41 |
|
| 42 |
{!isAnchorNav && ( |
| 43 |
<a href={folder.url} |
| 44 |
aria-current={currentUrl === folder.url ? 'page' : undefined} |
| 45 |
class:list={[linkClasses, 'block mb-2 truncate']}> |
| 46 |
Overview |
| 47 |
</a> |
| 48 |
)} |
| 49 |
|
| 50 |
{folder.folders.map((subFolder) => { |
| 51 |
const files = subFolder.files; |
| 52 |
|
| 53 |
return ( |
| 54 |
<div class="w-full not-first:mt-3"> |
| 55 |
<h3 class="font-sans text-[0.625rem] tracking-widest uppercase truncate min-w-0 px-3 py-1 text-neutral-600 dark:text-neutral-400" |
| 56 |
set:html={subFolder.frontmatter.title}/> |
| 57 |
|
| 58 |
{files.length > 0 && ( |
| 59 |
<ul class="space-y-0.5 border-l border-neutral-150 dark:border-neutral-850 ml-3 pl-3 mt-1 mb-4"> |
| 60 |
{files.map((file: ContentFile) => { |
| 61 |
const isActive = currentUrl === file.url; |
| 62 |
const isSoon = file.frontmatter.soon; |
| 63 |
return ( |
| 64 |
<li> |
| 65 |
<a href={isSoon ? undefined : file.url} |
| 66 |
title={file.frontmatter.description} |
| 67 |
aria-current={isActive ? 'page' : undefined} |
| 68 |
aria-disabled={isSoon ? 'true' : undefined} |
| 69 |
hx-boost={isSoon && 'false'} |
| 70 |
class:list={[ |
| 71 |
linkClasses, |
| 72 |
isReference && 'font-mono', |
| 73 |
isSoon && 'opacity-50 cursor-not-allowed', |
| 74 |
]}> |
| 75 |
{isPatterns && file.frontmatter.icon && ( |
| 76 |
<i class:list={[file.frontmatter.icon, "size-4 shrink-0"]}></i> |
| 77 |
)} |
| 78 |
<span class="truncate" set:html={file.frontmatter.title}/> |
| 79 |
{isSoon && ( |
| 80 |
<span class="text-[9px] px-1.5 py-0.5 shrink-0 rounded bg-yellow-300/5 text-yellow-700 dark:text-yellow-300 border border-yellow-600/50 dark:border-yellow-300 font-medium uppercase tracking-wide ml-auto">Soon</span> |
| 81 |
)} |
| 82 |
</a> |
| 83 |
</li> |
| 84 |
); |
| 85 |
})} |
| 86 |
</ul> |
| 87 |
)} |
| 88 |
</div> |
| 89 |
); |
| 90 |
})} |
| 91 |
|
| 92 |
{folder.files.map((f: ContentFile) => { |
| 93 |
const isActive = currentUrl === f.url; |
| 94 |
return ( |
| 95 |
<a href={f.url} |
| 96 |
title={f.frontmatter.description} |
| 97 |
aria-current={isActive ? 'page' : undefined} |
| 98 |
class:list={[linkClasses, 'block truncate']}> |
| 99 |
<span set:html={f.frontmatter.title}/> |
| 100 |
</a> |
| 101 |
); |
| 102 |
})} |
| 103 |
</div> |
| 104 |
</nav> |
| 105 |
|
| 106 |
<input id="sidebar-toggle-mobile" type="checkbox" class="sr-only" _="on click from <a/> set my.checked to false"> |
| 107 |
</aside> |