igniteui-astro-components 0.0.15 → 0.0.16

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.16",
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": {
@@ -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);
@@ -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 {
@@ -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),