@uxfront/layer-docs 0.7.1 → 0.8.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/README.md CHANGED
@@ -49,6 +49,63 @@ export default defineAppConfig({
49
49
 
50
50
  The wordmark links home, and its accessible name is Docus's `header.title`, or the site name. 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
+ ## Header links
53
+
54
+ Most docs sites link a few places from the header, like the docs themselves, a changelog or GitHub. List them in `docsTheme.headerLinks`, and the layer shows them beside the header's buttons from `768px` up, and at the top of the header's menu below that, where the buttons leave them no room:
55
+
56
+ ```ts
57
+ // app/app.config.ts
58
+ export default defineAppConfig({
59
+ docsTheme: {
60
+ headerLinks: [
61
+ { label: "Docs", to: "/docs/getting-started/introduction", activeFor: "/docs" },
62
+ { label: "GitHub", to: "https://github.com/uxfront-com/open-components", target: "_blank" },
63
+ ],
64
+ },
65
+ });
66
+ ```
67
+
68
+ Each link is a Nuxt UI navigation item:
69
+
70
+ | Key | Type | What it does |
71
+ | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
72
+ | `label` | `string` | The link's text. |
73
+ | `to` | `string` | Where it goes: a path on the site or a full URL. |
74
+ | `icon` | `string` | An [Iconify](https://icones.js.org) icon before the label, like `i-simple-icons-github`. |
75
+ | `target` | `string` | Where it opens, like `_blank`. |
76
+ | `activeFor` | `string` | A path the link stands for. It's marked active, with `aria-current="page"`, on that path and on every page below it, so `/docs` covers `/docs/a/b` too. |
77
+
78
+ Without `activeFor`, Nuxt UI decides, as for any link, which usually means on the page it points to and nowhere else. That's rarely what you want for a link to the docs, which points at one page but stands for all of them. Note that `/docs` doesn't cover `/docs-old`: a path counts as below it only after a `/`.
79
+
80
+ The layer ships no links of its own, since Nuxt adds app config arrays across layers instead of replacing them.
81
+
82
+ ### Composing your own header
83
+
84
+ The links and the Framework select are components of their own, so a site that replaces `AppHeaderCTA` or `AppHeaderBody` to add something of its own can compose them instead of copying them:
85
+
86
+ | Component | Props | What it renders |
87
+ | -------------------- | -------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
88
+ | `AppHeaderLinks` | `orientation`: `"horizontal"` or `"vertical"`. `items`: the links to render, `docsTheme.headerLinks` if unset. | The links, with `activeFor` applied. Its root carries `data-header-links`. |
89
+ | `AppHeaderFramework` | None. | The Framework label and select. Its root carries `data-header-framework`. |
90
+
91
+ `items` lets you split the links around a control of your own. To put a Version select between the docs link and GitHub, for example:
92
+
93
+ ```vue
94
+ <!-- app/components/app/AppHeaderCTA.vue -->
95
+ <script setup lang="ts">
96
+ const appConfig = useAppConfig();
97
+ const links = computed(() => appConfig.docsTheme.headerLinks ?? []);
98
+ </script>
99
+
100
+ <template>
101
+ <AppHeaderLinks :items="links.slice(0, -1)" orientation="horizontal" />
102
+ <AppVersionSelect />
103
+ <AppHeaderLinks :items="links.slice(-1)" orientation="horizontal" />
104
+ </template>
105
+ ```
106
+
107
+ Keep in mind that your override replaces the layer's whole, breakpoints included, so hide the links below `768px` yourself if your menu shows them there.
108
+
52
109
  ## Writing examples
53
110
 
54
111
  Put one slot per framework in a `::framework-switcher`:
@@ -88,9 +145,12 @@ export default defineNuxtConfig({
88
145
  ## What it adds
89
146
 
90
147
  - **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.
91
- - **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 select. It replaces Docus's `AppHeaderBody` and renders Docus's below it.
148
+ - **Header links.** `docsTheme.headerLinks` beside the header's buttons from `768px` up. It replaces Docus's `AppHeaderCTA`, which is empty.
149
+ - **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
+ - **`AppHeaderLinks` and `AppHeaderFramework`.** The links and the Framework select on their own, for a site that replaces `AppHeaderCTA` or `AppHeaderBody`.
92
151
  - **`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.
93
152
  - **A header wordmark and byline.** It replaces Docus's `AppHeaderLeft`, and renders Docus's unless the app sets a wordmark.
153
+ - **Typed app config.** `useAppConfig()` knows `docsTheme`, so `wordmark`, `byline` and `headerLinks` typecheck even in an app that leaves them unset.
94
154
  - **`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.
95
155
  - **Highlighting for the frameworks' languages.** `tsx`, `svelte`, `angular-html`, `angular-ts` and `astro`, on top of Docus's.
96
156
  - **Bundled icons.** Nuxt Icon bundles the icons named in app config too, so the select's icons don't come from the Iconify API.
@@ -1,19 +1,34 @@
1
1
  <script setup lang="ts">
2
- // Replaces Docus's to put the framework select above the navigation in the
3
- // header's menu, which stands in for the sidebar on smaller screens, as
4
- // DocsAsideLeftTop does above the sidebar. Docus's renders below it.
2
+ // Replaces Docus's to start the header's menu, which stands in for the sidebar
3
+ // on smaller screens, with `docsTheme.headerLinks` below 768px, where
4
+ // AppHeaderCTA hides them, and the framework select, as DocsAsideLeftTop puts
5
+ // it above the sidebar. Docus's renders below them.
5
6
  import DocusAppHeaderBody from "docus/app/components/app/AppHeaderBody.vue";
6
7
 
7
- const { frameworks } = useFramework();
8
- const labelId = useId();
8
+ const appConfig = useAppConfig();
9
9
  </script>
10
10
 
11
11
  <template>
12
- <div v-if="frameworks.length">
13
- <span :id="labelId" class="w-full pr-2.5 py-1.5 flex items-center text-sm text-muted">
14
- Framework
15
- </span>
16
- <DocsFrameworkSelect :aria-labelledby="labelId" class="mb-2" />
12
+ <!-- A wrapper of its own, as in AppHeaderCTA: the scoped attribute doesn't
13
+ reach AppHeaderLinks' root inside the menu. -->
14
+ <div v-if="appConfig.docsTheme.headerLinks?.length" class="docs-header-links">
15
+ <AppHeaderLinks orientation="vertical" />
17
16
  </div>
17
+ <AppHeaderFramework />
18
18
  <DocusAppHeaderBody />
19
19
  </template>
20
+
21
+ <style scoped>
22
+ /* Scoped CSS rather than Tailwind's `md:` utilities: Docus's stylesheet doesn't
23
+ list this layer among Tailwind's sources. The negative margin lines the
24
+ links' text up with the navigation's below. */
25
+ .docs-header-links {
26
+ margin: 0 -0.625rem 1rem;
27
+ }
28
+
29
+ @media (min-width: 768px) {
30
+ .docs-header-links {
31
+ display: none;
32
+ }
33
+ }
34
+ </style>
@@ -0,0 +1,28 @@
1
+ <script setup lang="ts">
2
+ // Replaces Docus's, which is empty, to put `docsTheme.headerLinks` beside the
3
+ // header's buttons from 768px up. Below that, they leave the buttons no room,
4
+ // so they're at the top of the header's menu instead (AppHeaderBody).
5
+ const appConfig = useAppConfig();
6
+ </script>
7
+
8
+ <template>
9
+ <!-- A wrapper of its own: in the copy of the bar that the opened menu shows,
10
+ the scoped attribute doesn't reach AppHeaderLinks' root. -->
11
+ <div v-if="appConfig.docsTheme.headerLinks?.length" class="docs-header-cta">
12
+ <AppHeaderLinks orientation="horizontal" />
13
+ </div>
14
+ </template>
15
+
16
+ <style scoped>
17
+ /* Scoped CSS rather than Tailwind's `md:` utilities: Docus's stylesheet doesn't
18
+ list this layer among Tailwind's sources. */
19
+ .docs-header-cta {
20
+ display: none;
21
+ }
22
+
23
+ @media (min-width: 768px) {
24
+ .docs-header-cta {
25
+ display: flex;
26
+ }
27
+ }
28
+ </style>
@@ -0,0 +1,15 @@
1
+ <script setup lang="ts">
2
+ // The Framework label and select, as the header's menu shows them, for a site
3
+ // that replaces AppHeaderBody and keeps the select.
4
+ const { frameworks } = useFramework();
5
+ const labelId = useId();
6
+ </script>
7
+
8
+ <template>
9
+ <div v-if="frameworks.length" data-header-framework>
10
+ <span :id="labelId" class="w-full pr-2.5 py-1.5 flex items-center text-sm text-muted">
11
+ Framework
12
+ </span>
13
+ <DocsFrameworkSelect :aria-labelledby="labelId" class="mb-2" />
14
+ </div>
15
+ </template>
@@ -0,0 +1,33 @@
1
+ <script setup lang="ts">
2
+ // The header's links, from `docsTheme.headerLinks`, or `items` for a site that
3
+ // splits them around controls of its own, like a Version select. A link with
4
+ // `activeFor` is active on that path and below it, so the docs link stays
5
+ // highlighted on every docs page, not only the one it points to.
6
+ import type { HeaderLink } from "../../composables/useFramework";
7
+
8
+ const props = defineProps<{
9
+ orientation: "horizontal" | "vertical";
10
+ /** The links to render, in place of `docsTheme.headerLinks`. */
11
+ items?: HeaderLink[];
12
+ }>();
13
+
14
+ const appConfig = useAppConfig();
15
+ const route = useRoute();
16
+
17
+ const links = computed(() =>
18
+ (props.items ?? appConfig.docsTheme.headerLinks ?? []).map(({ activeFor, ...link }) => {
19
+ if (activeFor === undefined) return link;
20
+ const active = route.path === activeFor || route.path.startsWith(`${activeFor}/`);
21
+ return { ...link, active, "aria-current": active ? ("page" as const) : undefined };
22
+ }),
23
+ );
24
+ </script>
25
+
26
+ <template>
27
+ <UNavigationMenu
28
+ v-if="links.length"
29
+ data-header-links
30
+ :items="links"
31
+ :orientation="orientation"
32
+ />
33
+ </template>
@@ -21,16 +21,50 @@ export interface DocsWordmark {
21
21
  regular: string;
22
22
  }
23
23
 
24
- declare module "nuxt/schema" {
24
+ /**
25
+ * A link in the docs header, beside its buttons and at the top of its menu: a
26
+ * Nuxt UI navigation item, plus the path it stands for.
27
+ */
28
+ export interface HeaderLink {
29
+ label: string;
30
+ to: string;
31
+ /** An Iconify icon, as `i-simple-icons-github`. */
32
+ icon?: string;
33
+ /** Where the link opens, as `_blank`. */
34
+ target?: string;
35
+ /**
36
+ * Marks the link active on this path and below it, as `/docs` does for
37
+ * `/docs/getting-started/introduction`. Without it, Nuxt UI decides, as for
38
+ * any link.
39
+ */
40
+ activeFor?: string;
41
+ }
42
+
43
+ /** `docsTheme`, as an app sets it. */
44
+ interface DocsThemeInput {
45
+ /** The frameworks the docs' examples come in, in display order. The first is the default. */
46
+ frameworks?: FrameworkOption[];
47
+ /** The header's site name, in place of Docus's plain-text title. */
48
+ wordmark?: DocsWordmark;
49
+ /** Signs the header's site name "by UXFront", linked to uxfront.com. */
50
+ byline?: boolean;
51
+ /** The header's links, beside its buttons from 768px up, and at the top of its menu below. */
52
+ headerLinks?: HeaderLink[];
53
+ }
54
+
55
+ // `@nuxt/schema`, which declares these interfaces, rather than `nuxt/schema`,
56
+ // which only re-exports them: an augmentation through the re-export doesn't
57
+ // reach the `AppConfig` that `useAppConfig()` returns.
58
+ declare module "@nuxt/schema" {
25
59
  interface AppConfigInput {
26
- docsTheme?: {
27
- /** The frameworks the docs' examples come in, in display order. The first is the default. */
28
- frameworks?: FrameworkOption[];
29
- /** The header's site name, in place of Docus's plain-text title. */
30
- wordmark?: DocsWordmark;
31
- /** Signs the header's site name "by UXFront", linked to uxfront.com. */
32
- byline?: boolean;
33
- };
60
+ docsTheme?: DocsThemeInput;
61
+ }
62
+
63
+ // Nuxt types app config from the values the app and its layers set, so a key
64
+ // the app leaves unset, like `wordmark`, wouldn't exist on `useAppConfig()`.
65
+ // The layer always sets `frameworks`, if only to an empty list.
66
+ interface CustomAppConfig {
67
+ docsTheme?: DocsThemeInput & { frameworks: FrameworkOption[] };
34
68
  }
35
69
  }
36
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxfront/layer-docs",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
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",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@uxfront/ui": "^0.5.0",
39
+ "@uxfront/ui": "^0.7.0",
40
40
  "@vueuse/core": "^14.4.0",
41
41
  "docus": "^5.13.0"
42
42
  },