igniteui-astro-components 0.0.15 → 0.0.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "igniteui-astro-components",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Reusable Astro components, layouts, and integrations for Infragistics / Ignite UI documentation sites. Replaces the Starlight defaults with project-specific implementations.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -43,6 +43,7 @@
43
43
  "./components/GlobalNavBar.astro": "./src/components/GlobalNavBar/GlobalNavBar.astro",
44
44
  "./components/GlobalFooter.astro": "./src/components/GlobalFooter/GlobalFooter.astro",
45
45
  "./components/DocsSubHeader.astro": "./src/components/DocsSubHeader/DocsSubHeader.astro",
46
+ "./components/CopyCode.astro": "./src/components/CopyCode/CopyCode.astro",
46
47
  "./components/Search.astro": "./src/components/Search/Search.astro",
47
48
  "./components/SearchAdvanced.astro": "./src/components/SearchAdvanced/SearchAdvanced.astro",
48
49
  "./components/ThemingWidget.astro": "./src/components/ThemingWidget/ThemingWidget.astro",
@@ -0,0 +1,73 @@
1
+ <script>
2
+ import '../../scripts/icon-registry';
3
+ import { defineComponents, IgcIconButtonComponent, IgcIconComponent } from 'igniteui-webcomponents';
4
+
5
+ defineComponents(IgcIconButtonComponent, IgcIconComponent);
6
+
7
+ function initCopyButtons(): void {
8
+ document.querySelectorAll<HTMLPreElement>('pre.astro-code, pre.shiki').forEach((pre) => {
9
+ if (pre.closest('.copy-code-wrapper')) return;
10
+
11
+ const wrapper = document.createElement('div');
12
+ wrapper.className = 'copy-code-wrapper';
13
+ pre.parentNode!.insertBefore(wrapper, pre);
14
+ wrapper.appendChild(pre);
15
+
16
+ const btn = document.createElement('igc-icon-button') as HTMLElement;
17
+ btn.setAttribute('variant', 'flat');
18
+ btn.setAttribute('aria-label', 'Copy code');
19
+ btn.className = 'copy-btn';
20
+
21
+ const icon = document.createElement('igc-icon') as HTMLElement;
22
+ icon.setAttribute('name', 'copy');
23
+ icon.setAttribute('collection', 'docs');
24
+ btn.appendChild(icon);
25
+
26
+ btn.addEventListener('click', () => {
27
+ const code = pre.querySelector('code');
28
+ const text = code ? (code.textContent ?? '') : (pre.textContent ?? '');
29
+
30
+ const resetState = () => {
31
+ icon.setAttribute('name', 'copy');
32
+ btn.setAttribute('aria-label', 'Copy code');
33
+ };
34
+
35
+ const showCopied = () => {
36
+ icon.setAttribute('name', 'check');
37
+ btn.setAttribute('aria-label', 'Copied!');
38
+ setTimeout(resetState, 1500);
39
+ };
40
+
41
+ const showFailed = () => {
42
+ btn.setAttribute('aria-label', 'Copy failed');
43
+ setTimeout(resetState, 1500);
44
+ };
45
+
46
+ const fallback = (value: string): boolean => {
47
+ const ta = document.createElement('textarea');
48
+ ta.value = value;
49
+ ta.setAttribute('readonly', '');
50
+ ta.style.cssText = 'position:fixed;opacity:0;pointer-events:none';
51
+ document.body.appendChild(ta);
52
+ ta.select();
53
+ ta.setSelectionRange(0, value.length);
54
+ try { return document.execCommand('copy'); } catch { return false; }
55
+ finally { document.body.removeChild(ta); }
56
+ };
57
+
58
+ if (navigator.clipboard?.writeText) {
59
+ navigator.clipboard.writeText(text).then(showCopied).catch(() => {
60
+ fallback(text) ? showCopied() : showFailed();
61
+ });
62
+ } else {
63
+ fallback(text) ? showCopied() : showFailed();
64
+ }
65
+ });
66
+
67
+ wrapper.appendChild(btn);
68
+ });
69
+ }
70
+
71
+ initCopyButtons();
72
+ document.addEventListener('astro:page-load', initCopyButtons);
73
+ </script>
@@ -16,10 +16,12 @@
16
16
  height: calc(100dvh - var(--igd-header-height));
17
17
  max-height: 100dvh;
18
18
  align-self: start;
19
- gap: rem(24px);
19
+ gap: rem(8px);
20
20
  view-transition-name: docs-sidebar;
21
21
 
22
22
  .sidebar-gutter {
23
+ display: grid;
24
+ gap: rem(8px);
23
25
  overflow-y: hidden;
24
26
 
25
27
  // This Makes sure the input border is visible
@@ -63,7 +63,7 @@ igc-button {
63
63
  }
64
64
 
65
65
  color: light-dark(var(--ig-gray-600), var(--ig-gray-700));
66
- padding-inline: rem(24px);
66
+ padding-inline: 0;
67
67
 
68
68
  &:empty {
69
69
  display: none;
@@ -150,11 +150,9 @@ class SidebarFilter extends HTMLElement {
150
150
  // ── Events ───────────────────────────────────────────────────────────────
151
151
 
152
152
  private bindEvents(): void {
153
- // igc-input fires 'igcInput' instead of the native 'input' event.
154
- this.input.addEventListener('igcInput', this.onFilterInput as EventListener);
153
+ this.input.addEventListener('igcInput', this.onFilterInput as EventListener);
155
154
  this.input.addEventListener('keydown', this.onFilterKeydown);
156
155
  this.clearBtn.addEventListener('click', this.onClearClick);
157
-
158
156
  this.bindTreeEvents();
159
157
  }
160
158
 
@@ -167,14 +165,43 @@ class SidebarFilter extends HTMLElement {
167
165
  }
168
166
 
169
167
  private onFilterInput = (): void => {
168
+ this.pinScrollY();
170
169
  safeSet(FILTER_KEY, this.input.value);
171
170
  this.applyFilter(this.input.value, 'user');
172
171
  };
173
172
 
174
173
  private onFilterKeydown = (e: KeyboardEvent): void => {
174
+ this.pinScrollY();
175
175
  if (e.key === 'Escape' && this.input.value) this.resetFilter();
176
176
  };
177
177
 
178
+ /**
179
+ * Chrome-only: filter mutations trigger a browser-internal scroll. Pin
180
+ * scrollY via rAF for ~200ms (before-paint, invisible) and force
181
+ * `scroll-behavior: auto` so it's an instant jump, not a smooth animation
182
+ * we'd have to fight each frame. Prior inline value is restored at end.
183
+ */
184
+ private pinFrames = 0;
185
+ private prevScrollBehavior: string | null = null;
186
+ private pinScrollY = (): void => {
187
+ const wasActive = this.pinFrames > 0;
188
+ const y = window.scrollY;
189
+ this.pinFrames = 10;
190
+ if (wasActive) return;
191
+ this.prevScrollBehavior = document.documentElement.style.getPropertyValue('scroll-behavior');
192
+ document.documentElement.style.setProperty('scroll-behavior', 'auto', 'important');
193
+ const tick = (): void => {
194
+ if (window.scrollY !== y) window.scrollTo({ top: y, behavior: 'instant' as ScrollBehavior });
195
+ if (--this.pinFrames > 0) requestAnimationFrame(tick);
196
+ else {
197
+ if (this.prevScrollBehavior) document.documentElement.style.setProperty('scroll-behavior', this.prevScrollBehavior);
198
+ else document.documentElement.style.removeProperty('scroll-behavior');
199
+ this.prevScrollBehavior = null;
200
+ }
201
+ };
202
+ tick();
203
+ };
204
+
178
205
  private onClearClick = (): void => {
179
206
  this.resetFilter();
180
207
  this.input.focus();
@@ -237,22 +264,35 @@ class SidebarFilter extends HTMLElement {
237
264
  private restoreScroll(isClientNav: boolean): void {
238
265
  const sc = this.scrollEl;
239
266
  if (!sc) return;
240
- requestAnimationFrame(() => {
241
- sc.scrollTop = isClientNav
242
- ? (parseInt(safeGet(SCROLL_KEY) || '0', 10) || 0)
243
- : this.activeScrollOffset(sc);
244
- sc.style.visibility = '';
245
- });
267
+ if (isClientNav) {
268
+ // igc-tree-item is already defined; one rAF is enough for layout.
269
+ requestAnimationFrame(() => {
270
+ // Snap to the pre-navigation position first so the sidebar appears
271
+ // where the user last saw it, then smooth-scroll the short remaining
272
+ // distance to center the active item.
273
+ sc.scrollTop = parseInt(safeGet(SCROLL_KEY) || '0', 10) || 0;
274
+ sc.style.visibility = '';
275
+ sc.scrollTo({ top: this.activeScrollOffset(sc), behavior: 'smooth' });
276
+ });
277
+ } else {
278
+ // Hard page load: wait for igc-tree-item so Lit microtasks drain first.
279
+ customElements.whenDefined('igc-tree-item').then(() =>
280
+ requestAnimationFrame(() => {
281
+ sc.scrollTop = this.activeScrollOffset(sc);
282
+ sc.style.visibility = '';
283
+ })
284
+ );
285
+ }
246
286
  }
247
287
 
248
288
  private activeScrollOffset(sc: HTMLElement): number {
249
- const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
289
+ const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
250
290
  if (!active) return 0;
251
291
  const linkRect = active.getBoundingClientRect();
252
292
  const cRect = sc.getBoundingClientRect();
253
- if (linkRect.top < cRect.top) return sc.scrollTop + (linkRect.top - cRect.top);
254
- if (linkRect.bottom > cRect.bottom) return sc.scrollTop + (linkRect.bottom - cRect.bottom);
255
- return sc.scrollTop;
293
+ // Center the active item in the scroll container.
294
+ const itemTop = sc.scrollTop + (linkRect.top - cRect.top);
295
+ return itemTop - (sc.clientHeight / 2) + (linkRect.height / 2);
256
296
  }
257
297
 
258
298
  // ── Filter ───────────────────────────────────────────────────────────────
@@ -395,6 +435,7 @@ class SidebarFilter extends HTMLElement {
395
435
  }
396
436
 
397
437
  private resetFilter(): void {
438
+ this.pinScrollY();
398
439
  this.input.value = '';
399
440
  this.syncClearButton('');
400
441
  safeRemove(FILTER_KEY);
@@ -120,7 +120,7 @@ const crumbs = sidebarCrumbs.length > 0 ? sidebarCrumbs : (pageTitle ? [pageTitl
120
120
 
121
121
  <div class="igd-logo">
122
122
  <Fragment set:html={logoRaw} />
123
- <h1>{logoText}</h1>
123
+ <span class="igd-logo-text">{logoText}</span>
124
124
  </div>
125
125
 
126
126
  <div class="igd-docs-subheader__content">
@@ -38,11 +38,11 @@
38
38
  }
39
39
  }
40
40
 
41
- > h1 {
41
+ > .igd-logo-text {
42
42
  @include type-style('body-2') {
43
43
  margin: 0;
44
44
  };
45
-
45
+
46
46
  opacity: 1;
47
47
  transition: opacity 200ms ease, transform 200ms ease;
48
48
  }
@@ -61,7 +61,7 @@
61
61
  position: relative;
62
62
  }
63
63
 
64
- h1 {
64
+ .igd-logo-text {
65
65
  opacity: 0;
66
66
  transform: translateY(4px);
67
67
  position: absolute;
@@ -56,8 +56,12 @@ igc-tree[data-variant='toc'] igc-tree-item[selected] > [slot='label'] {
56
56
  anchor-name: --selected-tree-item;
57
57
  }
58
58
 
59
+ igc-tree-item + igc-tree-item[data-has-children] {
60
+ margin-block-start: rem(4px);
61
+ }
62
+
59
63
  igc-tree-item[data-has-children] {
60
- margin-block-end: rem(8px);
64
+ margin-block-end: rem(4px);
61
65
  }
62
66
 
63
67
  igc-tree-item {
@@ -186,7 +186,9 @@ import './Search.scss';
186
186
  }
187
187
  updateSearchHint();
188
188
 
189
- document.getElementById('search-trigger')?.addEventListener('click', () => openSearch());
189
+ document.addEventListener('click', (e: Event) => {
190
+ if ((e.target as Element).closest('#search-trigger')) openSearch();
191
+ });
190
192
 
191
193
  document.addEventListener('keydown', (e: KeyboardEvent) => {
192
194
  if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
@@ -202,26 +204,24 @@ import './Search.scss';
202
204
  });
203
205
 
204
206
  let debounceTimer: ReturnType<typeof setTimeout> | null = null;
205
- document.querySelector('igc-input.igd-search-input')?.addEventListener('igcInput', () => {
207
+ document.addEventListener('igcInput', (e: Event) => {
208
+ if (!(e.target as Element).closest('igc-input.igd-search-input')) return;
206
209
  if (debounceTimer !== null) clearTimeout(debounceTimer);
207
210
  const val = (document.querySelector<any>('igc-input.igd-search-input')?.value as string) ?? '';
208
211
  debounceTimer = setTimeout(() => runSearch(val), INPUT_DEBOUNCE_MS);
209
212
  });
210
213
 
211
- document.querySelector('.igd-search-clear')?.addEventListener('click', () => {
212
- const input = document.querySelector<any>('igc-input.igd-search-input');
213
- if (!input) return;
214
- input.value = '';
215
- input.focus();
216
- runSearch('');
217
- });
218
-
219
- document.querySelector('.igd-search-shell .search-close')?.addEventListener('click', () => {
220
- document.querySelector<any>('igc-dialog.igd-search-dialog')?.hide();
221
- });
222
-
223
- document.querySelector('.igd-search-shell')?.addEventListener('click', (e: Event) => {
224
- if ((e.target as Element).closest('a[href]')) {
214
+ document.addEventListener('click', (e: Event) => {
215
+ const target = e.target as Element;
216
+ if (target.closest('.igd-search-clear')) {
217
+ const input = document.querySelector<any>('igc-input.igd-search-input');
218
+ if (!input) return;
219
+ input.value = '';
220
+ input.focus();
221
+ runSearch('');
222
+ } else if (target.closest('.igd-search-shell .search-close')) {
223
+ document.querySelector<any>('igc-dialog.igd-search-dialog')?.hide();
224
+ } else if (target.closest('.igd-search-shell') && target.closest('a[href]')) {
225
225
  document.querySelector<any>('igc-dialog.igd-search-dialog')?.hide();
226
226
  }
227
227
  });
@@ -536,6 +536,17 @@ const resolvedIndexUrl = indexUrl ?? `${basePath}api-search-index/manifest.json`
536
536
  return;
537
537
  }
538
538
 
539
+ // Avoid searching on very short queries — a single or two-character query matches
540
+ // virtually everything and causes the classify + render path to freeze the main thread.
541
+ if (q.length < 3) {
542
+ this.statusEl.textContent = 'Type at least 3 characters to search\u2026';
543
+ this.tabsEl.hidden = true;
544
+ this.tabsEl.innerHTML = '';
545
+ this.flatListEl.hidden = true;
546
+ this.flatListEl.innerHTML = '';
547
+ return;
548
+ }
549
+
539
550
  this.statusEl.textContent = 'Searching\u2026';
540
551
 
541
552
  let pages: IndexedPage[];
@@ -829,15 +840,20 @@ const resolvedIndexUrl = indexUrl ?? `${basePath}api-search-index/manifest.json`
829
840
  `</igc-tab>`
830
841
  );
831
842
 
832
- // Per-category tabs — full result list in each tab body
843
+ // Per-category tabs — capped to avoid freezing the main thread when many
844
+ // results match (e.g. a short query against a large cross-version index).
845
+ const MAX_PER_CATEGORY_TAB = 100;
833
846
  for (const cat of this.categories) {
834
847
  const list = this.currentMatches.get(cat.id) ?? [];
835
848
  if (list.length === 0) continue;
836
849
  const isSelected = this.currentTab === cat.id;
850
+ const displayList = list.slice(0, MAX_PER_CATEGORY_TAB);
851
+ const hasMore = list.length > MAX_PER_CATEGORY_TAB;
837
852
  tabsHtml.push(
838
853
  `<igc-tab data-tab-id="${cat.id}" label="${escapeHtml(cat.label)}"${isSelected ? ' selected' : ''}>` +
839
854
  `<span slot="suffix" class="igd-search-tab-count">/${list.length}/</span>` +
840
- `<igc-list class="igd-search-results">${list.map(m => this.matchHtml(m)).join('')}</igc-list>` +
855
+ `<igc-list class="igd-search-results">${displayList.map(m => this.matchHtml(m)).join('')}</igc-list>` +
856
+ (hasMore ? `<p class="igd-search-refine-hint">Showing first ${MAX_PER_CATEGORY_TAB} of ${list.length} matches &mdash; refine your search to narrow results.</p>` : '') +
841
857
  `</igc-tab>`
842
858
  );
843
859
  }
@@ -108,6 +108,26 @@
108
108
  .igd-search-tab-count {
109
109
  color: light-dark(var(--ig-gray-500), var(--ig-gray-300));
110
110
  }
111
+
112
+ .igd-search-refine-hint {
113
+ @include type-style('caption') {
114
+ margin: 0;
115
+ }
116
+
117
+ padding-inline-start: calc(#{rem(26px)} + #{rem(16px)});
118
+ margin-block-start: rem(16px);
119
+ color: light-dark(var(--ig-gray-600), var(--ig-gray-400));
120
+ }
121
+
122
+ .igd-search-refine-hint {
123
+ @include type-style('caption') {
124
+ margin: 0;
125
+ }
126
+
127
+ padding-inline-start: calc(#{rem(26px)} + #{rem(16px)});
128
+ margin-block-start: rem(16px);
129
+ color: light-dark(var(--ig-gray-600), var(--ig-gray-400));
130
+ }
111
131
 
112
132
  igc-divider {
113
133
  --color: light-dark(var(--ig-gray-400), var(--ig-gray-300));
@@ -10,6 +10,7 @@ import DocsSubHeader from '../../components/DocsSubHeader/DocsSubHeader.astro';
10
10
  import DocsBreadcrumb from '../../components/DocsBreadcrumb/DocsBreadcrumb.astro';
11
11
  import LicenseIndicator from '../../components/LicenseIndicator/LicenseIndicator.astro';
12
12
  import MobileSidebarToggle from '../../components/MobileSidebarToggle/MobileSidebarToggle.astro';
13
+ import CopyCode from '../../components/CopyCode/CopyCode.astro';
13
14
  import { widgetScriptSrc, platform as virtualPlatform } from 'virtual:docs-template/nav-html';
14
15
  import { title as siteTitle, headEntries, navLang } from 'virtual:docs-template/site-meta';
15
16
  import '../../styles/theme.scss';
@@ -270,6 +271,8 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
270
271
  </div>
271
272
  </div>
272
273
 
274
+ <CopyCode />
275
+
273
276
  <!-- Footer is inside the grid so the sidebar's sticky containing block extends through it.
274
277
  The JS initSidebarHeights() clamps sidebar max-height to prevent visual overlap. -->
275
278
  <GlobalFooter lang={navLang}/>
@@ -313,10 +313,6 @@
313
313
  }
314
314
  }
315
315
 
316
- igc-divider:not([variant="vertical"]) {
317
- margin-block: rem(24px);
318
- }
319
-
320
316
  @media (max-width: #{$bp-hide-toc}) {
321
317
  .igd-main-content__inner {
322
318
  aside {
@@ -33,31 +33,44 @@ pre.shiki {
33
33
  background-color: var(--shiki-color-background) !important;
34
34
  }
35
35
 
36
- /* Copy button */
37
- pre.shiki {
38
- position: relative; /* ensure anchor for absolute button */
36
+ .copy-code-wrapper {
37
+ position: relative;
39
38
  }
40
39
 
41
- pre.shiki igc-icon-button.copy-btn {
42
- position: absolute;
43
- top: 0.5rem;
44
- right: 0.5rem;
45
- opacity: 0;
46
- transition: opacity 0.15s ease;
47
-
48
- --ig-icon-button-foreground: var(--ig-gray-600);
49
- --ig-icon-button-foreground-hover: var(--igd-accent);
50
- --ig-icon-button-background: transparent;
51
- --ig-icon-button-background-hover: transparent;
52
- --ig-icon-button-background-focus: transparent;
53
- --ig-icon-button-border-color: transparent;
54
- --ig-icon-button-border-color-hover: transparent;
40
+ .copy-code-wrapper > .copy-btn {
41
+ position: absolute;
42
+ inset-block-start: rem(8px);
43
+ inset-inline-end: rem(8px);
44
+ opacity: 0;
45
+ z-index: 1;
46
+
47
+ --foreground: var(--ig-primary-600-contrast);
48
+ --hover-foreground: var(--ig-primary-600-contrast);
49
+ --focus-foreground: var(--ig-primary-600-contrast);
50
+ --active-foreground: var(--ig-primary-600-contrast);
51
+ --background: var(--ig-primary-500);
52
+ --hover-background: var(--ig-primary-500);
53
+ --focus-background: var(--ig-primary-500);
54
+ --active-background: var(--ig-primary-500);
55
+ --border-color: transparent;
56
+ --border-color-hover: transparent;
57
+ --border-color-focus: transparent;
58
+
59
+ &:has([name="check"]) {
60
+ --foreground: var(--ig-success-300-contrast);
61
+ --hover-foreground: var(--ig-success-300-contrast);
62
+ --focus-foreground: var(--ig-success-300-contrast);
63
+ --active-foreground: var(--ig-success-300-contrast);
64
+
65
+ --background: var(--ig-success-300);
66
+ --hover-background: var(--ig-success-300);
67
+ --focus-background: var(--ig-success-300);
68
+ --active-background: var(--ig-success-300);
69
+ }
55
70
  }
56
71
 
57
- pre.shiki:hover igc-icon-button.copy-btn,
58
- pre.shiki:focus-within igc-icon-button.copy-btn,
59
- pre.shiki igc-icon-button.copy-btn:focus {
60
- opacity: 1;
72
+ .copy-code-wrapper:hover > .copy-btn,
73
+ .copy-code-wrapper:focus-within > .copy-btn {
74
+ opacity: 1;
61
75
  }
62
76
 
63
-
@@ -5,6 +5,11 @@
5
5
  // generated by typography() but type-style() only accepts standard names.
6
6
  // Read the generated --ig-* vars directly to avoid the warning.
7
7
  .igd-main-content__markdown {
8
+
9
+ igc-divider:not([variant="vertical"]) {
10
+ margin-block: rem(24px);
11
+ }
12
+
8
13
  .license-indicator-badge {
9
14
  margin-block-end: rem(26px);
10
15
  }
@@ -80,6 +85,11 @@
80
85
  margin-block-end: rem(26px);
81
86
  }
82
87
 
88
+ pre.astro-code {
89
+ padding: rem(24px);
90
+ border-radius: rem(8px);
91
+ }
92
+
83
93
  kbd {
84
94
  @include type-style('code', false) {
85
95
  margin: 0;
@@ -154,6 +164,12 @@
154
164
  }
155
165
  }
156
166
 
167
+ iframe {
168
+ border: rem(1px) solid light-dark(var(--ig-gray-200), var(--ig-gray-100));
169
+ margin-block-end: rem(26px);
170
+ border-radius: rem(8px);
171
+ }
172
+
157
173
  // <ul> that is not inside <li>
158
174
  // <ol> that is not inside <li>
159
175
  ul:not(li ul),