igniteui-astro-components 1.7.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.
Files changed (60) hide show
  1. package/README.md +322 -158
  2. package/llms-full.txt +3207 -0
  3. package/llms.txt +103 -0
  4. package/package.json +17 -5
  5. package/src/assets/icons/figma-logo.svg +10 -0
  6. package/src/code-theme/README.md +72 -0
  7. package/src/code-theme/index.ts +57 -0
  8. package/src/components/CopyCode/CopyCode.astro +6 -1
  9. package/src/components/CopyCode/README.md +38 -0
  10. package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +28 -30
  11. package/src/components/DocsSidebar/README.md +58 -30
  12. package/src/components/DocsSidebar/SidebarLabel.astro +34 -36
  13. package/src/components/DocsSubHeader/README.md +24 -31
  14. package/src/components/DocsToc/DocsToc.astro +12 -14
  15. package/src/components/DocsToc/README.md +7 -7
  16. package/src/components/DocsTree/DocsTree.astro +9 -11
  17. package/src/components/DocsTree/DocsTreeItem.astro +36 -40
  18. package/src/components/DocsTree/README.md +12 -9
  19. package/src/components/GlobalFooter/GlobalFooter.astro +6 -8
  20. package/src/components/GlobalNavBar/GlobalNavBar.astro +2 -4
  21. package/src/components/LicenseIndicator/LicenseIndicator.astro +6 -8
  22. package/src/components/MobileTocToggle/MobileTocToggle.astro +31 -33
  23. package/src/components/MobileTocToggle/README.md +45 -0
  24. package/src/components/Search/README.md +10 -10
  25. package/src/components/Search/Search.astro +12 -6
  26. package/src/components/SearchAdvanced/README.md +15 -8
  27. package/src/components/SearchAdvanced/SearchAdvanced.astro +17 -15
  28. package/src/components/ThemingWidget/ThemingWidget.astro +62 -60
  29. package/src/components/mdx/Anatomy/Anatomy.scss +1 -1
  30. package/src/components/mdx/Anatomy/README.md +40 -0
  31. package/src/components/mdx/ApiLink/ApiLink.astro +7 -9
  32. package/src/components/mdx/ApiLink/README.md +1 -0
  33. package/src/components/mdx/ApiRef/ApiRef.astro +7 -9
  34. package/src/components/mdx/ApiRef/README.md +1 -1
  35. package/src/components/mdx/Badge/Badge.astro +3 -1
  36. package/src/components/mdx/Badge/README.md +1 -3
  37. package/src/components/mdx/DocsAside/DocsAside.astro +3 -5
  38. package/src/components/mdx/DocsAside/README.md +47 -29
  39. package/src/components/mdx/Faq/Faq.astro +11 -13
  40. package/src/components/mdx/Faq/FaqItem.astro +20 -26
  41. package/src/components/mdx/FigmaUiKits/FigmaUiKits.astro +126 -0
  42. package/src/components/mdx/FigmaUiKits/FigmaUiKits.scss +165 -0
  43. package/src/components/mdx/FigmaUiKits/README.md +115 -0
  44. package/src/components/mdx/FigmaUiKits/kits.ts +26 -0
  45. package/src/components/mdx/PlatformBlock/README.md +5 -18
  46. package/src/components/mdx/Sample/README.md +67 -50
  47. package/src/components/mdx/Sample/Sample.astro +108 -33
  48. package/src/components/mdx/Sample/Sample.scss +38 -17
  49. package/src/integration.ts +6 -21
  50. package/src/layouts/DocsLayout/README.md +63 -28
  51. package/src/lib/warn-once.ts +8 -0
  52. package/src/scripts/copy-status.ts +35 -0
  53. package/src/scripts/icon-manifest.ts +1 -0
  54. package/src/scripts/sample-widget.ts +109 -42
  55. package/src/styles/global/_code-blocks.scss +58 -36
  56. package/src/styles/global/_copy-button.scss +18 -25
  57. package/src/styles/global/_markdown.scss +15 -8
  58. package/src/styles/global/_variables.scss +57 -0
  59. package/src/styles/theme.scss +4 -1
  60. package/src/virtual-modules.d.ts +1 -1
@@ -10,23 +10,58 @@ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
10
10
 
11
11
  ## Props
12
12
 
13
- | Prop | Type | Default | Description |
14
- | ------------- | ---------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
15
- | `title` | `string` | — | Page `<title>` prepended to the site name. Omit to show the site name only. |
16
- | `description` | `string \| null` | — | `<meta name="description">` value. |
17
- | `keywords` | `string \| null` | — | `<meta name="keywords">` value. |
18
- | `hasSidebar` | `boolean` | `true` | Renders the sidebar rail when `true`. Provide content via `<… slot="sidebar">`. |
19
- | `currentSlug` | `string` | `''` | Slug of the current page — used for breadcrumbs in the sub-header. |
20
- | `siteTitle` | `string` | virtual module | Override the site name used in `<title>` and the sub-header. Use this when not running `siteMetaIntegration`. |
13
+ | Prop | Type | Default | Description |
14
+ | ----------------- | ---------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
15
+ | `title` | `string` | — | Page `<title>` prepended to the site name. Omit to show the site name only. |
16
+ | `description` | `string \| null` | — | `<meta name="description">` value. |
17
+ | `keywords` | `string \| null` | — | `<meta name="keywords">` value. |
18
+ | `hasSidebar` | `boolean` | `true` | Renders the sidebar rail when `true`. Provide content via `<… slot="sidebar">`. |
19
+ | `currentSlug` | `string` | `''` | Slug of the current page — used for the breadcrumb above the content. |
20
+ | `siteTitle` | `string` | virtual module | Override the site name used in `<title>` and the breadcrumb. Use this when not running `siteMetaIntegration`. |
21
+ | `license` | `string` | — | `license` frontmatter value. `'commercial'` shows a Premium badge, `'MIT'` an Open Source badge. |
22
+ | `is404` | `boolean` | `false` | Adds the `igd-page-layout--404` modifier class on 404 pages. |
23
+ | `packages` | `string[]` | — | Entries for the sub-header package selector. Hidden when omitted. |
24
+ | `selectedPackage` | `string` | — | Currently selected package (must match one of `packages`). |
25
+ | `packageLabel` | `string` | `'Package'` | `aria-label` of the sub-header package selector (not a visible label). |
26
+ | `versions` | `string[]` | — | Entries for the sub-header version selector. Hidden when omitted. |
27
+ | `selectedVersion` | `string` | — | Currently selected version (must match one of `versions`). |
28
+ | `versionLabel` | `string` | `'Version'` | `aria-label` of the sub-header version selector (not a visible label). |
29
+ | `showThemeToggle` | `boolean` | `false` | Forwarded to `DocsSubHeader`, which does not render a toggle; no effect today. |
30
+ | `themeStorageKey` | `string` | `'docs-theme'` | Forwarded to `DocsSubHeader` and unused; the layout's restore script reads the `'docs-theme'` key only. |
31
+
32
+ `hasToc` (`boolean`, default `true`) is also read at runtime and hides the `toc`
33
+ slot when `false`, but it is not yet declared in the `Props` interface (issue #161), so
34
+ TypeScript consumers must spread it in (`{...{ hasToc: false }}`).
21
35
 
22
36
  ## Slots
23
37
 
24
- | Slot | Description |
25
- | ----------- | ---------------------------------------------------------------------------------------------------------------------- |
26
- | _(default)_ | Main page content. |
27
- | `sidebar` | Sidebar content — typically `<DocsSidebar>`. Only rendered when `hasSidebar={true}`. |
28
- | `toc` | "On this page" column — pass `<DocsToc slot="toc" headings={headings} />` here. Omit to hide the TOC sidebar entirely. |
29
- | `head` | Extra `<head>` entries injected after platform defaults. |
38
+ | Slot | Description |
39
+ | ------------ | ---------------------------------------------------------------------------------------------------------------------- |
40
+ | _(default)_ | Main page content, rendered inside `<main data-pagefind-body>`. |
41
+ | `sidebar` | Sidebar content — typically `<DocsSidebar>`. Only rendered when `hasSidebar={true}`. |
42
+ | `toc` | "On this page" column — pass `<DocsToc slot="toc" headings={headings} />` here. Omit to hide the TOC sidebar entirely. |
43
+ | `mobile-toc` | Mobile-only TOC row below the sub-header — pass `<MobileTocToggle slot="mobile-toc" headings={headings} />`. |
44
+ | `subheader` | Replaces the default `<DocsSubHeader>`; use it to mount your own sub-header (for example with `SearchAdvanced`). |
45
+ | `head` | Extra `<head>` entries injected after platform defaults. |
46
+
47
+ ## What the layout brings in
48
+
49
+ - `styles/theme.scss` (the package's global stylesheet) and the JetBrains Mono
50
+ variable font from `@fontsource-variable/jetbrains-mono`. You do not need to
51
+ import either yourself.
52
+ - `GlobalNavBar`, `DocsSubHeader`, `DocsBreadcrumb`, `LicenseIndicator`,
53
+ `CopyCode` and `GlobalFooter`.
54
+ - `<html data-theme="light|dark">`, restored from `localStorage` before paint.
55
+ - Astro's `<ClientRouter>` for view transitions.
56
+
57
+ ## Host requirements
58
+
59
+ - The two virtual modules below must resolve (stub them if you do not use the
60
+ integration).
61
+ - Components rendered inside the layout that read
62
+ `Astro.locals.platformContext` or `Astro.locals.envVars` (`ApiLink`,
63
+ `ApiRef`, `PlatformBlock`, `Sample`, `ThemingWidget`) need a middleware that
64
+ sets them — see [Quick start](../../../README.md#quick-start) step 3.
30
65
 
31
66
  ## Example
32
67
 
@@ -34,12 +69,12 @@ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
34
69
 
35
70
  Pass all data directly as props. The `virtual:docs-template/site-meta` module
36
71
  still needs to be resolvable at Vite build time — supply a minimal stub (see
37
- [playground/astro.config.mjs](../../../playground/astro.config.mjs)).
72
+ [Quick start](../../../README.md#quick-start) step 2).
38
73
 
39
74
  ```astro
40
75
  ---
41
76
  import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
42
- import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
77
+ import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
43
78
  import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
44
79
  import type { SidebarEntry } from 'igniteui-astro-components/lib/sidebar/types';
45
80
  import type { MarkdownHeading } from 'astro';
@@ -55,7 +90,7 @@ const sidebar: SidebarEntry[] = [
55
90
 
56
91
  <DocsLayout title="Toast" siteTitle="My Library" hasSidebar currentSlug={slug}>
57
92
  <DocsSidebar slot="sidebar" items={sidebar} currentSlug={slug} />
58
- <DocsToc slot="toc" headings={headings} offsetTarget=".docs-subheader" />
93
+ <DocsToc slot="toc" headings={headings} />
59
94
  <slot />
60
95
  </DocsLayout>
61
96
  ```
@@ -67,7 +102,7 @@ Omit the `toc` slot entirely — the TOC sidebar collapses automatically via CSS
67
102
  ```astro
68
103
  ---
69
104
  import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
70
- import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
105
+ import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
71
106
 
72
107
  const slug = Astro.params.slug ?? '';
73
108
  ---
@@ -86,7 +121,7 @@ can be omitted — it is read from the virtual module automatically.
86
121
  ```astro
87
122
  ---
88
123
  import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
89
- import DocsSidebar from 'igniteui-astro-components/components/sidebar/DocsSidebar.astro';
124
+ import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
90
125
  import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
91
126
 
92
127
  const { headings } = Astro.props;
@@ -95,7 +130,7 @@ const slug = Astro.params.slug ?? '';
95
130
 
96
131
  <DocsLayout title="Toast" description="Toast component documentation" hasSidebar currentSlug={slug}>
97
132
  <DocsSidebar slot="sidebar" currentSlug={slug} />
98
- <DocsToc slot="toc" headings={headings} offsetTarget=".docs-subheader" />
133
+ <DocsToc slot="toc" headings={headings} />
99
134
  <slot />
100
135
  </DocsLayout>
101
136
  ```
@@ -119,12 +154,12 @@ with `data-igd-footer`, persisted across navigations. See
119
154
 
120
155
  ## Virtual module dependencies
121
156
 
122
- `DocsLayout` imports from two virtual modules. When using `siteMetaIntegration`
123
- they are provided automatically. When not, supply minimal stubs via a Vite
124
- plugin (see [playground/astro.config.mjs](../../../playground/astro.config.mjs)
125
- for a reference implementation):
157
+ `DocsLayout` imports from two virtual modules. Supply them with a Vite plugin
158
+ (see [Quick start](../../../README.md#quick-start) step 2; `siteMetaIntegration`
159
+ does not emit `packages` and `selectedPackage`, so it cannot provide them
160
+ today):
126
161
 
127
- | Module | Used for | Can be overridden by prop |
128
- | --------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
129
- | `virtual:docs-template/site-meta` | Site title, sidebar tree, product links, extra `<head>` entries | `siteTitle` on `DocsLayout`, `items` on `DocsSidebar`, `productLinks`/`sidebarItems` on `DocsSubHeader` |
130
- | `virtual:docs-template/nav-html` | Pre-fetched nav/footer HTML, widget script URL, platform key | — (not yet prop-overridable) |
162
+ | Module | Used for | Can be overridden by prop |
163
+ | --------------------------------- | ------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
164
+ | `virtual:docs-template/site-meta` | `title`, `sidebar`, `productLinks`, `headEntries`, `trailingSlash`, `navLang`, `packages`, `selectedPackage` | `siteTitle` on `DocsLayout`, `items`/`trailingSlash` on `DocsSidebar`, `packages`/`selectedPackage` on `DocsSubHeader` |
165
+ | `virtual:docs-template/nav-html` | Pre-fetched nav/footer HTML, widget script URL, platform key | — (not yet prop-overridable) |
@@ -0,0 +1,8 @@
1
+ const warned = new Set<string>();
2
+
3
+ /** Logs each build warning message once per process. */
4
+ export function warnOnce(message: string): void {
5
+ if (warned.has(message)) return;
6
+ warned.add(message);
7
+ console.warn(message);
8
+ }
@@ -0,0 +1,35 @@
1
+ /** Visually hidden live region that announces the copy-code result to screen readers. */
2
+ const REGION_CLASS = 'igd-copy-status';
3
+
4
+ // Visually hidden styles, set inline.
5
+ const HIDDEN_STYLE =
6
+ 'position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap';
7
+
8
+ function getRegion(host: HTMLElement): HTMLElement {
9
+ let region = host.querySelector<HTMLElement>(`:scope > .${REGION_CLASS}`);
10
+ if (!region) {
11
+ region = document.createElement('span');
12
+ region.className = REGION_CLASS;
13
+ region.setAttribute('role', 'status');
14
+ region.setAttribute('aria-live', 'polite');
15
+ region.style.cssText = HIDDEN_STYLE;
16
+ host.appendChild(region);
17
+ }
18
+ return region;
19
+ }
20
+
21
+ /** Announces `message` from the live region inside `host`. */
22
+ export function announceCopyStatus(host: HTMLElement, message: string): void {
23
+ const region = getRegion(host);
24
+ region.textContent = '';
25
+ // Sets the text on the next frame so a repeated message is announced again.
26
+ requestAnimationFrame(() => {
27
+ region.textContent = message;
28
+ });
29
+ }
30
+
31
+ /** Clears the live region inside `host`. */
32
+ export function clearCopyStatus(host: HTMLElement): void {
33
+ const region = host.querySelector<HTMLElement>(`:scope > .${REGION_CLASS}`);
34
+ if (region) region.textContent = '';
35
+ }
@@ -25,6 +25,7 @@ export const BRAND_ICONS = new Set([
25
25
  'react-logo',
26
26
  'wc-logo',
27
27
  'github-logo',
28
+ 'figma-logo',
28
29
  'chatgpt',
29
30
  'claude',
30
31
  ]);
@@ -20,6 +20,7 @@ import {
20
20
  IgcIconButtonComponent,
21
21
  IgcIconComponent,
22
22
  IgcCircularProgressComponent,
23
+ IgcTooltipComponent,
23
24
  registerIconFromText,
24
25
  } from 'igniteui-webcomponents';
25
26
  defineComponents(
@@ -28,10 +29,12 @@ defineComponents(
28
29
  IgcIconButtonComponent,
29
30
  IgcIconComponent,
30
31
  IgcCircularProgressComponent,
32
+ IgcTooltipComponent,
31
33
  );
32
34
 
33
35
  import './icon-registry';
34
36
  import type { BundledLanguage, Highlighter } from 'shiki';
37
+ import { announceCopyStatus, clearCopyStatus } from './copy-status';
35
38
  import { ULTIMATE_UI_PLATFORMS } from '../lib/ultimate-ui-platforms';
36
39
  import footerStackblitzIcon from '../components/mdx/Sample/assets/stackblitz.svg?raw';
37
40
  import footerOpenExternalIcon from '../components/mdx/Sample/assets/open-external.svg?raw';
@@ -71,9 +74,6 @@ const SANDBOX_UNSUPPORTED_PLATFORMS = new Set(['blazor', 'winui', 'uno']);
71
74
 
72
75
  const DV_PATHS = ['gauges/', 'maps/', 'excel/', 'charts/'];
73
76
  const ASSETS_RE = /([.]{0,2}\/)*assets\//g;
74
- const DEFAULT_CODE_THEME = 'dark-plus';
75
-
76
- declare const __IGD_SAMPLE_CODE_THEME__: string | undefined;
77
77
 
78
78
  // ─── Types ────────────────────────────────────────────────────────────────────
79
79
 
@@ -187,17 +187,12 @@ const HIGHLIGHT_LANGS: ReadonlySet<string> = new Set([...SHIKI_LANGS, ...SHIKI_L
187
187
 
188
188
  let _highlighterPromise: Promise<Highlighter> | null = null;
189
189
 
190
- function getCodeTheme(): string {
191
- return typeof __IGD_SAMPLE_CODE_THEME__ === 'string' && __IGD_SAMPLE_CODE_THEME__.trim()
192
- ? __IGD_SAMPLE_CODE_THEME__
193
- : DEFAULT_CODE_THEME;
194
- }
195
-
190
+ // Shiki and the brand theme load lazily, only once a code tab exists.
196
191
  function getHighlighter(): Promise<Highlighter> {
197
192
  if (!_highlighterPromise) {
198
- _highlighterPromise = import('shiki')
199
- .then(({ createHighlighter }) =>
200
- createHighlighter({ themes: [getCodeTheme()], langs: [...SHIKI_LANGS] }),
193
+ _highlighterPromise = Promise.all([import('shiki'), import('../code-theme')])
194
+ .then(([{ createHighlighter }, { igCodeTheme }]) =>
195
+ createHighlighter({ themes: [igCodeTheme], langs: [...SHIKI_LANGS] }),
201
196
  )
202
197
  .catch((err) => {
203
198
  _highlighterPromise = null;
@@ -207,6 +202,7 @@ function getHighlighter(): Promise<Highlighter> {
207
202
  return _highlighterPromise;
208
203
  }
209
204
 
205
+ /** Highlight a code tab with the brand theme the page's fenced blocks use. */
210
206
  function highlightCode(codeEl: HTMLElement, lang: string): void {
211
207
  const safeLang = HIGHLIGHT_LANGS.has(lang) ? lang : 'text';
212
208
  getHighlighter()
@@ -217,13 +213,17 @@ function highlightCode(codeEl: HTMLElement, lang: string): void {
217
213
  const tmp = document.createElement('div');
218
214
  tmp.innerHTML = h.codeToHtml(codeEl.textContent ?? '', {
219
215
  lang: safeLang,
220
- theme: getCodeTheme(),
216
+ theme: h.getLoadedThemes()[0],
221
217
  });
222
218
  const shikiPre = tmp.firstElementChild as HTMLElement | null;
223
219
  const shikiCode = shikiPre?.querySelector('code');
224
220
  if (!shikiPre || !shikiCode) return;
225
221
  const parentPre = codeEl.parentElement;
226
- if (parentPre) parentPre.style.cssText = shikiPre.style.cssText;
222
+ if (parentPre) {
223
+ // Shiki's inline background and text colour.
224
+ parentPre.style.cssText = shikiPre.style.cssText;
225
+ parentPre.classList.add('igd-code');
226
+ }
227
227
  codeEl.innerHTML = shikiCode.innerHTML;
228
228
  })
229
229
  .catch(console.warn);
@@ -233,6 +233,70 @@ function normalizeCodeLang(lang: string | undefined): string {
233
233
  return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
234
234
  }
235
235
 
236
+ // ─── Action Tooltips ──────────────────────────────────────────────────────────
237
+
238
+ const COPY_CODE_LABEL = 'Copy code';
239
+ const CODE_COPIED_LABEL = 'Code copied';
240
+
241
+ /**
242
+ * Give an icon-only action button a hover/focus tooltip that names its action.
243
+ * The text is the button's `aria-label`, so the visible and accessible names
244
+ * stay the same. Call after the button is in the DOM: the tooltip is inserted
245
+ * as its next sibling.
246
+ */
247
+ function addActionTooltip(btn: HTMLElement): IgcTooltipComponent {
248
+ const tooltip = document.createElement('igc-tooltip') as IgcTooltipComponent;
249
+ tooltip.className = 'igd-sample-action-tooltip';
250
+ tooltip.withArrow = true;
251
+ tooltip.message = btn.getAttribute('aria-label') ?? '';
252
+ tooltip.anchor = btn;
253
+ btn.after(tooltip);
254
+ return tooltip;
255
+ }
256
+
257
+ /**
258
+ * Wire a code-tab copy button: copy on click, then switch its icon,
259
+ * `aria-label` and tooltip to the "copied" state for a moment.
260
+ */
261
+ function wireCopyButton(btn: HTMLElement, getText: () => string): void {
262
+ const icon = btn.querySelector<HTMLElement>('igc-icon');
263
+ const tooltip = addActionTooltip(btn);
264
+ // `click` is a default hide trigger; drop it so the tooltip stays open to
265
+ // confirm the copy.
266
+ tooltip.hideTriggers = 'pointerleave,focusout';
267
+
268
+ const setLabel = (label: string) => {
269
+ btn.setAttribute('aria-label', label);
270
+ tooltip.message = label;
271
+ };
272
+
273
+ // Element that holds the copy-status live region.
274
+ const host = btn.parentElement ?? btn;
275
+
276
+ btn.addEventListener('click', () => {
277
+ navigator.clipboard
278
+ .writeText(getText())
279
+ .then(() => {
280
+ icon?.setAttribute('name', 'check');
281
+ setLabel(CODE_COPIED_LABEL);
282
+ announceCopyStatus(host, 'Code copied to clipboard');
283
+ // A click inside the show delay cancels the pending show; open it now.
284
+ void tooltip.show();
285
+ })
286
+ .catch(() => {
287
+ setLabel('Copy failed');
288
+ announceCopyStatus(host, 'Copy failed');
289
+ })
290
+ .then(() =>
291
+ setTimeout(() => {
292
+ icon?.setAttribute('name', 'copy');
293
+ setLabel(COPY_CODE_LABEL);
294
+ clearCopyStatus(host);
295
+ }, 1500),
296
+ );
297
+ });
298
+ }
299
+
236
300
  // ─── Code Tab Rendering ───────────────────────────────────────────────────────
237
301
 
238
302
  function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false): void {
@@ -245,6 +309,7 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
245
309
  wrapper.className = 'code-wrapper';
246
310
 
247
311
  const pre = document.createElement('pre');
312
+ pre.className = 'igd-code';
248
313
  const code = document.createElement('code');
249
314
  code.className = `language-${lang}`;
250
315
  code.textContent = file.content;
@@ -254,7 +319,7 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
254
319
  // affordances look identical.
255
320
  const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
256
321
  copyBtn.setAttribute('variant', 'flat');
257
- copyBtn.setAttribute('aria-label', 'Copy code');
322
+ copyBtn.setAttribute('aria-label', COPY_CODE_LABEL);
258
323
  copyBtn.className = 'cv-hljs-code-copy';
259
324
 
260
325
  const copyIcon = document.createElement('igc-icon');
@@ -262,19 +327,9 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
262
327
  copyIcon.setAttribute('collection', 'docs');
263
328
  copyBtn.appendChild(copyIcon);
264
329
 
265
- copyBtn.addEventListener('click', () => {
266
- navigator.clipboard.writeText(file.content).then(() => {
267
- copyIcon.setAttribute('name', 'check');
268
- copyBtn.setAttribute('aria-label', 'Code copied');
269
- setTimeout(() => {
270
- copyIcon.setAttribute('name', 'copy');
271
- copyBtn.setAttribute('aria-label', 'Copy code');
272
- }, 1500);
273
- });
274
- });
275
-
276
330
  wrapper.appendChild(pre);
277
331
  wrapper.appendChild(copyBtn);
332
+ wireCopyButton(copyBtn, () => file.content);
278
333
  tab.appendChild(wrapper);
279
334
  igcTabs.appendChild(tab);
280
335
 
@@ -314,6 +369,7 @@ function addFooter(
314
369
  btn.className = 'stackblitz-btn igd-edit-in-btn';
315
370
  btn.addEventListener('click', onStackblitz);
316
371
  actions.appendChild(btn);
372
+ addActionTooltip(btn);
317
373
  }
318
374
 
319
375
  // CodeSandbox hidden, re-enable when https://github.com/codesandbox/codesandbox-client/issues/8884 is fixed.
@@ -341,6 +397,7 @@ function addFooter(
341
397
  fsBtn.setAttribute('target', '_blank');
342
398
  }
343
399
  actions.appendChild(fsBtn);
400
+ addActionTooltip(fsBtn);
344
401
  }
345
402
  if (actions.childElementCount) footer.appendChild(actions);
346
403
 
@@ -349,7 +406,7 @@ function addFooter(
349
406
  footer.appendChild(themingBar);
350
407
  }
351
408
 
352
- // Nothing to show (e.g. a `hideCode` sample without a theme picker): no footer.
409
+ // Nothing to show (e.g. a `chrome="demo"` sample without a theme picker): no footer.
353
410
  if (footer.childElementCount) widget.appendChild(footer);
354
411
  }
355
412
 
@@ -657,6 +714,14 @@ const FIT_CONTENT_ENABLE_MESSAGE = 'igd-sample-fit';
657
714
 
658
715
  let _fitContentMessageBound = false;
659
716
 
717
+ /**
718
+ * The document of each fit-content iframe that has reported its own size.
719
+ * Keyed by document, not set on the iframe, so that navigating the iframe to
720
+ * a page that does not report resumes direct measurement. A report that
721
+ * arrives before the new page's load event is already from the new document.
722
+ */
723
+ const _reportingDocuments = new WeakMap<HTMLIFrameElement, Document | null>();
724
+
660
725
  /**
661
726
  * Apply a measured content size to a fit-content iframe. The size goes on the
662
727
  * iframe itself; the container has `height: auto` in fit-content mode, so it
@@ -728,6 +793,9 @@ function bindFitContentMessages(): void {
728
793
  .querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
729
794
  .forEach((iframe) => {
730
795
  if (iframe.contentWindow !== e.source) return;
796
+ // A demo that reports its own size knows it best. Direct measurement
797
+ // of this same-origin document stops from here on (see wireFitContent).
798
+ _reportingDocuments.set(iframe, iframe.contentDocument);
731
799
  // Width only matters when the host aligns the iframe
732
800
  // horizontally (position → data-justify); otherwise the iframe
733
801
  // stays full-width and a reported width is ignored. Resizable
@@ -749,6 +817,12 @@ function bindFitContentMessages(): void {
749
817
  * in sync with a ResizeObserver on their <body>. Cross-origin demos can't be
750
818
  * read, so they must post their height (see FIT_CONTENT_MESSAGE).
751
819
  *
820
+ * A same-origin demo that also posts its height is sized by its messages
821
+ * alone. Its page may fill the iframe (`html, body { height: 100% }`), and
822
+ * then the direct measurement only echoes the iframe height back. Both paths
823
+ * writing the height race: a stale echo can land after the demo's last
824
+ * report and leave the iframe cut off.
825
+ *
752
826
  * The `height` prop is only the placeholder/fallback in fit-content mode —
753
827
  * once a size is measured/reported, the content dictates it. Measurement uses
754
828
  * the html/body offset heights (not the document scrollHeight, which is
@@ -767,6 +841,7 @@ function wireFitContent(iframe: HTMLIFrameElement): void {
767
841
  const doc = iframe.contentDocument;
768
842
  const body = doc?.body;
769
843
  if (!body) return; // cross-origin — rely on postMessage instead
844
+ if (_reportingDocuments.get(iframe) === doc) return; // the demo reports its own size
770
845
  setFitSize(iframe, {
771
846
  height: Math.max(doc!.documentElement.offsetHeight, body.offsetHeight, body.scrollHeight),
772
847
  width: measureContentWidth(iframe, body),
@@ -818,7 +893,7 @@ function wireFitContent(iframe: HTMLIFrameElement): void {
818
893
  }, 3000);
819
894
  };
820
895
 
821
- // iframeOnly renders `src` directly, so the iframe may already be loaded —
896
+ // chrome="bare" renders `src` directly, so the iframe may already be loaded —
822
897
  // and a cross-origin iframe gives no way to detect that (contentDocument is
823
898
  // null whether it's loaded or not). Run the handler once at wire time as
824
899
  // well: on a not-yet-loaded iframe the enable message is simply lost and
@@ -919,7 +994,7 @@ function initResizableSamples(): void {
919
994
  * `.ig-code-view` elements managed by code-view.js.
920
995
  */
921
996
  export function initSampleWidgets(): void {
922
- // Wire fit-content iframes (both full widgets and iframeOnly samples) up front
997
+ // Wire fit-content iframes (widgets and chrome="bare" samples alike) up front
923
998
  // so they start measuring as soon as their content loads.
924
999
  initFitContentIframes();
925
1000
 
@@ -969,8 +1044,8 @@ export function initSampleWidgets(): void {
969
1044
  const demosBaseUrl = widget.dataset.demosBaseUrl || '';
970
1045
  const githubSrc = widget.dataset.githubSrc || '';
971
1046
  const platform = normalizePlatform(widget.dataset.platform || 'angular');
972
- // `hideCode` samples render no tabs: only the demo and the theme picker.
973
- const hideCode = widget.dataset.hideCode === 'true';
1047
+ // `chrome="demo"` samples render no tabs: only the demo and the theme picker.
1048
+ const isDemo = widget.dataset.chrome === 'demo';
974
1049
 
975
1050
  if (!iframeSrc) return;
976
1051
 
@@ -978,7 +1053,7 @@ export function initSampleWidgets(): void {
978
1053
  const samplePane = widget.querySelector<HTMLElement>('.igd-sample-container');
979
1054
  const iframe = widget.querySelector<HTMLIFrameElement>('iframe');
980
1055
 
981
- if (!igcTabs && !hideCode) return;
1056
+ if (!igcTabs && !isDemo) return;
982
1057
 
983
1058
  const exampleTabId = `${widget.id}-example`;
984
1059
 
@@ -1046,19 +1121,11 @@ export function initSampleWidgets(): void {
1046
1121
  // Wire copy buttons for pre-rendered code tabs (e.g. MockSample in playground).
1047
1122
  widget.querySelectorAll<HTMLElement>('.code-wrapper').forEach((pre) => {
1048
1123
  const btn = pre.querySelector<HTMLElement>('.cv-hljs-code-copy');
1049
- const icon = btn?.querySelector<HTMLElement>('igc-icon');
1050
1124
  const code = pre.querySelector<HTMLElement>('code');
1051
1125
  if (!btn || !code) return;
1052
1126
  const codeLang = (code.className.match(/language-(\S+)/) ?? [])[1] ?? 'text';
1053
1127
  highlightCode(code, normalizeCodeLang(codeLang));
1054
- btn.addEventListener('click', () => {
1055
- navigator.clipboard.writeText(code.textContent ?? '').then(() => {
1056
- icon?.setAttribute('name', 'check');
1057
- setTimeout(() => {
1058
- icon?.setAttribute('name', 'copy');
1059
- }, 1500);
1060
- });
1061
- });
1128
+ wireCopyButton(btn, () => code.textContent ?? '');
1062
1129
  });
1063
1130
 
1064
1131
  // Enqueue iframe loading.
@@ -1082,7 +1149,7 @@ export function initSampleWidgets(): void {
1082
1149
 
1083
1150
  // No code to fetch and nothing to live-edit or open in full screen: the
1084
1151
  // footer carries only the theme picker, right away.
1085
- if (hideCode || !igcTabs) {
1152
+ if (isDemo || !igcTabs) {
1086
1153
  addFooter(widget, iframeSrc, null, null, null, false);
1087
1154
  return;
1088
1155
  }
@@ -1,55 +1,77 @@
1
- @use 'igniteui-theming' as *;
2
1
  @use 'copy-button' as *;
3
2
 
4
3
  /* ============================================================
5
- Code Blocks (Shiki dual-theme)
6
- Shiki emits CSS variables per span:
7
- --shiki-light / --shiki-light-bg (default, inline style)
8
- --shiki-dark / --shiki-dark-bg (need CSS to activate)
4
+ Code snippets: fenced blocks and <Code> (`pre.astro-code`), direct
5
+ `codeToHtml()` output (`pre.shiki`) and Sample code tabs (`pre.igd-code`).
6
+ Shiki writes the background, default text and token colours inline
7
+ (src/code-theme); these rules only shape the surface.
8
+ Surface tokens (`--igd-code-*`) live in _variables.scss.
9
9
  ============================================================ */
10
10
 
11
- .shiki {
12
- border: 1px solid var(--ig-gray-200);
13
- margin-bottom: rem(26px);
14
- }
15
-
16
- pre.shiki {
17
- overflow-x: auto;
11
+ pre.astro-code,
12
+ pre.shiki,
13
+ pre.igd-code {
14
+ // Snippets are always dark: dark scrollbars and form-control colours.
15
+ color-scheme: dark;
16
+ border: var(--igd-code-border);
17
+ border-radius: var(--igd-code-radius);
18
+ padding: var(--igd-code-padding);
19
+ margin-block: 0 var(--igd-code-margin-bottom);
20
+ font-family: var(--igd-code-font-family);
21
+ font-size: var(--igd-code-font-size);
22
+ line-height: var(--igd-code-line-height);
23
+ font-weight: 400;
24
+ tab-size: 2;
18
25
  max-width: 100%;
19
- word-wrap: break-word;
20
- white-space: pre-wrap;
21
- border-radius: var(--igd-border-radius);
22
- padding: rem(32px);
23
- }
24
-
25
- pre.shiki code {
26
+ overflow-x: auto;
26
27
  white-space: pre-wrap;
28
+ overflow-wrap: break-word;
27
29
  word-break: break-word;
28
- }
29
30
 
30
- /* ── Always use the dark theme ──────────────────────────────
31
- Single dark theme — Shiki outputs colors directly, no CSS
32
- variable switching required. */
33
- pre.shiki {
34
- background-color: var(--shiki-color-background) !important;
31
+ code {
32
+ display: block;
33
+ font: inherit;
34
+ white-space: inherit;
35
+ overflow-wrap: inherit;
36
+ word-break: inherit;
37
+ background: none;
38
+ border: 0;
39
+ padding: 0;
40
+ margin: 0;
41
+ }
35
42
  }
36
43
 
44
+ /* ── Copy button (added by CopyCode.astro around every pre.astro-code / pre.shiki) ── */
45
+
37
46
  .copy-code-wrapper {
38
47
  position: relative;
39
48
  z-index: 0;
40
- }
49
+ margin-block-end: var(--igd-code-margin-bottom);
50
+
51
+ > pre {
52
+ margin-block-end: 0;
53
+ }
54
+
55
+ > .copy-btn {
56
+ position: absolute;
57
+ inset-block-start: var(--igd-code-copy-inset);
58
+ inset-inline-end: var(--igd-code-copy-inset);
59
+ z-index: 1;
60
+ opacity: 0;
61
+ transition: opacity 0.15s ease;
41
62
 
42
- .copy-code-wrapper > .copy-btn {
43
- position: absolute;
44
- inset-block-start: rem(8px);
45
- inset-inline-end: rem(8px);
46
- opacity: 0;
47
- z-index: 1;
63
+ @include copy-button-colors;
64
+ }
48
65
 
49
- @include copy-button-colors;
66
+ &:hover > .copy-btn,
67
+ &:focus-within > .copy-btn {
68
+ opacity: 1;
69
+ }
50
70
  }
51
71
 
52
- .copy-code-wrapper:hover > .copy-btn,
53
- .copy-code-wrapper:focus-within > .copy-btn {
54
- opacity: 1;
72
+ // Always shows the copy button on touch devices.
73
+ @media (hover: none) {
74
+ .copy-code-wrapper > .copy-btn {
75
+ opacity: 1;
76
+ }
55
77
  }