igniteui-astro-components 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/ThemingWidget/README.md +113 -0
- package/src/components/ThemingWidget/ThemingWidget.astro +374 -0
- package/src/components/ThemingWidget/ThemingWidget.scss +275 -0
- package/src/components/ThemingWidget/assets/check.svg +5 -0
- package/src/components/ThemingWidget/assets/chevron.svg +5 -0
- package/src/components/ThemingWidget/assets/moon.svg +5 -0
- package/src/components/ThemingWidget/assets/sun.svg +5 -0
- package/src/components/ThemingWidget/assets/swatch-leading.svg +5 -0
- package/src/components/mdx/Sample/README.md +17 -16
- package/src/components/mdx/Sample/Sample.astro +44 -1
- package/src/components/mdx/Sample/Sample.scss +68 -1
- package/src/components/mdx/Sample/assets/open-external.svg +5 -0
- package/src/components/mdx/Sample/assets/stackblitz.svg +5 -0
- package/src/layouts/DocsLayout/DocsLayout.scss +0 -1
- package/src/scripts/sample-widget.ts +103 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-astro-components",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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,113 @@
|
|
|
1
|
+
# ThemingWidget
|
|
2
|
+
|
|
3
|
+
A compact theme picker dropdown for sample viewers. An `igc-select` shows the
|
|
4
|
+
active theme with its multi-dot swatch. Its menu includes an optional **MODE**
|
|
5
|
+
row with Light and Dark icon buttons, followed by selectable theme options.
|
|
6
|
+
|
|
7
|
+
The widget uses `igniteui-webcomponents`: `igc-select`, `igc-select-item`,
|
|
8
|
+
`igc-select-header`, `igc-icon-button`, and `igc-icon`. A small client script
|
|
9
|
+
synchronizes widget state and publishes changes to sample iframes.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```astro
|
|
14
|
+
---
|
|
15
|
+
import ThemingWidget from 'igniteui-astro-components/components/ThemingWidget.astro';
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<ThemingWidget target="#sample-preview" />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
On change the widget:
|
|
22
|
+
|
|
23
|
+
- dispatches a bubbling `igd-theme-change` `CustomEvent` with
|
|
24
|
+
`{ theme, mode, modePreference }`, and
|
|
25
|
+
- reflects `data-igd-theme` / `data-igd-mode` on every element matching `target`.
|
|
26
|
+
|
|
27
|
+
The selection is not persisted — the widget resets to its initial props on every
|
|
28
|
+
page load.
|
|
29
|
+
|
|
30
|
+
## Color mode
|
|
31
|
+
|
|
32
|
+
The MODE row exposes **Light** and **Dark** controls. A `system` value remains
|
|
33
|
+
accepted as an initial prop for compatibility; it resolves against
|
|
34
|
+
`prefers-color-scheme` before it is emitted or reflected onto `target`.
|
|
35
|
+
|
|
36
|
+
## Panel placement
|
|
37
|
+
|
|
38
|
+
`igc-select` owns the popup. Its built-in `igc-popover` anchors the menu to the
|
|
39
|
+
input, flips it when necessary, and keeps the menu aligned with the select.
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
document.addEventListener('igd-theme-change', (e) => {
|
|
43
|
+
// e.g. { theme: 'fluent', mode: 'dark', modePreference: 'system' }
|
|
44
|
+
const { theme, mode, modePreference } = e.detail;
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Props
|
|
49
|
+
|
|
50
|
+
| Prop | Type | Default | Description |
|
|
51
|
+
| --------------- | ------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
52
|
+
| `themes` | `ThemeOption[]` | Material, Fluent, Bootstrap, Indigo | Selectable themes. Each has `name`, optional `label`, and a `swatch` array. |
|
|
53
|
+
| `selectedTheme` | `string` | env, then first theme | Active theme `name`. See [Ambient defaults](#ambient-defaults). |
|
|
54
|
+
| `mode` | `'light' \| 'dark' \| 'system'` | env, then `'light'` | Active color mode. See [Color mode](#color-mode) and [Ambient defaults](#ambient-defaults). |
|
|
55
|
+
| `showMode` | `boolean` | `true` | Show the MODE (Light / Dark) control row. |
|
|
56
|
+
| `target` | `string` | — | CSS selector to reflect `data-igd-theme` / `data-igd-mode` onto. |
|
|
57
|
+
| `label` | `string` | `'Select theme'` | Accessible label for the select. |
|
|
58
|
+
| `id` | `string` | auto | Root element id. |
|
|
59
|
+
| `class` | `string` | — | Extra class(es) forwarded to the root. |
|
|
60
|
+
|
|
61
|
+
### `ThemeOption`
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
interface ThemeOption {
|
|
65
|
+
name: string; // stable id, used as the event/storage value
|
|
66
|
+
label?: string; // display label (defaults to a title-cased `name`)
|
|
67
|
+
swatch: string[]; // dot colors, left → right (the design uses three)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Ambient defaults
|
|
72
|
+
|
|
73
|
+
`selectedTheme` and `mode` fall back to the host site's configuration before
|
|
74
|
+
they fall back to the built-in defaults, so a docs site picks its starting theme
|
|
75
|
+
once instead of at every call site. The host publishes it on
|
|
76
|
+
`Astro.locals.envVars` from its middleware — the same channel `Sample.astro`
|
|
77
|
+
already reads its demo URLs from:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// docs host middleware
|
|
81
|
+
ctx.locals.envVars = { defaultSampleTheme: 'bootstrap', defaultSampleMode: 'light' };
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Key | Falls back to |
|
|
85
|
+
| -------------------- | ------------------------ |
|
|
86
|
+
| `defaultSampleTheme` | the first `themes` entry |
|
|
87
|
+
| `defaultSampleMode` | `'light'` |
|
|
88
|
+
|
|
89
|
+
An explicit prop always wins. An unrecognized `defaultSampleMode` is ignored, and
|
|
90
|
+
a `defaultSampleTheme` matching no entry in `themes` falls through to the first
|
|
91
|
+
one. Consumers without middleware get an empty `Astro.locals` and the built-in
|
|
92
|
+
defaults.
|
|
93
|
+
|
|
94
|
+
`Sample.astro` adds one step on top: when it renders the widget it derives the
|
|
95
|
+
theme from the current platform — Angular → Material, React / Web Components /
|
|
96
|
+
Blazor → Bootstrap — unless `defaultSampleTheme` is set. That default is
|
|
97
|
+
functional, not cosmetic: the picker's selection is posted into the sample
|
|
98
|
+
iframe on every load, so it decides how the demo actually renders.
|
|
99
|
+
|
|
100
|
+
## Styling
|
|
101
|
+
|
|
102
|
+
The widget exposes CSS custom properties for retuning per context — override
|
|
103
|
+
them from an ancestor or via `class`:
|
|
104
|
+
|
|
105
|
+
| Variable | Default |
|
|
106
|
+
| ------------------------ | ---------------------------- |
|
|
107
|
+
| `--igd-theming-radius` | `5px` |
|
|
108
|
+
| `--igd-theming-border` | `var(--ig-gray-300)` |
|
|
109
|
+
| `--igd-theming-bg` | `light-dark(#fff, gray-100)` |
|
|
110
|
+
| `--igd-theming-fg` | `var(--ig-gray-900)` |
|
|
111
|
+
| `--igd-theming-muted` | `var(--ig-gray-500)` |
|
|
112
|
+
| `--igd-theming-hover-bg` | `var(--ig-gray-100)` |
|
|
113
|
+
| `--igd-theming-accent` | `var(--igd-accent)` |
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* ThemingWidget
|
|
4
|
+
*
|
|
5
|
+
* A compact theme picker dropdown used inside sample viewers. The select shows
|
|
6
|
+
* the active theme (a small multi-dot color swatch and its name). Opening it
|
|
7
|
+
* reveals a panel with:
|
|
8
|
+
*
|
|
9
|
+
* • an optional MODE row — two icon toggles for Light / Dark, and
|
|
10
|
+
* • a list of selectable themes, each with its swatch; the active one is checked.
|
|
11
|
+
*
|
|
12
|
+
* The widget uses Ignite UI Web Components for the select, selectable options,
|
|
13
|
+
* and mode buttons. A small client script synchronizes the state. On change it:
|
|
14
|
+
* • dispatches a bubbling `igd-theme-change` CustomEvent with
|
|
15
|
+
* `{ theme, mode, modePreference }`, and
|
|
16
|
+
* • reflects `data-igd-theme` / `data-igd-mode` on the optional `target` element.
|
|
17
|
+
*
|
|
18
|
+
* `system` is resolved against the OS `prefers-color-scheme` before it leaves
|
|
19
|
+
* the widget: `mode` (and everything reflected onto `target`) is always a
|
|
20
|
+
* concrete `light` / `dark`, while `modePreference` keeps the raw selection.
|
|
21
|
+
* While `system` is selected the widget follows OS changes live, re-reflecting
|
|
22
|
+
* and re-emitting whenever the preference flips.
|
|
23
|
+
*
|
|
24
|
+
* The selection is not persisted — the widget resets to its initial props on
|
|
25
|
+
* every page load.
|
|
26
|
+
*
|
|
27
|
+
* When `selectedTheme` / `mode` are omitted the widget falls back to the docs
|
|
28
|
+
* host's ambient configuration — `defaultSampleTheme` / `defaultSampleMode` on
|
|
29
|
+
* `Astro.locals.envVars` — so a site sets its starting theme once instead of at
|
|
30
|
+
* every call site.
|
|
31
|
+
*
|
|
32
|
+
* The select's built-in popover owns overlay positioning and keyboard navigation.
|
|
33
|
+
* Mirrors the Combo Input and Dropdown designs from the Doc Samples Figma file.
|
|
34
|
+
*/
|
|
35
|
+
import './ThemingWidget.scss';
|
|
36
|
+
|
|
37
|
+
export interface ThemeOption {
|
|
38
|
+
/** Stable identifier, also used as the value in events. */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Display label. Defaults to a title-cased `name`. */
|
|
41
|
+
label?: string;
|
|
42
|
+
/** Swatch dot colors (left → right). Any length; the design uses three. */
|
|
43
|
+
swatch: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
47
|
+
|
|
48
|
+
interface Props {
|
|
49
|
+
/** Selectable themes. Defaults to Material, Fluent, Bootstrap and Indigo. */
|
|
50
|
+
themes?: ThemeOption[];
|
|
51
|
+
/**
|
|
52
|
+
* Active theme `name`. When omitted, falls back to the host's
|
|
53
|
+
* `defaultSampleTheme` env var and then to the first theme.
|
|
54
|
+
*/
|
|
55
|
+
selectedTheme?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Active color mode. When omitted, falls back to the host's
|
|
58
|
+
* `defaultSampleMode` env var and then to `'light'`.
|
|
59
|
+
*/
|
|
60
|
+
mode?: ThemeMode;
|
|
61
|
+
/** Show the MODE (Light / Dark) toggle row. Defaults to `true`. */
|
|
62
|
+
showMode?: boolean;
|
|
63
|
+
/** Element id for the root. Defaults to an auto-generated id. */
|
|
64
|
+
id?: string;
|
|
65
|
+
/** Extra class(es) forwarded to the root. */
|
|
66
|
+
class?: string;
|
|
67
|
+
/** Accessible label for the trigger. Defaults to `'Select theme'`. */
|
|
68
|
+
label?: string;
|
|
69
|
+
/**
|
|
70
|
+
* CSS selector for an element to reflect the selection onto via
|
|
71
|
+
* `data-igd-theme` / `data-igd-mode`. When omitted, nothing is reflected.
|
|
72
|
+
*/
|
|
73
|
+
target?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const DEFAULT_THEMES: ThemeOption[] = [
|
|
77
|
+
{ name: 'material', label: 'Material', swatch: ['#000000', '#df1b74', '#0099ff'] },
|
|
78
|
+
{ name: 'fluent', label: 'Fluent', swatch: ['#000000', '#0078D4', '#2B88D8'] },
|
|
79
|
+
{ name: 'bootstrap', label: 'Bootstrap', swatch: ['#000000', '#0D6EFD', '#6C757D'] },
|
|
80
|
+
{ name: 'indigo', label: 'Indigo', swatch: ['#000000', '#3F51B5', '#3F51B5'] },
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
themes = DEFAULT_THEMES,
|
|
85
|
+
selectedTheme,
|
|
86
|
+
mode: modeProp,
|
|
87
|
+
showMode = true,
|
|
88
|
+
id,
|
|
89
|
+
class: className,
|
|
90
|
+
label = 'Select theme',
|
|
91
|
+
target,
|
|
92
|
+
} = Astro.props;
|
|
93
|
+
|
|
94
|
+
const rootId = id ?? `igd-theming-${Math.random().toString(36).slice(2, 9)}`;
|
|
95
|
+
const modeButtonId = (mode: ThemeMode) => `${rootId}-${mode}-mode`;
|
|
96
|
+
|
|
97
|
+
const titleCase = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
98
|
+
|
|
99
|
+
// Ambient defaults published by the docs host on `Astro.locals.envVars` (set
|
|
100
|
+
// there by its middleware). Reading them means a widget rendered without props
|
|
101
|
+
// still opens on the theme the surrounding site ships, instead of every call
|
|
102
|
+
// site having to pass one. `locals` is `{}` when the consumer has no
|
|
103
|
+
// middleware, so this degrades to the built-in defaults.
|
|
104
|
+
const env = Astro.locals.envVars ?? {};
|
|
105
|
+
|
|
106
|
+
const activeName = selectedTheme ?? env.defaultSampleTheme ?? themes[0]?.name;
|
|
107
|
+
const active = themes.find((t) => t.name === activeName) ?? themes[0];
|
|
108
|
+
const activeLabel = active ? (active.label ?? titleCase(active.name)) : '';
|
|
109
|
+
// Only explicit light and dark modes are offered by the sample theme picker.
|
|
110
|
+
const MODES: ThemeMode[] = ['light', 'dark'];
|
|
111
|
+
|
|
112
|
+
// The env var is free-form text, so an unrecognized value falls back to 'light'
|
|
113
|
+
// instead of reaching the markup as a bogus `data-mode`.
|
|
114
|
+
const requestedMode = modeProp ?? env.defaultSampleMode;
|
|
115
|
+
const mode: ThemeMode = MODES.includes(requestedMode as ThemeMode)
|
|
116
|
+
? (requestedMode as ThemeMode)
|
|
117
|
+
: 'light';
|
|
118
|
+
|
|
119
|
+
const modeLabels: Record<ThemeMode, string> = {
|
|
120
|
+
light: 'Light',
|
|
121
|
+
dark: 'Dark',
|
|
122
|
+
system: 'System',
|
|
123
|
+
};
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
<div
|
|
127
|
+
class:list={['igd-theming', className]}
|
|
128
|
+
id={rootId}
|
|
129
|
+
data-target={target}
|
|
130
|
+
data-mode={mode}
|
|
131
|
+
data-resolved-mode={mode === 'system' ? undefined : mode}
|
|
132
|
+
data-theme={active?.name}
|
|
133
|
+
>
|
|
134
|
+
<igc-select
|
|
135
|
+
class="igd-theming__select"
|
|
136
|
+
aria-label={label}
|
|
137
|
+
distance="4"
|
|
138
|
+
placement="bottom-end"
|
|
139
|
+
value={active?.name}
|
|
140
|
+
data-theme-select
|
|
141
|
+
>
|
|
142
|
+
<igc-icon
|
|
143
|
+
slot="toggle-icon"
|
|
144
|
+
name="chevron"
|
|
145
|
+
collection="theming-widget"
|
|
146
|
+
class="igd-theming__toggle-icon igd-theming__toggle-icon--collapsed"
|
|
147
|
+
aria-hidden="true"></igc-icon>
|
|
148
|
+
<igc-icon
|
|
149
|
+
slot="toggle-icon-expanded"
|
|
150
|
+
name="chevron"
|
|
151
|
+
collection="theming-widget"
|
|
152
|
+
class="igd-theming__toggle-icon"
|
|
153
|
+
aria-hidden="true"></igc-icon>
|
|
154
|
+
<span slot="prefix" class="igd-theming__swatch" data-swatch>
|
|
155
|
+
{active?.swatch.map((c) => <span class="igd-theming__dot" style={`--dot: ${c}`} />)}
|
|
156
|
+
</span>
|
|
157
|
+
{
|
|
158
|
+
showMode && (
|
|
159
|
+
<igc-select-header slot="header" class="igd-theming__mode-row">
|
|
160
|
+
<span class="igd-theming__section-label">Mode</span>
|
|
161
|
+
<div class="igd-theming__mode-buttons" role="group" aria-label="Color mode">
|
|
162
|
+
{MODES.map((m) => (
|
|
163
|
+
<igc-icon-button
|
|
164
|
+
variant="flat"
|
|
165
|
+
name={m === 'light' ? 'sun' : 'moon'}
|
|
166
|
+
collection="theming-widget"
|
|
167
|
+
class="igd-theming__mode-btn"
|
|
168
|
+
id={modeButtonId(m)}
|
|
169
|
+
data-mode-btn={m}
|
|
170
|
+
aria-pressed={m === mode ? 'true' : 'false'}
|
|
171
|
+
aria-label={modeLabels[m]}
|
|
172
|
+
/>
|
|
173
|
+
))}
|
|
174
|
+
</div>
|
|
175
|
+
</igc-select-header>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
{
|
|
179
|
+
themes.map((t) => {
|
|
180
|
+
const name = t.label ?? titleCase(t.name);
|
|
181
|
+
return (
|
|
182
|
+
<igc-select-item
|
|
183
|
+
class="igd-theming__option"
|
|
184
|
+
value={t.name}
|
|
185
|
+
data-option={t.name}
|
|
186
|
+
data-label={name}
|
|
187
|
+
data-swatch={t.swatch.join(',')}
|
|
188
|
+
>
|
|
189
|
+
<span slot="prefix" class="igd-theming__swatch">
|
|
190
|
+
{t.swatch.map((c) => (
|
|
191
|
+
<span class="igd-theming__dot" style={`--dot: ${c}`} />
|
|
192
|
+
))}
|
|
193
|
+
</span>
|
|
194
|
+
<span class="igd-theming__option-name">{name}</span>
|
|
195
|
+
<igc-icon slot="suffix" name="check" collection="theming-widget" aria-hidden="true" />
|
|
196
|
+
</igc-select-item>
|
|
197
|
+
);
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
</igc-select>
|
|
201
|
+
{
|
|
202
|
+
showMode &&
|
|
203
|
+
MODES.map((m) => (
|
|
204
|
+
<igc-tooltip
|
|
205
|
+
anchor={modeButtonId(m)}
|
|
206
|
+
class="igd-theming__mode-tooltip"
|
|
207
|
+
placement="bottom"
|
|
208
|
+
with-arrow
|
|
209
|
+
>
|
|
210
|
+
{modeLabels[m]}
|
|
211
|
+
</igc-tooltip>
|
|
212
|
+
))
|
|
213
|
+
}
|
|
214
|
+
<span class="igd-theming__selected-value" aria-hidden="true">
|
|
215
|
+
<span class="igd-theming__selected-theme" data-selected-theme>{activeLabel}</span>
|
|
216
|
+
<span class="igd-theming__selected-mode" data-selected-mode>{modeLabels[mode]}</span>
|
|
217
|
+
</span>
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
<script>
|
|
221
|
+
import {
|
|
222
|
+
defineComponents,
|
|
223
|
+
IgcIconButtonComponent,
|
|
224
|
+
IgcIconComponent,
|
|
225
|
+
IgcSelectComponent,
|
|
226
|
+
IgcSelectHeaderComponent,
|
|
227
|
+
IgcSelectItemComponent,
|
|
228
|
+
IgcTooltipComponent,
|
|
229
|
+
registerIconFromText,
|
|
230
|
+
} from 'igniteui-webcomponents';
|
|
231
|
+
import sun from './assets/sun.svg?raw';
|
|
232
|
+
import moon from './assets/moon.svg?raw';
|
|
233
|
+
import check from './assets/check.svg?raw';
|
|
234
|
+
import chevron from './assets/chevron.svg?raw';
|
|
235
|
+
|
|
236
|
+
defineComponents(
|
|
237
|
+
IgcIconButtonComponent,
|
|
238
|
+
IgcIconComponent,
|
|
239
|
+
IgcSelectComponent,
|
|
240
|
+
IgcSelectHeaderComponent,
|
|
241
|
+
IgcSelectItemComponent,
|
|
242
|
+
IgcTooltipComponent,
|
|
243
|
+
);
|
|
244
|
+
registerIconFromText('sun', sun, 'theming-widget');
|
|
245
|
+
registerIconFromText('moon', moon, 'theming-widget');
|
|
246
|
+
registerIconFromText('check', check, 'theming-widget');
|
|
247
|
+
registerIconFromText('chevron', chevron, 'theming-widget');
|
|
248
|
+
|
|
249
|
+
class IgdThemingWidget {
|
|
250
|
+
private root: HTMLElement;
|
|
251
|
+
private select: HTMLElement & { value?: string };
|
|
252
|
+
/** Backs the `system` mode: the OS color-scheme preference. */
|
|
253
|
+
private scheme = window.matchMedia('(prefers-color-scheme: dark)');
|
|
254
|
+
private onSchemeChange = () => {
|
|
255
|
+
// Only `system` tracks the OS; an explicit light/dark choice is fixed.
|
|
256
|
+
if (this.preference !== 'system') return;
|
|
257
|
+
this.applyResolvedMode();
|
|
258
|
+
this.emit();
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
constructor(root: HTMLElement) {
|
|
262
|
+
this.root = root;
|
|
263
|
+
this.select = root.querySelector('[data-theme-select]') as HTMLElement & { value?: string };
|
|
264
|
+
|
|
265
|
+
this.bind();
|
|
266
|
+
|
|
267
|
+
// Turn a `system` selection into a concrete mode now, and keep following
|
|
268
|
+
// the OS for as long as it stays selected.
|
|
269
|
+
this.applyResolvedMode();
|
|
270
|
+
this.scheme.addEventListener('change', this.onSchemeChange);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private bind() {
|
|
274
|
+
this.select.addEventListener('igcChange', (event) => {
|
|
275
|
+
const option = (event as CustomEvent<HTMLElement>).detail;
|
|
276
|
+
if (option) this.selectTheme(option, true);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
this.root.querySelectorAll<HTMLElement>('.igd-theming__mode-btn').forEach((btn) => {
|
|
280
|
+
btn.addEventListener('click', (event) => {
|
|
281
|
+
event.stopPropagation();
|
|
282
|
+
this.selectMode(btn.dataset.modeBtn || 'light', true);
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
private selectTheme(opt: HTMLElement, emit: boolean) {
|
|
288
|
+
const name = opt.dataset.option || '';
|
|
289
|
+
const swatch = (opt.dataset.swatch || '').split(',').filter(Boolean);
|
|
290
|
+
|
|
291
|
+
const swatchEl = this.root.querySelector('[data-swatch]');
|
|
292
|
+
if (swatchEl) {
|
|
293
|
+
swatchEl.innerHTML = swatch
|
|
294
|
+
.map((c) => `<span class="igd-theming__dot" style="--dot: ${c}"></span>`)
|
|
295
|
+
.join('');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const themeLabel = this.root.querySelector<HTMLElement>('[data-selected-theme]');
|
|
299
|
+
if (themeLabel) themeLabel.textContent = opt.dataset.label || name;
|
|
300
|
+
|
|
301
|
+
this.root.dataset.theme = name;
|
|
302
|
+
this.reflect();
|
|
303
|
+
if (emit) this.emit();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** The user's selection: `light`, `dark` or `system`. */
|
|
307
|
+
private get preference() {
|
|
308
|
+
return this.root.dataset.mode || 'light';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** The concrete mode that selection maps to: `light` or `dark`. */
|
|
312
|
+
private get resolvedMode() {
|
|
313
|
+
const pref = this.preference;
|
|
314
|
+
if (pref === 'system') return this.scheme.matches ? 'dark' : 'light';
|
|
315
|
+
return pref === 'dark' ? 'dark' : 'light';
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Publish the resolved mode on the root — so consumers that read the DOM
|
|
320
|
+
* instead of listening (the sample widget does, when its iframe loads) get
|
|
321
|
+
* a concrete value — and push it out to the `target` elements.
|
|
322
|
+
*/
|
|
323
|
+
private applyResolvedMode() {
|
|
324
|
+
const resolved = this.resolvedMode;
|
|
325
|
+
this.root.dataset.resolvedMode = resolved;
|
|
326
|
+
|
|
327
|
+
this.reflect();
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private selectMode(mode: string, emit: boolean) {
|
|
331
|
+
this.root.querySelectorAll<HTMLElement>('.igd-theming__mode-btn').forEach((b) => {
|
|
332
|
+
b.setAttribute('aria-pressed', b.dataset.modeBtn === mode ? 'true' : 'false');
|
|
333
|
+
});
|
|
334
|
+
this.root.dataset.mode = mode;
|
|
335
|
+
|
|
336
|
+
const modeLabel = this.root.querySelector<HTMLElement>('[data-selected-mode]');
|
|
337
|
+
if (modeLabel) modeLabel.textContent = mode === 'dark' ? 'Dark' : 'Light';
|
|
338
|
+
|
|
339
|
+
this.applyResolvedMode();
|
|
340
|
+
if (emit) this.emit();
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private reflect() {
|
|
344
|
+
const sel = this.root.dataset.target;
|
|
345
|
+
if (!sel) return;
|
|
346
|
+
document.querySelectorAll<HTMLElement>(sel).forEach((el) => {
|
|
347
|
+
el.dataset.igdTheme = this.root.dataset.theme || '';
|
|
348
|
+
el.dataset.igdMode = this.root.dataset.resolvedMode || '';
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private emit() {
|
|
353
|
+
const detail = {
|
|
354
|
+
theme: this.root.dataset.theme,
|
|
355
|
+
// Concrete, so consumers never have to resolve `system` themselves...
|
|
356
|
+
mode: this.root.dataset.resolvedMode,
|
|
357
|
+
// ...while the raw selection stays available for mirroring the UI.
|
|
358
|
+
modePreference: this.root.dataset.mode,
|
|
359
|
+
};
|
|
360
|
+
this.root.dispatchEvent(new CustomEvent('igd-theme-change', { detail, bubbles: true }));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function initThemingWidgets() {
|
|
365
|
+
document.querySelectorAll<HTMLElement>('.igd-theming').forEach((el) => {
|
|
366
|
+
if ((el as HTMLElement & { _igdInit?: boolean })._igdInit) return;
|
|
367
|
+
(el as HTMLElement & { _igdInit?: boolean })._igdInit = true;
|
|
368
|
+
new IgdThemingWidget(el);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
document.addEventListener('astro:page-load', initThemingWidgets);
|
|
373
|
+
initThemingWidgets();
|
|
374
|
+
</script>
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
@use 'igniteui-theming/sass/typography' as *;
|
|
2
|
+
|
|
3
|
+
@layer components {
|
|
4
|
+
.igd-theming {
|
|
5
|
+
--igd-theming-radius: #{rem(4px)};
|
|
6
|
+
--igd-theming-border: var(--ig-gray-300);
|
|
7
|
+
--igd-theming-bg: light-dark(#fff, var(--ig-gray-100));
|
|
8
|
+
--igd-theming-fg: var(--ig-gray-900);
|
|
9
|
+
--igd-theming-muted: var(--ig-gray-500);
|
|
10
|
+
--igd-theming-hover-bg: var(--ig-gray-100);
|
|
11
|
+
--igd-theming-accent: var(--igd-accent, var(--ig-primary-500));
|
|
12
|
+
|
|
13
|
+
position: relative;
|
|
14
|
+
display: inline-block;
|
|
15
|
+
width: rem(203px);
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
color: var(--igd-theming-fg);
|
|
18
|
+
font-family: var(--ig-font-family, 'Aktiv Grotesk', var(--igd-font-sans, sans-serif));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.igd-theming__select {
|
|
22
|
+
width: 100%;
|
|
23
|
+
--ig-input-group-border-color: var(--igd-theming-border);
|
|
24
|
+
--ig-input-group-hover-border-color: var(--ig-gray-400);
|
|
25
|
+
--ig-input-group-focused-border-color: var(--igd-theming-accent);
|
|
26
|
+
--ig-input-group-border-border-radius: var(--igd-theming-radius);
|
|
27
|
+
--ig-input-group-input-prefix-background: transparent;
|
|
28
|
+
--ig-input-group-input-prefix-background--filled: transparent;
|
|
29
|
+
--ig-input-group-input-prefix-color--filled: var(--igd-theming-fg);
|
|
30
|
+
--ig-input-group-input-suffix-background: transparent;
|
|
31
|
+
--ig-input-group-input-suffix-background--filled: transparent;
|
|
32
|
+
--ig-input-group-idle-text-color: transparent;
|
|
33
|
+
--ig-input-group-filled-text-color: transparent;
|
|
34
|
+
--ig-input-group-filled-text-hover-color: transparent;
|
|
35
|
+
--ig-input-group-focused-text-color: transparent;
|
|
36
|
+
--ig-select-toggle-button-background: transparent;
|
|
37
|
+
--ig-select-toggle-button-foreground: var(--ig-gray-600);
|
|
38
|
+
--ig-drop-down-background-color: var(--igd-theming-bg);
|
|
39
|
+
--ig-drop-down-border-color: var(--igd-theming-border);
|
|
40
|
+
--ig-drop-down-border-width: #{rem(1px)};
|
|
41
|
+
--ig-drop-down-border-radius: var(--igd-theming-radius);
|
|
42
|
+
--ig-drop-down-size: #{rem(40px)};
|
|
43
|
+
--ig-drop-down-hover-item-background: var(--igd-theming-hover-bg);
|
|
44
|
+
--ig-drop-down-item-text-color: var(--igd-theming-fg);
|
|
45
|
+
--ig-drop-down-item-icon-color: var(--igd-theming-fg);
|
|
46
|
+
--ig-drop-down-hover-item-text-color: var(--igd-theming-fg);
|
|
47
|
+
--ig-drop-down-hover-item-icon-color: var(--igd-theming-fg);
|
|
48
|
+
--ig-drop-down-focused-item-background: var(--igd-theming-hover-bg);
|
|
49
|
+
--ig-drop-down-focused-item-text-color: var(--igd-theming-fg);
|
|
50
|
+
--ig-drop-down-focused-item-icon-color: var(--igd-theming-fg);
|
|
51
|
+
--ig-drop-down-focused-item-border-color: transparent;
|
|
52
|
+
--ig-drop-down-selected-item-background: transparent;
|
|
53
|
+
--ig-drop-down-selected-item-text-color: var(--igd-theming-fg);
|
|
54
|
+
--ig-drop-down-selected-item-icon-color: var(--igd-theming-accent);
|
|
55
|
+
--ig-drop-down-selected-hover-item-background: var(--igd-theming-hover-bg);
|
|
56
|
+
--ig-drop-down-selected-hover-item-text-color: var(--igd-theming-fg);
|
|
57
|
+
--ig-drop-down-selected-hover-item-icon-color: var(--igd-theming-accent);
|
|
58
|
+
--ig-drop-down-selected-focus-item-background: transparent;
|
|
59
|
+
--ig-drop-down-selected-focus-item-text-color: var(--igd-theming-fg);
|
|
60
|
+
--ig-drop-down-selected-focus-item-icon-color: var(--igd-theming-accent);
|
|
61
|
+
|
|
62
|
+
&::part(input) {
|
|
63
|
+
min-height: rem(40px);
|
|
64
|
+
color: transparent;
|
|
65
|
+
font-family: inherit;
|
|
66
|
+
font-size: rem(14px);
|
|
67
|
+
font-weight: 500;
|
|
68
|
+
letter-spacing: rem(0.25px);
|
|
69
|
+
line-height: rem(20px);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
&::part(base) {
|
|
73
|
+
padding-block: 0;
|
|
74
|
+
border: rem(1px) solid var(--igd-theming-border);
|
|
75
|
+
border-radius: var(--igd-theming-radius);
|
|
76
|
+
box-shadow:
|
|
77
|
+
0 rem(10px) rem(15px) rem(-3px) rgb(0 0 0 / 10%),
|
|
78
|
+
0 rem(4px) rem(6px) rem(-4px) rgb(0 0 0 / 10%);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.igd-theming__selected-value {
|
|
83
|
+
position: absolute;
|
|
84
|
+
z-index: 1;
|
|
85
|
+
top: 50%;
|
|
86
|
+
left: rem(48px);
|
|
87
|
+
display: inline-flex;
|
|
88
|
+
align-items: baseline;
|
|
89
|
+
gap: rem(4px);
|
|
90
|
+
max-width: calc(100% - #{rem(88px)});
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
transform: translateY(-50%);
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Dark mode displays all three swatch dots. Reserve space for the extra dot
|
|
97
|
+
// before the absolutely positioned label so the two never overlap.
|
|
98
|
+
.igd-theming[data-resolved-mode='dark'] .igd-theming__selected-value {
|
|
99
|
+
left: rem(56px);
|
|
100
|
+
max-width: calc(100% - #{rem(96px)});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.igd-theming__selected-theme,
|
|
104
|
+
.igd-theming__selected-mode {
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
text-overflow: ellipsis;
|
|
107
|
+
font-size: rem(14px);
|
|
108
|
+
letter-spacing: rem(0.25px);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.igd-theming__selected-theme {
|
|
112
|
+
color: var(--igd-theming-fg);
|
|
113
|
+
font-weight: 500;
|
|
114
|
+
line-height: rem(20px);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.igd-theming__selected-mode {
|
|
118
|
+
color: var(--igd-theming-muted);
|
|
119
|
+
font-size: rem(12px);
|
|
120
|
+
font-weight: 400;
|
|
121
|
+
line-height: rem(16px);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.igd-theming__swatch {
|
|
125
|
+
display: inline-flex;
|
|
126
|
+
flex-shrink: 0;
|
|
127
|
+
align-items: center;
|
|
128
|
+
gap: rem(2px);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Bootstrap's medium select prefix inset is 10px; the Figma trigger uses 16px.
|
|
132
|
+
.igd-theming__select > .igd-theming__swatch {
|
|
133
|
+
margin-inline-start: rem(6px);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.igd-theming__dot {
|
|
137
|
+
display: inline-block;
|
|
138
|
+
width: rem(12px);
|
|
139
|
+
height: rem(12px);
|
|
140
|
+
border-radius: 50%;
|
|
141
|
+
background: var(--dot);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.igd-theming__dot:not(:last-child) {
|
|
145
|
+
width: rem(10.123px);
|
|
146
|
+
border-radius: 0;
|
|
147
|
+
mask: url('./assets/swatch-leading.svg') center / contain no-repeat;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.igd-theming[data-mode='light'] .igd-theming__dot:first-child {
|
|
151
|
+
display: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@media (prefers-color-scheme: light) {
|
|
155
|
+
.igd-theming[data-mode='system'] .igd-theming__dot:first-child {
|
|
156
|
+
display: none;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.igd-theming__mode-row {
|
|
161
|
+
// igc-select-header is non-interactive by default. This header contains
|
|
162
|
+
// the color-mode controls, so restore hit testing only for this widget.
|
|
163
|
+
pointer-events: auto !important;
|
|
164
|
+
display: flex;
|
|
165
|
+
align-items: center;
|
|
166
|
+
justify-content: space-between;
|
|
167
|
+
margin: 0;
|
|
168
|
+
min-height: rem(40px);
|
|
169
|
+
padding-inline: rem(16px);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.igd-theming__section-label {
|
|
173
|
+
@include type-style('overline');
|
|
174
|
+
|
|
175
|
+
color: var(--igd-theming-muted);
|
|
176
|
+
font-size: rem(10px);
|
|
177
|
+
letter-spacing: rem(1.5px);
|
|
178
|
+
text-transform: uppercase;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.igd-theming__mode-buttons {
|
|
182
|
+
display: inline-flex;
|
|
183
|
+
align-items: center;
|
|
184
|
+
pointer-events: auto;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.igd-theming__mode-btn {
|
|
188
|
+
width: rem(24px);
|
|
189
|
+
height: rem(24px);
|
|
190
|
+
pointer-events: auto;
|
|
191
|
+
--foreground: var(--igd-theming-muted);
|
|
192
|
+
--hover-foreground: var(--igd-theming-fg);
|
|
193
|
+
--focus-foreground: var(--igd-theming-fg);
|
|
194
|
+
--hover-background: var(--igd-theming-hover-bg);
|
|
195
|
+
--focus-background: var(--igd-theming-hover-bg);
|
|
196
|
+
--active-background: var(--igd-theming-hover-bg);
|
|
197
|
+
--border-radius: 50%;
|
|
198
|
+
|
|
199
|
+
&::part(base) {
|
|
200
|
+
width: rem(24px);
|
|
201
|
+
height: rem(24px);
|
|
202
|
+
padding: rem(3px);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&::part(icon) {
|
|
206
|
+
--size: #{rem(18px)};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
&[aria-pressed='true'] {
|
|
210
|
+
--foreground: var(--igd-theming-fg);
|
|
211
|
+
--background: rgb(0 20 43 / 8%);
|
|
212
|
+
--hover-background: rgb(0 20 43 / 8%);
|
|
213
|
+
--focus-background: rgb(0 20 43 / 8%);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.igd-theming__mode-tooltip {
|
|
218
|
+
--ig-tooltip-background: rgb(52 75 101 / 90%);
|
|
219
|
+
--ig-tooltip-text-color: var(--ig-gray-50);
|
|
220
|
+
--ig-tooltip-border-radius: var(--igd-theming-radius);
|
|
221
|
+
|
|
222
|
+
&::part(base) {
|
|
223
|
+
min-height: rem(24px);
|
|
224
|
+
padding: rem(4px) rem(8px);
|
|
225
|
+
font-family: inherit;
|
|
226
|
+
font-size: rem(10px);
|
|
227
|
+
font-weight: 500;
|
|
228
|
+
letter-spacing: rem(0.33px);
|
|
229
|
+
line-height: rem(16px);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.igd-theming__toggle-icon {
|
|
234
|
+
--size: #{rem(18px)};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// The exported Figma chevron points upward; the collapsed select state
|
|
238
|
+
// uses the same glyph rotated to point down.
|
|
239
|
+
.igd-theming__toggle-icon--collapsed {
|
|
240
|
+
transform: rotate(180deg);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.igd-theming__option {
|
|
244
|
+
border: 0;
|
|
245
|
+
outline: none;
|
|
246
|
+
min-height: rem(40px);
|
|
247
|
+
padding-inline: rem(24px) rem(18px);
|
|
248
|
+
font-family: inherit;
|
|
249
|
+
font-size: rem(14px);
|
|
250
|
+
font-weight: 500;
|
|
251
|
+
letter-spacing: rem(0.25px);
|
|
252
|
+
line-height: rem(20px);
|
|
253
|
+
|
|
254
|
+
&::part(prefix) {
|
|
255
|
+
margin-inline-end: rem(8px);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
&:not([selected]) igc-icon {
|
|
259
|
+
visibility: hidden;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
igc-icon {
|
|
263
|
+
--size: #{rem(20px)};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&[active],
|
|
267
|
+
&[selected] {
|
|
268
|
+
outline: none;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.igd-theming__option-name {
|
|
273
|
+
color: var(--igd-theming-fg);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Doc-Samples-Icons">
|
|
3
|
+
<path id="Vector" d="M8.10816 12.3124L14.3373 6.08325C14.4901 5.93048 14.6672 5.85409 14.8686 5.85409C15.07 5.85409 15.247 5.93048 15.3998 6.08325C15.5526 6.23603 15.629 6.41312 15.629 6.6145C15.629 6.81589 15.5526 6.99298 15.3998 7.14575L8.64982 13.9166C8.49704 14.0694 8.31996 14.1458 8.11857 14.1458C7.91718 14.1458 7.7401 14.0694 7.58732 13.9166L4.60815 10.9374C4.45538 10.7846 4.37899 10.6076 4.37899 10.4062C4.37899 10.2048 4.45538 10.0277 4.60815 9.87492C4.76093 9.72214 4.93802 9.64575 5.1394 9.64575C5.34079 9.64575 5.51788 9.72214 5.67065 9.87492L8.10816 12.3124Z" fill="#0176FF"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Icon">
|
|
3
|
+
<path id="Color" fill-rule="evenodd" clip-rule="evenodd" d="M5.5575 11.5575L9 8.1225L12.4425 11.5575L13.5 10.5L9 6L4.5 10.5L5.5575 11.5575Z" fill="#556C86"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Doc-Samples-Icons">
|
|
3
|
+
<path id="Vector" d="M9.09321 14.8362C7.45384 14.8362 6.05652 14.2586 4.90127 13.1033C3.74602 11.9479 3.1684 10.5504 3.1684 8.91062C3.1684 7.55625 3.58877 6.34419 4.42952 5.27444C5.2704 4.20469 6.37852 3.50906 7.7539 3.18756C7.89777 3.14944 8.02665 3.15706 8.14052 3.21044C8.25452 3.26381 8.34327 3.33712 8.40677 3.43037C8.47015 3.52375 8.50809 3.637 8.52059 3.77012C8.53309 3.90325 8.50765 4.03619 8.44427 4.16894C8.3269 4.41319 8.23696 4.6715 8.17446 4.94387C8.11196 5.21625 8.08071 5.48869 8.08071 5.76119C8.08071 6.92781 8.48284 7.91325 9.28709 8.7175C10.0912 9.52162 11.0766 9.92369 12.2432 9.92369C12.561 9.92369 12.8628 9.88644 13.1486 9.81194C13.4345 9.73744 13.6971 9.65112 13.9365 9.553C14.0596 9.49925 14.1798 9.48337 14.2971 9.50537C14.4145 9.5275 14.5116 9.56981 14.5885 9.63231C14.6741 9.69481 14.7423 9.77706 14.7932 9.87906C14.8442 9.98094 14.8524 10.0924 14.8178 10.2136C14.5514 11.5636 13.8838 12.6715 12.8151 13.5374C11.7463 14.4032 10.5057 14.8362 9.09321 14.8362ZM9.07446 13.8612C10.1111 13.8612 11.0416 13.5736 11.8661 12.9985C12.6906 12.4235 13.2913 11.6736 13.6682 10.7487C13.4182 10.8112 13.1745 10.8612 12.937 10.8987C12.6995 10.9362 12.462 10.9549 12.2245 10.9549C10.7961 10.9549 9.57965 10.4519 8.57515 9.44594C7.57052 8.43994 7.06821 7.22175 7.06821 5.79137C7.06821 5.55875 7.08696 5.32369 7.12446 5.08619C7.16196 4.84869 7.21196 4.60494 7.27446 4.35494C6.34946 4.72994 5.59946 5.3295 5.02446 6.15362C4.44946 6.97775 4.16196 7.90781 4.16196 8.94381C4.16196 10.3096 4.64152 11.4706 5.60065 12.4268C6.55977 13.3831 7.71771 13.8612 9.07446 13.8612Z" fill="black"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Doc-Samples-Icons">
|
|
3
|
+
<path id="Vector" d="M10.5973 10.5937C11.0348 10.1562 11.2536 9.62498 11.2536 8.99998C11.2536 8.37498 11.0348 7.84373 10.5973 7.40623C10.1598 6.96873 9.62859 6.74998 9.00359 6.74998C8.37859 6.74998 7.84734 6.96873 7.40984 7.40623C6.97234 7.84373 6.75359 8.37498 6.75359 8.99998C6.75359 9.62498 6.97234 10.1562 7.40984 10.5937C7.84734 11.0312 8.37859 11.25 9.00359 11.25C9.62859 11.25 10.1598 11.0312 10.5973 10.5937ZM6.71684 11.2824C6.09134 10.6542 5.77859 9.89192 5.77859 8.99567C5.77859 8.09954 6.09277 7.33873 6.72115 6.71323C7.3494 6.08773 8.11165 5.77498 9.0079 5.77498C9.90402 5.77498 10.6648 6.08917 11.2903 6.71754C11.9158 7.34579 12.2286 8.10804 12.2286 9.00429C12.2286 9.90042 11.9144 10.6612 11.286 11.2867C10.6578 11.9122 9.89552 12.225 8.99927 12.225C8.10315 12.225 7.34234 11.9108 6.71684 11.2824ZM1.57859 9.48748C1.44021 9.48748 1.3244 9.44117 1.23115 9.34854C1.13777 9.25604 1.09109 9.14117 1.09109 9.00392C1.09109 8.86667 1.13777 8.75048 1.23115 8.65536C1.3244 8.56011 1.44021 8.51248 1.57859 8.51248H3.56609C3.70446 8.51248 3.82027 8.55879 3.91352 8.65142C4.0069 8.74392 4.05359 8.85879 4.05359 8.99604C4.05359 9.13329 4.0069 9.24948 3.91352 9.34461C3.82027 9.43986 3.70446 9.48748 3.56609 9.48748H1.57859ZM14.4411 9.48748C14.3027 9.48748 14.1869 9.44117 14.0936 9.34854C14.0003 9.25604 13.9536 9.14117 13.9536 9.00392C13.9536 8.86667 14.0003 8.75048 14.0936 8.65536C14.1869 8.56011 14.3027 8.51248 14.4411 8.51248H16.4286C16.567 8.51248 16.6828 8.55879 16.776 8.65142C16.8694 8.74392 16.9161 8.85879 16.9161 8.99604C16.9161 9.13329 16.8694 9.24948 16.776 9.34461C16.6828 9.43986 16.567 9.48748 16.4286 9.48748H14.4411ZM8.65896 3.90992C8.56371 3.81667 8.51609 3.70086 8.51609 3.56248V1.57498C8.51609 1.43661 8.5624 1.32079 8.65502 1.22754C8.74752 1.13417 8.8624 1.08748 8.99965 1.08748C9.1369 1.08748 9.25309 1.13417 9.34821 1.22754C9.44346 1.32079 9.49109 1.43661 9.49109 1.57498V3.56248C9.49109 3.70086 9.44477 3.81667 9.35215 3.90992C9.25965 4.00329 9.14477 4.04998 9.00752 4.04998C8.87027 4.04998 8.75409 4.00329 8.65896 3.90992ZM8.65896 16.7724C8.56371 16.6792 8.51609 16.5634 8.51609 16.425V14.4375C8.51609 14.2991 8.5624 14.1833 8.65502 14.09C8.74752 13.9967 8.8624 13.95 8.99965 13.95C9.1369 13.95 9.25309 13.9967 9.34821 14.09C9.44346 14.1833 9.49109 14.2991 9.49109 14.4375V16.425C9.49109 16.5634 9.44477 16.6792 9.35215 16.7724C9.25965 16.8658 9.14477 16.9125 9.00752 16.9125C8.87027 16.9125 8.75409 16.8658 8.65896 16.7724ZM4.8079 5.48661L3.73334 4.40042C3.63434 4.30904 3.58365 4.20042 3.58127 4.07454C3.5789 3.94854 3.62959 3.83361 3.73334 3.72973C3.83021 3.62598 3.94215 3.57411 4.06915 3.57411C4.19627 3.57411 4.3079 3.62598 4.40402 3.72973L5.49734 4.79717C5.60596 4.90029 5.66027 5.01654 5.66027 5.14592C5.66027 5.27542 5.60596 5.39173 5.49734 5.49486C5.40596 5.59798 5.29421 5.64954 5.16209 5.64954C5.02984 5.64954 4.91177 5.59523 4.8079 5.48661ZM13.6031 14.2702L12.5098 13.2028C12.4012 13.1032 12.3469 12.9894 12.3469 12.8614C12.3469 12.7332 12.4012 12.6149 12.5098 12.5062C12.6012 12.4024 12.713 12.3504 12.8451 12.3504C12.9773 12.3504 13.0954 12.4047 13.1993 12.5134L14.2738 13.5995C14.3728 13.6909 14.4235 13.7995 14.4259 13.9254C14.4283 14.0514 14.3805 14.1664 14.2826 14.2702C14.1729 14.374 14.0593 14.4259 13.942 14.4259C13.8247 14.4259 13.7118 14.374 13.6031 14.2702ZM12.5087 5.49373C12.4056 5.40236 12.354 5.29061 12.354 5.15848C12.354 5.02623 12.4083 4.90817 12.517 4.80429L13.6031 3.72973C13.707 3.63073 13.8188 3.58317 13.9384 3.58704C14.0581 3.59092 14.17 3.63879 14.2738 3.73067C14.3776 3.83392 14.4295 3.94423 14.4295 4.06161C14.4295 4.17886 14.3776 4.29179 14.2738 4.40042L13.2064 5.49373C13.1033 5.60236 12.987 5.65667 12.8576 5.65667C12.7281 5.65667 12.6118 5.60236 12.5087 5.49373ZM3.73334 14.2702C3.62959 14.1734 3.57771 14.0614 3.57771 13.9344C3.57771 13.8073 3.62959 13.6957 3.73334 13.5995L4.80077 12.5062C4.9004 12.4101 5.01421 12.362 5.14221 12.362C5.27034 12.362 5.38871 12.4101 5.49734 12.5062C5.59634 12.6101 5.64296 12.726 5.63721 12.854C5.63159 12.982 5.58259 13.0959 5.49021 13.1957L4.40402 14.2702C4.3079 14.374 4.19809 14.4271 4.07459 14.4296C3.95096 14.432 3.83721 14.3789 3.73334 14.2702Z" fill="#7D91AB"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="10.123" height="12" viewBox="0 0 10.123 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Group 3">
|
|
3
|
+
<path id="Subtract" d="M6 0C7.59747 0 9.04787 0.62563 10.123 1.64355C9.40759 2.93442 9 4.41957 9 6C9 7.58012 9.40785 9.06478 10.123 10.3555C9.04782 11.3737 7.59771 12 6 12C2.68629 12 0 9.31371 0 6C0 2.68629 2.68629 0 6 0Z" fill="black"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -10,22 +10,23 @@ import Sample from 'igniteui-astro-components/components/mdx/Sample.astro';
|
|
|
10
10
|
|
|
11
11
|
## Props
|
|
12
12
|
|
|
13
|
-
| Prop
|
|
14
|
-
|
|
|
15
|
-
| `src`
|
|
16
|
-
| `height`
|
|
17
|
-
| `alt`
|
|
18
|
-
| `lob`
|
|
19
|
-
| `dv`
|
|
20
|
-
| `crm`
|
|
21
|
-
| `iframeOnly`
|
|
22
|
-
| `fullscreenBtn`
|
|
23
|
-
| `fitContent`
|
|
24
|
-
| `spacing`
|
|
25
|
-
| `position`
|
|
26
|
-
| `resizable`
|
|
27
|
-
| `noBorder`
|
|
28
|
-
| `noBackground`
|
|
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. |
|
|
29
|
+
| `whiteBackground` | `boolean` | `false` | Paint the backdrop behind the iframe pure white (`#fff`) instead of the default light gray. Only the light side changes — dark mode (the site's, or the in-sample theming widget's) is left as is. Implies a painted background, so it also overrides the transparency `noBackground` leaves behind in light mode. |
|
|
29
30
|
|
|
30
31
|
## Examples
|
|
31
32
|
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* when a separate demosBaseUrl is present in the environment config.
|
|
16
16
|
*/
|
|
17
17
|
import type { PlatformContext } from '../../../lib/types.ts';
|
|
18
|
+
import ThemingWidget from '../../ThemingWidget/ThemingWidget.astro';
|
|
18
19
|
import './Sample.scss';
|
|
19
20
|
|
|
20
21
|
interface Props {
|
|
@@ -35,6 +36,11 @@ interface Props {
|
|
|
35
36
|
iframeOnly?: boolean;
|
|
36
37
|
/** When used with iframeOnly, also render a "View in full screen" button below. */
|
|
37
38
|
fullscreenBtn?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Opt in to the in-sample theme picker for this sample. Its initial theme is
|
|
41
|
+
* resolved from the site (see `defaultTheme` below), not passed per usage.
|
|
42
|
+
*/
|
|
43
|
+
showThemePicker?: boolean;
|
|
38
44
|
/**
|
|
39
45
|
* Size the iframe to fit its content: the embedded page dictates the
|
|
40
46
|
* iframe's size. `height` serves only as the placeholder/fallback — shown
|
|
@@ -77,8 +83,21 @@ interface Props {
|
|
|
77
83
|
* Hide the grid-pattern backdrop drawn behind the iframe (default). The
|
|
78
84
|
* container is fully transparent, so a demo without a background of its own
|
|
79
85
|
* sits directly on the page.
|
|
86
|
+
*
|
|
87
|
+
* Defaults to `false` when `showThemePicker` is on: a sample whose theme —
|
|
88
|
+
* and mode — the reader can switch needs a surface of its own to switch
|
|
89
|
+
* against, otherwise a dark-mode demo would sit on the page's own light
|
|
90
|
+
* background. An explicit value always wins.
|
|
80
91
|
*/
|
|
81
92
|
noBackground?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Paint the backdrop behind the iframe pure white (#fff) instead of the
|
|
95
|
+
* default light gray. Only the light side changes: in dark mode — the site's
|
|
96
|
+
* own, or the in-sample theming widget's — the background is left exactly as
|
|
97
|
+
* it was. Asking for a white background implies a painted one, so it also
|
|
98
|
+
* overrides the transparency `noBackground` leaves behind (in light mode).
|
|
99
|
+
*/
|
|
100
|
+
whiteBackground?: boolean;
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
const {
|
|
@@ -89,14 +108,19 @@ const {
|
|
|
89
108
|
crm = false,
|
|
90
109
|
iframeOnly = false,
|
|
91
110
|
fullscreenBtn = false,
|
|
111
|
+
showThemePicker = false,
|
|
92
112
|
fitContent = false,
|
|
93
113
|
spacing = 'none',
|
|
94
114
|
position,
|
|
95
115
|
resizable = false,
|
|
96
116
|
noBorder = true,
|
|
97
|
-
|
|
117
|
+
whiteBackground = false,
|
|
98
118
|
} = Astro.props;
|
|
99
119
|
|
|
120
|
+
// The theme picker implies a painted backdrop (see the prop's doc), so its
|
|
121
|
+
// default flips with `showThemePicker`. An explicitly passed value still wins.
|
|
122
|
+
const noBackground = Astro.props.noBackground ?? !showThemePicker;
|
|
123
|
+
|
|
100
124
|
// Fixed samples default to 150px. In fitContent mode `height` is only the
|
|
101
125
|
// loading placeholder, so an unspecified one defaults lower (50px) to avoid
|
|
102
126
|
// reserving a tall wall of space that collapses once the demo reports its size.
|
|
@@ -105,6 +129,18 @@ const { name, lower } = Astro.locals.platformContext as PlatformContext;
|
|
|
105
129
|
|
|
106
130
|
const env = Astro.locals.envVars ?? {};
|
|
107
131
|
|
|
132
|
+
// The in-sample theme picker opens on the theme the platform's sample browser
|
|
133
|
+
// itself ships: the Angular browser serves Material, the xplat ones (React /
|
|
134
|
+
// Web Components / Blazor) serve Bootstrap. Deriving it from the platform keeps
|
|
135
|
+
// every <Sample> in the docs correct without a per-usage prop, and a host can
|
|
136
|
+
// still override it for a whole site via `defaultSampleTheme`. This is not
|
|
137
|
+
// cosmetic — the picker's current selection is posted into the iframe on every
|
|
138
|
+
// load (sample-widget.ts), so a wrong default actively re-themes the demo.
|
|
139
|
+
const PLATFORM_DEFAULT_THEME: Partial<Record<PlatformContext['name'], string>> = {
|
|
140
|
+
Angular: 'material',
|
|
141
|
+
};
|
|
142
|
+
const defaultTheme = env.defaultSampleTheme ?? PLATFORM_DEFAULT_THEME[name] ?? 'bootstrap';
|
|
143
|
+
|
|
108
144
|
// ─ Layout options (spacing / position / resize) ────────────────────────────────
|
|
109
145
|
const spacingVal = ['none', 'sm', 'md', 'lg'].includes(spacing) ? spacing : 'none';
|
|
110
146
|
|
|
@@ -167,6 +203,7 @@ const exampleTabId = `${widgetId}-example`;
|
|
|
167
203
|
'igd-sample-container--resizable': isResizable,
|
|
168
204
|
'igd-sample-container--no-border': noBorder,
|
|
169
205
|
'igd-sample-container--no-background': noBackground,
|
|
206
|
+
'igd-sample-container--white-background': whiteBackground,
|
|
170
207
|
},
|
|
171
208
|
]}
|
|
172
209
|
data-fit-content={fitContent ? 'true' : undefined}
|
|
@@ -228,6 +265,7 @@ const exampleTabId = `${widgetId}-example`;
|
|
|
228
265
|
'igd-sample-container--resizable': isResizable,
|
|
229
266
|
'igd-sample-container--no-border': noBorder,
|
|
230
267
|
'igd-sample-container--no-background': noBackground,
|
|
268
|
+
'igd-sample-container--white-background': whiteBackground,
|
|
231
269
|
},
|
|
232
270
|
]}
|
|
233
271
|
data-fit-content={fitContent ? 'true' : undefined}
|
|
@@ -264,6 +302,11 @@ const exampleTabId = `${widgetId}-example`;
|
|
|
264
302
|
</igc-tab>
|
|
265
303
|
</igc-tabs>
|
|
266
304
|
</div>
|
|
305
|
+
{showThemePicker && (
|
|
306
|
+
<div class="igd-sample-theming" hidden>
|
|
307
|
+
<ThemingWidget selectedTheme={defaultTheme} />
|
|
308
|
+
</div>
|
|
309
|
+
)}
|
|
267
310
|
</div>
|
|
268
311
|
</>
|
|
269
312
|
)
|
|
@@ -124,6 +124,11 @@ igc-tab::part(tab-header) {
|
|
|
124
124
|
|
|
125
125
|
.igd-sample-container {
|
|
126
126
|
--sample-container-header-height: #{rem(66px)};
|
|
127
|
+
// Two selectable backgrounds: the site's own light/dark surface (default),
|
|
128
|
+
// or a dedicated dark surface used when the in-sample theming widget's mode
|
|
129
|
+
// is `dark` — see `[data-igd-mode='dark']` below.
|
|
130
|
+
--igd-sample-bg-light-dark: light-dark(var(--ig-gray-100), var(--ig-surface-500));
|
|
131
|
+
--igd-sample-bg-dark: #0a0b10;
|
|
127
132
|
|
|
128
133
|
display: grid;
|
|
129
134
|
position: relative;
|
|
@@ -131,7 +136,11 @@ igc-tab::part(tab-header) {
|
|
|
131
136
|
overflow: hidden;
|
|
132
137
|
margin-block-end: rem(26px);
|
|
133
138
|
z-index: 0;
|
|
134
|
-
background:
|
|
139
|
+
background: var(--igd-sample-bg-light-dark);
|
|
140
|
+
|
|
141
|
+
&[data-igd-mode='dark'] {
|
|
142
|
+
background: var(--igd-sample-bg-dark);
|
|
143
|
+
}
|
|
135
144
|
|
|
136
145
|
iframe {
|
|
137
146
|
display: block;
|
|
@@ -202,6 +211,21 @@ igc-tab::part(tab-header) {
|
|
|
202
211
|
}
|
|
203
212
|
}
|
|
204
213
|
|
|
214
|
+
// Pure white backdrop instead of the default light gray. Only the light half
|
|
215
|
+
// of the token is swapped, so dark mode is untouched — both the site's dark
|
|
216
|
+
// surface and the theming widget's dedicated `--igd-sample-bg-dark`.
|
|
217
|
+
&--white-background {
|
|
218
|
+
--igd-sample-bg-light-dark: light-dark(#fff, var(--ig-surface-500));
|
|
219
|
+
|
|
220
|
+
// Asking for white implies a painted surface, so it also wins over the
|
|
221
|
+
// transparent container `--no-background` leaves behind — in light mode
|
|
222
|
+
// only: dark keeps the transparency it had. The `:not()` guard leaves the
|
|
223
|
+
// theming widget's dark surface in charge whenever its mode is `dark`.
|
|
224
|
+
&.igd-sample-container--no-background:not([data-igd-mode='dark']) {
|
|
225
|
+
background: light-dark(#fff, transparent);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
205
229
|
// Wrapper around the iframe. In the default (block) layout it is transparent
|
|
206
230
|
// (fills the container just like the bare iframe did); when the container
|
|
207
231
|
// opts into flex layout it becomes the positioned/resizable element.
|
|
@@ -375,6 +399,28 @@ igc-tab::part(tab-header) {
|
|
|
375
399
|
|
|
376
400
|
.igd-code-view__footer-actions {
|
|
377
401
|
border-block-start: rem(1px) solid var(--ig-gray-300);
|
|
402
|
+
border-end-start-radius: 0.25rem;
|
|
403
|
+
border-end-end-radius: 0.25rem;
|
|
404
|
+
min-height: rem(56px);
|
|
405
|
+
padding: rem(8px) rem(24px);
|
|
406
|
+
gap: rem(8px);
|
|
407
|
+
background: light-dark(#fff, var(--ig-surface-500));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// The footer picker is intentionally borderless: the footer itself provides
|
|
411
|
+
// the visual container while the select continues to own its menu and state.
|
|
412
|
+
.igd-code-view__footer-actions .igd-sample-theming {
|
|
413
|
+
margin-inline-start: 0;
|
|
414
|
+
|
|
415
|
+
.igd-theming__select {
|
|
416
|
+
--ig-input-group-border-color: transparent;
|
|
417
|
+
--ig-input-group-hover-border-color: transparent;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.igd-theming__select::part(input) {
|
|
421
|
+
border-color: transparent;
|
|
422
|
+
box-shadow: none;
|
|
423
|
+
}
|
|
378
424
|
}
|
|
379
425
|
|
|
380
426
|
.igd-code-view__header-actions,
|
|
@@ -387,6 +433,27 @@ igc-tab::part(tab-header) {
|
|
|
387
433
|
gap: rem(16px);
|
|
388
434
|
}
|
|
389
435
|
|
|
436
|
+
.igd-code-view__footer-actions {
|
|
437
|
+
padding: rem(8px) rem(24px);
|
|
438
|
+
gap: rem(8px);
|
|
439
|
+
|
|
440
|
+
.igd-code-view__footer-edit-actions {
|
|
441
|
+
display: flex;
|
|
442
|
+
flex: 1 0 0;
|
|
443
|
+
align-items: center;
|
|
444
|
+
justify-content: flex-end;
|
|
445
|
+
min-width: 0;
|
|
446
|
+
padding-inline-start: rem(16px);
|
|
447
|
+
gap: rem(8px);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.igd-edit-in-btn {
|
|
451
|
+
--size: #{rem(24px)};
|
|
452
|
+
--ig-icon-size: #{rem(18px)};
|
|
453
|
+
--border-radius: #{rem(18px)};
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
390
457
|
.igd-code-view__header-actions {
|
|
391
458
|
height: var(--sample-container-header-height);
|
|
392
459
|
border-block-start: rem(1px) solid var(--ig-gray-300);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Icon">
|
|
3
|
+
<path id="Vector" d="M3.75654 15.5834C3.3814 15.5834 3.06432 15.4538 2.80529 15.1948C2.54626 14.9358 2.41675 14.6187 2.41675 14.2436V3.75648C2.41675 3.38134 2.54626 3.06426 2.80529 2.80523C3.06432 2.5462 3.3814 2.41669 3.75654 2.41669H8.13779C8.29154 2.41669 8.42029 2.46814 8.52404 2.57106C8.62765 2.67384 8.67946 2.80148 8.67946 2.95398C8.67946 3.10648 8.62765 3.23558 8.52404 3.34127C8.42029 3.4471 8.29154 3.50002 8.13779 3.50002H3.75654C3.69237 3.50002 3.63362 3.52676 3.58029 3.58023C3.52682 3.63356 3.50008 3.69231 3.50008 3.75648V14.2436C3.50008 14.3077 3.52682 14.3665 3.58029 14.4198C3.63362 14.4733 3.69237 14.5 3.75654 14.5H14.2436C14.3078 14.5 14.3665 14.4733 14.4199 14.4198C14.4733 14.3665 14.5001 14.3077 14.5001 14.2436V9.86231C14.5001 9.70856 14.5515 9.57981 14.6542 9.47606C14.7572 9.37245 14.8849 9.32065 15.0374 9.32065C15.1899 9.32065 15.319 9.37245 15.4247 9.47606C15.5305 9.57981 15.5834 9.70856 15.5834 9.86231V14.2436C15.5834 14.6187 15.4539 14.9358 15.1949 15.1948C14.9358 15.4538 14.6188 15.5834 14.2436 15.5834H3.75654ZM14.5001 4.27398L7.45529 11.319C7.33987 11.4343 7.21564 11.4898 7.08258 11.4856C6.94966 11.4813 6.82279 11.4188 6.70196 11.2981C6.58126 11.1773 6.52091 11.0483 6.52091 10.9111C6.52091 10.7738 6.58126 10.6448 6.70196 10.524L13.7261 3.50002H11.5417C11.388 3.50002 11.2593 3.44863 11.1557 3.34585C11.052 3.24294 11.0001 3.11523 11.0001 2.96273C11.0001 2.81023 11.052 2.68113 11.1557 2.57544C11.2593 2.4696 11.388 2.41669 11.5417 2.41669H14.9134C15.1047 2.41669 15.2641 2.48058 15.3917 2.60835C15.5195 2.73599 15.5834 2.89544 15.5834 3.08669V6.45835C15.5834 6.6121 15.532 6.74078 15.429 6.8444C15.3263 6.94815 15.1986 7.00002 15.0461 7.00002C14.8936 7.00002 14.7645 6.94815 14.6588 6.8444C14.553 6.74078 14.5001 6.6121 14.5001 6.45835V4.27398Z" fill="#00142B"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg preserveAspectRatio="none" overflow="visible" style="display: block;" width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g id="Icon">
|
|
3
|
+
<path id="Vector" d="M8.09783 10.6365H2.72633L12.5461 2.0504e-05L9.90233 7.36352H15.2738L5.45408 18L8.09708 10.6365H8.09783Z" fill="#00142B"/>
|
|
4
|
+
</g>
|
|
5
|
+
</svg>
|
|
@@ -17,15 +17,14 @@ import {
|
|
|
17
17
|
defineComponents,
|
|
18
18
|
IgcTabsComponent,
|
|
19
19
|
IgcTabComponent,
|
|
20
|
-
IgcButtonComponent,
|
|
21
20
|
IgcIconButtonComponent,
|
|
22
21
|
IgcIconComponent,
|
|
23
22
|
IgcCircularProgressComponent,
|
|
23
|
+
registerIconFromText,
|
|
24
24
|
} from 'igniteui-webcomponents';
|
|
25
25
|
defineComponents(
|
|
26
26
|
IgcTabsComponent,
|
|
27
27
|
IgcTabComponent,
|
|
28
|
-
IgcButtonComponent,
|
|
29
28
|
IgcIconButtonComponent,
|
|
30
29
|
IgcIconComponent,
|
|
31
30
|
IgcCircularProgressComponent,
|
|
@@ -33,7 +32,12 @@ defineComponents(
|
|
|
33
32
|
|
|
34
33
|
import './icon-registry';
|
|
35
34
|
import type { Highlighter } from 'shiki';
|
|
36
|
-
import
|
|
35
|
+
import footerStackblitzIcon from '../components/mdx/Sample/assets/stackblitz.svg?raw';
|
|
36
|
+
import footerOpenExternalIcon from '../components/mdx/Sample/assets/open-external.svg?raw';
|
|
37
|
+
|
|
38
|
+
const FOOTER_ICON_COLLECTION = 'sample-footer';
|
|
39
|
+
registerIconFromText('stackblitz', footerStackblitzIcon, FOOTER_ICON_COLLECTION);
|
|
40
|
+
registerIconFromText('open-external', footerOpenExternalIcon, FOOTER_ICON_COLLECTION);
|
|
37
41
|
|
|
38
42
|
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
39
43
|
|
|
@@ -256,14 +260,22 @@ function addFooter(
|
|
|
256
260
|
const footer = document.createElement('div');
|
|
257
261
|
footer.className = 'igd-code-view__footer-actions';
|
|
258
262
|
|
|
263
|
+
const actions = document.createElement('div');
|
|
264
|
+
actions.className = 'igd-code-view__footer-edit-actions';
|
|
265
|
+
|
|
266
|
+
// Move the server-rendered theme picker (if any) into the existing footer,
|
|
267
|
+
// after the edit controls so it is the rightmost footer item.
|
|
268
|
+
const themingBar = widget.querySelector<HTMLElement>('.igd-sample-theming');
|
|
269
|
+
|
|
259
270
|
if ((!explicitEditor || explicitEditor === 'stackblitz') && onStackblitz) {
|
|
260
|
-
const btn = document.createElement('igc-button') as HTMLElement;
|
|
261
|
-
btn.setAttribute('
|
|
271
|
+
const btn = document.createElement('igc-icon-button') as HTMLElement;
|
|
272
|
+
btn.setAttribute('name', 'stackblitz');
|
|
273
|
+
btn.setAttribute('collection', FOOTER_ICON_COLLECTION);
|
|
274
|
+
btn.setAttribute('variant', 'flat');
|
|
262
275
|
btn.setAttribute('aria-label', 'Edit in StackBlitz');
|
|
263
276
|
btn.className = 'stackblitz-btn igd-edit-in-btn';
|
|
264
|
-
btn.innerHTML = stackblitzSvg;
|
|
265
277
|
btn.addEventListener('click', onStackblitz);
|
|
266
|
-
|
|
278
|
+
actions.appendChild(btn);
|
|
267
279
|
}
|
|
268
280
|
|
|
269
281
|
// CodeSandbox hidden, re-enable when https://github.com/codesandbox/codesandbox-client/issues/8884 is fixed.
|
|
@@ -280,9 +292,9 @@ function addFooter(
|
|
|
280
292
|
// }
|
|
281
293
|
|
|
282
294
|
const fsBtn = document.createElement('igc-icon-button') as HTMLElement;
|
|
283
|
-
fsBtn.setAttribute('name', 'open-
|
|
284
|
-
fsBtn.setAttribute('collection',
|
|
285
|
-
fsBtn.setAttribute('variant', '
|
|
295
|
+
fsBtn.setAttribute('name', 'open-external');
|
|
296
|
+
fsBtn.setAttribute('collection', FOOTER_ICON_COLLECTION);
|
|
297
|
+
fsBtn.setAttribute('variant', 'flat');
|
|
286
298
|
fsBtn.setAttribute('aria-label', 'Open in full screen');
|
|
287
299
|
fsBtn.className = 'igd-full-screen-btn igd-edit-in-btn';
|
|
288
300
|
if (iframeSrc) {
|
|
@@ -290,7 +302,13 @@ function addFooter(
|
|
|
290
302
|
fsBtn.setAttribute('href', fullscreenSrc);
|
|
291
303
|
fsBtn.setAttribute('target', '_blank');
|
|
292
304
|
}
|
|
293
|
-
|
|
305
|
+
actions.appendChild(fsBtn);
|
|
306
|
+
footer.appendChild(actions);
|
|
307
|
+
|
|
308
|
+
if (themingBar) {
|
|
309
|
+
themingBar.hidden = false;
|
|
310
|
+
footer.appendChild(themingBar);
|
|
311
|
+
}
|
|
294
312
|
|
|
295
313
|
widget.appendChild(footer);
|
|
296
314
|
}
|
|
@@ -428,6 +446,9 @@ class XplatCodeService {
|
|
|
428
446
|
this.platform = platform;
|
|
429
447
|
this.samplesOrder = XPLAT_SAMPLES_ORDER[platform] || ['ts', 'html', 'css'];
|
|
430
448
|
this.codeBase = XPLAT_CODE_BASE[platform] || '/code-viewer/';
|
|
449
|
+
// Gates only the StackBlitz / CodeSandbox buttons — Blazor samples can't be
|
|
450
|
+
// live-edited in a browser sandbox. The footer itself is always rendered:
|
|
451
|
+
// it also carries the fullscreen button and the in-sample theme picker.
|
|
431
452
|
this.enableLiveEditing = platform !== 'blazor';
|
|
432
453
|
}
|
|
433
454
|
|
|
@@ -436,6 +457,10 @@ class XplatCodeService {
|
|
|
436
457
|
const samplePath = getSamplePath(iframeSrc, demosBaseUrl);
|
|
437
458
|
const fallbackStackblitz = () => this._openStackBlitzUrl(githubSrc, demosBaseUrl);
|
|
438
459
|
const fallbackCodeSandbox = () => this._openCodeSandbox(githubSrc, demosBaseUrl);
|
|
460
|
+
// Live editing needs both a platform that supports it and a repo path to
|
|
461
|
+
// open; without either, the footer is still built — just without the
|
|
462
|
+
// edit-in buttons.
|
|
463
|
+
const liveEdit = this.enableLiveEditing && Boolean(githubSrc);
|
|
439
464
|
|
|
440
465
|
try {
|
|
441
466
|
// Blazor's local dev server uses a self-signed cert on a non-4200 port,
|
|
@@ -460,15 +485,23 @@ class XplatCodeService {
|
|
|
460
485
|
)
|
|
461
486
|
.forEach((file: SampleFile) => addCodeTab(igcTabs, file));
|
|
462
487
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
488
|
+
// Use sdk.openProject() to avoid the StackBlitz GitHub clone freeze bug.
|
|
489
|
+
addFooter(
|
|
490
|
+
widget,
|
|
491
|
+
iframeSrc,
|
|
492
|
+
null,
|
|
493
|
+
liveEdit ? () => this._openInStackBlitz(data) : null,
|
|
494
|
+
liveEdit ? fallbackCodeSandbox : null,
|
|
495
|
+
);
|
|
467
496
|
} catch (err: any) {
|
|
468
497
|
console.warn('[sample-widget] Could not fetch xplat sample files:', err.message);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
498
|
+
addFooter(
|
|
499
|
+
widget,
|
|
500
|
+
iframeSrc,
|
|
501
|
+
null,
|
|
502
|
+
liveEdit ? fallbackStackblitz : null,
|
|
503
|
+
liveEdit ? fallbackCodeSandbox : null,
|
|
504
|
+
);
|
|
472
505
|
}
|
|
473
506
|
}
|
|
474
507
|
|
|
@@ -902,6 +935,58 @@ export function initSampleWidgets(): void {
|
|
|
902
935
|
|
|
903
936
|
const exampleTabId = `${widget.id}-example`;
|
|
904
937
|
|
|
938
|
+
// Wire the in-sample theme picker: on change (and on each iframe load)
|
|
939
|
+
// post the selection to the sample iframe so it can re-render with the
|
|
940
|
+
// chosen theme/mode. Targets the iframe's own origin (never a wildcard
|
|
941
|
+
// when the origin is known) to avoid leaking the message to other frames.
|
|
942
|
+
const themingBar = widget.querySelector<HTMLElement>('.igd-sample-theming');
|
|
943
|
+
if (themingBar && iframe) {
|
|
944
|
+
const targetOrigin = (() => {
|
|
945
|
+
try {
|
|
946
|
+
return new URL(iframeSrc, window.location.origin).origin;
|
|
947
|
+
} catch {
|
|
948
|
+
return window.location.origin;
|
|
949
|
+
}
|
|
950
|
+
})();
|
|
951
|
+
const postTheme = (theme?: string, mode?: string) => {
|
|
952
|
+
if (!theme) return;
|
|
953
|
+
iframe.contentWindow?.postMessage(
|
|
954
|
+
{
|
|
955
|
+
// `type` is kept compatible with the existing Angular sample
|
|
956
|
+
// browser contract. `event` is an explicit alias for xplat
|
|
957
|
+
// sample browsers that use a named event discriminator.
|
|
958
|
+
type: 'igd-sample-theme',
|
|
959
|
+
event: 'igd-sample-theme',
|
|
960
|
+
theme,
|
|
961
|
+
themeName: theme,
|
|
962
|
+
mode,
|
|
963
|
+
},
|
|
964
|
+
targetOrigin,
|
|
965
|
+
);
|
|
966
|
+
};
|
|
967
|
+
const themingRoot = themingBar.querySelector<HTMLElement>('.igd-theming');
|
|
968
|
+
// Reflects the widget's mode onto the sample pane so its own background
|
|
969
|
+
// (not just the iframe content) can switch between the light-dark
|
|
970
|
+
// default and the dedicated dark surface — see `--igd-sample-bg-dark`.
|
|
971
|
+
const reflectMode = (mode?: string) => {
|
|
972
|
+
if (samplePane) samplePane.dataset.igdMode = mode || '';
|
|
973
|
+
};
|
|
974
|
+
themingBar.addEventListener('igd-theme-change', (e: Event) => {
|
|
975
|
+
const detail = (e as CustomEvent<{ theme: string; mode: string }>).detail;
|
|
976
|
+
postTheme(detail?.theme, detail?.mode);
|
|
977
|
+
reflectMode(detail?.mode);
|
|
978
|
+
});
|
|
979
|
+
// Send the current (possibly persisted) selection once the sample
|
|
980
|
+
// loads. `resolvedMode` is the widget's `system` selection already
|
|
981
|
+
// resolved against `prefers-color-scheme`; `mode` is only the fallback
|
|
982
|
+
// for a widget whose script has not initialized yet.
|
|
983
|
+
iframe.addEventListener('load', () => {
|
|
984
|
+
const mode = themingRoot?.dataset.resolvedMode || themingRoot?.dataset.mode;
|
|
985
|
+
postTheme(themingRoot?.dataset.theme, mode);
|
|
986
|
+
reflectMode(mode);
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
|
|
905
990
|
// Toggle fullscreen button visibility based on active tab.
|
|
906
991
|
igcTabs.addEventListener('igcChange', (e: Event) => {
|
|
907
992
|
const detail = (e as CustomEvent<HTMLElement>).detail;
|