@krate/simple-docs-theme 0.0.0-stage → 0.5.0-beta.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/src/layout.tsx ADDED
@@ -0,0 +1,232 @@
1
+ import { createCSSChoice, createCSSToggle } from "@krate/runtime";
2
+ import type { DocsLayoutProps } from "@krate/plugin";
3
+ import {
4
+ Breadcrumbs,
5
+ PrevNext,
6
+ SidebarNav,
7
+ SocialLinks,
8
+ TOCAside,
9
+ TOCNav,
10
+ ThemeSwitch,
11
+ } from "./chrome";
12
+ import type { SimpleDocsThemeOptions } from "./index";
13
+ import "./theme.css";
14
+
15
+ function feedbackURL(feedback: { repo: string; discussions?: boolean }, title: string, positive: boolean): string {
16
+ const kind = feedback.discussions ? "discussions/new" : "issues/new";
17
+ const heading = (positive ? "Docs feedback (helpful): " : "Docs feedback (not helpful): ") + title;
18
+ const body = "Page: " + title;
19
+ return (
20
+ "https://github.com/" + feedback.repo + "/" + kind +
21
+ "?title=" + encodeURIComponent(heading) +
22
+ "&body=" + encodeURIComponent(body)
23
+ );
24
+ }
25
+
26
+ function Switcher(props: {
27
+ label: string;
28
+ icon: string;
29
+ current?: string;
30
+ links: { code?: string; label: string; url: string }[];
31
+ }) {
32
+ if (!props.links || props.links.length < 2) return null;
33
+ return (
34
+ <details class="simple-switcher">
35
+ <summary aria-label={props.label}>
36
+ <Icon name={props.icon} width="15" height="15" />
37
+ {props.current && <span>{props.current}</span>}
38
+ </summary>
39
+ <div class="simple-switcher-menu">
40
+ {props.links.map((link) => (
41
+ <a class={link.code === props.current ? "is-active" : undefined} href={link.url}>{link.label}</a>
42
+ ))}
43
+ </div>
44
+ </details>
45
+ );
46
+ }
47
+
48
+ export default function SimpleDocsLayout(props: DocsLayoutProps) {
49
+ const theme = createCSSChoice<string>("auto", ["auto", "light", "dark"]);
50
+ const nav = createCSSToggle(false);
51
+ const options = (props.options || {}) as SimpleDocsThemeOptions;
52
+
53
+ const routeBase = props.routeBase || "/docs";
54
+ const tocItems = props.tocItems || [];
55
+ const showToc = !props.tocHidden && tocItems.length > 0;
56
+ const tocLabel = props.tocLabel || "On this page";
57
+ const tags = props.tags || [];
58
+ const categories = props.categories || [];
59
+ const tagLinks = props.tagLinks || [];
60
+ const categoryLinks = props.categoryLinks || [];
61
+ const i18n = props.i18n || {};
62
+ const localeLinks = i18n.locales || [];
63
+ const versionLinks = i18n.versions || [];
64
+ const activeVersion = i18n.version || i18n.currentVersion || "";
65
+ const hero = props.hero;
66
+ const isHero = props.template === "hero";
67
+ const heroTitle = hero && hero.title ? hero.title : props.pageTitle;
68
+ const heroActions = hero && hero.actions ? hero.actions : [];
69
+ let currentVersionURL = "";
70
+ for (const version of versionLinks) {
71
+ if (version.code === i18n.currentVersion) currentVersionURL = version.url;
72
+ }
73
+
74
+ return (
75
+ <div class="simple-page" data-template={props.template || "doc"} data-toc={showToc ? "true" : "false"}>
76
+ <Head>
77
+ <title>{props.pageTitle} - {props.siteTitle}</title>
78
+ {props.description && <meta name="description" content={props.description} />}
79
+ <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)" />
80
+ <meta name="theme-color" content="#0b0b0f" media="(prefers-color-scheme: dark)" />
81
+ </Head>
82
+
83
+ <a class="simple-skip" href="#main">Skip to content</a>
84
+
85
+ {i18n.versionBanner && (
86
+ <div class="simple-version-banner">
87
+ <span>You are viewing an older version ({i18n.version}).</span>
88
+ {currentVersionURL && <a href={currentVersionURL}>Go to the latest</a>}
89
+ </div>
90
+ )}
91
+
92
+ <header class="simple-header">
93
+ <a class="simple-brand" href={routeBase + "/"}>
94
+ <span class="simple-brand-mark" aria-hidden="true">
95
+ <Icon name="lucide:book-open" width="18" height="18" />
96
+ </span>
97
+ <span>{props.siteTitle}</span>
98
+ </a>
99
+
100
+ <div class="simple-header-actions">
101
+ {options.searchHref && (
102
+ <a class="simple-search-link" href={options.searchHref}>
103
+ <Icon name="lucide:search" width="16" height="16" />
104
+ <span>{props.search?.placeholder || "Search"}</span>
105
+ {props.search?.hotkey && <kbd>{props.search.hotkey}</kbd>}
106
+ </a>
107
+ )}
108
+
109
+ <div class="simple-header-switchers">
110
+ <Switcher label="Change version" icon="lucide:git-branch" current={activeVersion} links={versionLinks} />
111
+ <Switcher label="Change language" icon="lucide:languages" current={i18n.locale} links={localeLinks} />
112
+ </div>
113
+
114
+ <SocialLinks links={props.socialLinks} />
115
+ <ThemeSwitch theme={theme} />
116
+
117
+ <button
118
+ class="simple-icon-button simple-nav-open"
119
+ type="button"
120
+ aria-label="Open navigation"
121
+ aria-controls="simple-nav-drawer"
122
+ {...nav.trigger()}
123
+ >
124
+ <Icon name="lucide:menu" width="20" height="20" />
125
+ </button>
126
+ </div>
127
+ </header>
128
+
129
+ <div class="simple-nav-panel" {...nav.panel(true)}>
130
+ <div class="simple-nav-backdrop" {...nav.close()}></div>
131
+ <aside class="simple-nav-drawer" id="simple-nav-drawer">
132
+ <div class="simple-nav-drawer-head">
133
+ <span>Menu</span>
134
+ <button class="simple-icon-button" type="button" aria-label="Close navigation" {...nav.close()}>
135
+ <Icon name="lucide:x" width="18" height="18" />
136
+ </button>
137
+ </div>
138
+ <div class="simple-nav-drawer-switchers">
139
+ <Switcher label="Change version" icon="lucide:git-branch" current={activeVersion} links={versionLinks} />
140
+ <Switcher label="Change language" icon="lucide:languages" current={i18n.locale} links={localeLinks} />
141
+ </div>
142
+ <SidebarNav items={props.sidebarItems} />
143
+ </aside>
144
+ </div>
145
+
146
+ <div class="simple-shell">
147
+ <aside class="simple-sidebar">
148
+ <SidebarNav items={props.sidebarItems} />
149
+ </aside>
150
+
151
+ <main class="simple-main" id="main">
152
+ <Breadcrumbs items={props.breadcrumbs} />
153
+
154
+ {props.description && !isHero && <p class="simple-description">{props.description}</p>}
155
+
156
+ {isHero && (
157
+ <section class="simple-hero">
158
+ <h1>{heroTitle}</h1>
159
+ {hero && hero.tagline && <p class="simple-hero-tagline">{hero.tagline}</p>}
160
+ {hero && hero.image && <img class="simple-hero-image" src={hero.image} alt="" />}
161
+ {heroActions.length > 0 && (
162
+ <div class="simple-hero-actions">
163
+ {heroActions.map((action) => (
164
+ <a
165
+ class={`simple-hero-action${action.variant ? " simple-hero-action-" + action.variant : ""}`}
166
+ href={action.link}
167
+ >
168
+ {action.text}
169
+ </a>
170
+ ))}
171
+ </div>
172
+ )}
173
+ </section>
174
+ )}
175
+
176
+ {showToc && <TOCNav items={tocItems} label={tocLabel} />}
177
+
178
+ <div class="simple-content">{props.children}</div>
179
+
180
+ {(tags.length > 0 || categories.length > 0) && (
181
+ <div class="simple-taxonomy">
182
+ {tagLinks.length > 0
183
+ ? tagLinks.map((tag) => <a class="simple-chip" href={tag.url}>{tag.name}</a>)
184
+ : tags.map((tag) => <span class="simple-chip">{tag}</span>)}
185
+ {categoryLinks.length > 0
186
+ ? categoryLinks.map((category) => <a class="simple-chip simple-chip-category" href={category.url}>{category.name}</a>)
187
+ : categories.map((category) => <span class="simple-chip simple-chip-category">{category}</span>)}
188
+ </div>
189
+ )}
190
+
191
+ {(props.date || props.lastUpdated) && (
192
+ <p class="simple-dates">
193
+ {props.date && <span>Published: {props.date.slice(0, 10)}</span>}
194
+ {props.lastUpdated && <span>Last updated: {props.lastUpdated.slice(0, 10)}</span>}
195
+ </p>
196
+ )}
197
+
198
+ <PrevNext
199
+ prevTitle={props.prevTitle}
200
+ prevLink={props.prevLink}
201
+ nextTitle={props.nextTitle}
202
+ nextLink={props.nextLink}
203
+ />
204
+
205
+ {(props.editUrl || options.feedback) && (
206
+ <div class="simple-page-footer">
207
+ {props.editUrl && (
208
+ <a class="simple-edit-link" href={props.editUrl}>
209
+ <Icon name="lucide:pencil" width="14" height="14" />
210
+ <span>{options.editLabel || "Edit this page"}</span>
211
+ </a>
212
+ )}
213
+ {options.feedback && (
214
+ <div class="simple-feedback">
215
+ <span>{options.feedback.label || "Was this helpful?"}</span>
216
+ <a class="simple-icon-button" href={feedbackURL(options.feedback, props.pageTitle, true)} target="_blank" rel="noopener noreferrer" aria-label="Yes, this page was helpful">
217
+ <Icon name="lucide:thumbs-up" width="16" height="16" />
218
+ </a>
219
+ <a class="simple-icon-button" href={feedbackURL(options.feedback, props.pageTitle, false)} target="_blank" rel="noopener noreferrer" aria-label="No, this page was not helpful">
220
+ <Icon name="lucide:thumbs-down" width="16" height="16" />
221
+ </a>
222
+ </div>
223
+ )}
224
+ </div>
225
+ )}
226
+ </main>
227
+
228
+ {showToc && <TOCAside items={tocItems} label={tocLabel} />}
229
+ </div>
230
+ </div>
231
+ );
232
+ }