@opentf/afw-docs 0.0.0-stage → 0.30.0
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/build/blog-posts-plugin.js +141 -0
- package/build/docs-nav-plugin.js +196 -0
- package/build/feed.js +147 -0
- package/build/frontmatter.js +45 -0
- package/build/host.js +54 -0
- package/build/index.js +12 -0
- package/build/last-updated-plugin.js +99 -0
- package/build/last-updated.js +40 -0
- package/build/llms.js +176 -0
- package/build/reading-time.js +16 -0
- package/build/search.js +27 -0
- package/components/BlogLayout.jsx +90 -0
- package/components/Breadcrumbs.jsx +71 -0
- package/components/Callout.jsx +29 -0
- package/components/Card.jsx +21 -0
- package/components/Cards.jsx +11 -0
- package/components/CodeBlock.jsx +39 -0
- package/components/DocsLayout.jsx +106 -0
- package/components/Footer.jsx +25 -0
- package/components/LastUpdated.jsx +22 -0
- package/components/NavIcon.jsx +34 -0
- package/components/Navbar.jsx +64 -0
- package/components/NavbarLink.jsx +40 -0
- package/components/Pagination.jsx +49 -0
- package/components/PostBanner.jsx +25 -0
- package/components/PostCard.jsx +19 -0
- package/components/PostList.jsx +17 -0
- package/components/PostMeta.jsx +28 -0
- package/components/ReadingTime.jsx +6 -0
- package/components/Search.jsx +191 -0
- package/components/SearchTrigger.jsx +32 -0
- package/components/Sidebar.jsx +199 -0
- package/components/SidebarNode.jsx +143 -0
- package/components/SidebarToggle.jsx +47 -0
- package/components/Steps.jsx +14 -0
- package/components/Table.jsx +10 -0
- package/components/Tabs.jsx +77 -0
- package/components/ThemeToggle.jsx +164 -0
- package/components/Toc.jsx +79 -0
- package/components/Tooltip.jsx +19 -0
- package/components/format.js +21 -0
- package/components/post-dates.js +21 -0
- package/components/sidebar-collapse.js +38 -0
- package/config.js +77 -0
- package/index.js +67 -0
- package/nav-virtual.js +18 -0
- package/package.json +75 -4
- package/posts-virtual.js +17 -0
- package/search.js +285 -0
- package/theme/index.css +1749 -0
- package/types/config.d.ts +37 -0
- package/types/index.d.ts +66 -0
- package/types/nav.d.ts +9 -0
- package/types/posts.d.ts +17 -0
- package/types/search.d.ts +28 -0
- package/types/updated.d.ts +4 -0
- package/updated-virtual.js +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Documentation sidebar — renders the build-time nav tree (from
|
|
2
|
+
// `@opentf/afw-docs/nav`). Static content (crawlable with JS off); the active link
|
|
3
|
+
// updates reactively in SidebarNode.
|
|
4
|
+
//
|
|
5
|
+
// On desktop it is the sticky left column of the docs grid. On mobile (< 768px) the
|
|
6
|
+
// same element becomes an off-canvas drawer: hidden off-screen, slid in over a
|
|
7
|
+
// backdrop. The drawer is opened by the navbar hamburger, which lives in a different
|
|
8
|
+
// component (and, on the website, a different layout), so the two are coupled the same
|
|
9
|
+
// way Search/SearchTrigger are — through a global toggle installed here:
|
|
10
|
+
//
|
|
11
|
+
// • `window.__afwToggleSidebar()` / `__afwCloseSidebar()` — called by the burger.
|
|
12
|
+
// • `document.documentElement[data-afw-has-sidebar]` — set while a Sidebar is
|
|
13
|
+
// mounted, so the burger shows only on pages that actually have one.
|
|
14
|
+
// • a `afw:sidebar` CustomEvent (`{ open }`) — lets the burger mirror `aria-expanded`.
|
|
15
|
+
//
|
|
16
|
+
// The drawer closes on navigation, Escape, backdrop click, or a viewport resize up to
|
|
17
|
+
// the desktop breakpoint, and locks body scroll while open.
|
|
18
|
+
//
|
|
19
|
+
// Above the tree sits a single icon button that collapses (or re-expands) every group at
|
|
20
|
+
// once — it drives the nodes through the shared `collapseAll` signal, since they are
|
|
21
|
+
// rendered recursively by SidebarNode.
|
|
22
|
+
|
|
23
|
+
import { onMount, router } from "@opentf/afw";
|
|
24
|
+
|
|
25
|
+
import SidebarNode from "./SidebarNode.jsx";
|
|
26
|
+
import NavbarLink from "./NavbarLink.jsx";
|
|
27
|
+
import { collapseAll } from "./sidebar-collapse.js";
|
|
28
|
+
|
|
29
|
+
const DESKTOP_QUERY = "(min-width: 768px)";
|
|
30
|
+
|
|
31
|
+
// How many Sidebars are mounted right now. On SPA navigation a new section's Sidebar can
|
|
32
|
+
// mount *before* the old one unmounts, so the burger's `data-afw-has-sidebar` flag must
|
|
33
|
+
// be reference-counted — otherwise the departing instance's cleanup would clear the flag
|
|
34
|
+
// the arriving instance just set, and the burger would vanish after navigating.
|
|
35
|
+
let liveSidebars = 0;
|
|
36
|
+
|
|
37
|
+
export default function Sidebar(props) {
|
|
38
|
+
const nav = props.nav || [];
|
|
39
|
+
// Top-level site links (config.nav). On desktop they live in the navbar; on mobile the
|
|
40
|
+
// navbar hides them and the drawer surfaces them above the section tree, so the whole
|
|
41
|
+
// nav is reachable from one place.
|
|
42
|
+
const navLinks = (props.config && props.config.nav) || [];
|
|
43
|
+
// The collapse-all button is only meaningful when the tree actually has groups.
|
|
44
|
+
const hasGroups = nav.some((item) => item.items && item.items.length > 0);
|
|
45
|
+
let open = $state(false);
|
|
46
|
+
const asideRef = $ref();
|
|
47
|
+
|
|
48
|
+
const close = () => (open = false);
|
|
49
|
+
// Stable per-instance toggle so cleanup can tell whether the global still points at us.
|
|
50
|
+
const toggle = () => (open = !open);
|
|
51
|
+
|
|
52
|
+
onMount(() => {
|
|
53
|
+
const root = document.documentElement;
|
|
54
|
+
liveSidebars += 1;
|
|
55
|
+
root.setAttribute("data-afw-has-sidebar", "");
|
|
56
|
+
|
|
57
|
+
// The burger (navbar) drives the drawer through these globals — same decoupling as
|
|
58
|
+
// the Search modal's `__afwOpenSearch`. The latest-mounted Sidebar owns them.
|
|
59
|
+
window.__afwToggleSidebar = toggle;
|
|
60
|
+
window.__afwCloseSidebar = close;
|
|
61
|
+
|
|
62
|
+
const onKey = (e) => e.key === "Escape" && close();
|
|
63
|
+
window.addEventListener("keydown", onKey);
|
|
64
|
+
|
|
65
|
+
// If the viewport grows to desktop while the drawer is open, drop the drawer state
|
|
66
|
+
// (CSS turns the element back into the sticky column; this releases the scroll lock
|
|
67
|
+
// and resyncs the burger).
|
|
68
|
+
const mql = window.matchMedia(DESKTOP_QUERY);
|
|
69
|
+
const onDesktop = (e) => e.matches && close();
|
|
70
|
+
mql.addEventListener?.("change", onDesktop);
|
|
71
|
+
|
|
72
|
+
return () => {
|
|
73
|
+
window.removeEventListener("keydown", onKey);
|
|
74
|
+
mql.removeEventListener?.("change", onDesktop);
|
|
75
|
+
document.body.style.removeProperty("overflow");
|
|
76
|
+
root.removeAttribute("data-afw-sidebar-open");
|
|
77
|
+
// Only drop the flag/globals if we're the last Sidebar and still the owner — an
|
|
78
|
+
// arriving instance may already have taken over during navigation.
|
|
79
|
+
liveSidebars -= 1;
|
|
80
|
+
if (liveSidebars <= 0) {
|
|
81
|
+
liveSidebars = 0;
|
|
82
|
+
root.removeAttribute("data-afw-has-sidebar");
|
|
83
|
+
}
|
|
84
|
+
if (window.__afwToggleSidebar === toggle) delete window.__afwToggleSidebar;
|
|
85
|
+
if (window.__afwCloseSidebar === close) delete window.__afwCloseSidebar;
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Reflect open state: lock body scroll, mark the root (for styling), and notify the
|
|
90
|
+
// burger so it can mirror `aria-expanded`. Reading `open` (not writing it) keeps this
|
|
91
|
+
// effect free of the route/resize effects.
|
|
92
|
+
$effect(() => {
|
|
93
|
+
const isOpen = open;
|
|
94
|
+
if (typeof document === "undefined") return;
|
|
95
|
+
document.documentElement.toggleAttribute("data-afw-sidebar-open", isOpen);
|
|
96
|
+
document.body.style.overflow = isOpen ? "hidden" : "";
|
|
97
|
+
window.dispatchEvent(new CustomEvent("afw:sidebar", { detail: { open: isOpen } }));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Close on navigation — clicking a drawer link should dismiss it.
|
|
101
|
+
$effect(() => {
|
|
102
|
+
router.pathname; // subscribe
|
|
103
|
+
close();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Keep the active item in view. On navigation a fresh Sidebar mounts (see the
|
|
107
|
+
// reference-count note above) scrolled to the top, so a deep-in-a-long-tree active link
|
|
108
|
+
// would sit off-screen. When it's outside the sidebar's own scroll viewport, bring it
|
|
109
|
+
// into view — adjusting only the sidebar's scrollTop, never the page's scroll.
|
|
110
|
+
$effect(() => {
|
|
111
|
+
router.pathname; // re-run on navigation
|
|
112
|
+
if (typeof requestAnimationFrame === "undefined") return;
|
|
113
|
+
// Defer a frame so the newly-active class (and any auto-expanded branch) is in the DOM.
|
|
114
|
+
const raf = requestAnimationFrame(() => {
|
|
115
|
+
const aside = asideRef;
|
|
116
|
+
const active = aside && aside.querySelector(".afwd-sidebar-nav .afwd-active");
|
|
117
|
+
if (!active) return;
|
|
118
|
+
const a = active.getBoundingClientRect();
|
|
119
|
+
const c = aside.getBoundingClientRect();
|
|
120
|
+
if (a.top < c.top || a.bottom > c.bottom) {
|
|
121
|
+
aside.scrollTop += a.top - c.top - (aside.clientHeight - a.height) / 2;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return () => cancelAnimationFrame(raf);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<div class="afwd-sidebar-shell">
|
|
129
|
+
<div
|
|
130
|
+
class={open ? "afwd-sidebar-backdrop is-open" : "afwd-sidebar-backdrop"}
|
|
131
|
+
onclick={close}
|
|
132
|
+
aria-hidden="true"
|
|
133
|
+
></div>
|
|
134
|
+
<aside id="afw-sidebar" ref={asideRef} class={open ? "afwd-sidebar is-open" : "afwd-sidebar"}>
|
|
135
|
+
{navLinks.length ? (
|
|
136
|
+
<nav class="afwd-drawer-links" aria-label="Site">
|
|
137
|
+
{navLinks.map((link) => (
|
|
138
|
+
<NavbarLink link={link} />
|
|
139
|
+
))}
|
|
140
|
+
</nav>
|
|
141
|
+
) : null}
|
|
142
|
+
{hasGroups ? (
|
|
143
|
+
<div class="afwd-sidebar-tools">
|
|
144
|
+
<button
|
|
145
|
+
type="button"
|
|
146
|
+
class="afwd-sidebar-collapse-all"
|
|
147
|
+
onclick={() => collapseAll.set(collapseAll.collapsed)}
|
|
148
|
+
aria-label={collapseAll.collapsed ? "Expand all sections" : "Collapse all sections"}
|
|
149
|
+
title={collapseAll.collapsed ? "Expand all sections" : "Collapse all sections"}
|
|
150
|
+
>
|
|
151
|
+
{() =>
|
|
152
|
+
collapseAll.collapsed ? (
|
|
153
|
+
// chevrons pointing apart — press to expand everything
|
|
154
|
+
<svg
|
|
155
|
+
width="15"
|
|
156
|
+
height="15"
|
|
157
|
+
viewBox="0 0 24 24"
|
|
158
|
+
fill="none"
|
|
159
|
+
stroke="currentColor"
|
|
160
|
+
stroke-width="2"
|
|
161
|
+
stroke-linecap="round"
|
|
162
|
+
stroke-linejoin="round"
|
|
163
|
+
aria-hidden="true"
|
|
164
|
+
>
|
|
165
|
+
<path d="m7 9 5-5 5 5" />
|
|
166
|
+
<path d="m7 15 5 5 5-5" />
|
|
167
|
+
</svg>
|
|
168
|
+
) : (
|
|
169
|
+
// chevrons pointing together — press to collapse everything
|
|
170
|
+
<svg
|
|
171
|
+
width="15"
|
|
172
|
+
height="15"
|
|
173
|
+
viewBox="0 0 24 24"
|
|
174
|
+
fill="none"
|
|
175
|
+
stroke="currentColor"
|
|
176
|
+
stroke-width="2"
|
|
177
|
+
stroke-linecap="round"
|
|
178
|
+
stroke-linejoin="round"
|
|
179
|
+
aria-hidden="true"
|
|
180
|
+
>
|
|
181
|
+
<path d="m7 4 5 5 5-5" />
|
|
182
|
+
<path d="m7 20 5-5 5 5" />
|
|
183
|
+
</svg>
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
</button>
|
|
187
|
+
</div>
|
|
188
|
+
) : null}
|
|
189
|
+
<nav class="afwd-sidebar-nav" aria-label="Documentation">
|
|
190
|
+
<ul class="afwd-sidebar-list">
|
|
191
|
+
{nav.map((item, i) => (
|
|
192
|
+
<SidebarNode item={item} nodeId={String(i)} />
|
|
193
|
+
))}
|
|
194
|
+
</ul>
|
|
195
|
+
</nav>
|
|
196
|
+
</aside>
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// One node of the sidebar tree — a link, a collapsible group, or both. Recurses into
|
|
2
|
+
// `item.items`. Groups with children get a chevron toggle; the branch containing the
|
|
3
|
+
// active route stays open, and top-level groups start expanded. Open/closed state is
|
|
4
|
+
// per-session only (no persistence) — a reload resets to this derived default.
|
|
5
|
+
//
|
|
6
|
+
// The sidebar's "collapse all" button drives every node at once through the shared
|
|
7
|
+
// `collapseAll` signal (components/sidebar-collapse.js).
|
|
8
|
+
|
|
9
|
+
import { Link, router } from "@opentf/afw";
|
|
10
|
+
|
|
11
|
+
import { collapseAll } from "./sidebar-collapse.js";
|
|
12
|
+
|
|
13
|
+
// True when `path` is `node` itself or lives somewhere in its subtree.
|
|
14
|
+
function treeContainsPath(node, path) {
|
|
15
|
+
if (!node) return false;
|
|
16
|
+
if (node.path === path) return true;
|
|
17
|
+
if (!node.items || !node.items.length) return false;
|
|
18
|
+
return node.items.some((child) => treeContainsPath(child, path));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function SidebarNode(props) {
|
|
22
|
+
const item = props.item || {};
|
|
23
|
+
const depth = props.depth || 0;
|
|
24
|
+
// Deterministic position path ("0", "0-2", "0-2-1") — unique and identical on
|
|
25
|
+
// server/client, so the aria-controls id is collision-free and hydration-safe.
|
|
26
|
+
const nodeId = props.nodeId || "0";
|
|
27
|
+
const hasChildren = item.items && item.items.length > 0;
|
|
28
|
+
const panelId = `afw-nav-${nodeId}`;
|
|
29
|
+
|
|
30
|
+
const containsActive = () => treeContainsPath(item, router.pathname);
|
|
31
|
+
let expanded = $state(hasChildren && (containsActive() || depth === 0));
|
|
32
|
+
|
|
33
|
+
// Re-open the branch that holds the active route whenever navigation enters it.
|
|
34
|
+
$effect(() => {
|
|
35
|
+
if (hasChildren && containsActive()) expanded = true;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Follow the sidebar's "collapse all" / "expand all" button. A press collapses *every*
|
|
39
|
+
// group, the active branch included — otherwise, reading a page inside the only open
|
|
40
|
+
// branch, the press would visibly change nothing. Navigation under a standing
|
|
41
|
+
// collapse-all is the other case: there the branch holding the new route opens, exactly
|
|
42
|
+
// as it does without the button. Deciding both here (rather than leaning on the effect
|
|
43
|
+
// above) keeps the two independent of the order they run in.
|
|
44
|
+
// A command already standing when this node is created isn't a press — it's the tree
|
|
45
|
+
// being rebuilt under one.
|
|
46
|
+
let seenSeq = collapseAll.command ? collapseAll.command.seq : 0;
|
|
47
|
+
$effect(() => {
|
|
48
|
+
const cmd = collapseAll.command;
|
|
49
|
+
if (!hasChildren || !cmd) return;
|
|
50
|
+
const isPress = cmd.seq !== seenSeq;
|
|
51
|
+
seenSeq = cmd.seq;
|
|
52
|
+
expanded = cmd.expanded || (!isPress && containsActive());
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const toggle = () => (expanded = !expanded);
|
|
56
|
+
const chevronClass = () =>
|
|
57
|
+
expanded ? "afwd-sidebar-chevron is-open" : "afwd-sidebar-chevron";
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<li class={hasChildren ? "afwd-sidebar-node afwd-sidebar-group" : "afwd-sidebar-node"}>
|
|
61
|
+
{hasChildren ? (
|
|
62
|
+
item.path ? (
|
|
63
|
+
// Group that is also a page: leading chevron toggles, the link navigates.
|
|
64
|
+
// Chevron on the left mirrors the label-only groups below (no leading dot —
|
|
65
|
+
// the chevron already marks the row).
|
|
66
|
+
<div class="afwd-sidebar-group-row">
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
class="afwd-sidebar-group-toggle afwd-sidebar-group-toggle--icon"
|
|
70
|
+
aria-expanded={expanded ? "true" : "false"}
|
|
71
|
+
aria-controls={panelId}
|
|
72
|
+
aria-label={expanded ? `Collapse ${item.title}` : `Expand ${item.title}`}
|
|
73
|
+
onclick={toggle}
|
|
74
|
+
>
|
|
75
|
+
<svg
|
|
76
|
+
class={chevronClass()}
|
|
77
|
+
width="14"
|
|
78
|
+
height="14"
|
|
79
|
+
viewBox="0 0 24 24"
|
|
80
|
+
fill="none"
|
|
81
|
+
stroke="currentColor"
|
|
82
|
+
stroke-width="2"
|
|
83
|
+
stroke-linecap="round"
|
|
84
|
+
stroke-linejoin="round"
|
|
85
|
+
aria-hidden="true"
|
|
86
|
+
>
|
|
87
|
+
<polyline points="9 18 15 12 9 6" />
|
|
88
|
+
</svg>
|
|
89
|
+
</button>
|
|
90
|
+
<Link
|
|
91
|
+
href={item.path}
|
|
92
|
+
class={router.pathname === item.path ? "afwd-sidebar-link afwd-active" : "afwd-sidebar-link"}
|
|
93
|
+
>
|
|
94
|
+
{item.title}
|
|
95
|
+
</Link>
|
|
96
|
+
</div>
|
|
97
|
+
) : (
|
|
98
|
+
// Section title with no page of its own — the whole row toggles.
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
class="afwd-sidebar-group-toggle"
|
|
102
|
+
aria-expanded={expanded ? "true" : "false"}
|
|
103
|
+
aria-controls={panelId}
|
|
104
|
+
onclick={toggle}
|
|
105
|
+
>
|
|
106
|
+
<svg
|
|
107
|
+
class={chevronClass()}
|
|
108
|
+
width="14"
|
|
109
|
+
height="14"
|
|
110
|
+
viewBox="0 0 24 24"
|
|
111
|
+
fill="none"
|
|
112
|
+
stroke="currentColor"
|
|
113
|
+
stroke-width="2"
|
|
114
|
+
stroke-linecap="round"
|
|
115
|
+
stroke-linejoin="round"
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
>
|
|
118
|
+
<polyline points="9 18 15 12 9 6" />
|
|
119
|
+
</svg>
|
|
120
|
+
<span class="afwd-sidebar-group-label">{item.title}</span>
|
|
121
|
+
</button>
|
|
122
|
+
)
|
|
123
|
+
) : item.path ? (
|
|
124
|
+
<Link
|
|
125
|
+
href={item.path}
|
|
126
|
+
class={router.pathname === item.path ? "afwd-sidebar-link afwd-active" : "afwd-sidebar-link"}
|
|
127
|
+
>
|
|
128
|
+
<span class="afwd-sidebar-dot" aria-hidden="true"></span>
|
|
129
|
+
{item.title}
|
|
130
|
+
</Link>
|
|
131
|
+
) : (
|
|
132
|
+
<span class="afwd-sidebar-group-title">{item.title}</span>
|
|
133
|
+
)}
|
|
134
|
+
{hasChildren && expanded ? (
|
|
135
|
+
<ul id={panelId} class="afwd-sidebar-sublist">
|
|
136
|
+
{item.items.map((child, i) => (
|
|
137
|
+
<SidebarNode item={child} depth={depth + 1} nodeId={`${nodeId}-${i}`} />
|
|
138
|
+
))}
|
|
139
|
+
</ul>
|
|
140
|
+
) : null}
|
|
141
|
+
</li>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Hamburger button in the navbar that opens the mobile sidebar drawer. Like
|
|
2
|
+
// SearchTrigger, it is decoupled from the thing it controls: the <Sidebar> installs
|
|
3
|
+
// `window.__afwToggleSidebar` and emits an `afw:sidebar` event, so this button works
|
|
4
|
+
// even when the navbar and the sidebar live in different layouts (the website renders
|
|
5
|
+
// the navbar at its root, the sidebar only inside the docs/api sections).
|
|
6
|
+
//
|
|
7
|
+
// The button is hidden by default and revealed by CSS only on small screens and only
|
|
8
|
+
// while a Sidebar is mounted (`:root[data-afw-has-sidebar]`), so it never shows on a
|
|
9
|
+
// page without a drawer (e.g. the marketing home).
|
|
10
|
+
|
|
11
|
+
import { onMount } from "@opentf/afw";
|
|
12
|
+
|
|
13
|
+
export default function SidebarToggle() {
|
|
14
|
+
let expanded = $state(false);
|
|
15
|
+
|
|
16
|
+
onMount(() => {
|
|
17
|
+
// Mirror the drawer's real state so aria-expanded stays correct however it was
|
|
18
|
+
// toggled (button, backdrop, Escape, navigation, resize).
|
|
19
|
+
const onState = (e) => (expanded = !!(e.detail && e.detail.open));
|
|
20
|
+
window.addEventListener("afw:sidebar", onState);
|
|
21
|
+
return () => window.removeEventListener("afw:sidebar", onState);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const toggle = () => window.__afwToggleSidebar?.();
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<button
|
|
28
|
+
class="afwd-navbar-icon afwd-navbar-burger"
|
|
29
|
+
onclick={toggle}
|
|
30
|
+
aria-label="Toggle navigation"
|
|
31
|
+
aria-controls="afw-sidebar"
|
|
32
|
+
aria-expanded={expanded ? "true" : "false"}
|
|
33
|
+
>
|
|
34
|
+
{() =>
|
|
35
|
+
expanded ? (
|
|
36
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
37
|
+
<path d="M6 6l12 12M18 6L6 18" />
|
|
38
|
+
</svg>
|
|
39
|
+
) : (
|
|
40
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
41
|
+
<path d="M3 6h18M3 12h18M3 18h18" />
|
|
42
|
+
</svg>
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
</button>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Numbered, vertically-connected steps for walkthroughs. Each child heading
|
|
2
|
+
// (`<h3>`/`<h4>`) becomes a numbered step via a CSS counter, so it composes with
|
|
3
|
+
// plain Markdown inside MDX:
|
|
4
|
+
//
|
|
5
|
+
// <Steps>
|
|
6
|
+
// ### Install
|
|
7
|
+
// …
|
|
8
|
+
// ### Run the dev server
|
|
9
|
+
// …
|
|
10
|
+
// </Steps>
|
|
11
|
+
|
|
12
|
+
export default function Steps(props) {
|
|
13
|
+
return <div class="afwd-steps">{props.children}</div>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Styled, horizontally-scrollable table wrapper. (MDX GFM tables already emit
|
|
2
|
+
// the same wrapper around a theme-styled <table>; use <Table> in JSX pages.)
|
|
3
|
+
|
|
4
|
+
export default function Table(props) {
|
|
5
|
+
return (
|
|
6
|
+
<div class="afw-table-wrap" tabindex="0">
|
|
7
|
+
<table class="afwd-table">{props.children}</table>
|
|
8
|
+
</div>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Generic tabbed panel. `tabs` is an array of `{ label, content }`. `content` is
|
|
2
|
+
// rendered as-is: a string is plain text, a node is the node. For a code panel with a
|
|
3
|
+
// copy button, pass a `CodeBlock`: `{ label, content: <CodeBlock code="…" /> }`.
|
|
4
|
+
//
|
|
5
|
+
// <Tabs label="Package manager" tabs={[{ label: "npm", content: <CodeBlock code="npm i …" /> }, …]} />
|
|
6
|
+
//
|
|
7
|
+
// Follows the WAI-ARIA tabs pattern: one tab stop for the list (roving `tabindex`),
|
|
8
|
+
// Arrow Left/Right (wrapping), Home and End move focus and select the tab, and each
|
|
9
|
+
// tab names and controls its panel. Ids are assigned on mount so a server-rendered
|
|
10
|
+
// tab set and its hydrated copy never disagree.
|
|
11
|
+
|
|
12
|
+
let instances = 0;
|
|
13
|
+
|
|
14
|
+
export default function Tabs(props) {
|
|
15
|
+
let active = $state(0);
|
|
16
|
+
let list = $ref();
|
|
17
|
+
const tabs = $derived(props.tabs || []);
|
|
18
|
+
|
|
19
|
+
onMount(() => {
|
|
20
|
+
const id = `afw-tabs-${++instances}`;
|
|
21
|
+
const buttons = list.querySelectorAll('[role="tab"]');
|
|
22
|
+
const panels = list.nextElementSibling.children;
|
|
23
|
+
buttons.forEach((button, i) => {
|
|
24
|
+
button.id = `${id}-tab-${i}`;
|
|
25
|
+
button.setAttribute("aria-controls", `${id}-panel-${i}`);
|
|
26
|
+
});
|
|
27
|
+
Array.from(panels).forEach((panel, i) => {
|
|
28
|
+
panel.id = `${id}-panel-${i}`;
|
|
29
|
+
panel.setAttribute("aria-labelledby", `${id}-tab-${i}`);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function onKeyDown(event) {
|
|
34
|
+
const last = tabs.length - 1;
|
|
35
|
+
const next = {
|
|
36
|
+
ArrowRight: active === last ? 0 : active + 1,
|
|
37
|
+
ArrowLeft: active === 0 ? last : active - 1,
|
|
38
|
+
Home: 0,
|
|
39
|
+
End: last,
|
|
40
|
+
}[event.key];
|
|
41
|
+
if (next === undefined || last < 0) return;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
active = next;
|
|
44
|
+
list.querySelectorAll('[role="tab"]')[next]?.focus();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div class="afwd-tabs">
|
|
49
|
+
<div class="afwd-tabs-list" role="tablist" aria-label={props.label} ref={list} onkeydown={onKeyDown}>
|
|
50
|
+
{tabs.map((tab, i) => (
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
role="tab"
|
|
54
|
+
class={active === i ? "afwd-tab afwd-active" : "afwd-tab"}
|
|
55
|
+
aria-selected={active === i ? "true" : "false"}
|
|
56
|
+
tabindex={active === i ? "0" : "-1"}
|
|
57
|
+
onclick={() => (active = i)}
|
|
58
|
+
>
|
|
59
|
+
{tab.label}
|
|
60
|
+
</button>
|
|
61
|
+
))}
|
|
62
|
+
</div>
|
|
63
|
+
<div class="afwd-tabs-panels">
|
|
64
|
+
{tabs.map((tab, i) => (
|
|
65
|
+
<div
|
|
66
|
+
role="tabpanel"
|
|
67
|
+
tabindex="0"
|
|
68
|
+
class={active === i ? "afwd-tab-panel" : "afwd-tab-panel afwd-hidden"}
|
|
69
|
+
hidden={active !== i}
|
|
70
|
+
>
|
|
71
|
+
{tab.content}
|
|
72
|
+
</div>
|
|
73
|
+
))}
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Theme switcher: a subtle ghost icon button that opens a Light / Dark / System menu.
|
|
2
|
+
//
|
|
3
|
+
// The chosen *mode* is persisted to localStorage("theme") as "light" | "dark" |
|
|
4
|
+
// "system" (default "system"). The applied theme is the resolved value — in System
|
|
5
|
+
// mode it follows the OS and live-updates when the OS preference flips. The trigger
|
|
6
|
+
// shows the mode's icon; in System mode it shows the monitor icon plus a small badge of
|
|
7
|
+
// the currently resolved icon (sun/moon), so you can see both the choice and the result.
|
|
8
|
+
//
|
|
9
|
+
// Pair with the no-flash inline script in index.html, which must resolve "system"/none
|
|
10
|
+
// to a concrete theme on first paint.
|
|
11
|
+
|
|
12
|
+
import { onMount } from "@opentf/afw";
|
|
13
|
+
|
|
14
|
+
import Tooltip from "./Tooltip.jsx";
|
|
15
|
+
|
|
16
|
+
const STORAGE_KEY = "theme";
|
|
17
|
+
const prefersDark = () =>
|
|
18
|
+
typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
19
|
+
|
|
20
|
+
export default function ThemeToggle() {
|
|
21
|
+
let mode = $state("system"); // "light" | "dark" | "system"
|
|
22
|
+
let resolved = $state("light"); // "light" | "dark"
|
|
23
|
+
let openMenu = $state(false);
|
|
24
|
+
|
|
25
|
+
const rootRef = $ref();
|
|
26
|
+
|
|
27
|
+
const resolve = (m) => (m === "system" ? (prefersDark() ? "dark" : "light") : m);
|
|
28
|
+
|
|
29
|
+
const apply = (m) => {
|
|
30
|
+
resolved = resolve(m);
|
|
31
|
+
if (typeof document !== "undefined") {
|
|
32
|
+
document.documentElement.setAttribute("data-theme", resolved);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const setMode = (m) => {
|
|
37
|
+
mode = m;
|
|
38
|
+
openMenu = false;
|
|
39
|
+
try {
|
|
40
|
+
localStorage.setItem(STORAGE_KEY, m);
|
|
41
|
+
} catch {}
|
|
42
|
+
apply(m);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
onMount(() => {
|
|
46
|
+
const saved = (() => {
|
|
47
|
+
try {
|
|
48
|
+
return localStorage.getItem(STORAGE_KEY);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
})();
|
|
53
|
+
mode = saved === "light" || saved === "dark" || saved === "system" ? saved : "system";
|
|
54
|
+
apply(mode);
|
|
55
|
+
|
|
56
|
+
// Follow the OS while in System mode.
|
|
57
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
58
|
+
const onOS = () => mode === "system" && apply("system");
|
|
59
|
+
mql.addEventListener?.("change", onOS);
|
|
60
|
+
|
|
61
|
+
// Close the menu on outside click / Escape.
|
|
62
|
+
const onDocClick = (e) => {
|
|
63
|
+
if (openMenu && rootRef && !rootRef.contains(e.target)) openMenu = false;
|
|
64
|
+
};
|
|
65
|
+
const onKey = (e) => e.key === "Escape" && (openMenu = false);
|
|
66
|
+
document.addEventListener("click", onDocClick);
|
|
67
|
+
document.addEventListener("keydown", onKey);
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
mql.removeEventListener?.("change", onOS);
|
|
71
|
+
document.removeEventListener("click", onDocClick);
|
|
72
|
+
document.removeEventListener("keydown", onKey);
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div class="afwd-theme" ref={rootRef}>
|
|
78
|
+
<Tooltip text="Change theme">
|
|
79
|
+
<button
|
|
80
|
+
class="afwd-navbar-icon afwd-theme-trigger"
|
|
81
|
+
onclick={(e) => {
|
|
82
|
+
e.stopPropagation();
|
|
83
|
+
openMenu = !openMenu;
|
|
84
|
+
}}
|
|
85
|
+
aria-label="Change theme"
|
|
86
|
+
aria-haspopup="menu"
|
|
87
|
+
aria-expanded={openMenu ? "true" : "false"}
|
|
88
|
+
>
|
|
89
|
+
{() =>
|
|
90
|
+
mode === "system" ? (
|
|
91
|
+
<span class="afwd-theme-trigger-system">
|
|
92
|
+
<MonitorIcon />
|
|
93
|
+
<span class="afwd-theme-trigger-badge">
|
|
94
|
+
{resolved === "dark" ? <MoonIcon small /> : <SunIcon small />}
|
|
95
|
+
</span>
|
|
96
|
+
</span>
|
|
97
|
+
) : mode === "dark" ? (
|
|
98
|
+
<MoonIcon />
|
|
99
|
+
) : (
|
|
100
|
+
<SunIcon />
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
</button>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
|
|
106
|
+
{() =>
|
|
107
|
+
openMenu ? (
|
|
108
|
+
<div class="afwd-theme-menu" role="menu">
|
|
109
|
+
<MenuItem active={mode === "light"} onclick={() => setMode("light")}>
|
|
110
|
+
<SunIcon small /> Light
|
|
111
|
+
</MenuItem>
|
|
112
|
+
<MenuItem active={mode === "dark"} onclick={() => setMode("dark")}>
|
|
113
|
+
<MoonIcon small /> Dark
|
|
114
|
+
</MenuItem>
|
|
115
|
+
<MenuItem active={mode === "system"} onclick={() => setMode("system")}>
|
|
116
|
+
<MonitorIcon small /> System
|
|
117
|
+
</MenuItem>
|
|
118
|
+
</div>
|
|
119
|
+
) : null
|
|
120
|
+
}
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function MenuItem(props) {
|
|
126
|
+
return (
|
|
127
|
+
<button
|
|
128
|
+
class={props.active ? "afwd-theme-item is-active" : "afwd-theme-item"}
|
|
129
|
+
role="menuitemradio"
|
|
130
|
+
aria-checked={props.active ? "true" : "false"}
|
|
131
|
+
onclick={props.onclick}
|
|
132
|
+
>
|
|
133
|
+
{props.children}
|
|
134
|
+
</button>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function SunIcon(props) {
|
|
139
|
+
const s = props.small ? 15 : 17;
|
|
140
|
+
return (
|
|
141
|
+
<svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
142
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364-6.364l-.707.707M6.343 17.657l-.707.707m12.728 0l-.707-.707M6.343 6.343l-.707-.707M12 5a7 7 0 100 14 7 7 0 000-14z" />
|
|
143
|
+
</svg>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function MoonIcon(props) {
|
|
148
|
+
const s = props.small ? 15 : 17;
|
|
149
|
+
return (
|
|
150
|
+
<svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
151
|
+
<path stroke-linecap="round" stroke-linejoin="round" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" />
|
|
152
|
+
</svg>
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function MonitorIcon(props) {
|
|
157
|
+
const s = props.small ? 15 : 17;
|
|
158
|
+
return (
|
|
159
|
+
<svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
160
|
+
<rect x="2" y="3" width="20" height="14" rx="2" />
|
|
161
|
+
<path d="M8 21h8M12 17v4" />
|
|
162
|
+
</svg>
|
|
163
|
+
);
|
|
164
|
+
}
|