@clarusjs/theme-docs 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -6
- package/src/learn-path.tscl +134 -0
- package/src/lesson-bar.tscl +2 -0
- package/src/lesson.css +30 -3
- package/src/lesson.tscl +21 -1
- package/src/nav.ts +24 -6
- package/src/parts/icon.tscl +21 -0
- package/src/parts/icons.ts +17 -0
- package/src/parts/sidebar.tscl +100 -12
- package/src/search.tscl +4 -0
- package/src/styles/theme.css +413 -0
- package/src/theme.css +1567 -259
- package/src/vite.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clarusjs/theme-docs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A docs theme for clarusjs: layout with header, sidebar, content and on-this-page, design tokens, dark mode, copy buttons and callouts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"clarusjs": "^0.
|
|
19
|
+
"clarusjs": "^0.14.0"
|
|
20
20
|
},
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": "^22.12.0 || ^24.0.0 || >=26.0.0"
|
|
@@ -38,15 +38,18 @@
|
|
|
38
38
|
"url": "https://github.com/forinda/clarusjs/issues"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
+
"@tailwindcss/cli": "4.3.5",
|
|
41
42
|
"@types/node": "^26.6.6",
|
|
42
|
-
"clarusjs": "^0.
|
|
43
|
+
"clarusjs": "^0.14.0",
|
|
44
|
+
"tailwindcss": "4.3.5",
|
|
43
45
|
"typescript": "^7.0.2",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
+
"vite": "^8.3.8",
|
|
47
|
+
"vitest": "^5.1.1"
|
|
46
48
|
},
|
|
47
49
|
"scripts": {
|
|
48
50
|
"types": "node scripts/types.mjs",
|
|
49
51
|
"test": "vitest run",
|
|
50
|
-
"typecheck": "pnpm types && tsc --noEmit"
|
|
52
|
+
"typecheck": "pnpm types && tsc --noEmit",
|
|
53
|
+
"css": "node scripts/classes.js && tailwindcss -i src/styles/theme.css -o src/theme.css"
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
{{--
|
|
2
|
+
The Learn path (#371), beside a lesson from 1024px: the course and how far you are, each lesson with the XP it can
|
|
3
|
+
earn (done, the one you're on, the next, then locked: a hint, every lesson stays open), this lesson's steps, and your
|
|
4
|
+
XP and badges. Progress is read from this browser, so without JavaScript only the lessons and steps show.
|
|
5
|
+
The steps follow the lesson bar (learn:step); everything else follows saved progress (learn:progress).
|
|
6
|
+
--}}
|
|
7
|
+
@import type { Heading } from './nav.ts'
|
|
8
|
+
@interface Lesson { title: string; href: string; xp?: number; minutes?: number }
|
|
9
|
+
@input lessons: Lesson[]
|
|
10
|
+
@input path: string
|
|
11
|
+
@input eyebrow: string = 'Learn'
|
|
12
|
+
@input course: string = ''
|
|
13
|
+
@input steps: Heading[] = []
|
|
14
|
+
@input progress: string = ''
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
import { load, stats } from './progress.ts'
|
|
18
|
+
let ready = state(false)
|
|
19
|
+
let statuses = state(Object.create(null)) // lesson href → done, current, next or locked
|
|
20
|
+
let done = state(0)
|
|
21
|
+
let xp = state(0)
|
|
22
|
+
let earned = state(0)
|
|
23
|
+
let step = state(0)
|
|
24
|
+
function refresh() {
|
|
25
|
+
const s = stats(
|
|
26
|
+
load(),
|
|
27
|
+
lessons.map((l) => l.href),
|
|
28
|
+
)
|
|
29
|
+
const current = lessons.findIndex((l) => s.status(l.href) === 'current')
|
|
30
|
+
statuses = Object.fromEntries(
|
|
31
|
+
lessons.map((l, i) => [l.href, s.status(l.href) === 'locked' && i === current + 1 ? 'next' : s.status(l.href)]),
|
|
32
|
+
)
|
|
33
|
+
done = s.done
|
|
34
|
+
xp = s.xp
|
|
35
|
+
earned = s.badges.filter((b) => b.earned).length
|
|
36
|
+
ready = true
|
|
37
|
+
}
|
|
38
|
+
const note = (lesson, i) =>
|
|
39
|
+
ready && statuses[lesson.href] === 'done'
|
|
40
|
+
? 'Done'
|
|
41
|
+
: ready && statuses[lesson.href] === 'locked'
|
|
42
|
+
? 'Finish lesson ' + i + ' first'
|
|
43
|
+
: lesson.minutes
|
|
44
|
+
? lesson.minutes + ' min'
|
|
45
|
+
: ''
|
|
46
|
+
if (typeof document !== 'undefined') {
|
|
47
|
+
refresh()
|
|
48
|
+
window.addEventListener('learn:progress', refresh)
|
|
49
|
+
window.addEventListener('learn:step', (event) => {
|
|
50
|
+
if (event instanceof CustomEvent) step = event.detail
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<nav class="learn-path flex flex-col" aria-label="Lessons">
|
|
56
|
+
<div class="border-b border-rule px-4 pt-5 pb-4">
|
|
57
|
+
<p class="m-0 text-[11px] font-bold tracking-wider text-accent uppercase">{{ eyebrow }}</p>
|
|
58
|
+
<p class="m-0 mt-0.5 text-[17px] font-bold text-fg">{{ course }}</p>
|
|
59
|
+
<div class="mt-3 flex items-center gap-2.5">
|
|
60
|
+
<progress
|
|
61
|
+
class="path-progress h-1.5 flex-1"
|
|
62
|
+
[value]="done"
|
|
63
|
+
[max]="lessons.length"
|
|
64
|
+
aria-label="Lessons done"
|
|
65
|
+
></progress>
|
|
66
|
+
<span class="text-[13px] font-semibold text-fg">{{ done }} of {{ lessons.length }}</span>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<ol class="m-0 flex-1 list-none overflow-y-auto p-3">
|
|
70
|
+
@for (lesson of lessons; track lesson.href) {
|
|
71
|
+
<li class="m-0 mb-1" [data-status]="ready ? statuses[lesson.href] : false">
|
|
72
|
+
<a
|
|
73
|
+
class="path-lesson flex items-center gap-3 rounded-xl border-2 border-transparent px-2.5 py-2.5 text-fg no-underline aria-[current=page]:border-accent"
|
|
74
|
+
[href]="lesson.href"
|
|
75
|
+
[aria-current]="lesson.href === path ? 'page' : false"
|
|
76
|
+
>
|
|
77
|
+
<span
|
|
78
|
+
class="path-dot grid size-7 flex-none place-items-center rounded-full text-xs font-bold"
|
|
79
|
+
aria-hidden="true"
|
|
80
|
+
>
|
|
81
|
+
@if (ready && statuses[lesson.href] === 'done') {
|
|
82
|
+
<svg
|
|
83
|
+
width="14"
|
|
84
|
+
height="14"
|
|
85
|
+
viewBox="0 0 24 24"
|
|
86
|
+
fill="none"
|
|
87
|
+
stroke="currentColor"
|
|
88
|
+
stroke-width="3"
|
|
89
|
+
stroke-linecap="round"
|
|
90
|
+
stroke-linejoin="round"
|
|
91
|
+
>
|
|
92
|
+
<path d="m5 12 5 5 9-10"></path>
|
|
93
|
+
</svg>
|
|
94
|
+
} @else if (!(ready && statuses[lesson.href] === 'locked')) {
|
|
95
|
+
{{ $index + 1 }}
|
|
96
|
+
}
|
|
97
|
+
</span>
|
|
98
|
+
<span class="min-w-0 flex-1">
|
|
99
|
+
<span class="path-title block text-sm leading-snug font-semibold">{{ lesson.title }}</span>
|
|
100
|
+
<span class="block text-xs text-muted">{{ note(lesson, $index) }}</span>
|
|
101
|
+
</span>
|
|
102
|
+
@if (lesson.xp) {
|
|
103
|
+
<span class="path-xp text-xs font-bold">+{{ lesson.xp }}</span>
|
|
104
|
+
}
|
|
105
|
+
</a>
|
|
106
|
+
@if (lesson.href === path && steps.length) {
|
|
107
|
+
<ol class="path-steps my-1.5 ml-[46px] list-none p-0" aria-label="Steps">
|
|
108
|
+
@for (s of steps; track s.id) {
|
|
109
|
+
<li class="m-0" [data-step]="$index < step ? 'done' : $index === step ? 'current' : 'next'">
|
|
110
|
+
<a
|
|
111
|
+
class="flex items-center gap-2.5 py-1 text-[13px] text-muted no-underline"
|
|
112
|
+
[href]="'#' + s.id"
|
|
113
|
+
[aria-current]="$index === step ? 'step' : false"
|
|
114
|
+
><span class="step-dot size-2 flex-none rounded-full" aria-hidden="true"></span>{{ s.text }}</a
|
|
115
|
+
>
|
|
116
|
+
</li>
|
|
117
|
+
}
|
|
118
|
+
</ol>
|
|
119
|
+
}
|
|
120
|
+
</li>
|
|
121
|
+
}
|
|
122
|
+
</ol>
|
|
123
|
+
<a
|
|
124
|
+
class="path-footer m-3 mt-0 flex items-center gap-2 rounded-xl px-3.5 py-3 text-sm font-bold no-underline"
|
|
125
|
+
[href]="progress"
|
|
126
|
+
>
|
|
127
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
|
|
128
|
+
<path d="M13 2L4 14h7l-1 8 9-12h-7z"></path>
|
|
129
|
+
</svg>
|
|
130
|
+
<span class="flex-1" [hidden]="!ready">{{ xp }} XP · {{ earned }} {{ earned === 1 ? 'badge' : 'badges' }}</span>
|
|
131
|
+
<span class="flex-1" [hidden]="ready">Your progress</span>
|
|
132
|
+
<span aria-hidden="true">→</span>
|
|
133
|
+
</a>
|
|
134
|
+
</nav>
|
package/src/lesson-bar.tscl
CHANGED
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
all.forEach((step, j) => {
|
|
41
41
|
step.hidden = j !== current
|
|
42
42
|
})
|
|
43
|
+
// The Learn path's steps follow along.
|
|
44
|
+
window.dispatchEvent(new CustomEvent('learn:step', { detail: current }))
|
|
43
45
|
checking = !!all[current].querySelector('[data-quiz]:not([data-answered])')
|
|
44
46
|
verdict('', '', '')
|
|
45
47
|
const id = all[current].getAttribute('aria-labelledby') ?? ''
|
package/src/lesson.css
CHANGED
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
/* Segments: one per step; with JavaScript done ones fill in. The names are for screen readers and no-JS jumps. */
|
|
15
15
|
.segments { display: flex; flex: 1; gap: 6px; max-width: 420px; margin: 0 0 0 auto; padding: 0; list-style: none; }
|
|
16
16
|
.segments li { flex: 1; margin: 0; }
|
|
17
|
-
|
|
18
|
-
.segments
|
|
19
|
-
.segments
|
|
17
|
+
/* Each segment is a 24px tap target (WCAG 2.5.8); the bar is drawn 8px high in its middle, as before. */
|
|
18
|
+
.segments a { position: relative; display: block; height: 24px; color: transparent; font-size: 0; }
|
|
19
|
+
.segments a::before { content: ''; position: absolute; inset: 8px 0; border-radius: 4px; background: var(--rule); }
|
|
20
|
+
.segments li.done a::before { background: var(--accent); }
|
|
21
|
+
.segments li.current a::before { background: linear-gradient(90deg, var(--accent) 50%, var(--rule) 50%); }
|
|
20
22
|
.segments a:focus-visible { outline-offset: 4px; }
|
|
21
23
|
|
|
22
24
|
.lesson { max-width: 1200px; margin: 0 auto; padding: 28px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }
|
|
@@ -70,3 +72,28 @@
|
|
|
70
72
|
.lesson-actions button { padding: 0 16px; }
|
|
71
73
|
.feedback-title { font-size: 14px; }
|
|
72
74
|
}
|
|
75
|
+
|
|
76
|
+
/* The Learn path (#371): beside the lesson from 1024px, above the action bar. Below that the header's segments do. */
|
|
77
|
+
.lesson-path { display: none; }
|
|
78
|
+
@media (min-width: 1024px) {
|
|
79
|
+
.lesson-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
|
|
80
|
+
.lesson-path { display: block; position: sticky; top: var(--header-height); align-self: start; height: calc(100vh - var(--header-height)); border-right: 1px solid var(--rule); }
|
|
81
|
+
.one-step .lesson-path { height: calc(100vh - var(--header-height) - var(--bar-height)); }
|
|
82
|
+
.lesson-path cl-island, .lesson-path .learn-path { height: 100%; }
|
|
83
|
+
.lesson-body .lesson { width: 100%; }
|
|
84
|
+
}
|
|
85
|
+
.path-progress { appearance: none; border: 0; border-radius: 999px; background: var(--rule); overflow: hidden; }
|
|
86
|
+
.path-progress::-webkit-progress-bar { background: var(--rule); }
|
|
87
|
+
.path-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
|
|
88
|
+
.path-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }
|
|
89
|
+
.path-dot { background: var(--surface); color: var(--muted); border: 2px solid var(--rule); }
|
|
90
|
+
.path-xp { color: var(--xp); }
|
|
91
|
+
.learn-path [data-status='done'] .path-dot { background: var(--accent); border-color: var(--accent); color: var(--bg); }
|
|
92
|
+
.learn-path a[aria-current='page'] .path-dot { background: var(--bg); border-color: var(--accent); color: var(--accent); }
|
|
93
|
+
.learn-path [data-status='locked'] .path-dot { background: var(--surface); border-color: var(--surface); }
|
|
94
|
+
.learn-path [data-status='locked'] .path-title, .learn-path [data-status='locked'] .path-xp { color: var(--muted); }
|
|
95
|
+
.step-dot { background: var(--rule); }
|
|
96
|
+
.path-steps [data-step='done'] .step-dot { background: var(--accent); }
|
|
97
|
+
.path-steps [data-step='current'] .step-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--accent); }
|
|
98
|
+
.path-steps [data-step='current'] a { color: var(--accent); font-weight: 650; }
|
|
99
|
+
.path-footer { background: var(--xp-soft); color: var(--xp); }
|
package/src/lesson.tscl
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
--}}
|
|
8
8
|
@import lessonBar from './lesson-bar.tscl'
|
|
9
9
|
@import learnStatus from './learn-status.tscl'
|
|
10
|
+
@import learnPath from './learn-path.tscl'
|
|
10
11
|
@import pageHead from './page-head.tscl'
|
|
11
12
|
@import type { ThemeConfig, Heading } from './nav.ts'
|
|
12
13
|
@import { lessonOf, lessonsOf } from './nav.ts'
|
|
@@ -56,7 +57,26 @@
|
|
|
56
57
|
@if (config.learn) {<learnStatus [lessons]="lessonsOf(config).map((l) => l.href)" [progress]="config.learn.progress" />}
|
|
57
58
|
<slot name="header-end"></slot>
|
|
58
59
|
</header>
|
|
59
|
-
<
|
|
60
|
+
<div class="lesson-body">
|
|
61
|
+
{{-- The path (#371): a lesson of config.learn's section, from 1024px. --}}
|
|
62
|
+
@if (config.learn && lessonsOf(config).some((l) => l.href === path)) {
|
|
63
|
+
<aside class="lesson-path">
|
|
64
|
+
<learnPath
|
|
65
|
+
[lessons]="lessonsOf(config)"
|
|
66
|
+
[path]="path"
|
|
67
|
+
[eyebrow]="config.sections.find((s) => s.key === config.learn?.section)?.title ?? 'Learn'"
|
|
68
|
+
[course]="
|
|
69
|
+
config.sections
|
|
70
|
+
.find((s) => s.key === config.learn?.section)
|
|
71
|
+
?.groups.find((g) => g.items.some((i) => i.href === path))?.title ?? ''
|
|
72
|
+
"
|
|
73
|
+
[steps]="headings.filter((h) => h.level === 2)"
|
|
74
|
+
[progress]="config.learn.progress"
|
|
75
|
+
/>
|
|
76
|
+
</aside>
|
|
77
|
+
}
|
|
78
|
+
<main class="lesson" id="content" tabindex="-1"><slot /></main>
|
|
79
|
+
</div>
|
|
60
80
|
<div class="lesson-bar" role="region" aria-label="Lesson actions" hidden>
|
|
61
81
|
<lessonBar
|
|
62
82
|
[lesson]="path"
|
package/src/nav.ts
CHANGED
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
// readonly, as a template's inputs are: the layout passes its config to these helpers as it gets it.
|
|
3
3
|
|
|
4
4
|
/** A sidebar entry; `order` sorts it within its group (lowest first, then by title). */
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A sidebar entry. `badge`: a short label beside it ("New"), also from a page's frontmatter. For a lesson (#371): `xp`,
|
|
7
|
+
* what it can earn (from its steps and quizzes), and `minutes` (frontmatter), shown in the Learn path.
|
|
8
|
+
*/
|
|
9
|
+
export type Item = { title: string; href: string; order?: number; badge?: string; xp?: number; minutes?: number }
|
|
10
|
+
/** The icons a sidebar group can show (#369). */
|
|
11
|
+
export type GroupIcon = 'info' | 'code' | 'box' | 'shield' | 'download' | 'book' | 'terminal' | 'sparkles' | 'layers' | 'wrench' | 'rocket' | 'file'
|
|
12
|
+
/**
|
|
13
|
+
* A sidebar group. `icon`: shown beside its title. `collapsed`: closed until opened (the group of the current page is
|
|
14
|
+
* always open).
|
|
15
|
+
*/
|
|
16
|
+
export type Group = { title: string; icon?: GroupIcon; collapsed?: boolean; items: readonly Item[] }
|
|
7
17
|
/** A top-level part of the docs (Guide, Reference): its own sidebar groups. */
|
|
8
|
-
|
|
18
|
+
/** A top-level section. `switch: false` leaves it out of the phone drawer's switch (#370; link it with `menuLinks`). */
|
|
19
|
+
export type Section = { key: string; title: string; href: string; switch?: boolean; groups: readonly Group[] }
|
|
9
20
|
export type Social = { label: string; href: string; icon: 'github' | 'npm' | 'link' }
|
|
10
21
|
/** A heading on the page, for "On this page". */
|
|
11
22
|
export type Heading = { id: string; text: string; level: number }
|
|
@@ -40,6 +51,8 @@ export type ThemeConfig = {
|
|
|
40
51
|
sections: readonly Section[]
|
|
41
52
|
/** Icon links at the right of the header (GitHub, npm…). */
|
|
42
53
|
social?: readonly Social[]
|
|
54
|
+
/** Text links at the bottom of the phone drawer, before the social links (Reference, Releases…) (#370). */
|
|
55
|
+
menuLinks?: readonly { label: string; href: string }[]
|
|
43
56
|
/**
|
|
44
57
|
* "Edit this page": a pattern where `:file` is the page's source file under src/pages (`guide/start.md`, found in
|
|
45
58
|
* `pages`), or a function of the route (the page's source route, for dynamic pages). None without it.
|
|
@@ -95,7 +108,7 @@ export function pager(sections: readonly Section[], path: string): { prev: Item;
|
|
|
95
108
|
* A page as `themeDocs()` reads it (`import pages from 'virtual:theme-docs/pages'`): its route, source file under
|
|
96
109
|
* src/pages, last commit time (unix seconds), sidebar entry, and `hidden` when it isn't in the sidebar.
|
|
97
110
|
*/
|
|
98
|
-
export type PageInfo = { href: string; title: string; file: string; group?: string; order?: number; updated?: number; hidden?: boolean }
|
|
111
|
+
export type PageInfo = { href: string; title: string; file: string; group?: string; order?: number; badge?: string; xp?: number; minutes?: number; updated?: number; hidden?: boolean }
|
|
99
112
|
|
|
100
113
|
/**
|
|
101
114
|
* The sections with their sidebar filled from the pages under `/<section key>/`: a page sits in its `group` (else the
|
|
@@ -104,7 +117,7 @@ export type PageInfo = { href: string; title: string; file: string; group?: stri
|
|
|
104
117
|
*/
|
|
105
118
|
export function pagesNav(sections: readonly Section[], pages: readonly PageInfo[]): Section[] {
|
|
106
119
|
return sections.map((section) => {
|
|
107
|
-
const groups = section.groups.map((g) => ({
|
|
120
|
+
const groups: { title: string; icon?: GroupIcon; collapsed?: boolean; items: Item[] }[] = section.groups.map((g) => ({ ...g, items: [...g.items] }))
|
|
108
121
|
const listed = new Set(groups.flatMap((g) => g.items.map((i) => i.href)))
|
|
109
122
|
for (const page of pages) {
|
|
110
123
|
const inSection = page.href === `/${section.key}` || page.href.startsWith(`/${section.key}/`)
|
|
@@ -112,7 +125,12 @@ export function pagesNav(sections: readonly Section[], pages: readonly PageInfo[
|
|
|
112
125
|
const title = page.group ?? section.title
|
|
113
126
|
let group = groups.find((g) => g.title === title)
|
|
114
127
|
if (!group) groups.push(group = { title, items: [] })
|
|
115
|
-
|
|
128
|
+
const item: Item = { title: page.title, href: page.href }
|
|
129
|
+
if (page.order !== undefined) item.order = page.order
|
|
130
|
+
if (page.badge) item.badge = page.badge
|
|
131
|
+
if (page.xp) item.xp = page.xp
|
|
132
|
+
if (page.minutes) item.minutes = page.minutes
|
|
133
|
+
group.items.push(item)
|
|
116
134
|
}
|
|
117
135
|
const rank = (i: Item) => i.order ?? Infinity
|
|
118
136
|
for (const g of groups) g.items.sort((a, b) => rank(a) - rank(b) || a.title.localeCompare(b.title))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{{-- A sidebar group's icon (#369), by name: see parts/icons.ts. Decorative: the group's title says what it is. --}}
|
|
2
|
+
@import type { GroupIcon } from '../nav.ts'
|
|
3
|
+
@import { ICONS } from './icons.ts'
|
|
4
|
+
@input name: GroupIcon
|
|
5
|
+
|
|
6
|
+
<svg
|
|
7
|
+
[data-icon]="name"
|
|
8
|
+
width="14"
|
|
9
|
+
height="14"
|
|
10
|
+
viewBox="0 0 24 24"
|
|
11
|
+
fill="none"
|
|
12
|
+
stroke="currentColor"
|
|
13
|
+
stroke-width="2"
|
|
14
|
+
stroke-linecap="round"
|
|
15
|
+
stroke-linejoin="round"
|
|
16
|
+
aria-hidden="true"
|
|
17
|
+
>
|
|
18
|
+
@for (d of ICONS[name] ?? []; track d) {
|
|
19
|
+
<path [d]="d"></path>
|
|
20
|
+
}
|
|
21
|
+
</svg>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The sidebar groups' icons (#369): 24×24 outline paths, drawn with currentColor (Lucide, ISC licence).
|
|
2
|
+
import type { GroupIcon } from '../nav.ts'
|
|
3
|
+
|
|
4
|
+
export const ICONS: Record<GroupIcon, string[]> = {
|
|
5
|
+
info: ['M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20Z', 'M12 16v-4', 'M12 8h.01'],
|
|
6
|
+
code: ['m16 18 6-6-6-6', 'm8 6-6 6 6 6'],
|
|
7
|
+
box: ['M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z', 'm3.3 7 8.7 5 8.7-5', 'M12 22V12'],
|
|
8
|
+
shield: ['M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z'],
|
|
9
|
+
download: ['M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4', 'm7 10 5 5 5-5', 'M12 15V3'],
|
|
10
|
+
book: ['M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20'],
|
|
11
|
+
terminal: ['m4 17 6-6-6-6', 'M12 19h8'],
|
|
12
|
+
sparkles: ['M9.94 14.06 8 20l-1.94-5.94L0 12l6.06-1.94L8 4l1.94 6.06L16 12Z', 'M20 3v4', 'M22 5h-4'],
|
|
13
|
+
layers: ['m12 2 10 5-10 5L2 7Z', 'm2 17 10 5 10-5', 'm2 12 10 5 10-5'],
|
|
14
|
+
wrench: ['M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z'],
|
|
15
|
+
rocket: ['M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z', 'm12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z'],
|
|
16
|
+
file: ['M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5Z', 'M14 2v6h6'],
|
|
17
|
+
}
|
package/src/parts/sidebar.tscl
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{{--
|
|
2
2
|
The page list (a public part, #360): a drawer below 1024px (popover: Escape and a click outside close it), always
|
|
3
3
|
visible from 1024px. Slots: top, bottom. Replace it with themeDocs({ components: { sidebar } }) (#361).
|
|
4
|
+
|
|
5
|
+
As designed (#369): search at the top; each group a <details> with its icon and a chevron (the current page's
|
|
6
|
+
group always open, a `collapsed` one closed until opened: no JavaScript); its pages on a guide line, the current one
|
|
7
|
+
marked with a bar; a badge ("New") beside a page that has one.
|
|
8
|
+
As a drawer (#370): "Menu" and a close button, a switch between the sections, then the groups (larger, without icons
|
|
9
|
+
or the search box: the header has one on phones), and a row of links at the bottom.
|
|
4
10
|
--}}
|
|
11
|
+
@import groupIcon from './icon.tscl'
|
|
5
12
|
@import type { ThemeConfig } from '../nav.ts'
|
|
6
|
-
@import { groupsOf } from '../nav.ts'
|
|
13
|
+
@import { groupsOf, sectionKey } from '../nav.ts'
|
|
7
14
|
@input config: ThemeConfig
|
|
8
15
|
@input path: string = '/'
|
|
9
16
|
|
|
10
17
|
<nav id="sidebar" class="sidebar" aria-label="Pages" popover>
|
|
11
18
|
<div class="sidebar-head">
|
|
12
|
-
<span>
|
|
19
|
+
<span>Menu</span>
|
|
13
20
|
<button type="button" popovertarget="sidebar" popovertargetaction="hide" aria-label="Close the menu">
|
|
14
21
|
<svg
|
|
15
22
|
width="20"
|
|
@@ -25,18 +32,99 @@
|
|
|
25
32
|
</svg>
|
|
26
33
|
</button>
|
|
27
34
|
</div>
|
|
35
|
+
<div class="sidebar-switch mb-3 auto-cols-fr grid-flow-col gap-1 rounded-xl bg-surface p-1">
|
|
36
|
+
@for (s of config.sections.filter((s) => s.switch !== false); track s.key) {
|
|
37
|
+
<a
|
|
38
|
+
[href]="s.href"
|
|
39
|
+
[aria-current]="s.key === sectionKey(config.sections, path) ? 'true' : false"
|
|
40
|
+
class="rounded-lg py-2 text-center text-sm font-semibold text-muted no-underline aria-[current=true]:bg-bg aria-[current=true]:text-accent aria-[current=true]:shadow-sm"
|
|
41
|
+
>{{ s.title }}</a
|
|
42
|
+
>
|
|
43
|
+
}
|
|
44
|
+
</div>
|
|
45
|
+
@if (config.search) {
|
|
46
|
+
{{-- Opens the search dialog, as the header's button and Ctrl/⌘K do (search.tscl listens for data-search-open). --}}
|
|
47
|
+
<button
|
|
48
|
+
type="button"
|
|
49
|
+
data-search-open
|
|
50
|
+
aria-haspopup="dialog"
|
|
51
|
+
class="sidebar-search mb-4 flex h-9 w-full cursor-pointer items-center gap-2 rounded-lg border border-rule bg-bg px-2.5 text-left text-[13px] text-muted transition-colors hover:border-accent hover:text-fg"
|
|
52
|
+
>
|
|
53
|
+
<svg
|
|
54
|
+
width="14"
|
|
55
|
+
height="14"
|
|
56
|
+
viewBox="0 0 24 24"
|
|
57
|
+
fill="none"
|
|
58
|
+
stroke="currentColor"
|
|
59
|
+
stroke-width="2"
|
|
60
|
+
stroke-linecap="round"
|
|
61
|
+
aria-hidden="true"
|
|
62
|
+
>
|
|
63
|
+
<circle cx="11" cy="11" r="7"></circle>
|
|
64
|
+
<path d="m20 20-3.5-3.5"></path>
|
|
65
|
+
</svg>
|
|
66
|
+
<span class="flex-1">Search</span>
|
|
67
|
+
<kbd class="rounded border border-rule bg-surface px-1.5 py-px font-sans text-[11px] leading-4 text-muted"
|
|
68
|
+
>⌘K</kbd
|
|
69
|
+
>
|
|
70
|
+
</button>
|
|
71
|
+
}
|
|
28
72
|
<slot name="top"></slot>
|
|
29
73
|
@for (group of groupsOf(config.sections, path); track group.title) {
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
74
|
+
<details
|
|
75
|
+
class="group mb-1.5"
|
|
76
|
+
[data-group]="group.title"
|
|
77
|
+
[open]="!group.collapsed || group.items.some((i) => i.href === path)"
|
|
78
|
+
>
|
|
79
|
+
<summary
|
|
80
|
+
class="flex cursor-pointer list-none items-center gap-2.5 rounded-md py-1.5 pr-1 text-[13px] font-semibold text-fg select-none [&::-webkit-details-marker]:hidden"
|
|
81
|
+
>
|
|
82
|
+
<span class="group-icon grid size-[22px] flex-none place-items-center rounded-md bg-accent-soft text-accent"
|
|
83
|
+
>@if (group.icon) {<groupIcon [name]="group.icon" />}</span
|
|
84
|
+
>
|
|
85
|
+
<span class="flex-1">{{ group.title }}</span>
|
|
86
|
+
<svg
|
|
87
|
+
class="flex-none text-muted transition-transform group-open:rotate-90"
|
|
88
|
+
width="12"
|
|
89
|
+
height="12"
|
|
90
|
+
viewBox="0 0 24 24"
|
|
91
|
+
fill="none"
|
|
92
|
+
stroke="currentColor"
|
|
93
|
+
stroke-width="2.5"
|
|
94
|
+
stroke-linecap="round"
|
|
95
|
+
stroke-linejoin="round"
|
|
96
|
+
aria-hidden="true"
|
|
97
|
+
>
|
|
98
|
+
<path d="m9 6 6 6-6 6"></path>
|
|
99
|
+
</svg>
|
|
100
|
+
</summary>
|
|
101
|
+
<ul class="my-1 ml-[10px] list-none border-l border-rule p-0">
|
|
102
|
+
@for (item of group.items; track item.href) {
|
|
103
|
+
<li class="m-0">
|
|
104
|
+
<a
|
|
105
|
+
[href]="item.href"
|
|
106
|
+
[aria-current]="item.href === path ? 'page' : false"
|
|
107
|
+
class="-ml-px flex items-center gap-2 rounded-r-md border-l-2 border-transparent py-[5px] pr-2 pl-3 text-[13px] text-fg/80 no-underline transition-colors hover:text-fg aria-[current=page]:border-accent aria-[current=page]:bg-accent-soft aria-[current=page]:font-semibold aria-[current=page]:text-accent"
|
|
108
|
+
>
|
|
109
|
+
<span class="flex-1">{{ item.title }}</span>
|
|
110
|
+
@if (item.badge) {
|
|
111
|
+
<span class="badge rounded bg-xp-soft px-1.5 py-px text-[10.5px] font-bold text-xp">{{
|
|
112
|
+
item.badge
|
|
113
|
+
}}</span>
|
|
114
|
+
}
|
|
115
|
+
</a>
|
|
116
|
+
</li>
|
|
117
|
+
}
|
|
118
|
+
</ul>
|
|
119
|
+
</details>
|
|
38
120
|
}
|
|
39
121
|
<slot name="bottom"></slot>
|
|
40
|
-
{{--
|
|
41
|
-
<div
|
|
122
|
+
{{-- The drawer's links row: config.menuLinks, then the social links. --}}
|
|
123
|
+
<div
|
|
124
|
+
class="sidebar-links mt-auto justify-between gap-x-3 gap-y-1 border-t border-rule pt-3 text-[13px] font-medium [&_a]:text-accent [&_a]:no-underline"
|
|
125
|
+
>
|
|
126
|
+
@for (link of [...(config.menuLinks ?? []), ...(config.social ?? [])]; track link.href) {
|
|
127
|
+
<a [href]="link.href">{{ link.label }}</a>
|
|
128
|
+
}
|
|
129
|
+
</div>
|
|
42
130
|
</nav>
|
package/src/search.tscl
CHANGED
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
open()
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
|
+
// The sidebar's search box (any element marked data-search-open) opens the same dialog.
|
|
77
|
+
document.addEventListener('click', (event) => {
|
|
78
|
+
if (event.target instanceof Element && event.target.closest('[data-search-open]')) open()
|
|
79
|
+
})
|
|
76
80
|
}
|
|
77
81
|
</script>
|
|
78
82
|
|