@uxfront/layer-docs 0.8.2 → 0.8.4
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/README.md +25 -1
- package/app/components/IconMenuToggle.vue +82 -0
- package/app/components/app/AppHeaderLeft.vue +3 -3
- package/modules/hydration-ids.ts +34 -0
- package/nuxt.config.ts +26 -3
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ export default defineAppConfig({
|
|
|
47
47
|
});
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
The wordmark links home, and
|
|
50
|
+
The wordmark links home, and the link's accessible name is the text it shows, like "OpenComponents", so someone who uses voice control can say what they see to follow it. The byline sits beside the link, not inside it, and phones leave it out so the header's buttons keep their room. With neither set, the header shows Docus's own title or logo.
|
|
51
51
|
|
|
52
52
|
## Header links
|
|
53
53
|
|
|
@@ -142,6 +142,27 @@ export default defineNuxtConfig({
|
|
|
142
142
|
});
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
## Code themes
|
|
146
|
+
|
|
147
|
+
The layer highlights code in GitHub's high-contrast themes, `github-light-high-contrast` in light mode and `github-dark-high-contrast` in dark mode. Every token colour in them reaches 4.5:1 on the code blocks' background, the contrast [WCAG 1.4.3](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html) asks of text, whichever neutral colour the app gives Nuxt UI. The Material themes Nuxt UI sets otherwise go as low as 2.18:1, so some comments and strings are hard to read.
|
|
148
|
+
|
|
149
|
+
To use other themes, set all three keys in the app's `nuxt.config.ts`. Shiki writes a rule for `light` that outranks `default`, so if you leave `light` out, light mode keeps the layer's theme:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
// nuxt.config.ts
|
|
153
|
+
export default defineNuxtConfig({
|
|
154
|
+
content: {
|
|
155
|
+
build: {
|
|
156
|
+
markdown: {
|
|
157
|
+
highlight: {
|
|
158
|
+
theme: { default: "github-light", light: "github-light", dark: "github-dark" },
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
145
166
|
## What it adds
|
|
146
167
|
|
|
147
168
|
- **A Framework select above the sidebar.** It picks the framework for the whole site, and lines up with the navigation's pages below it. It replaces Docus's `DocsAsideLeftTop` and renders Docus's below it.
|
|
@@ -149,10 +170,13 @@ export default defineNuxtConfig({
|
|
|
149
170
|
- **The links and the same select in the header's menu.** On smaller screens, where Docus hides the sidebar, the menu that stands in for it starts with the header links below `768px`, then the select. It replaces Docus's `AppHeaderBody` and renders Docus's below them.
|
|
150
171
|
- **`AppHeaderLinks` and `AppHeaderFramework`.** The links and the Framework select on their own, for a site that replaces `AppHeaderCTA` or `AppHeaderBody`.
|
|
151
172
|
- **`FrameworkSwitcher`.** It shows the slot for the reader's framework, with no tabs of its own, since the select already picks one for every page. A page doesn't have to cover every framework: a missing one shows the first one the page has, with a note saying so.
|
|
173
|
+
- **A named menu toggle.** On smaller screens, the header's menu button says what it does, "Open menu" or "Close menu", in Nuxt UI's words, translated with its locale. Docus's has no name, which [WCAG 4.1.2](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html) asks every control to have, so screen readers announce it only as "button". It replaces Docus's `IconMenuToggle`, and its lines don't move for readers who ask for reduced motion.
|
|
152
174
|
- **A header wordmark and byline.** It replaces Docus's `AppHeaderLeft`, and renders Docus's unless the app sets a wordmark.
|
|
153
175
|
- **Typed app config.** `useAppConfig()` knows `docsTheme`, so `wordmark`, `byline` and `headerLinks` typecheck even in an app that leaves them unset.
|
|
154
176
|
- **`useFramework()`.** The reader's pick, shared by every switcher and the select, and kept in `localStorage` across visits. It's read once the page is mounted, so the prerendered HTML shows the default framework and hydrates cleanly.
|
|
155
177
|
- **Highlighting for the frameworks' languages.** `tsx`, `svelte`, `angular-html`, `angular-ts` and `astro`, on top of Docus's.
|
|
178
|
+
- **Readable code colours.** GitHub's high-contrast themes, whose every colour reaches 4.5:1 on the code blocks' background (see [Code themes](#code-themes)).
|
|
156
179
|
- **Bundled icons.** Nuxt Icon bundles the icons named in app config too, so the select's icons don't come from the Iconify API.
|
|
180
|
+
- **Ids that survive hydration.** Ids from `useId()` come out the same in the prerendered page and in the browser, so the select's label and the sidebar's accordions still point at elements that exist once the page hydrates. Nuxt removes `onServerPrefetch` calls from production client builds, and Nuxt Icon's CSS icons make one, so without this every id after the header's first icon changed in the browser. The layer keeps those calls in the client build, where they never run.
|
|
157
181
|
|
|
158
182
|
Everything else is Docus's: configure it as its [docs](https://docus.dev) describe.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Replaces Docus's mobile menu toggle (docus/app/components/IconMenuToggle.vue),
|
|
4
|
+
* which its header (docus/app/components/app/AppHeader.vue) renders in place of
|
|
5
|
+
* Nuxt UI's, to name it. Docus's is an icon-only button with no name, so screen
|
|
6
|
+
* readers announce just "button". This one says what it does, "Open menu" or
|
|
7
|
+
* "Close menu", in Nuxt UI's words for its own toggle, translated with its locale.
|
|
8
|
+
*
|
|
9
|
+
* Docus springs the three lines into a cross with motion-v, which isn't the
|
|
10
|
+
* layer's to import, so they turn with a CSS transition here, and don't move for
|
|
11
|
+
* readers who ask for reduced motion. Keep the props and the button in step with
|
|
12
|
+
* Docus's. Docus 5.15.0 names its own toggle, so this file can go once the layer
|
|
13
|
+
* requires that version or later.
|
|
14
|
+
*/
|
|
15
|
+
import { useLocale } from "#ui/composables/useLocale";
|
|
16
|
+
|
|
17
|
+
defineProps<{
|
|
18
|
+
open: boolean;
|
|
19
|
+
}>();
|
|
20
|
+
|
|
21
|
+
const { t } = useLocale();
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<UButton
|
|
26
|
+
size="sm"
|
|
27
|
+
variant="ghost"
|
|
28
|
+
color="neutral"
|
|
29
|
+
class="-me-1.5"
|
|
30
|
+
square
|
|
31
|
+
:aria-label="open ? t('header.close') : t('header.open')"
|
|
32
|
+
>
|
|
33
|
+
<svg
|
|
34
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
35
|
+
class="docs-menu-toggle size-5"
|
|
36
|
+
:class="{ 'docs-menu-toggle--open': open }"
|
|
37
|
+
viewBox="0 0 24 24"
|
|
38
|
+
fill="none"
|
|
39
|
+
stroke="currentColor"
|
|
40
|
+
stroke-width="2"
|
|
41
|
+
stroke-linecap="round"
|
|
42
|
+
stroke-linejoin="round"
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
>
|
|
45
|
+
<line x1="4" y1="6" x2="20" y2="6" />
|
|
46
|
+
<line x1="4" y1="12" x2="20" y2="12" />
|
|
47
|
+
<line x1="4" y1="18" x2="20" y2="18" />
|
|
48
|
+
</svg>
|
|
49
|
+
</UButton>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<style scoped>
|
|
53
|
+
/* Styled here rather than with Tailwind utilities: Docus's stylesheet doesn't
|
|
54
|
+
list this layer among Tailwind's sources, so only utilities Docus happens to
|
|
55
|
+
use itself, like the button's `-me-1.5` and the icon's `size-5`, are generated. */
|
|
56
|
+
.docs-menu-toggle line {
|
|
57
|
+
transform-box: fill-box;
|
|
58
|
+
transform-origin: center;
|
|
59
|
+
transition:
|
|
60
|
+
transform 0.2s ease-out,
|
|
61
|
+
opacity 0.2s ease-out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* The top and bottom lines meet in the middle and cross, and the middle one fades. */
|
|
65
|
+
.docs-menu-toggle--open line:nth-child(1) {
|
|
66
|
+
transform: translateY(6px) rotate(45deg);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.docs-menu-toggle--open line:nth-child(2) {
|
|
70
|
+
opacity: 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.docs-menu-toggle--open line:nth-child(3) {
|
|
74
|
+
transform: translateY(-6px) rotate(-45deg);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@media (prefers-reduced-motion: reduce) {
|
|
78
|
+
.docs-menu-toggle line {
|
|
79
|
+
transition: none;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// Replaces Docus's, which prints the site name as plain text, to set the app's
|
|
3
3
|
// wordmark (`docsTheme.wordmark`) and sign it "by UXFront" (`docsTheme.byline`),
|
|
4
4
|
// the way the UXFront homepage headers do. With neither, it renders Docus's own.
|
|
5
|
+
// The link has no `aria-label`, so its name is the wordmark it shows, as WCAG
|
|
6
|
+
// 2.5.3 asks: someone who says "click OpenComponents" reaches it.
|
|
5
7
|
import UxFrontMark from "@uxfront/ui/components/icons/UxFrontMark.vue";
|
|
6
8
|
import DocusAppHeaderLeft from "docus/app/components/app/AppHeaderLeft.vue";
|
|
7
9
|
|
|
8
10
|
const appConfig = useAppConfig();
|
|
9
|
-
const site = useSiteConfig();
|
|
10
11
|
const { localePath } = useDocusI18n();
|
|
11
12
|
|
|
12
13
|
const wordmark = computed(() => appConfig.docsTheme.wordmark);
|
|
13
|
-
const ariaLabel = computed(() => appConfig.header?.title || site.name);
|
|
14
14
|
</script>
|
|
15
15
|
|
|
16
16
|
<template>
|
|
17
17
|
<div class="docs-header-left">
|
|
18
|
-
<NuxtLink v-if="wordmark" :to="localePath('/')"
|
|
18
|
+
<NuxtLink v-if="wordmark" :to="localePath('/')" class="docs-wordmark">
|
|
19
19
|
<strong>{{ wordmark.bold }}</strong
|
|
20
20
|
>{{ wordmark.regular }}
|
|
21
21
|
</NuxtLink>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineNuxtModule } from "@nuxt/kit";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Takes `onServerPrefetch` off the list of composables Nuxt removes from the
|
|
5
|
+
* client build, so the browser registers the same hooks the server does.
|
|
6
|
+
*/
|
|
7
|
+
export function keepServerPrefetch(composables: Record<string, string[]>) {
|
|
8
|
+
for (const [source, names] of Object.entries(composables)) {
|
|
9
|
+
composables[source] = names.filter((name) => name !== "onServerPrefetch");
|
|
10
|
+
}
|
|
11
|
+
return composables;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Keeps the ids `useId` makes the same on the server and in the browser.
|
|
16
|
+
*
|
|
17
|
+
* Vue builds each id from the async boundaries above the component: every
|
|
18
|
+
* component with an async setup or an `onServerPrefetch` hook starts a new one.
|
|
19
|
+
* Nuxt removes `onServerPrefetch` calls from production client builds, since the
|
|
20
|
+
* browser never runs them, so a component that registers one, like the icons
|
|
21
|
+
* `@nuxt/icon` renders in CSS mode, is a boundary on the server and not in the
|
|
22
|
+
* browser. Every id after the docs header's first icon then changes as the page
|
|
23
|
+
* hydrates, and the Framework select, the sidebar's accordions and a page's tabs
|
|
24
|
+
* lose the elements their `aria-labelledby` and `aria-controls` point to.
|
|
25
|
+
* Development builds keep the calls, which is why only the built site shows it.
|
|
26
|
+
*
|
|
27
|
+
* It runs before Nuxt reads the list, when every module is set up.
|
|
28
|
+
*/
|
|
29
|
+
export default defineNuxtModule({
|
|
30
|
+
meta: { name: "hydration-ids" },
|
|
31
|
+
setup(_, nuxt) {
|
|
32
|
+
keepServerPrefetch(nuxt.options.optimization.treeShake.composables.client);
|
|
33
|
+
},
|
|
34
|
+
});
|
package/nuxt.config.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createResolver } from "@nuxt/kit";
|
|
2
|
+
|
|
3
|
+
const resolver = createResolver(import.meta.url);
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* `@uxfront/layer-docs`: the Nuxt side of UXFront's documentation sites.
|
|
3
7
|
*
|
|
@@ -8,20 +12,39 @@
|
|
|
8
12
|
* which shows the reader's pick. The app lists its frameworks in
|
|
9
13
|
* `docsTheme.frameworks` in its `app.config.ts`. It can also set the header's
|
|
10
14
|
* site name as a wordmark, signed "by UXFront" (`docsTheme.wordmark` and
|
|
11
|
-
* `docsTheme.byline`).
|
|
15
|
+
* `docsTheme.byline`). It names Docus's mobile menu toggle, and highlights code
|
|
16
|
+
* in GitHub's high-contrast themes, whose every colour reaches 4.5:1 on the code
|
|
17
|
+
* blocks' background. Its `hydration-ids` module keeps the ids `useId()` makes
|
|
18
|
+
* the same on the server and in the browser, so the select's label and the
|
|
19
|
+
* sidebar's accordions still find their elements once the prerendered page
|
|
20
|
+
* hydrates.
|
|
12
21
|
*
|
|
13
22
|
* https://nuxt.com/docs/getting-started/layers
|
|
14
23
|
*/
|
|
15
24
|
export default defineNuxtConfig({
|
|
16
25
|
extends: ["docus"],
|
|
17
26
|
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
modules: [resolver.resolve("./modules/hydration-ids")],
|
|
28
|
+
|
|
20
29
|
content: {
|
|
21
30
|
build: {
|
|
22
31
|
markdown: {
|
|
23
32
|
highlight: {
|
|
33
|
+
// The languages of the per-framework examples, on top of the ones Docus
|
|
34
|
+
// highlights (Vue, TypeScript, HTML, CSS, …). Nuxt merges these with the app's.
|
|
24
35
|
langs: ["tsx", "svelte", "angular-html", "angular-ts", "astro"],
|
|
36
|
+
// GitHub's high-contrast themes, since every token colour in them reaches
|
|
37
|
+
// 4.5:1 on the code blocks' background (Nuxt UI's neutral 50 and 800) for
|
|
38
|
+
// every neutral Nuxt UI offers: at least 4.81:1 in light mode and 6.89:1
|
|
39
|
+
// in dark mode (WCAG 1.4.3). The Material themes Nuxt UI sets otherwise
|
|
40
|
+
// go as low as 2.18:1. All three keys are set, since Shiki emits a `.light`
|
|
41
|
+
// rule that outranks `default`, so leaving `light` out would keep the old
|
|
42
|
+
// palette in light mode.
|
|
43
|
+
theme: {
|
|
44
|
+
default: "github-light-high-contrast",
|
|
45
|
+
light: "github-light-high-contrast",
|
|
46
|
+
dark: "github-dark-high-contrast",
|
|
47
|
+
},
|
|
25
48
|
},
|
|
26
49
|
},
|
|
27
50
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxfront/layer-docs",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "Nuxt layer for UXFront documentation sites: Docus, plus a framework switcher that shows every reader the examples for their framework, and the UXFront header wordmark.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"nuxt",
|
|
10
10
|
"nuxt-layer"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://uxfront.com",
|
|
13
13
|
"bugs": "https://github.com/uxfront-com/uxfront/issues",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"app",
|
|
22
|
+
"modules",
|
|
22
23
|
"nuxt.config.ts",
|
|
23
24
|
"README.md"
|
|
24
25
|
],
|
|
@@ -36,16 +37,21 @@
|
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@
|
|
40
|
+
"@nuxt/kit": "^4.5.2",
|
|
41
|
+
"@uxfront/ui": "^0.9.1",
|
|
40
42
|
"@vueuse/core": "^14.4.0",
|
|
41
43
|
"docus": "^5.13.0"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"nuxt": "^4.5.2",
|
|
47
|
+
"vitest": "^5.0.1",
|
|
45
48
|
"vue": "^3.5.43"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
51
|
"nuxt": "^4.5.0",
|
|
49
52
|
"vue": "^3.5.0"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"test": "vitest run"
|
|
50
56
|
}
|
|
51
57
|
}
|