igniteui-astro-components 0.0.29 → 0.0.30
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 +1 -1
- package/src/components/DocsSidebar/DocsSidebar.scss +3 -2
- package/src/components/DocsSidebar/SidebarFilterInput.scss +1 -3
- package/src/components/DocsSubHeader/DocsSubHeader.scss +1 -1
- package/src/components/DocsTree/docs-tree.scss +0 -1
- package/src/components/mdx/Sample/README.md +16 -10
- package/src/components/mdx/Sample/Sample.astro +156 -19
- package/src/components/mdx/Sample/Sample.scss +238 -9
- package/src/layouts/DocsLayout/DocsLayout.scss +0 -4
- package/src/scripts/sample-widget.ts +288 -1
- package/src/styles/global/_code-blocks.scss +2 -23
- package/src/styles/global/_copy-button.scss +32 -0
- package/src/styles/global/_search-shared.scss +1 -1
- package/src/styles/global/_variables.scss +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-astro-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
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": {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// Desktop base. On tablet/mobile DocsLayout.scss turns this into a slide-in overlay.
|
|
5
5
|
.docs-sidebar {
|
|
6
6
|
--igd-sidebar-z-index: 0;
|
|
7
|
+
|
|
7
8
|
display: flex;
|
|
8
9
|
flex-direction: column;
|
|
9
10
|
z-index: var(--igd-sidebar-z-index);
|
|
@@ -15,7 +16,6 @@
|
|
|
15
16
|
height: calc(100dvh - var(--igd-header-height));
|
|
16
17
|
max-height: 100dvh;
|
|
17
18
|
align-self: start;
|
|
18
|
-
view-transition-name: docs-sidebar;
|
|
19
19
|
|
|
20
20
|
.sidebar-gutter {
|
|
21
21
|
display: grid;
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
overflow-y: hidden;
|
|
24
24
|
padding: rem(16px);
|
|
25
25
|
border-bottom: var(--igd-app-outline);
|
|
26
|
-
min-height: rem(73px);
|
|
27
26
|
|
|
28
27
|
&:empty {
|
|
29
28
|
display: none;
|
|
@@ -66,6 +65,8 @@
|
|
|
66
65
|
padding-block: rem(12px);
|
|
67
66
|
scroll-behavior: smooth;
|
|
68
67
|
overscroll-behavior: contain;
|
|
68
|
+
flex-grow: 1;
|
|
69
|
+
flex-basis: 0%;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
.sidebar-premium-icon {
|
|
@@ -10,16 +10,22 @@ import Sample from 'igniteui-astro-components/components/mdx/Sample.astro';
|
|
|
10
10
|
|
|
11
11
|
## Props
|
|
12
12
|
|
|
13
|
-
| Prop | Type
|
|
14
|
-
| --------------- |
|
|
15
|
-
| `src` | `string`
|
|
16
|
-
| `height` | `number`
|
|
17
|
-
| `alt` | `string`
|
|
18
|
-
| `lob` | `boolean`
|
|
19
|
-
| `dv` | `boolean`
|
|
20
|
-
| `crm` | `boolean`
|
|
21
|
-
| `iframeOnly` | `boolean`
|
|
22
|
-
| `fullscreenBtn` | `boolean`
|
|
13
|
+
| Prop | Type | Default | Description |
|
|
14
|
+
| --------------- | ------------------------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `src` | `string` | _(required)_ | Sample path relative to the demos base URL, e.g. `"/charts/data-chart/axis-crossing"`. |
|
|
16
|
+
| `height` | `number` | `150` (`50` if `fitContent`) | iframe height in pixels. With `fitContent` it is only the loading placeholder / cross-origin fallback. |
|
|
17
|
+
| `alt` | `string` | `''` | `title` attribute for the iframe (accessibility). |
|
|
18
|
+
| `lob` | `boolean` | `false` | Use `lobDemosBaseUrl` instead of `demosBaseUrl` (LOB/grid-dynamic demos). |
|
|
19
|
+
| `dv` | `boolean` | `false` | Force use of `dvDemosBaseUrl` (data-viz demos). Auto-detected for paths starting with `charts/`, `gauges/`, `maps/`, `excel/`. |
|
|
20
|
+
| `crm` | `boolean` | `false` | Use `crmDemoBaseUrl` (CRM demo samples). |
|
|
21
|
+
| `iframeOnly` | `boolean` | `false` | Render only the iframe — no navbar, no code tabs, no live-edit footer. |
|
|
22
|
+
| `fullscreenBtn` | `boolean` | `false` | When `iframeOnly={true}`, also renders a "View in full screen" button below the iframe. |
|
|
23
|
+
| `fitContent` | `boolean` | `false` | Size the iframe to fit its content — the embedded page dictates the size. Same-origin demos are measured directly; cross-origin demos must report via `postMessage`. Demos with ink overflow (shadows, glows, focus rings) must reserve room for it in their own layout, since an iframe clips at its edge. |
|
|
24
|
+
| `spacing` | `'none' \| 'sm' \| 'md' \| 'lg'` | `'none'` | Padding around the iframe inside the container: `none` = 0, `sm` = 8px, `md` = 16px, `lg` = 32px. Applied by the host container, never inside the embedded page. |
|
|
25
|
+
| `position` | `string` | — | Where the iframe sits inside the container when it doesn't fill it. Accepts a horizontal token (`start`, `center`, `end`) and/or a vertical token (`top`, `center`, `bottom`), space-separated in any order — e.g. `"center"`, `"start top"`, `"end bottom"`. |
|
|
26
|
+
| `resizable` | `boolean` | `false` | Show a drag handle on the right edge that resizes the iframe's width so responsive demos can be previewed at different widths. Left/right arrow keys resize it when focused. Combines with `fitContent`: the drag owns the width, the content keeps dictating the height. |
|
|
27
|
+
| `noBorder` | `boolean` | `true` | Drop the 1px border drawn around the iframe/container. Pass `noBorder={false}` to draw it — recommended whenever chrome (code tabs or `fullscreenBtn`) is visible. |
|
|
28
|
+
| `noBackground` | `boolean` | `true` | Hide the grid-pattern backdrop drawn behind the iframe, keeping the container fully transparent. Pass `noBackground={false}` to show it. |
|
|
23
29
|
|
|
24
30
|
## Examples
|
|
25
31
|
|
|
@@ -19,6 +19,10 @@ import './Sample.scss';
|
|
|
19
19
|
|
|
20
20
|
interface Props {
|
|
21
21
|
src: string;
|
|
22
|
+
/**
|
|
23
|
+
* Iframe height in px. Default 150. With `fitContent` it is only the
|
|
24
|
+
* loading placeholder / cross-origin fallback and defaults to 50.
|
|
25
|
+
*/
|
|
22
26
|
height?: number;
|
|
23
27
|
alt?: string;
|
|
24
28
|
/** Use lobDemosBaseUrl instead of demosBaseUrl (for LOB/grid-dynamic demos). */
|
|
@@ -31,21 +35,106 @@ interface Props {
|
|
|
31
35
|
iframeOnly?: boolean;
|
|
32
36
|
/** When used with iframeOnly, also render a "View in full screen" button below. */
|
|
33
37
|
fullscreenBtn?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Size the iframe to fit its content: the embedded page dictates the
|
|
40
|
+
* iframe's size. `height` serves only as the placeholder/fallback — shown
|
|
41
|
+
* while the demo loads and kept if a cross-origin demo never reports its
|
|
42
|
+
* size. Same-origin demos are measured directly; cross-origin demos must
|
|
43
|
+
* report via postMessage. See sample-widget.ts for the contract.
|
|
44
|
+
* Note: an iframe clips at its edge, so demos with ink overflow (shadows,
|
|
45
|
+
* glows, focus rings) must reserve room for it in their own layout —
|
|
46
|
+
* e.g. body padding matching the shadow's blur + offset.
|
|
47
|
+
*/
|
|
48
|
+
fitContent?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Padding around the iframe inside the container: `none` = 0 (default),
|
|
51
|
+
* `sm` = 8px, `md` = 16px, `lg` = 32px. The padding is applied by the host
|
|
52
|
+
* container, never inside the embedded page.
|
|
53
|
+
*/
|
|
54
|
+
spacing?: 'none' | 'sm' | 'md' | 'lg';
|
|
55
|
+
/**
|
|
56
|
+
* Where the iframe sits inside the container when it doesn't fill it (e.g.
|
|
57
|
+
* after being resized narrower, or with `fitContent` on small content).
|
|
58
|
+
* Accepts a horizontal token (`start`, `center`, `end`) and/or a vertical
|
|
59
|
+
* token (`top`, `center`, `bottom`), space-separated in any order — e.g.
|
|
60
|
+
* "center", "start top", "end bottom". Demo pages must never position
|
|
61
|
+
* themselves (no centering/min-height on their body); this prop is the
|
|
62
|
+
* single place alignment is decided.
|
|
63
|
+
*/
|
|
64
|
+
position?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Show a drag handle on the right edge that resizes the iframe's width so
|
|
67
|
+
* responsive demos can be previewed at different widths. Only the iframe is
|
|
68
|
+
* resized (horizontally); the component's own footprint never changes.
|
|
69
|
+
* When focused, the left/right arrow keys resize it too. Combines with
|
|
70
|
+
* `fitContent`: the drag owns the width while the content keeps dictating
|
|
71
|
+
* the height, so a reflowed demo never scrolls inside the iframe.
|
|
72
|
+
*/
|
|
73
|
+
resizable?: boolean;
|
|
74
|
+
/** Drop the 1px border drawn around the iframe/container. Defaults to true. */
|
|
75
|
+
noBorder?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Hide the grid-pattern backdrop drawn behind the iframe (default). The
|
|
78
|
+
* container is fully transparent, so a demo without a background of its own
|
|
79
|
+
* sits directly on the page.
|
|
80
|
+
*/
|
|
81
|
+
noBackground?: boolean;
|
|
34
82
|
}
|
|
35
83
|
|
|
36
84
|
const {
|
|
37
85
|
src,
|
|
38
|
-
height = 400,
|
|
39
86
|
alt = '',
|
|
40
87
|
lob = false,
|
|
41
88
|
dv = false,
|
|
42
89
|
crm = false,
|
|
43
90
|
iframeOnly = false,
|
|
44
91
|
fullscreenBtn = false,
|
|
92
|
+
fitContent = false,
|
|
93
|
+
spacing = 'none',
|
|
94
|
+
position,
|
|
95
|
+
resizable = false,
|
|
96
|
+
noBorder = true,
|
|
97
|
+
noBackground = true,
|
|
45
98
|
} = Astro.props;
|
|
99
|
+
|
|
100
|
+
// Fixed samples default to 150px. In fitContent mode `height` is only the
|
|
101
|
+
// loading placeholder, so an unspecified one defaults lower (50px) to avoid
|
|
102
|
+
// reserving a tall wall of space that collapses once the demo reports its size.
|
|
103
|
+
const height = Astro.props.height ?? (fitContent ? 50 : 150);
|
|
46
104
|
const { name, lower } = Astro.locals.platformContext as PlatformContext;
|
|
105
|
+
|
|
47
106
|
const env = Astro.locals.envVars ?? {};
|
|
48
107
|
|
|
108
|
+
// ─ Layout options (spacing / position / resize) ────────────────────────────────
|
|
109
|
+
const spacingVal = ['none', 'sm', 'md', 'lg'].includes(spacing) ? spacing : 'none';
|
|
110
|
+
|
|
111
|
+
// fitContent: the container grows around the iframe, so it gets no inline
|
|
112
|
+
// height. The iframe carries `height` as the placeholder/fallback until the
|
|
113
|
+
// demo's measured/reported size replaces it (sample-widget.ts).
|
|
114
|
+
const containerStyle = fitContent ? undefined : `height: ${height}px`;
|
|
115
|
+
const iframeStyle = fitContent ? `width: 100%; height: ${height}px;` : 'width: 100%; height: 100%;';
|
|
116
|
+
|
|
117
|
+
// Split `position` into a horizontal + vertical token. "center" applies to
|
|
118
|
+
// whichever axis isn't otherwise specified. These become data-attributes the
|
|
119
|
+
// SCSS turns into flex alignment (and gives the frame slack so the alignment is
|
|
120
|
+
// actually visible — a full-size frame has nothing to align).
|
|
121
|
+
const posTokens = (position ?? '').toLowerCase().split(/\s+/).filter(Boolean);
|
|
122
|
+
const hToken =
|
|
123
|
+
posTokens.find((t) => t === 'start' || t === 'end') ??
|
|
124
|
+
(posTokens.includes('center') ? 'center' : undefined);
|
|
125
|
+
const vToken =
|
|
126
|
+
posTokens.find((t) => t === 'top' || t === 'bottom') ??
|
|
127
|
+
(posTokens.includes('center') ? 'center' : undefined);
|
|
128
|
+
|
|
129
|
+
// Resizing is horizontal-only. With fitContent the drag owns the width and the
|
|
130
|
+
// measured content keeps dictating the height (sample-widget.ts skips width
|
|
131
|
+
// measurement on resizable containers so the two never fight).
|
|
132
|
+
const isResizable = resizable;
|
|
133
|
+
|
|
134
|
+
// Flex layout is only needed (and only turned on) when one of the new options
|
|
135
|
+
// requires it — keeps the default rendering byte-for-byte unchanged.
|
|
136
|
+
const useFlex = Boolean(hToken || vToken || isResizable);
|
|
137
|
+
|
|
49
138
|
// DV samples (charts, gauges, maps, excel) use dvDemosBaseUrl when available.
|
|
50
139
|
const DV_PREFIXES = ['gauges/', 'maps/', 'excel/', 'charts/'];
|
|
51
140
|
const srcNoSlash = src.replace(/^\//, '');
|
|
@@ -69,14 +158,38 @@ const exampleTabId = `${widgetId}-example`;
|
|
|
69
158
|
{
|
|
70
159
|
iframeOnly ? (
|
|
71
160
|
<>
|
|
72
|
-
<div
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
161
|
+
<div
|
|
162
|
+
class:list={[
|
|
163
|
+
'igd-sample-container',
|
|
164
|
+
{
|
|
165
|
+
'igd-sample-container--fit-content': fitContent,
|
|
166
|
+
'igd-sample-container--flex': useFlex,
|
|
167
|
+
'igd-sample-container--resizable': isResizable,
|
|
168
|
+
'igd-sample-container--no-border': noBorder,
|
|
169
|
+
'igd-sample-container--no-background': noBackground,
|
|
170
|
+
},
|
|
171
|
+
]}
|
|
172
|
+
data-fit-content={fitContent ? 'true' : undefined}
|
|
173
|
+
data-spacing={spacingVal}
|
|
174
|
+
data-justify={hToken}
|
|
175
|
+
data-valign={vToken}
|
|
176
|
+
data-resizable={isResizable ? 'true' : undefined}
|
|
177
|
+
tabindex={isResizable ? '0' : undefined}
|
|
178
|
+
aria-label={
|
|
179
|
+
isResizable ? 'Resizable sample — use the left and right arrow keys to resize' : undefined
|
|
180
|
+
}
|
|
181
|
+
style={containerStyle}
|
|
182
|
+
>
|
|
183
|
+
<div class="igd-sample-frame">
|
|
184
|
+
<iframe
|
|
185
|
+
src={iframeSrc}
|
|
186
|
+
title={alt || `${name} Example`}
|
|
187
|
+
style={iframeStyle}
|
|
188
|
+
frameborder="0"
|
|
189
|
+
seamless
|
|
190
|
+
/>
|
|
191
|
+
{isResizable && <div class="igd-sample-resize-handle" aria-hidden="true" />}
|
|
192
|
+
</div>
|
|
80
193
|
{fullscreenBtn && (
|
|
81
194
|
<div class="igd-code-view__header-actions">
|
|
82
195
|
<igc-icon-button
|
|
@@ -106,23 +219,47 @@ const exampleTabId = `${widgetId}-example`;
|
|
|
106
219
|
<igc-tabs id={`${widgetId}-tabs`} alignment="start">
|
|
107
220
|
<igc-tab id={exampleTabId} label="EXAMPLE" selected>
|
|
108
221
|
<div
|
|
109
|
-
class=
|
|
222
|
+
class:list={[
|
|
223
|
+
'igd-sample-container',
|
|
224
|
+
'loading',
|
|
225
|
+
{
|
|
226
|
+
'igd-sample-container--fit-content': fitContent,
|
|
227
|
+
'igd-sample-container--flex': useFlex,
|
|
228
|
+
'igd-sample-container--resizable': isResizable,
|
|
229
|
+
'igd-sample-container--no-border': noBorder,
|
|
230
|
+
'igd-sample-container--no-background': noBackground,
|
|
231
|
+
},
|
|
232
|
+
]}
|
|
233
|
+
data-fit-content={fitContent ? 'true' : undefined}
|
|
234
|
+
data-spacing={spacingVal}
|
|
235
|
+
data-justify={hToken}
|
|
236
|
+
data-valign={vToken}
|
|
237
|
+
data-resizable={isResizable ? 'true' : undefined}
|
|
238
|
+
tabindex={isResizable ? '0' : undefined}
|
|
239
|
+
aria-label={
|
|
240
|
+
isResizable
|
|
241
|
+
? 'Resizable sample — use the left and right arrow keys to resize'
|
|
242
|
+
: undefined
|
|
243
|
+
}
|
|
110
244
|
aria-busy="true"
|
|
111
|
-
style={
|
|
245
|
+
style={containerStyle}
|
|
112
246
|
>
|
|
113
247
|
<igc-circular-progress
|
|
114
248
|
indeterminate
|
|
115
249
|
class="sample-loading-indicator"
|
|
116
250
|
aria-label="Loading sample"
|
|
117
251
|
/>
|
|
118
|
-
<
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
252
|
+
<div class="igd-sample-frame">
|
|
253
|
+
<iframe
|
|
254
|
+
data-src={iframeSrc}
|
|
255
|
+
title={alt || `${name} Example`}
|
|
256
|
+
style={iframeStyle}
|
|
257
|
+
frameborder="0"
|
|
258
|
+
seamless
|
|
259
|
+
aria-hidden="true"
|
|
260
|
+
/>
|
|
261
|
+
{isResizable && <div class="igd-sample-resize-handle" aria-hidden="true" />}
|
|
262
|
+
</div>
|
|
126
263
|
</div>
|
|
127
264
|
</igc-tab>
|
|
128
265
|
</igc-tabs>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use 'igniteui-theming/sass/typography' as *;
|
|
2
|
+
@use '../../../styles/global/copy-button' as *;
|
|
2
3
|
|
|
3
4
|
igc-tabs {
|
|
4
5
|
position: relative;
|
|
@@ -28,6 +29,7 @@ igc-tabs {
|
|
|
28
29
|
.igd-code-view__header-actions {
|
|
29
30
|
border-block: rem(1px) solid light-dark(var(--ig-gray-300), var(--ig-gray-200));
|
|
30
31
|
}
|
|
32
|
+
border-radius: rem(4px) rem(4px) 0 0;
|
|
31
33
|
|
|
32
34
|
.igd-sample-container {
|
|
33
35
|
border-inline: none;
|
|
@@ -51,23 +53,37 @@ igc-tab {
|
|
|
51
53
|
border: none;
|
|
52
54
|
border-top: rem(1px) solid var(--ig-gray-300);
|
|
53
55
|
max-height: rem(400px);
|
|
54
|
-
|
|
56
|
+
// Vertical scroll only — long lines wrap (see the pre below) instead of
|
|
57
|
+
// forcing a horizontal scrollbar on the pane.
|
|
58
|
+
overflow: hidden auto;
|
|
55
59
|
overscroll-behavior: contain;
|
|
56
60
|
|
|
57
61
|
pre {
|
|
58
62
|
margin: 0;
|
|
59
63
|
border: none;
|
|
60
|
-
|
|
64
|
+
// Same spacing token the EXAMPLE pane uses for `md`, so the code
|
|
65
|
+
// and the demo share the same breathing room (and both follow an
|
|
66
|
+
// --igd-sample-spacing-md override).
|
|
67
|
+
padding: var(--igd-sample-spacing-md, #{rem(16px)});
|
|
61
68
|
border-radius: 0;
|
|
69
|
+
white-space: pre-wrap;
|
|
70
|
+
word-break: break-word;
|
|
62
71
|
}
|
|
63
72
|
|
|
73
|
+
// Match the page-level CopyCode button (.copy-btn): flat variant, same
|
|
74
|
+
// 8px corner offset, and the shared palette — the code pane is always
|
|
75
|
+
// dark (single dark Shiki theme) while the button's default colors
|
|
76
|
+
// follow the site theme, so without the palette the icon was invisible
|
|
77
|
+
// in light mode until hovered.
|
|
64
78
|
.cv-hljs-code-copy {
|
|
65
79
|
position: absolute;
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
inset-block-start: rem(8px);
|
|
81
|
+
inset-inline-end: rem(8px);
|
|
68
82
|
opacity: 0;
|
|
69
83
|
transition: opacity 0.2s ease;
|
|
70
84
|
pointer-events: none;
|
|
85
|
+
|
|
86
|
+
@include copy-button-colors;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
89
|
&:hover .cv-hljs-code-copy,
|
|
@@ -93,6 +109,7 @@ igc-tab::part(tab-header) {
|
|
|
93
109
|
.igd-code-view {
|
|
94
110
|
width: 100%;
|
|
95
111
|
border: rem(1px) solid var(--ig-gray-300);
|
|
112
|
+
border-radius: rem(4px);
|
|
96
113
|
margin-block-end: rem(26px);
|
|
97
114
|
|
|
98
115
|
.igd-sample-container {
|
|
@@ -108,17 +125,19 @@ igc-tab::part(tab-header) {
|
|
|
108
125
|
.igd-sample-container {
|
|
109
126
|
--sample-container-header-height: #{rem(66px)};
|
|
110
127
|
|
|
128
|
+
display: grid;
|
|
111
129
|
position: relative;
|
|
112
130
|
border: rem(1px) solid var(--ig-gray-300);
|
|
113
|
-
|
|
114
|
-
max-height: rem(800px);
|
|
115
|
-
overflow: hidden auto;
|
|
131
|
+
overflow: hidden;
|
|
116
132
|
margin-block-end: rem(26px);
|
|
133
|
+
z-index: 0;
|
|
134
|
+
background: light-dark(var(--ig-gray-100), var(--ig-surface-500));
|
|
117
135
|
|
|
118
136
|
iframe {
|
|
119
137
|
display: block;
|
|
120
138
|
border: none;
|
|
121
139
|
margin: 0;
|
|
140
|
+
overflow: hidden;
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
.sample-loading-indicator {
|
|
@@ -136,6 +155,217 @@ igc-tab::part(tab-header) {
|
|
|
136
155
|
&.loading .sample-loading-indicator {
|
|
137
156
|
opacity: 1;
|
|
138
157
|
}
|
|
158
|
+
|
|
159
|
+
// Fit-content mode: the embedded content dictates the size — the `height`
|
|
160
|
+
// prop is ignored (Sample.astro emits no inline height). sample-widget.ts
|
|
161
|
+
// sets an exact px height on the iframe (from same-origin measurement or a
|
|
162
|
+
// postMessage from the demo) and the frame/container grow around it,
|
|
163
|
+
// spacing padding included.
|
|
164
|
+
&--fit-content {
|
|
165
|
+
height: auto;
|
|
166
|
+
min-height: 0;
|
|
167
|
+
max-height: none;
|
|
168
|
+
// `clip` (not `visible`): the container is sized exactly to the iframe,
|
|
169
|
+
// and anything spilling out (e.g. the +1px grid-pattern ::after overlay)
|
|
170
|
+
// would otherwise inflate the ancestor igc-tabs' scrollWidth and lock its
|
|
171
|
+
// header into scroll-button mode.
|
|
172
|
+
overflow: clip;
|
|
173
|
+
|
|
174
|
+
iframe {
|
|
175
|
+
max-width: 100%;
|
|
176
|
+
// The iframe starts at the `height` placeholder and snaps to the
|
|
177
|
+
// measured content size once the demo loads/reports — ease that
|
|
178
|
+
// jump instead of letting the page reflow abruptly.
|
|
179
|
+
transition:
|
|
180
|
+
width 0.25s ease,
|
|
181
|
+
height 0.25s ease;
|
|
182
|
+
|
|
183
|
+
@media (prefers-reduced-motion: reduce) {
|
|
184
|
+
transition: none;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Drop the default border/outline drawn around the iframe.
|
|
190
|
+
&--no-border {
|
|
191
|
+
border: none;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Hide the grid-pattern backdrop drawn behind the iframe (the ::after
|
|
195
|
+
// overlay below) — the container becomes fully transparent, so demos
|
|
196
|
+
// without a background of their own sit directly on the page.
|
|
197
|
+
&--no-background {
|
|
198
|
+
background: transparent;
|
|
199
|
+
|
|
200
|
+
&::after {
|
|
201
|
+
display: none;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Wrapper around the iframe. In the default (block) layout it is transparent
|
|
206
|
+
// (fills the container just like the bare iframe did); when the container
|
|
207
|
+
// opts into flex layout it becomes the positioned/resizable element.
|
|
208
|
+
.igd-sample-frame {
|
|
209
|
+
position: relative;
|
|
210
|
+
width: 100%;
|
|
211
|
+
height: 100%;
|
|
212
|
+
max-width: 100%;
|
|
213
|
+
flex: 0 0 auto;
|
|
214
|
+
overflow: auto;
|
|
215
|
+
z-index: 1;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// In fit-content mode the frame hugs the JS-sized iframe instead of filling
|
|
219
|
+
// the container, so flex alignment (position) can move the content-sized box
|
|
220
|
+
// around. Must come after the base .igd-sample-frame rule — same specificity,
|
|
221
|
+
// order decides.
|
|
222
|
+
&--fit-content .igd-sample-frame {
|
|
223
|
+
// Height hugs the JS-sized iframe. Width intentionally stays 100% (base
|
|
224
|
+
// rule): a shrink-to-fit frame would make the iframe's `width: 100%`
|
|
225
|
+
// indefinite and collapse it to the 300px intrinsic default — inner
|
|
226
|
+
// horizontal scrollbars on every unmeasured/cross-origin demo. When a
|
|
227
|
+
// real content width is measured/reported, sample-widget.ts switches
|
|
228
|
+
// the frame to `width: auto` inline so flex alignment can center it.
|
|
229
|
+
height: auto;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Padding around the iframe. Applied by the host, never inside the demo.
|
|
233
|
+
// `md` is the default emitted by Sample.astro; `none` removes it entirely.
|
|
234
|
+
// Each size reads a CSS variable with the default as fallback, so consumers
|
|
235
|
+
// can retune the whole scale from any ancestor, e.g.
|
|
236
|
+
// :root { --igd-sample-spacing-md: 24px; }
|
|
237
|
+
&[data-spacing='none'] {
|
|
238
|
+
padding: 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
&[data-spacing='sm'] {
|
|
242
|
+
padding: var(--igd-sample-spacing-sm, #{rem(8px)});
|
|
243
|
+
|
|
244
|
+
.igd-code-view__header-actions {
|
|
245
|
+
margin-inline: calc(var(--igd-sample-spacing-sm, #{rem(8px)}) * -1);
|
|
246
|
+
margin-block-end: calc(var(--igd-sample-spacing-sm, #{rem(8px)}) * -1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
&[data-spacing='md'] {
|
|
251
|
+
padding: var(--igd-sample-spacing-md, #{rem(16px)});
|
|
252
|
+
|
|
253
|
+
.igd-code-view__header-actions {
|
|
254
|
+
margin-inline: calc(var(--igd-sample-spacing-md, #{rem(16px)}) * -1);
|
|
255
|
+
margin-block-end: calc(var(--igd-sample-spacing-md, #{rem(16px)}) * -1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
&[data-spacing='lg'] {
|
|
260
|
+
padding: var(--igd-sample-spacing-lg, #{rem(32px)});
|
|
261
|
+
|
|
262
|
+
.igd-code-view__header-actions {
|
|
263
|
+
margin-inline: calc(var(--igd-sample-spacing-lg, #{rem(32px)}) * -1);
|
|
264
|
+
margin-block-end: calc(var(--igd-sample-spacing-lg, #{rem(32px)}) * -1);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Flex layout — only enabled when position/resize needs it. The `position`
|
|
269
|
+
// prop is emitted as data-justify / data-valign attributes.
|
|
270
|
+
&--flex {
|
|
271
|
+
display: flex;
|
|
272
|
+
justify-content: flex-start;
|
|
273
|
+
align-items: stretch;
|
|
274
|
+
|
|
275
|
+
&[data-justify='start'] {
|
|
276
|
+
justify-content: flex-start;
|
|
277
|
+
}
|
|
278
|
+
&[data-justify='center'] {
|
|
279
|
+
justify-content: center;
|
|
280
|
+
}
|
|
281
|
+
&[data-justify='end'] {
|
|
282
|
+
justify-content: flex-end;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
&[data-valign='top'] {
|
|
286
|
+
align-items: flex-start;
|
|
287
|
+
}
|
|
288
|
+
&[data-valign='center'] {
|
|
289
|
+
align-items: center;
|
|
290
|
+
}
|
|
291
|
+
&[data-valign='bottom'] {
|
|
292
|
+
align-items: flex-end;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// A frame that fills the container has nothing to align, so give it slack
|
|
296
|
+
// on any axis that has an explicit (non-start/stretch) alignment. `start`
|
|
297
|
+
// keeps full width — it looks identical to the default. Resizing overrides
|
|
298
|
+
// the width inline, so this is only the initial state. Fit-content frames
|
|
299
|
+
// are excluded: there the measured content defines the frame size.
|
|
300
|
+
&[data-justify='center']:not([data-fit-content]) .igd-sample-frame,
|
|
301
|
+
&[data-justify='end']:not([data-fit-content]) .igd-sample-frame {
|
|
302
|
+
width: 65%;
|
|
303
|
+
}
|
|
304
|
+
&[data-valign]:not([data-fit-content]) .igd-sample-frame {
|
|
305
|
+
height: 65%;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Keep the fullscreen bar pinned to the bottom instead of becoming a
|
|
309
|
+
// flex sibling of the iframe frame.
|
|
310
|
+
> .igd-code-view__header-actions {
|
|
311
|
+
position: absolute;
|
|
312
|
+
inset-inline: 0;
|
|
313
|
+
inset-block-end: 0;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Resizable mode: a drag handle on the right edge resizes the iframe's width
|
|
318
|
+
// (see sample-widget.ts). The handle is always visible.
|
|
319
|
+
&--resizable {
|
|
320
|
+
&:focus-visible {
|
|
321
|
+
outline: rem(2px) solid var(--igd-accent);
|
|
322
|
+
outline-offset: rem(-2px);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// While dragging, stop the iframe from swallowing pointer moves.
|
|
327
|
+
&.resizing iframe {
|
|
328
|
+
pointer-events: none;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.igd-sample-resize-handle {
|
|
332
|
+
position: absolute;
|
|
333
|
+
inset-block: 0;
|
|
334
|
+
// Kept 16px off the edge at all times: the demo may show a vertical
|
|
335
|
+
// scrollbar at the iframe's right edge, and a handle sitting on top of
|
|
336
|
+
// it would intercept the pointer and make the scrollbar unusable.
|
|
337
|
+
inset-inline-end: rem(16px);
|
|
338
|
+
display: flex;
|
|
339
|
+
align-items: center;
|
|
340
|
+
justify-content: center;
|
|
341
|
+
width: rem(10px);
|
|
342
|
+
cursor: ew-resize;
|
|
343
|
+
touch-action: none;
|
|
344
|
+
z-index: 2;
|
|
345
|
+
|
|
346
|
+
&::before {
|
|
347
|
+
content: '';
|
|
348
|
+
width: rem(4px);
|
|
349
|
+
height: rem(32px);
|
|
350
|
+
border-radius: rem(2px);
|
|
351
|
+
background: light-dark(var(--ig-gray-500), var(--ig-gray-400));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Shod this conditionally
|
|
356
|
+
//&::after {
|
|
357
|
+
// position: absolute;
|
|
358
|
+
// inset: 0;
|
|
359
|
+
// width: calc(100% + 1px);
|
|
360
|
+
// height: calc(100% + 1px);
|
|
361
|
+
// content: '';
|
|
362
|
+
// background-color: #f9f9f9;
|
|
363
|
+
// opacity: 0.1;
|
|
364
|
+
// background-image: repeating-linear-gradient(to right, transparent 0, transparent 2px, #f9f9f9 2px, #f9f9f9 6px, transparent 6px, transparent 8px), repeating-linear-gradient(to bottom, transparent 0, transparent 2px, #f9f9f9 2px, #f9f9f9 6px, transparent 6px, transparent 8px), linear-gradient(to bottom, #000000 0.72px, transparent 0.72px), linear-gradient(to right, #000000 0.72px, transparent 0.72px) ;
|
|
365
|
+
// background-size: 100% 100%, 100% 100%, 24px 24px, 24px 24px;
|
|
366
|
+
// background-position: 0 0, 0 0, 0 -0.24px, -0.24px 0;
|
|
367
|
+
// z-index: 0;
|
|
368
|
+
//}
|
|
139
369
|
}
|
|
140
370
|
|
|
141
371
|
.full-screen-btn {
|
|
@@ -158,11 +388,10 @@ igc-tab::part(tab-header) {
|
|
|
158
388
|
}
|
|
159
389
|
|
|
160
390
|
.igd-code-view__header-actions {
|
|
161
|
-
position: sticky;
|
|
162
|
-
inset-block-end: 0;
|
|
163
391
|
height: var(--sample-container-header-height);
|
|
164
392
|
border-block-start: rem(1px) solid var(--ig-gray-300);
|
|
165
393
|
background-color: var(--igd-layout-sections-bg);
|
|
394
|
+
z-index: 1;
|
|
166
395
|
}
|
|
167
396
|
|
|
168
397
|
igc-button {
|
|
@@ -86,9 +86,6 @@
|
|
|
86
86
|
// ════════════════════════════════════════════════════════════════════════════
|
|
87
87
|
|
|
88
88
|
@media (min-width: #{$bp-desktop-wide}) {
|
|
89
|
-
.igd-page-layout {
|
|
90
|
-
--igd-page-layout-grid: #{rem(400px)} 1fr;
|
|
91
|
-
}
|
|
92
89
|
|
|
93
90
|
.igd-main-content__page {
|
|
94
91
|
gap: var(--ig-padding);
|
|
@@ -189,7 +186,6 @@
|
|
|
189
186
|
|
|
190
187
|
// This is the height of the input in fluent theme + 8px padding + height of the logo above
|
|
191
188
|
.sidebar-gutter {
|
|
192
|
-
min-height: rem(80px);
|
|
193
189
|
align-items: center;
|
|
194
190
|
}
|
|
195
191
|
}
|
|
@@ -209,8 +209,10 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile): void {
|
|
|
209
209
|
code.textContent = file.content;
|
|
210
210
|
pre.appendChild(code);
|
|
211
211
|
|
|
212
|
+
// Same flat variant as the page-level CopyCode button so both copy
|
|
213
|
+
// affordances look identical.
|
|
212
214
|
const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
|
|
213
|
-
copyBtn.setAttribute('variant', '
|
|
215
|
+
copyBtn.setAttribute('variant', 'flat');
|
|
214
216
|
copyBtn.setAttribute('aria-label', 'Copy code');
|
|
215
217
|
copyBtn.className = 'cv-hljs-code-copy';
|
|
216
218
|
|
|
@@ -247,6 +249,10 @@ function addFooter(
|
|
|
247
249
|
onStackblitz: (() => void) | null,
|
|
248
250
|
_onCodeSandbox: (() => void) | null,
|
|
249
251
|
): void {
|
|
252
|
+
// A footer may already be server-rendered (e.g. the playground's MockSample);
|
|
253
|
+
// don't append a second one.
|
|
254
|
+
if (widget.querySelector('.igd-code-view__footer-actions')) return;
|
|
255
|
+
|
|
250
256
|
const footer = document.createElement('div');
|
|
251
257
|
footer.className = 'igd-code-view__footer-actions';
|
|
252
258
|
|
|
@@ -550,6 +556,280 @@ class XplatCodeService {
|
|
|
550
556
|
}
|
|
551
557
|
}
|
|
552
558
|
|
|
559
|
+
// ─── Fit-to-content sizing ──────────────────────────────────────────────────────
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Message a demo can post to resize its host `<Sample fitContent>` iframe:
|
|
563
|
+
* parent.postMessage({ type: 'igd-sample-height', height: <px>, width: <px?> }, '*')
|
|
564
|
+
* This is the path for cross-origin demos, where the host page can't read the
|
|
565
|
+
* iframe's contentDocument to measure it directly. `width` is optional — post
|
|
566
|
+
* it when the sample is horizontally aligned via `position`.
|
|
567
|
+
*/
|
|
568
|
+
const FIT_CONTENT_MESSAGE = 'igd-sample-height';
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Posted INTO the iframe once it loads, telling the embedded demo that its
|
|
572
|
+
* host sizes itself to the content. The demo's reporter script reacts by
|
|
573
|
+
* neutralizing viewport-bound sizing (`html, body { height: 100% }` — which
|
|
574
|
+
* would otherwise just echo the iframe height back) and starts posting
|
|
575
|
+
* FIT_CONTENT_MESSAGE sizes. Demos in fixed-height samples never receive this
|
|
576
|
+
* and keep their percentage-height layouts.
|
|
577
|
+
*/
|
|
578
|
+
const FIT_CONTENT_ENABLE_MESSAGE = 'igd-sample-fit';
|
|
579
|
+
|
|
580
|
+
let _fitContentMessageBound = false;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Apply a measured content size to a fit-content iframe. The size goes on the
|
|
584
|
+
* iframe itself; the container has `height: auto` in fit-content mode, so it
|
|
585
|
+
* grows around the iframe (including any `spacing` padding). Width is only
|
|
586
|
+
* applied when reported/measured — see measureContentWidth().
|
|
587
|
+
*/
|
|
588
|
+
function setFitSize(iframe: HTMLIFrameElement, size: { height?: number; width?: number }): void {
|
|
589
|
+
if (size.height && size.height > 0) {
|
|
590
|
+
iframe.style.height = `${Math.ceil(size.height)}px`;
|
|
591
|
+
// Distinguish a real measured/reported size from the server-rendered
|
|
592
|
+
// `height` fallback the iframe starts with.
|
|
593
|
+
iframe.dataset.fitSized = 'true';
|
|
594
|
+
}
|
|
595
|
+
if (size.width && size.width > 0) {
|
|
596
|
+
iframe.style.width = `${Math.ceil(size.width)}px`;
|
|
597
|
+
// The frame defaults to full width (see Sample.scss); once the iframe
|
|
598
|
+
// has a definite px width, let the frame shrink-wrap it so the host's
|
|
599
|
+
// flex alignment (position) can move the content-sized box around.
|
|
600
|
+
const frame = iframe.closest<HTMLElement>('.igd-sample-frame');
|
|
601
|
+
if (frame) frame.style.width = 'auto';
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Measure the intrinsic width of a same-origin demo's content. Only used when
|
|
607
|
+
* the host container aligns the iframe horizontally (`position` → data-justify):
|
|
608
|
+
* block-level demo content stretches to the viewport width, so instead we take
|
|
609
|
+
* the right-most element box. Demos with intrinsically sized content (a lone
|
|
610
|
+
* avatar, a button…) shrink the iframe to that content, letting the host's
|
|
611
|
+
* flex alignment actually center/end-align it. Full-width demos measure the
|
|
612
|
+
* viewport width and are left as-is.
|
|
613
|
+
*
|
|
614
|
+
* Resizable containers are excluded entirely: there the user's drag owns the
|
|
615
|
+
* width, and applying a measured width would clobber it on every observer tick.
|
|
616
|
+
*/
|
|
617
|
+
function measureContentWidth(iframe: HTMLIFrameElement, body: HTMLElement): number | undefined {
|
|
618
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
619
|
+
if (!container?.dataset.justify || container.dataset.resizable) return undefined;
|
|
620
|
+
const left = body.getBoundingClientRect().left;
|
|
621
|
+
let right = left;
|
|
622
|
+
body.querySelectorAll('*').forEach((el) => {
|
|
623
|
+
right = Math.max(right, el.getBoundingClientRect().right);
|
|
624
|
+
});
|
|
625
|
+
if (right <= left) return undefined;
|
|
626
|
+
// The right-most element edge includes the body's leading padding but not
|
|
627
|
+
// its trailing padding. Demos use body padding to reserve room for ink
|
|
628
|
+
// overflow (shadows, glows) — keep that room on the trailing side too.
|
|
629
|
+
const cs = iframe.contentWindow?.getComputedStyle(body);
|
|
630
|
+
const trailing = cs
|
|
631
|
+
? parseFloat(cs.paddingRight || '0') + parseFloat(cs.borderRightWidth || '0')
|
|
632
|
+
: 0;
|
|
633
|
+
return right - left + trailing;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function bindFitContentMessages(): void {
|
|
637
|
+
if (_fitContentMessageBound) return;
|
|
638
|
+
_fitContentMessageBound = true;
|
|
639
|
+
window.addEventListener('message', (e: MessageEvent) => {
|
|
640
|
+
const data = e.data;
|
|
641
|
+
if (
|
|
642
|
+
!data ||
|
|
643
|
+
data.type !== FIT_CONTENT_MESSAGE ||
|
|
644
|
+
typeof data.height !== 'number' ||
|
|
645
|
+
!Number.isFinite(data.height) ||
|
|
646
|
+
data.height <= 0
|
|
647
|
+
)
|
|
648
|
+
return;
|
|
649
|
+
document
|
|
650
|
+
.querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
|
|
651
|
+
.forEach((iframe) => {
|
|
652
|
+
if (iframe.contentWindow !== e.source) return;
|
|
653
|
+
// Width only matters when the host aligns the iframe
|
|
654
|
+
// horizontally (position → data-justify); otherwise the iframe
|
|
655
|
+
// stays full-width and a reported width is ignored. Resizable
|
|
656
|
+
// containers ignore it too — the user's drag owns the width.
|
|
657
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
658
|
+
const useWidth = Boolean(container?.dataset.justify) && !container?.dataset.resizable;
|
|
659
|
+
setFitSize(iframe, {
|
|
660
|
+
height: data.height,
|
|
661
|
+
width: useWidth && typeof data.width === 'number' ? data.width : undefined,
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Wire an iframe whose container opted into fit-content sizing.
|
|
669
|
+
*
|
|
670
|
+
* Same-origin demos (e.g. the playground mock) are measured directly and kept
|
|
671
|
+
* in sync with a ResizeObserver on their <body>. Cross-origin demos can't be
|
|
672
|
+
* read, so they must post their height (see FIT_CONTENT_MESSAGE).
|
|
673
|
+
*
|
|
674
|
+
* The `height` prop is only the placeholder/fallback in fit-content mode —
|
|
675
|
+
* once a size is measured/reported, the content dictates it. Measurement uses
|
|
676
|
+
* the html/body offset heights (not the document scrollHeight, which is
|
|
677
|
+
* clamped to the viewport) so the iframe can shrink below its current height
|
|
678
|
+
* as well as grow.
|
|
679
|
+
*/
|
|
680
|
+
function wireFitContent(iframe: HTMLIFrameElement): void {
|
|
681
|
+
if (iframe.dataset.fitContentWired) return;
|
|
682
|
+
iframe.dataset.fitContentWired = 'true';
|
|
683
|
+
bindFitContentMessages();
|
|
684
|
+
|
|
685
|
+
let bodyObserver: ResizeObserver | null = null;
|
|
686
|
+
|
|
687
|
+
const measure = () => {
|
|
688
|
+
try {
|
|
689
|
+
const doc = iframe.contentDocument;
|
|
690
|
+
const body = doc?.body;
|
|
691
|
+
if (!body) return; // cross-origin — rely on postMessage instead
|
|
692
|
+
setFitSize(iframe, {
|
|
693
|
+
height: Math.max(doc!.documentElement.offsetHeight, body.offsetHeight, body.scrollHeight),
|
|
694
|
+
width: measureContentWidth(iframe, body),
|
|
695
|
+
});
|
|
696
|
+
} catch {
|
|
697
|
+
/* cross-origin — rely on postMessage instead */
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const onLoad = () => {
|
|
702
|
+
// Tell the demo this is a fit-content embed (see the constant's doc).
|
|
703
|
+
// `width: true` additionally asks it to shrink-wrap and report its
|
|
704
|
+
// intrinsic width, so the host's `position` can center/align it.
|
|
705
|
+
// Not on resizable containers — there the user's drag owns the width
|
|
706
|
+
// and the demo should keep filling whatever width it is given.
|
|
707
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
708
|
+
iframe.contentWindow?.postMessage(
|
|
709
|
+
{
|
|
710
|
+
type: FIT_CONTENT_ENABLE_MESSAGE,
|
|
711
|
+
width: Boolean(container?.dataset.justify) && !container?.dataset.resizable,
|
|
712
|
+
},
|
|
713
|
+
'*',
|
|
714
|
+
);
|
|
715
|
+
measure();
|
|
716
|
+
try {
|
|
717
|
+
const body = iframe.contentDocument?.body;
|
|
718
|
+
if (body && 'ResizeObserver' in window) {
|
|
719
|
+
// onLoad can run more than once (wire time + load event, or an
|
|
720
|
+
// iframe navigation) — replace the observer, never stack them.
|
|
721
|
+
bodyObserver?.disconnect();
|
|
722
|
+
bodyObserver = new ResizeObserver(measure);
|
|
723
|
+
bodyObserver.observe(body);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
} catch {
|
|
727
|
+
/* cross-origin — nothing to observe */
|
|
728
|
+
}
|
|
729
|
+
// Cross-origin demo: it must post its size (see FIT_CONTENT_MESSAGE) or
|
|
730
|
+
// the iframe stays at the `height` prop fallback. Surface that loudly —
|
|
731
|
+
// a silently non-fitting sample is hard to diagnose from the docs side.
|
|
732
|
+
setTimeout(() => {
|
|
733
|
+
if (!iframe.dataset.fitSized) {
|
|
734
|
+
console.warn(
|
|
735
|
+
`[sample-widget] fitContent: cross-origin demo "${iframe.src}" hasn't reported its size. ` +
|
|
736
|
+
`The demo must run: parent.postMessage({ type: '${FIT_CONTENT_MESSAGE}', height: document.documentElement.scrollHeight }, '*') ` +
|
|
737
|
+
`on load/resize; until then the iframe keeps the \`height\` prop as a fallback.`,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
}, 3000);
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// iframeOnly renders `src` directly, so the iframe may already be loaded —
|
|
744
|
+
// and a cross-origin iframe gives no way to detect that (contentDocument is
|
|
745
|
+
// null whether it's loaded or not). Run the handler once at wire time as
|
|
746
|
+
// well: on a not-yet-loaded iframe the enable message is simply lost and
|
|
747
|
+
// the `load` listener below re-sends it; on an already-loaded one this is
|
|
748
|
+
// the only chance to deliver it. Widget iframes load lazily (data-src, no
|
|
749
|
+
// src yet) and are handled purely by the `load` event.
|
|
750
|
+
if (iframe.src) onLoad();
|
|
751
|
+
iframe.addEventListener('load', onLoad);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function initFitContentIframes(): void {
|
|
755
|
+
document
|
|
756
|
+
.querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
|
|
757
|
+
.forEach(wireFitContent);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// ─── Resizable samples ──────────────────────────────────────────────────────────
|
|
761
|
+
|
|
762
|
+
const RESIZE_MIN_WIDTH = 200; // px — narrowest the iframe can be dragged.
|
|
763
|
+
const RESIZE_KEY_STEP = 24; // px — width change per arrow-key press.
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Wire a `<Sample resizable>` container: a right-edge drag handle plus left/right
|
|
767
|
+
* arrow keys resize the iframe's width (only the iframe, horizontally) so
|
|
768
|
+
* responsive demos can be previewed at different widths. The container's own
|
|
769
|
+
* footprint never changes.
|
|
770
|
+
*/
|
|
771
|
+
function wireResizable(container: HTMLElement): void {
|
|
772
|
+
if (container.dataset.resizableWired) return;
|
|
773
|
+
container.dataset.resizableWired = 'true';
|
|
774
|
+
|
|
775
|
+
const frame = container.querySelector<HTMLElement>('.igd-sample-frame');
|
|
776
|
+
const handle = container.querySelector<HTMLElement>('.igd-sample-resize-handle');
|
|
777
|
+
if (!frame) return;
|
|
778
|
+
|
|
779
|
+
// Widest the frame can be: the container's content box (minus padding).
|
|
780
|
+
const maxWidth = (): number => {
|
|
781
|
+
const cs = getComputedStyle(container);
|
|
782
|
+
const pad = parseFloat(cs.paddingLeft || '0') + parseFloat(cs.paddingRight || '0');
|
|
783
|
+
return Math.max(RESIZE_MIN_WIDTH, container.clientWidth - pad);
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const setWidth = (px: number): void => {
|
|
787
|
+
const clamped = Math.round(Math.min(maxWidth(), Math.max(RESIZE_MIN_WIDTH, px)));
|
|
788
|
+
frame.style.width = `${clamped}px`;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// ─ Pointer drag ─
|
|
792
|
+
if (handle) {
|
|
793
|
+
handle.addEventListener('pointerdown', (e: PointerEvent) => {
|
|
794
|
+
e.preventDefault();
|
|
795
|
+
container.classList.add('resizing');
|
|
796
|
+
handle.setPointerCapture(e.pointerId);
|
|
797
|
+
|
|
798
|
+
const startX = e.clientX;
|
|
799
|
+
const startW = frame.getBoundingClientRect().width;
|
|
800
|
+
// A centered frame grows from both sides, so the handle covers half
|
|
801
|
+
// the width change per pixel moved.
|
|
802
|
+
const factor = getComputedStyle(container).justifyContent === 'center' ? 2 : 1;
|
|
803
|
+
|
|
804
|
+
const onMove = (ev: PointerEvent) => setWidth(startW + (ev.clientX - startX) * factor);
|
|
805
|
+
const onUp = (ev: PointerEvent) => {
|
|
806
|
+
container.classList.remove('resizing');
|
|
807
|
+
handle.releasePointerCapture?.(ev.pointerId);
|
|
808
|
+
handle.removeEventListener('pointermove', onMove);
|
|
809
|
+
handle.removeEventListener('pointerup', onUp);
|
|
810
|
+
handle.removeEventListener('pointercancel', onUp);
|
|
811
|
+
};
|
|
812
|
+
handle.addEventListener('pointermove', onMove);
|
|
813
|
+
handle.addEventListener('pointerup', onUp);
|
|
814
|
+
handle.addEventListener('pointercancel', onUp);
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// ─ Keyboard (container is focusable via tabindex) ─
|
|
819
|
+
container.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
820
|
+
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
821
|
+
e.preventDefault();
|
|
822
|
+
const current = frame.getBoundingClientRect().width;
|
|
823
|
+
setWidth(current + (e.key === 'ArrowRight' ? RESIZE_KEY_STEP : -RESIZE_KEY_STEP));
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function initResizableSamples(): void {
|
|
828
|
+
document
|
|
829
|
+
.querySelectorAll<HTMLElement>('.igd-sample-container[data-resizable]')
|
|
830
|
+
.forEach(wireResizable);
|
|
831
|
+
}
|
|
832
|
+
|
|
553
833
|
// ─── Entry Point ──────────────────────────────────────────────────────────────
|
|
554
834
|
|
|
555
835
|
/**
|
|
@@ -561,6 +841,13 @@ class XplatCodeService {
|
|
|
561
841
|
* `.ig-code-view` elements managed by code-view.js.
|
|
562
842
|
*/
|
|
563
843
|
export function initSampleWidgets(): void {
|
|
844
|
+
// Wire fit-content iframes (both full widgets and iframeOnly samples) up front
|
|
845
|
+
// so they start measuring as soon as their content loads.
|
|
846
|
+
initFitContentIframes();
|
|
847
|
+
|
|
848
|
+
// Wire resizable samples so their drag handle / arrow keys work immediately.
|
|
849
|
+
initResizableSamples();
|
|
850
|
+
|
|
564
851
|
// Kick off the Shiki download immediately so it is ready before the user
|
|
565
852
|
// opens a code tab (tabs appear only after an IntersectionObserver fires
|
|
566
853
|
// + a JSON fetch completes, giving Shiki time to load in parallel).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use 'igniteui-theming' as *;
|
|
2
|
+
@use 'copy-button' as *;
|
|
2
3
|
|
|
3
4
|
/* ============================================================
|
|
4
5
|
Code Blocks (Shiki dual-theme)
|
|
@@ -45,29 +46,7 @@ pre.shiki {
|
|
|
45
46
|
opacity: 0;
|
|
46
47
|
z-index: 1;
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
--hover-foreground: var(--ig-primary-600-contrast);
|
|
50
|
-
--focus-foreground: var(--ig-primary-600-contrast);
|
|
51
|
-
--active-foreground: var(--ig-primary-600-contrast);
|
|
52
|
-
--background: var(--ig-primary-500);
|
|
53
|
-
--hover-background: var(--ig-primary-500);
|
|
54
|
-
--focus-background: var(--ig-primary-500);
|
|
55
|
-
--active-background: var(--ig-primary-500);
|
|
56
|
-
--border-color: transparent;
|
|
57
|
-
--border-color-hover: transparent;
|
|
58
|
-
--border-color-focus: transparent;
|
|
59
|
-
|
|
60
|
-
&:has([name='check']) {
|
|
61
|
-
--foreground: var(--ig-success-300-contrast);
|
|
62
|
-
--hover-foreground: var(--ig-success-300-contrast);
|
|
63
|
-
--focus-foreground: var(--ig-success-300-contrast);
|
|
64
|
-
--active-foreground: var(--ig-success-300-contrast);
|
|
65
|
-
|
|
66
|
-
--background: var(--ig-success-300);
|
|
67
|
-
--hover-background: var(--ig-success-300);
|
|
68
|
-
--focus-background: var(--ig-success-300);
|
|
69
|
-
--active-background: var(--ig-success-300);
|
|
70
|
-
}
|
|
49
|
+
@include copy-button-colors;
|
|
71
50
|
}
|
|
72
51
|
|
|
73
52
|
.copy-code-wrapper:hover > .copy-btn,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// Explicit palette for copy-code icon buttons (igc-icon-button).
|
|
2
|
+
///
|
|
3
|
+
/// Code panes always render the dark Shiki theme, while the icon-button's
|
|
4
|
+
/// default colors follow the site theme — in light mode that leaves the icon
|
|
5
|
+
/// near-invisible on the dark background until a hover state recolors it.
|
|
6
|
+
/// Pinning the full state palette keeps the button legible in both themes.
|
|
7
|
+
/// The success palette kicks in while the icon shows the post-copy check.
|
|
8
|
+
@mixin copy-button-colors {
|
|
9
|
+
--foreground: var(--ig-primary-600-contrast);
|
|
10
|
+
--hover-foreground: var(--ig-primary-600-contrast);
|
|
11
|
+
--focus-foreground: var(--ig-primary-600-contrast);
|
|
12
|
+
--active-foreground: var(--ig-primary-600-contrast);
|
|
13
|
+
--background: var(--ig-primary-500);
|
|
14
|
+
--hover-background: var(--ig-primary-500);
|
|
15
|
+
--focus-background: var(--ig-primary-500);
|
|
16
|
+
--active-background: var(--ig-primary-500);
|
|
17
|
+
--border-color: transparent;
|
|
18
|
+
--border-color-hover: transparent;
|
|
19
|
+
--border-color-focus: transparent;
|
|
20
|
+
|
|
21
|
+
&:has([name='check']) {
|
|
22
|
+
--foreground: var(--ig-success-300-contrast);
|
|
23
|
+
--hover-foreground: var(--ig-success-300-contrast);
|
|
24
|
+
--focus-foreground: var(--ig-success-300-contrast);
|
|
25
|
+
--active-foreground: var(--ig-success-300-contrast);
|
|
26
|
+
|
|
27
|
+
--background: var(--ig-success-300);
|
|
28
|
+
--hover-background: var(--ig-success-300);
|
|
29
|
+
--focus-background: var(--ig-success-300);
|
|
30
|
+
--active-background: var(--ig-success-300);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -253,12 +253,12 @@
|
|
|
253
253
|
--ig-size: var(--ig-size-large);
|
|
254
254
|
padding: rem(16px);
|
|
255
255
|
gap: rem(8px);
|
|
256
|
-
height: var(--search-header-footer-height);
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
// Visible only on mobile devices
|
|
260
259
|
.igd-search-footer {
|
|
261
260
|
display: none;
|
|
261
|
+
height: var(--search-header-footer-height);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
.igd-search-header {
|