igniteui-astro-components 1.6.0 → 1.8.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/README.md +322 -158
- package/llms-full.txt +3207 -0
- package/llms.txt +103 -0
- package/package.json +17 -5
- package/src/assets/icons/figma-logo.svg +10 -0
- package/src/code-theme/README.md +72 -0
- package/src/code-theme/index.ts +57 -0
- package/src/components/CopyCode/CopyCode.astro +6 -1
- package/src/components/CopyCode/README.md +38 -0
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +28 -30
- package/src/components/DocsSidebar/DocsSidebar.astro +14 -2
- package/src/components/DocsSidebar/README.md +58 -30
- package/src/components/DocsSidebar/SidebarLabel.astro +34 -36
- package/src/components/DocsSidebar/sidebar-filter.ts +53 -5
- package/src/components/DocsSidebar/toTreeNodes.ts +21 -5
- package/src/components/DocsSubHeader/DocsSubHeader.astro +22 -9
- package/src/components/DocsSubHeader/README.md +37 -31
- package/src/components/DocsToc/DocsToc.astro +12 -14
- package/src/components/DocsToc/README.md +7 -7
- package/src/components/DocsTree/DocsTree.astro +9 -11
- package/src/components/DocsTree/DocsTreeItem.astro +36 -40
- package/src/components/DocsTree/README.md +12 -9
- package/src/components/GlobalFooter/GlobalFooter.astro +6 -8
- package/src/components/GlobalNavBar/GlobalNavBar.astro +2 -4
- package/src/components/LicenseIndicator/LicenseIndicator.astro +6 -8
- package/src/components/MobileTocToggle/MobileTocToggle.astro +31 -33
- package/src/components/MobileTocToggle/README.md +45 -0
- package/src/components/Search/README.md +10 -10
- package/src/components/Search/Search.astro +12 -6
- package/src/components/SearchAdvanced/README.md +15 -8
- package/src/components/SearchAdvanced/SearchAdvanced.astro +17 -15
- package/src/components/ThemingWidget/ThemingWidget.astro +62 -60
- package/src/components/mdx/Anatomy/Anatomy.scss +1 -1
- package/src/components/mdx/Anatomy/README.md +40 -0
- package/src/components/mdx/ApiLink/ApiLink.astro +7 -9
- package/src/components/mdx/ApiLink/README.md +1 -0
- package/src/components/mdx/ApiRef/ApiRef.astro +7 -9
- package/src/components/mdx/ApiRef/README.md +1 -1
- package/src/components/mdx/Badge/Badge.astro +3 -1
- package/src/components/mdx/Badge/README.md +1 -3
- package/src/components/mdx/DocsAside/DocsAside.astro +3 -5
- package/src/components/mdx/DocsAside/README.md +47 -29
- package/src/components/mdx/Faq/Faq.astro +11 -13
- package/src/components/mdx/Faq/FaqItem.astro +20 -26
- package/src/components/mdx/FigmaUiKits/FigmaUiKits.astro +126 -0
- package/src/components/mdx/FigmaUiKits/FigmaUiKits.scss +165 -0
- package/src/components/mdx/FigmaUiKits/README.md +115 -0
- package/src/components/mdx/FigmaUiKits/kits.ts +26 -0
- package/src/components/mdx/PlatformBlock/README.md +5 -18
- package/src/components/mdx/Sample/README.md +67 -50
- package/src/components/mdx/Sample/Sample.astro +108 -33
- package/src/components/mdx/Sample/Sample.scss +38 -17
- package/src/integration.ts +6 -21
- package/src/layouts/DocsLayout/README.md +63 -28
- package/src/lib/warn-once.ts +8 -0
- package/src/scripts/copy-status.ts +35 -0
- package/src/scripts/icon-manifest.ts +1 -0
- package/src/scripts/sample-widget.ts +109 -42
- package/src/styles/global/_code-blocks.scss +58 -36
- package/src/styles/global/_copy-button.scss +18 -25
- package/src/styles/global/_markdown.scss +15 -8
- package/src/styles/global/_variables.scss +57 -0
- package/src/styles/theme.scss +4 -1
- package/src/virtual-modules.d.ts +2 -2
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# Sidebar suite
|
|
2
2
|
|
|
3
|
-
The sidebar is composed of
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
|
7
|
-
|
|
|
8
|
-
| `
|
|
9
|
-
| `
|
|
10
|
-
| `
|
|
11
|
-
| `
|
|
12
|
-
| `sidebar-
|
|
3
|
+
The sidebar is composed of a few focused pieces on top of the shared
|
|
4
|
+
[`DocsTree`](../DocsTree/README.md) component:
|
|
5
|
+
|
|
6
|
+
| File | Export path | Description |
|
|
7
|
+
| -------------------------- | --------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
8
|
+
| `DocsSidebar.astro` | `…/components/DocsSidebar/DocsSidebar.astro` | Composition root — logo, filter and the scrollable tree |
|
|
9
|
+
| `SidebarFilterInput.astro` | `…/components/DocsSidebar/SidebarFilterInput.astro` | Filter `<input>` markup (`data-sidebar-filter-*` hooks) |
|
|
10
|
+
| `SidebarLabel.astro` | `…/components/DocsSidebar/SidebarLabel.astro` | Label renderer passed to `DocsTree` (`node`, `depth`, `isLeaf`, `isActive`) |
|
|
11
|
+
| `toTreeNodes.ts` | `…/components/DocsSidebar/toTreeNodes` | `SidebarEntry[]` → `TreeNode[]` adapter |
|
|
12
|
+
| `sidebar-filter.ts` | `…/components/DocsSidebar/sidebar-filter` | `<sidebar-filter>` custom element |
|
|
13
|
+
| `sidebar-tooltip.ts` | (internal) | Full-text tooltip for truncated labels |
|
|
13
14
|
|
|
14
15
|
---
|
|
15
16
|
|
|
@@ -20,15 +21,20 @@ The only component you need to mount directly.
|
|
|
20
21
|
### Import
|
|
21
22
|
|
|
22
23
|
```astro
|
|
23
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
24
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
### Props
|
|
27
28
|
|
|
28
|
-
| Prop
|
|
29
|
-
|
|
|
30
|
-
| `currentSlug`
|
|
31
|
-
| `items`
|
|
29
|
+
| Prop | Type | Default | Description |
|
|
30
|
+
| -------------------- | ---------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `currentSlug` | `string` | `''` | Slug of the active page. Highlights the matching link and auto-expands ancestor groups. |
|
|
32
|
+
| `items` | `SidebarEntry[]` | virtual module | Sidebar tree to render. **Overrides** the `virtual:docs-template/site-meta` value when provided. Use this when not running `siteMetaIntegration`. |
|
|
33
|
+
| `showFilter` | `boolean` | `true` | Render the filter input above the tree. |
|
|
34
|
+
| `trailingSlash` | `boolean` | from Astro config | Append a trailing slash to generated links. Derived from the site's `trailingSlash` setting via the virtual module; `true` when unknown. |
|
|
35
|
+
| `logoText` | `string` | product family | Text in the slide-in sidebar's logo area. |
|
|
36
|
+
| `platformLabel` | `string \| null` | from virtual module | Platform label under the logo text (for example `'Angular'`). Pass `null` to hide it. |
|
|
37
|
+
| `singleBranchExpand` | `boolean` | `true` | Keep one branch open: only the current page's groups start open and expanding a group collapses the others. The filter still opens every match. With the default, a group's `collapsed` is ignored; set `false` to honour `collapsed`. |
|
|
32
38
|
|
|
33
39
|
### Example
|
|
34
40
|
|
|
@@ -36,14 +42,13 @@ import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSideba
|
|
|
36
42
|
|
|
37
43
|
```astro
|
|
38
44
|
---
|
|
39
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
45
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
40
46
|
import type { SidebarEntry } from 'igniteui-astro-components/lib/sidebar/types';
|
|
41
47
|
|
|
42
48
|
// Define the tree inline or import from a shared config file.
|
|
43
49
|
const sidebar: SidebarEntry[] = [
|
|
44
50
|
{
|
|
45
51
|
label: 'Getting Started',
|
|
46
|
-
collapsed: false,
|
|
47
52
|
items: [
|
|
48
53
|
{ label: 'Introduction', slug: '' },
|
|
49
54
|
{ label: 'Installation', slug: 'installation' },
|
|
@@ -51,13 +56,12 @@ const sidebar: SidebarEntry[] = [
|
|
|
51
56
|
},
|
|
52
57
|
{
|
|
53
58
|
label: 'Components',
|
|
54
|
-
collapsed: false,
|
|
55
59
|
items: [
|
|
56
60
|
{ label: 'Toast', slug: 'components/toast' },
|
|
57
61
|
{
|
|
58
62
|
label: 'Calendar',
|
|
59
63
|
slug: 'components/calendar',
|
|
60
|
-
|
|
64
|
+
badges: [{ text: 'New', variant: 'new' }],
|
|
61
65
|
},
|
|
62
66
|
],
|
|
63
67
|
},
|
|
@@ -83,7 +87,7 @@ When `createDocsSite()` / `siteMetaIntegration()` is configured, omit
|
|
|
83
87
|
|
|
84
88
|
```astro
|
|
85
89
|
---
|
|
86
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
90
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
87
91
|
---
|
|
88
92
|
|
|
89
93
|
<DocsSidebar currentSlug="components/toast" />
|
|
@@ -120,7 +124,7 @@ module:
|
|
|
120
124
|
// astro.config.ts
|
|
121
125
|
import { buildSidebarFromToc, siteMetaIntegration } from 'igniteui-astro-components/integration';
|
|
122
126
|
|
|
123
|
-
const sidebar = buildSidebarFromToc({ tocPath: './docs/toc.
|
|
127
|
+
const sidebar = buildSidebarFromToc({ tocPath: './docs/toc.json', docsDir: './docs/en' });
|
|
124
128
|
|
|
125
129
|
export default defineConfig({
|
|
126
130
|
integrations: [siteMetaIntegration({ title: 'My Docs', sidebar })],
|
|
@@ -129,23 +133,32 @@ export default defineConfig({
|
|
|
129
133
|
|
|
130
134
|
### SidebarEntry type
|
|
131
135
|
|
|
136
|
+
Import from `igniteui-astro-components/lib/sidebar/types`; the file is the
|
|
137
|
+
source of truth, this is a summary:
|
|
138
|
+
|
|
132
139
|
```ts
|
|
140
|
+
type SidebarBadge = { text: string; variant: 'new' | 'updated' | 'preview' | 'premium' };
|
|
141
|
+
|
|
133
142
|
type SidebarLink = {
|
|
134
143
|
label: string;
|
|
135
144
|
slug: string;
|
|
136
|
-
|
|
145
|
+
badges?: SidebarBadge[];
|
|
137
146
|
attrs?: Record<string, string | boolean | undefined>;
|
|
138
147
|
};
|
|
139
148
|
|
|
140
149
|
type SidebarGroup = {
|
|
141
150
|
label: string;
|
|
142
|
-
collapsed?: boolean; //
|
|
151
|
+
collapsed?: boolean; // closed by default when true; read only with singleBranchExpand={false}
|
|
143
152
|
items: SidebarEntry[];
|
|
144
153
|
};
|
|
145
154
|
|
|
146
155
|
type SidebarEntry = SidebarLink | SidebarGroup;
|
|
147
156
|
```
|
|
148
157
|
|
|
158
|
+
`SIDEBAR_BADGE_VARIANTS` is exported from the same module. Helpers such as
|
|
159
|
+
`isGroup`, `isActive`, `getBreadcrumb` and `joinPath` live in
|
|
160
|
+
`igniteui-astro-components/lib/sidebar/helpers`.
|
|
161
|
+
|
|
149
162
|
### Filter behaviour
|
|
150
163
|
|
|
151
164
|
The `<sidebar-filter>` custom element handles live filtering:
|
|
@@ -168,15 +181,30 @@ clamped and the tooltip is not shown.
|
|
|
168
181
|
|
|
169
182
|
---
|
|
170
183
|
|
|
171
|
-
##
|
|
184
|
+
## Building a custom sidebar
|
|
172
185
|
|
|
173
|
-
|
|
186
|
+
`DocsSidebar` converts `SidebarEntry[]` to `TreeNode[]` with `toTreeNodes()`
|
|
187
|
+
and renders them through `DocsTree` with `SidebarLabel` as the label renderer.
|
|
188
|
+
To build your own layout, reuse those pieces:
|
|
174
189
|
|
|
175
190
|
```astro
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
---
|
|
192
|
+
import DocsTree from 'igniteui-astro-components/components/DocsTree/DocsTree.astro';
|
|
193
|
+
import SidebarLabel from 'igniteui-astro-components/components/DocsSidebar/SidebarLabel.astro';
|
|
194
|
+
import { toTreeNodes } from 'igniteui-astro-components/components/DocsSidebar/toTreeNodes';
|
|
195
|
+
import { normalizeSlug } from 'igniteui-astro-components/lib/sidebar/helpers';
|
|
196
|
+
|
|
197
|
+
const nodes = toTreeNodes(sidebar, currentSlug, { trailingSlash: true });
|
|
198
|
+
---
|
|
179
199
|
|
|
180
|
-
|
|
200
|
+
<DocsTree
|
|
201
|
+
nodes={nodes}
|
|
202
|
+
variant="sidebar"
|
|
203
|
+
activeId={normalizeSlug(currentSlug)}
|
|
204
|
+
toggleNodeOnClick
|
|
205
|
+
renderLabel={SidebarLabel}
|
|
206
|
+
/>
|
|
207
|
+
```
|
|
181
208
|
|
|
182
|
-
|
|
209
|
+
See the [DocsTree README](../DocsTree/README.md) for the `TreeNode` shape and
|
|
210
|
+
the `--docs-tree-*` styling tokens.
|
|
@@ -26,41 +26,39 @@ const { node, isLeaf } = Astro.props;
|
|
|
26
26
|
const badges = (node.meta?.badges ?? []) as SidebarBadge[];
|
|
27
27
|
---
|
|
28
28
|
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.map((badge) => (
|
|
39
|
-
<>
|
|
40
|
-
<Badge variant={badge.variant} class="sidebar-badge" aria-hidden="true">
|
|
41
|
-
<span>{badge.text}</span>
|
|
42
|
-
</Badge>
|
|
43
|
-
<span class="visually-hidden">, {badge.text}</span>
|
|
44
|
-
</>
|
|
45
|
-
))}
|
|
46
|
-
{badges.some((b) => b.variant === 'premium') && (
|
|
29
|
+
{isLeaf ? (
|
|
30
|
+
<>
|
|
31
|
+
<div class="igd-label-and-badge">
|
|
32
|
+
<span class="docs-tree-label">{node.label}</span>
|
|
33
|
+
{badges.length > 0 && (
|
|
34
|
+
<div class="igd-badge-container">
|
|
35
|
+
{badges
|
|
36
|
+
.filter((b) => b.variant !== 'premium')
|
|
37
|
+
.map((badge) => (
|
|
47
38
|
<>
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
aria-hidden="true"
|
|
53
|
-
/>
|
|
54
|
-
<span class="visually-hidden">, Premium</span>
|
|
39
|
+
<Badge variant={badge.variant} class="sidebar-badge" aria-hidden="true">
|
|
40
|
+
<span>{badge.text}</span>
|
|
41
|
+
</Badge>
|
|
42
|
+
<span class="visually-hidden">, {badge.text}</span>
|
|
55
43
|
</>
|
|
56
|
-
)}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
))}
|
|
45
|
+
{badges.some((b) => b.variant === 'premium') && (
|
|
46
|
+
<>
|
|
47
|
+
<igc-icon
|
|
48
|
+
name="premium"
|
|
49
|
+
collection="docs"
|
|
50
|
+
class="sidebar-premium-icon"
|
|
51
|
+
aria-hidden="true"
|
|
52
|
+
/>
|
|
53
|
+
<span class="visually-hidden">, Premium</span>
|
|
54
|
+
</>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
</>
|
|
60
|
+
) : (
|
|
61
|
+
<span class="group-label-text">
|
|
62
|
+
<span>{node.label}</span>
|
|
63
|
+
</span>
|
|
64
|
+
)}
|
|
@@ -75,8 +75,13 @@ const collectExpandedKeys = (root: ParentNode): string[] => {
|
|
|
75
75
|
/**
|
|
76
76
|
* Apply expanded state using setAttribute / removeAttribute.
|
|
77
77
|
* Used ONLY in astro:before-swap on not-yet-upgraded DOM nodes.
|
|
78
|
+
* With `onlyActiveBranch`, the saved keys are ignored.
|
|
78
79
|
*/
|
|
79
|
-
const applyExpandedAttr = (
|
|
80
|
+
const applyExpandedAttr = (
|
|
81
|
+
root: ParentNode,
|
|
82
|
+
openKeys: Set<string>,
|
|
83
|
+
onlyActiveBranch: boolean,
|
|
84
|
+
): void => {
|
|
80
85
|
root.querySelectorAll<HTMLElement>(GROUP_SELECTOR).forEach((el) => {
|
|
81
86
|
// Always keep ancestors of the active page open.
|
|
82
87
|
if (el.querySelector('a[aria-current="page"]')) {
|
|
@@ -84,7 +89,7 @@ const applyExpandedAttr = (root: ParentNode, openKeys: Set<string>): void => {
|
|
|
84
89
|
return;
|
|
85
90
|
}
|
|
86
91
|
const key = el.dataset.groupKey;
|
|
87
|
-
if (key && openKeys.has(key)) el.setAttribute('expanded', '');
|
|
92
|
+
if (!onlyActiveBranch && key && openKeys.has(key)) el.setAttribute('expanded', '');
|
|
88
93
|
else el.removeAttribute('expanded');
|
|
89
94
|
});
|
|
90
95
|
};
|
|
@@ -115,13 +120,20 @@ document.addEventListener('astro:before-swap', (e) => {
|
|
|
115
120
|
const newScroll = newDoc.querySelector<HTMLElement>(SCROLL_SELECTOR);
|
|
116
121
|
if (newScroll) newScroll.style.visibility = 'hidden';
|
|
117
122
|
|
|
123
|
+
// Single-branch: the new page's branch replaces the saved one, unless the
|
|
124
|
+
// filter carries over and keeps every group it opened.
|
|
125
|
+
const onlyActiveBranch =
|
|
126
|
+
!!newDoc.querySelector('sidebar-filter[data-single-branch-expand]') &&
|
|
127
|
+
!!newDoc.querySelector(`${GROUP_SELECTOR} a[aria-current="page"]`) &&
|
|
128
|
+
!safeGet(FILTER_KEY);
|
|
129
|
+
|
|
118
130
|
const raw = safeGet(DETAILS_KEY);
|
|
119
|
-
applyExpandedAttr(newDoc, new Set(raw ? raw.split('\n').filter(Boolean) : []));
|
|
131
|
+
applyExpandedAttr(newDoc, new Set(raw ? raw.split('\n').filter(Boolean) : []), onlyActiveBranch);
|
|
120
132
|
});
|
|
121
133
|
|
|
122
134
|
// ── Custom element ───────────────────────────────────────────────────────────
|
|
123
135
|
|
|
124
|
-
type ExpandableEl = HTMLElement & { expanded: boolean };
|
|
136
|
+
type ExpandableEl = HTMLElement & { expanded: boolean; collapseWithEvent(): Promise<void> };
|
|
125
137
|
type FilterInputEl = HTMLElement & { value: string; focus(): void };
|
|
126
138
|
type FilterClearEl = HTMLElement & { hidden: boolean };
|
|
127
139
|
|
|
@@ -185,6 +197,7 @@ class SidebarFilter extends HTMLElement {
|
|
|
185
197
|
// the igc-tree-item instance in event.detail — NOT in e.target.
|
|
186
198
|
this.addEventListener('igcItemExpanded', this.onItemToggle as EventListener);
|
|
187
199
|
this.addEventListener('igcItemCollapsed', this.onItemToggle as EventListener);
|
|
200
|
+
this.addEventListener('igcItemExpanding', this.onItemExpanding as EventListener);
|
|
188
201
|
}
|
|
189
202
|
|
|
190
203
|
private onFilterInput = (): void => {
|
|
@@ -259,6 +272,22 @@ class SidebarFilter extends HTMLElement {
|
|
|
259
272
|
safeSet(DETAILS_KEY, [...keys].join('\n'));
|
|
260
273
|
};
|
|
261
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Single-branch: a user expand collapses every open group outside the new
|
|
277
|
+
* branch. igc-tree's own `singleBranchExpand` isn't used: turning it on
|
|
278
|
+
* collapses every group, the current page's included, and while filtering
|
|
279
|
+
* the next expand would collapse the groups the filter opened.
|
|
280
|
+
*/
|
|
281
|
+
private onItemExpanding = (e: Event): void => {
|
|
282
|
+
// While filtering, every group with a match stays open.
|
|
283
|
+
if (!this.singleBranch || this.openSnapshot) return;
|
|
284
|
+
|
|
285
|
+
const item = (e as CustomEvent<HTMLElement>).detail;
|
|
286
|
+
for (const el of this.groups as ExpandableEl[]) {
|
|
287
|
+
if (el.expanded && !el.contains(item)) void el.collapseWithEvent();
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
262
291
|
private syncSnapshotAttr(): void {
|
|
263
292
|
if (this.openSnapshot) this.dataset.openSnapshot = [...this.openSnapshot].join('\n');
|
|
264
293
|
else delete this.dataset.openSnapshot;
|
|
@@ -384,7 +413,11 @@ class SidebarFilter extends HTMLElement {
|
|
|
384
413
|
// Clear match marks — CSS restores visibility automatically.
|
|
385
414
|
for (const el of this.items) delete el.dataset.filterMatch;
|
|
386
415
|
|
|
387
|
-
|
|
416
|
+
// Single-branch: return to the current page's branch, not to the groups
|
|
417
|
+
// that were open before filtering, which may be a second branch.
|
|
418
|
+
const restore = this.singleBranch
|
|
419
|
+
? this.activeBranchKeys()
|
|
420
|
+
: (this.preFilterSnapshot ?? this.openSnapshot);
|
|
388
421
|
if (restore) {
|
|
389
422
|
this.withSuppressed(() => this.setExpandedState(restore!));
|
|
390
423
|
safeSet(DETAILS_KEY, [...restore].join('\n'));
|
|
@@ -462,6 +495,21 @@ class SidebarFilter extends HTMLElement {
|
|
|
462
495
|
}
|
|
463
496
|
}
|
|
464
497
|
|
|
498
|
+
private get singleBranch(): boolean {
|
|
499
|
+
return this.hasAttribute('data-single-branch-expand');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Keys of the groups that contain the active page. */
|
|
503
|
+
private activeBranchKeys(): Set<string> {
|
|
504
|
+
const keys = new Set<string>();
|
|
505
|
+
for (const el of this.groups) {
|
|
506
|
+
if (el.dataset.groupKey && el.querySelector('a[aria-current="page"]')) {
|
|
507
|
+
keys.add(el.dataset.groupKey);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return keys;
|
|
511
|
+
}
|
|
512
|
+
|
|
465
513
|
private ensureActiveAncestorsExpanded(): void {
|
|
466
514
|
const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
|
|
467
515
|
if (!active) return;
|
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
import type { TreeNode } from '../DocsTree/types';
|
|
16
16
|
import type { SidebarEntry } from '../../lib/sidebar/types';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
hasActive,
|
|
19
|
+
isGroup,
|
|
20
|
+
isInitiallyOpen,
|
|
21
|
+
joinPath,
|
|
22
|
+
normalizeSlug,
|
|
23
|
+
} from '../../lib/sidebar/helpers';
|
|
18
24
|
|
|
19
25
|
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
20
26
|
|
|
@@ -33,16 +39,20 @@ const toNode = (
|
|
|
33
39
|
ancestors: string[],
|
|
34
40
|
currentSlug: string,
|
|
35
41
|
trailingSlash: boolean,
|
|
42
|
+
singleBranch: boolean,
|
|
36
43
|
): TreeNode => {
|
|
37
44
|
const path = joinPath(ancestors, entry.label);
|
|
38
45
|
|
|
39
46
|
if (isGroup(entry)) {
|
|
47
|
+
const expanded = singleBranch
|
|
48
|
+
? hasActive(entry.items, currentSlug)
|
|
49
|
+
: isInitiallyOpen(entry, currentSlug);
|
|
40
50
|
return {
|
|
41
51
|
id: path,
|
|
42
52
|
label: entry.label,
|
|
43
|
-
expanded:
|
|
53
|
+
expanded: expanded || undefined,
|
|
44
54
|
children: entry.items.map((child) =>
|
|
45
|
-
toNode(child, [...ancestors, entry.label], currentSlug, trailingSlash),
|
|
55
|
+
toNode(child, [...ancestors, entry.label], currentSlug, trailingSlash, singleBranch),
|
|
46
56
|
),
|
|
47
57
|
itemData: {
|
|
48
58
|
path,
|
|
@@ -69,10 +79,16 @@ const toNode = (
|
|
|
69
79
|
export interface ToTreeNodesOptions {
|
|
70
80
|
/** Append trailing slash to sidebar links. Defaults to `true`. */
|
|
71
81
|
trailingSlash?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Open only the groups that contain the current page, ignoring each
|
|
84
|
+
* group's `collapsed` flag. Defaults to `false`.
|
|
85
|
+
*/
|
|
86
|
+
singleBranch?: boolean;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
export const toTreeNodes = (
|
|
75
90
|
entries: SidebarEntry[],
|
|
76
91
|
currentSlug: string,
|
|
77
|
-
{ trailingSlash = true }: ToTreeNodesOptions = {},
|
|
78
|
-
): TreeNode[] =>
|
|
92
|
+
{ trailingSlash = true, singleBranch = false }: ToTreeNodesOptions = {},
|
|
93
|
+
): TreeNode[] =>
|
|
94
|
+
entries.map((entry) => toNode(entry, [], currentSlug, trailingSlash, singleBranch));
|
|
@@ -73,8 +73,11 @@ interface Props {
|
|
|
73
73
|
* Items for the package/platform selector dropdown. When omitted the selector is hidden.
|
|
74
74
|
* Each entry is either a plain string label, or an object with a `label`, optional `value`
|
|
75
75
|
* (defaults to `label`), and optional `href` to navigate to when selected.
|
|
76
|
+
* Set `base` to the root URL of the entry's docs site to keep the reader on the current
|
|
77
|
+
* page: selecting the entry goes to the current URL with this site's base swapped for `base`.
|
|
78
|
+
* Nothing checks that the page exists there; redirect missing pages on the server.
|
|
76
79
|
*/
|
|
77
|
-
packages?: Array<string | { label: string; value?: string; href?: string }>;
|
|
80
|
+
packages?: Array<string | { label: string; value?: string; href?: string; base?: string }>;
|
|
78
81
|
/** Currently selected package value (must match one of `packages`). */
|
|
79
82
|
selectedPackage?: string;
|
|
80
83
|
/** Label rendered before the package selector. Defaults to `'Package'`. */
|
|
@@ -117,12 +120,12 @@ const resolvedSiteTitle = siteTitleProp ?? siteTitle;
|
|
|
117
120
|
const currentPlatform = virtualPlatform ?? null;
|
|
118
121
|
const resolvedLinks = (productLinksProp ?? productLinks) as ProductLink[];
|
|
119
122
|
const filteredLinks = resolvedLinks.filter((l: ProductLink) => l.platform !== currentPlatform);
|
|
120
|
-
type PackageEntry = string | { label: string; value?: string; href?: string };
|
|
123
|
+
type PackageEntry = string | { label: string; value?: string; href?: string; base?: string };
|
|
121
124
|
const rawPackages = packagesProp ?? (virtualPackages?.length > 0 ? virtualPackages : undefined);
|
|
122
125
|
const packages = (rawPackages as PackageEntry[] | undefined)?.map((p: PackageEntry) =>
|
|
123
126
|
typeof p === 'string'
|
|
124
|
-
? { label: p, value: p, href: undefined }
|
|
125
|
-
: { label: p.label, value: p.value ?? p.label, href: p.href },
|
|
127
|
+
? { label: p, value: p, href: undefined, base: undefined }
|
|
128
|
+
: { label: p.label, value: p.value ?? p.label, href: p.href, base: p.base },
|
|
126
129
|
);
|
|
127
130
|
const selectedPackage =
|
|
128
131
|
selectedPackageProp ?? (virtualSelectedPackage || undefined) ?? packages?.[0]?.value;
|
|
@@ -181,7 +184,7 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
181
184
|
{packages.map((p) => {
|
|
182
185
|
const icon = getPlatformIcon(p.value ?? '') ?? getPlatformIcon(p.label ?? '');
|
|
183
186
|
return (
|
|
184
|
-
<igc-select-item value={p.value} data-href={p.href}>
|
|
187
|
+
<igc-select-item value={p.value} data-href={p.href} data-base={p.base}>
|
|
185
188
|
{icon && (
|
|
186
189
|
<igc-icon slot="prefix" name={icon} collection="docs" aria-hidden="true" />
|
|
187
190
|
)}
|
|
@@ -233,6 +236,18 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
233
236
|
</docs-subheader-menu>
|
|
234
237
|
|
|
235
238
|
<script>
|
|
239
|
+
/**
|
|
240
|
+
* Where selecting a package entry should navigate. With a `base` (root URL of the entry's
|
|
241
|
+
* docs site) it is this page's URL with the site's own base swapped for the entry's; the
|
|
242
|
+
* server handles a page that does not exist there. Otherwise it is the entry's `href`.
|
|
243
|
+
*/
|
|
244
|
+
function packageHref({ href, base }: DOMStringMap): string | undefined {
|
|
245
|
+
const currentBase = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
246
|
+
const { pathname, search, hash } = window.location;
|
|
247
|
+
if (!base || !pathname.startsWith(currentBase)) return href;
|
|
248
|
+
return `${base.replace(/\/$/, '')}${pathname.slice(currentBase.length)}${search}${hash}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
236
251
|
if (!customElements.get('docs-subheader-menu')) {
|
|
237
252
|
class DocsSubHeaderMenu extends HTMLElement {
|
|
238
253
|
connectedCallback() {
|
|
@@ -276,7 +291,7 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
276
291
|
const item = packageSelect.querySelector<HTMLElement>(
|
|
277
292
|
`igc-select-item[value="${val}"]`,
|
|
278
293
|
);
|
|
279
|
-
const href = item
|
|
294
|
+
const href = item && packageHref(item.dataset);
|
|
280
295
|
if (href) window.location.href = href;
|
|
281
296
|
// Sync tooltip content with the new selection label
|
|
282
297
|
if (packageTooltip) {
|
|
@@ -387,12 +402,10 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
387
402
|
function initSelectors() {
|
|
388
403
|
const packageSelect = document.querySelector('#package-select');
|
|
389
404
|
if (packageSelect) {
|
|
405
|
+
// Navigation on change is handled by <docs-subheader-menu>.
|
|
390
406
|
packageSelect.addEventListener('igcChange', (e: Event) => {
|
|
391
407
|
const val = (e as CustomEvent).detail?.value ?? (packageSelect as any).value;
|
|
392
|
-
const item = packageSelect.querySelector<HTMLElement>(`igc-select-item[value="${val}"]`);
|
|
393
408
|
syncTriggerIcon(packageSelect, val);
|
|
394
|
-
const href = item?.dataset?.href;
|
|
395
|
-
if (href) window.location.href = href;
|
|
396
409
|
});
|
|
397
410
|
}
|
|
398
411
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# DocsSubHeader
|
|
2
2
|
|
|
3
|
-
Secondary fixed header bar rendered below the `GlobalNavBar`. Contains the
|
|
3
|
+
Secondary fixed header bar rendered below the `GlobalNavBar`. Contains the logo, the search button and the package and version selectors.
|
|
4
4
|
|
|
5
5
|
> **Note:** The breadcrumb trail was extracted into the standalone [`DocsBreadcrumb`](../DocsBreadcrumb/README.md) component and is now rendered inside the main content frame, above the page body — not in this bar.
|
|
6
6
|
|
|
@@ -12,18 +12,32 @@ import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.as
|
|
|
12
12
|
|
|
13
13
|
## Props
|
|
14
14
|
|
|
15
|
-
| Prop | Type
|
|
16
|
-
| ----------------- |
|
|
17
|
-
| `
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
20
|
-
| `
|
|
21
|
-
| `
|
|
22
|
-
| `
|
|
23
|
-
| `
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
| Prop | Type | Default | Description |
|
|
16
|
+
| ----------------- | ---------------------------------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `logoText` | `string` | by platform | Text shown in the logo area while `GlobalNavBar` is visible; `'Ignite UI'` or `'Ultimate UI'` by default. |
|
|
18
|
+
| `packages` | `Array<string \| { label: string; value?: string; href?: string; base?: string }>` | virtual module | Entries for the package selector. A string is both label and value; `href` navigates on selection; `base` swaps the site base to keep the current page. Falls back to the virtual module's `packages`; the selector is hidden only when both are empty. |
|
|
19
|
+
| `selectedPackage` | `string` | virtual module | Currently selected package (must match one of `packages`). Falls back to the virtual module's `selectedPackage`, then to the first entry. |
|
|
20
|
+
| `packageLabel` | `string` | `'Package'` | `aria-label` of the package selector (not a visible label). |
|
|
21
|
+
| `versions` | `string[]` | — | Version labels for the version selector dropdown. Hidden when omitted. |
|
|
22
|
+
| `selectedVersion` | `string` | — | Currently selected version (must match one of `versions`). |
|
|
23
|
+
| `versionLabel` | `string` | `'Version'` | `aria-label` of the version selector (not a visible label). |
|
|
24
|
+
|
|
25
|
+
Accepted but not rendered (kept for compatibility; see the DocsSubHeader dead-props issue):
|
|
26
|
+
|
|
27
|
+
| Prop | Why it has no effect |
|
|
28
|
+
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
29
|
+
| `siteTitle`, `pageTitle`, `currentSlug`, `sidebarItems` | Breadcrumb inputs. The breadcrumb moved to `DocsBreadcrumb`; the sub-header computes the crumbs and discards them. |
|
|
30
|
+
| `productLinks` | The product-links markup is commented out. |
|
|
31
|
+
| `showThemeToggle`, `themeStorageKey` | Destructured and never used. No toggle is rendered; `DocsLayout` hard-codes the `'docs-theme'` storage key. |
|
|
32
|
+
|
|
33
|
+
`PackageEntry` is `{ label: string; value?: string; href?: string; base?: string }`:
|
|
34
|
+
|
|
35
|
+
| Field | Description |
|
|
36
|
+
| ------- | -------------------------------------------------------------------------------- |
|
|
37
|
+
| `label` | Text shown in the dropdown. |
|
|
38
|
+
| `value` | Value matched against `selectedPackage`. Defaults to `label`. |
|
|
39
|
+
| `href` | Where selecting the entry navigates, e.g. the platform's getting started page. |
|
|
40
|
+
| `base` | Root URL of the entry's docs site. Switching keeps the current page (see below). |
|
|
27
41
|
|
|
28
42
|
## Slots
|
|
29
43
|
|
|
@@ -33,32 +47,27 @@ import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.as
|
|
|
33
47
|
|
|
34
48
|
## Behaviour
|
|
35
49
|
|
|
36
|
-
-
|
|
50
|
+
- Selecting a package navigates to its `href`. When the entry also has a `base`, it goes to the same
|
|
51
|
+
page on that site instead: the current URL with this site's base (`import.meta.env.BASE_URL`)
|
|
52
|
+
swapped for `base`, keeping the query and `#hash`. Nothing checks that the page exists there, so
|
|
53
|
+
the server should redirect missing pages, e.g. to the platform's getting started page.
|
|
37
54
|
- The search button opens the Pagefind dialog (see `Search` component).
|
|
38
|
-
-
|
|
39
|
-
- `--docs-global-nav-height` (default `4.7rem`) — height of the `GlobalNavBar` above
|
|
40
|
-
- `--docs-subheader-height` (default `2.5rem`) — height of this bar
|
|
55
|
+
- `DocsLayout` sets `--docs-global-nav-height` on the wrapper from the measured nav height; no stylesheet in this package reads it or `--docs-subheader-height`.
|
|
41
56
|
|
|
42
57
|
## Example
|
|
43
58
|
|
|
44
59
|
```astro
|
|
45
60
|
---
|
|
46
61
|
import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.astro';
|
|
47
|
-
|
|
48
|
-
const productLinks = [
|
|
49
|
-
{ label: 'Angular', href: '/angular/', platform: 'angular' },
|
|
50
|
-
{ label: 'React', href: '/react/', platform: 'react' },
|
|
51
|
-
{ label: 'Web Components', href: '/web-components/', platform: 'web-components' },
|
|
52
|
-
];
|
|
53
62
|
---
|
|
54
63
|
|
|
55
|
-
<DocsSubHeader
|
|
64
|
+
<DocsSubHeader />
|
|
56
65
|
```
|
|
57
66
|
|
|
58
67
|
This component is used automatically inside `DocsLayout` — you only need to
|
|
59
68
|
mount it directly when building a custom page shell.
|
|
60
69
|
|
|
61
|
-
### With package/version selectors
|
|
70
|
+
### With package/version selectors
|
|
62
71
|
|
|
63
72
|
```astro
|
|
64
73
|
---
|
|
@@ -67,20 +76,17 @@ import SearchAdvanced from 'igniteui-astro-components/components/SearchAdvanced.
|
|
|
67
76
|
---
|
|
68
77
|
|
|
69
78
|
<DocsSubHeader
|
|
70
|
-
siteTitle="Ignite UI for Angular"
|
|
71
79
|
packages={['igniteui-angular', 'igniteui-charts']}
|
|
72
80
|
selectedPackage="igniteui-angular"
|
|
73
81
|
packageLabel="Package"
|
|
74
82
|
versions={['19.1 (latest)', '18.2', '18.1']}
|
|
75
83
|
selectedVersion="19.1 (latest)"
|
|
76
84
|
versionLabel="Version"
|
|
77
|
-
showThemeToggle
|
|
78
|
-
themeStorageKey="api-docs-theme"
|
|
79
|
-
productLinks={[]}
|
|
80
85
|
>
|
|
81
86
|
<SearchAdvanced slot="search" showScope tabs={[]} />
|
|
82
87
|
</DocsSubHeader>
|
|
83
88
|
```
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
`#package-select` and `#version-select` are `igc-select` elements and emit
|
|
91
|
+
`igcChange` (not a native `change` event); attach your own navigation logic
|
|
92
|
+
via `document.getElementById`.
|