@rxova/astro-ui 0.6.2 → 0.7.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/package.json +1 -1
- package/src/components/DocsMenu.astro +46 -0
- package/src/components/ProjectSwitcher.astro +4 -6
- package/src/components/SiteFooter.astro +1 -1
- package/src/starlight/Header.astro +75 -0
- package/src/starlight/MenuContent.astro +25 -0
- package/src/starlight/MobileMenuFooter.astro +9 -0
- package/src/starlight/index.ts +4 -0
- package/src/styles/starlight.css +176 -41
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** A docs site's phone menu links: every project's docs, then the rxova.dev sections as the site
|
|
3
|
+
* header labels them. The Starlight wrappers add the social links and theme picker after it. */
|
|
4
|
+
import { PROJECTS, RXOVA_ORIGIN, SECTIONS, type ProjectId } from "@rxova/brand";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
/** The project whose docs these are, marked as current. */
|
|
8
|
+
current?: ProjectId;
|
|
9
|
+
/** Prefix for every link. '' links root-relative, for a build served on rxova.dev. */
|
|
10
|
+
origin?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { current, origin = RXOVA_ORIGIN } = Astro.props;
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<nav class="rx-docs-menu" aria-label="rxova.dev">
|
|
17
|
+
<p class="rx-docs-menu__label" aria-hidden="true">
|
|
18
|
+
Docs
|
|
19
|
+
</p>
|
|
20
|
+
<ul class="rx-docs-menu__list" aria-label="Docs">
|
|
21
|
+
{PROJECTS.map((project) => (
|
|
22
|
+
<li>
|
|
23
|
+
<a
|
|
24
|
+
class="rx-docs-menu__link"
|
|
25
|
+
href={`${origin}${project.mount}`}
|
|
26
|
+
aria-current={project.id === current ? "page" : undefined}
|
|
27
|
+
translate="no"
|
|
28
|
+
>
|
|
29
|
+
{project.label}
|
|
30
|
+
</a>
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
<p class="rx-docs-menu__label" aria-hidden="true">
|
|
35
|
+
rxova.dev
|
|
36
|
+
</p>
|
|
37
|
+
<ul class="rx-docs-menu__list" aria-label="Site">
|
|
38
|
+
{SECTIONS.map((section) => (
|
|
39
|
+
<li>
|
|
40
|
+
<a class="rx-docs-menu__link" href={`${origin}${section.path}`}>
|
|
41
|
+
{section.label}
|
|
42
|
+
</a>
|
|
43
|
+
</li>
|
|
44
|
+
))}
|
|
45
|
+
</ul>
|
|
46
|
+
</nav>
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* resolve under the current site's base path.
|
|
5
|
-
*/
|
|
2
|
+
/** Cross-project navigation as a zero-JS `<details>`, labelled "Docs" so it never reads as the
|
|
3
|
+
* Projects link beside it. Every href is absolute: a relative one would resolve under the base. */
|
|
6
4
|
import { PROJECTS, RXOVA_ORIGIN, type ProjectId } from "@rxova/brand";
|
|
7
5
|
|
|
8
6
|
interface Props {
|
|
@@ -14,8 +12,8 @@ const { current } = Astro.props;
|
|
|
14
12
|
---
|
|
15
13
|
|
|
16
14
|
<details class="rx-switcher">
|
|
17
|
-
<summary class="rx-switcher__trigger"
|
|
18
|
-
|
|
15
|
+
<summary class="rx-switcher__trigger">
|
|
16
|
+
Docs
|
|
19
17
|
<svg aria-hidden="true" viewBox="0 0 16 16" width="12" height="12">
|
|
20
18
|
<path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" stroke-width="1.75"></path>
|
|
21
19
|
</svg>
|
|
@@ -131,7 +131,7 @@ const surfaces: readonly SiteLink[] =
|
|
|
131
131
|
<a href="https://www.npmjs.com/org/rxova">npm</a>
|
|
132
132
|
</li>
|
|
133
133
|
<li>
|
|
134
|
-
<a href="mailto:
|
|
134
|
+
<a href="mailto:jonyk@rxova.dev">jonyk@rxova.dev</a>
|
|
135
135
|
</li>
|
|
136
136
|
</ul>
|
|
137
137
|
</div>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
---
|
|
2
|
+
/** Starlight `Header` override: adds a phone menu to pages without a sidebar, which Starlight gives
|
|
3
|
+
* none. A `<details>`, so it opens without JavaScript; the script adds Esc and outside-click closing. */
|
|
4
|
+
import Default from "@astrojs/starlight/components/Header.astro";
|
|
5
|
+
import MenuContent from "./MenuContent.astro";
|
|
6
|
+
|
|
7
|
+
// Narrowed structurally, as in SiteTitle.astro.
|
|
8
|
+
const { hasSidebar } = (Astro.locals as unknown as { starlightRoute: { hasSidebar: boolean } })
|
|
9
|
+
.starlightRoute;
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<Default>
|
|
13
|
+
<slot />
|
|
14
|
+
</Default>
|
|
15
|
+
{!hasSidebar && (
|
|
16
|
+
<details class="rx-menu md:sl-hidden print:hidden">
|
|
17
|
+
<summary class="rx-menu__toggle" aria-controls="rx-menu-panel">
|
|
18
|
+
<svg class="rx-menu__open" aria-hidden="true" viewBox="0 0 24 24" width="20" height="20">
|
|
19
|
+
<path
|
|
20
|
+
d="M4 7h16M4 12h16M4 17h16"
|
|
21
|
+
fill="none"
|
|
22
|
+
stroke="currentColor"
|
|
23
|
+
stroke-width="1.75"
|
|
24
|
+
stroke-linecap="round"
|
|
25
|
+
/>
|
|
26
|
+
</svg>
|
|
27
|
+
<svg class="rx-menu__close" aria-hidden="true" viewBox="0 0 24 24" width="20" height="20">
|
|
28
|
+
<path
|
|
29
|
+
d="M6 6l12 12M18 6L6 18"
|
|
30
|
+
fill="none"
|
|
31
|
+
stroke="currentColor"
|
|
32
|
+
stroke-width="1.75"
|
|
33
|
+
stroke-linecap="round"
|
|
34
|
+
/>
|
|
35
|
+
</svg>
|
|
36
|
+
<span class="sr-only">Menu</span>
|
|
37
|
+
</summary>
|
|
38
|
+
<div class="rx-menu__panel" id="rx-menu-panel">
|
|
39
|
+
<MenuContent />
|
|
40
|
+
</div>
|
|
41
|
+
</details>
|
|
42
|
+
)}
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
const menu = document.querySelector<HTMLDetailsElement>("details.rx-menu");
|
|
46
|
+
const toggle = menu?.querySelector<HTMLElement>(".rx-menu__toggle");
|
|
47
|
+
|
|
48
|
+
if (menu && toggle) {
|
|
49
|
+
const close = (refocus: boolean): void => {
|
|
50
|
+
if (!menu.open) return;
|
|
51
|
+
menu.open = false;
|
|
52
|
+
if (refocus) toggle.focus();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
menu.addEventListener("keydown", (event) => {
|
|
56
|
+
if (event.key !== "Escape" || !menu.open) return;
|
|
57
|
+
// Leave an open theme picker's own Esc alone.
|
|
58
|
+
if (event.defaultPrevented) return;
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
close(true);
|
|
61
|
+
});
|
|
62
|
+
// Outside a click, or focus moving elsewhere, the menu is no longer what the reader is using.
|
|
63
|
+
document.addEventListener("click", (event) => {
|
|
64
|
+
if (!menu.contains(event.target as Node)) close(false);
|
|
65
|
+
});
|
|
66
|
+
menu.addEventListener("focusout", (event) => {
|
|
67
|
+
const next = event.relatedTarget as Node | null;
|
|
68
|
+
if (next && !menu.contains(next)) close(false);
|
|
69
|
+
});
|
|
70
|
+
// Wider than a phone the menu is hidden; do not leave it open behind the desktop header.
|
|
71
|
+
matchMedia("(min-width: 50rem)").addEventListener("change", (event) => {
|
|
72
|
+
if (event.matches) close(false);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* What a docs site's phone menu holds below its own sidebar: every project's docs, the rxova.dev
|
|
4
|
+
* sections, then the social links and the theme picker, which the header hides on phones.
|
|
5
|
+
*/
|
|
6
|
+
import DefaultSocialIcons from "@astrojs/starlight/components/SocialIcons.astro";
|
|
7
|
+
import LanguageSelect from "@astrojs/starlight/components/LanguageSelect.astro";
|
|
8
|
+
import { projectFromBase } from "@rxova/brand";
|
|
9
|
+
import DocsMenu from "../components/DocsMenu.astro";
|
|
10
|
+
import ThemeSelect from "./ThemeSelect.astro";
|
|
11
|
+
|
|
12
|
+
// Overrides receive no props, so the current project is inferred from the base path.
|
|
13
|
+
const current = projectFromBase(import.meta.env.BASE_URL);
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
<div class="rx-menu-content">
|
|
17
|
+
<DocsMenu current={current} />
|
|
18
|
+
<div class="rx-menu-content__prefs">
|
|
19
|
+
<div class="rx-menu-content__social">
|
|
20
|
+
<DefaultSocialIcons />
|
|
21
|
+
</div>
|
|
22
|
+
<ThemeSelect />
|
|
23
|
+
<LanguageSelect />
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Starlight `MobileMenuFooter` override: the foot of Starlight's own phone menu (pages with a
|
|
4
|
+
* sidebar) carries the same links as the splash pages' menu in `Header.astro`, so no page needs two menus.
|
|
5
|
+
*/
|
|
6
|
+
import MenuContent from "./MenuContent.astro";
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
<MenuContent />
|
package/src/starlight/index.ts
CHANGED
|
@@ -59,6 +59,10 @@ export function sharedStarlightConfig({
|
|
|
59
59
|
Footer: "@rxova/astro-ui/starlight/Footer.astro",
|
|
60
60
|
// Starlight's own picker, plus a resync when a page is restored from the bfcache.
|
|
61
61
|
ThemeSelect: "@rxova/astro-ui/starlight/ThemeSelect.astro",
|
|
62
|
+
// Starlight's header, plus a phone menu on pages without a sidebar, which get none.
|
|
63
|
+
Header: "@rxova/astro-ui/starlight/Header.astro",
|
|
64
|
+
// The foot of Starlight's phone menu: the projects, the sections, the social links and theme.
|
|
65
|
+
MobileMenuFooter: "@rxova/astro-ui/starlight/MobileMenuFooter.astro",
|
|
62
66
|
...components,
|
|
63
67
|
},
|
|
64
68
|
|
package/src/styles/starlight.css
CHANGED
|
@@ -135,63 +135,198 @@ header.header {
|
|
|
135
135
|
color: var(--sl-color-white);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
/*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
/* --- Phone menu ----------------------------------------------------------- */
|
|
139
|
+
|
|
140
|
+
/* One row on phones: the mark and project, then search and the menu button. Every control is at
|
|
141
|
+
least 44px square, Starlight's menu button included. */
|
|
142
|
+
@media (max-width: 49.99rem) {
|
|
143
|
+
:root {
|
|
144
|
+
--sl-menu-button-size: 2.75rem;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Room for the menu button, which is fixed over the right edge like Starlight's. */
|
|
148
|
+
:root:not([data-has-sidebar]) header.header {
|
|
149
|
+
padding-inline-end: calc(var(--sl-nav-gap) + var(--sl-nav-pad-x) + var(--sl-menu-button-size));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
site-search button[data-open-modal] {
|
|
153
|
+
min-width: 2.75rem;
|
|
154
|
+
min-height: 2.75rem;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
}
|
|
142
157
|
}
|
|
143
158
|
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
/* Both menu buttons look like the site header's theme toggle, a quiet outlined square. Unlayered,
|
|
160
|
+
so they beat Starlight's `starlight.core` rules, light-theme ones included. */
|
|
161
|
+
.sl-menu-button,
|
|
162
|
+
.rx-menu__toggle {
|
|
163
|
+
place-items: center;
|
|
164
|
+
width: var(--sl-menu-button-size);
|
|
165
|
+
height: var(--sl-menu-button-size);
|
|
166
|
+
padding: 0;
|
|
167
|
+
border: 1px solid var(--rx-rule-strong);
|
|
168
|
+
border-radius: var(--rx-radius-sm);
|
|
169
|
+
background: var(--rx-bg);
|
|
170
|
+
color: var(--rx-fg);
|
|
171
|
+
box-shadow: none;
|
|
172
|
+
cursor: pointer;
|
|
146
173
|
}
|
|
147
174
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
inset-inline: 0 auto;
|
|
152
|
-
inset-block-end: 100%;
|
|
153
|
-
margin: 0 0 0.4rem;
|
|
175
|
+
.sl-menu-button:has(~ :popover-open),
|
|
176
|
+
.rx-menu[open] > .rx-menu__toggle {
|
|
177
|
+
background: var(--rx-tag-bg);
|
|
154
178
|
}
|
|
155
179
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
--sl-nav-height: 6rem;
|
|
161
|
-
}
|
|
180
|
+
.sl-menu-button:hover,
|
|
181
|
+
.rx-menu__toggle:hover {
|
|
182
|
+
border-color: var(--rx-faint);
|
|
183
|
+
}
|
|
162
184
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
185
|
+
.sl-menu-button:focus-visible,
|
|
186
|
+
.rx-menu__toggle:focus-visible {
|
|
187
|
+
outline: 2px solid var(--rx-fg);
|
|
188
|
+
outline-offset: 2px;
|
|
189
|
+
}
|
|
167
190
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
191
|
+
.sl-menu-button svg {
|
|
192
|
+
width: 1.25rem;
|
|
193
|
+
height: 1.25rem;
|
|
194
|
+
}
|
|
171
195
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
196
|
+
/* `display` only on phones: unlayered, it would otherwise beat Starlight's `md:sl-hidden`. */
|
|
197
|
+
@media (max-width: 49.99rem) {
|
|
198
|
+
.sl-menu-button,
|
|
199
|
+
.rx-menu__toggle {
|
|
200
|
+
display: grid;
|
|
175
201
|
}
|
|
202
|
+
}
|
|
176
203
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
:root:not([data-has-sidebar]) header.header .social-icons > :not(.rx-sections) {
|
|
204
|
+
@media (min-width: 50rem) {
|
|
205
|
+
.rx-menu {
|
|
180
206
|
display: none;
|
|
181
207
|
}
|
|
208
|
+
}
|
|
182
209
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
210
|
+
.rx-menu__toggle {
|
|
211
|
+
position: fixed;
|
|
212
|
+
z-index: var(--sl-z-index-navbar);
|
|
213
|
+
top: calc((var(--sl-nav-height) - var(--sl-menu-button-size)) / 2);
|
|
214
|
+
inset-inline-end: var(--sl-nav-pad-x);
|
|
215
|
+
list-style: none;
|
|
216
|
+
}
|
|
186
217
|
|
|
187
|
-
|
|
188
|
-
:
|
|
189
|
-
|
|
190
|
-
}
|
|
218
|
+
.rx-menu__toggle::-webkit-details-marker {
|
|
219
|
+
display: none;
|
|
220
|
+
}
|
|
191
221
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
222
|
+
.rx-menu:not([open]) .rx-menu__close,
|
|
223
|
+
.rx-menu[open] .rx-menu__open {
|
|
224
|
+
display: none;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* A sheet under the header bar, as tall as it needs and scrolling past the viewport. */
|
|
228
|
+
.rx-menu__panel {
|
|
229
|
+
position: fixed;
|
|
230
|
+
z-index: var(--sl-z-index-menu);
|
|
231
|
+
inset-block-start: var(--sl-nav-height);
|
|
232
|
+
inset-inline: 0;
|
|
233
|
+
max-height: calc(100dvh - var(--sl-nav-height));
|
|
234
|
+
overflow-y: auto;
|
|
235
|
+
padding: 0.5rem var(--sl-nav-pad-x) 1rem;
|
|
236
|
+
border-bottom: 1px solid var(--sl-color-hairline-shade);
|
|
237
|
+
background: var(--sl-color-bg-nav);
|
|
238
|
+
box-shadow: var(--sl-shadow-lg);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* The menu's links: the project docs, then the sections, as full-width 44px rows. */
|
|
242
|
+
.rx-docs-menu__label {
|
|
243
|
+
margin: 0.75rem 0 0.25rem;
|
|
244
|
+
padding-inline: 0.5rem;
|
|
245
|
+
color: var(--rx-muted);
|
|
246
|
+
font-family: var(--rx-font-mono);
|
|
247
|
+
font-size: var(--sl-text-xs);
|
|
248
|
+
letter-spacing: 0.08em;
|
|
249
|
+
text-transform: uppercase;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.rx-docs-menu__list {
|
|
253
|
+
margin: 0;
|
|
254
|
+
padding: 0;
|
|
255
|
+
list-style: none;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.rx-docs-menu__list li {
|
|
259
|
+
margin: 0;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.rx-docs-menu__link {
|
|
263
|
+
display: flex;
|
|
264
|
+
align-items: center;
|
|
265
|
+
min-height: 2.75rem;
|
|
266
|
+
padding-inline: 0.5rem;
|
|
267
|
+
border-radius: var(--rx-radius-sm);
|
|
268
|
+
color: var(--rx-fg);
|
|
269
|
+
font-size: var(--sl-text-base);
|
|
270
|
+
text-decoration: none;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.rx-docs-menu__link:hover {
|
|
274
|
+
color: var(--rx-fg);
|
|
275
|
+
background: var(--rx-tag-bg);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.rx-docs-menu__link:focus-visible {
|
|
279
|
+
outline: 2px solid var(--rx-fg);
|
|
280
|
+
outline-offset: -2px;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* The current project: the gradient dot the desktop switcher uses, and bold for everyone. */
|
|
284
|
+
.rx-docs-menu__link[aria-current="page"] {
|
|
285
|
+
font-weight: 600;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.rx-docs-menu__link[aria-current="page"]::before {
|
|
289
|
+
content: "";
|
|
290
|
+
width: 0.5rem;
|
|
291
|
+
height: 0.5rem;
|
|
292
|
+
margin-inline-end: 0.5rem;
|
|
293
|
+
border-radius: var(--rx-radius-pill);
|
|
294
|
+
background: var(--rx-gradient);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/* GitHub, npm and the theme picker share the last row, under a hairline. */
|
|
298
|
+
.rx-menu-content__prefs {
|
|
299
|
+
display: flex;
|
|
300
|
+
flex-wrap: wrap;
|
|
301
|
+
align-items: center;
|
|
302
|
+
justify-content: space-between;
|
|
303
|
+
gap: 0.5rem 1rem;
|
|
304
|
+
margin-top: 0.75rem;
|
|
305
|
+
padding-top: 0.5rem;
|
|
306
|
+
border-top: 1px solid var(--sl-color-hairline);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.rx-menu-content__social {
|
|
310
|
+
display: flex;
|
|
311
|
+
gap: 0.25rem;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.rx-menu-content__social a {
|
|
315
|
+
display: grid;
|
|
316
|
+
place-items: center;
|
|
317
|
+
min-width: 2.75rem;
|
|
318
|
+
min-height: 2.75rem;
|
|
319
|
+
padding: 0;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.rx-menu-content__prefs starlight-theme-select select {
|
|
323
|
+
min-height: 2.75rem;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/* Inside Starlight's own menu, below the sidebar. */
|
|
327
|
+
.sidebar-content .rx-menu-content {
|
|
328
|
+
padding-bottom: 1rem;
|
|
329
|
+
border-top: 1px solid var(--sl-color-hairline);
|
|
195
330
|
}
|
|
196
331
|
|
|
197
332
|
/* --- Footer -------------------------------------------------------------- */
|