Screen inspector
The prototype page's side panel: the screen picker, view options, and each screen's own controls and presets.
import 'material-next-web-components/marketing.js';On this page
Overview
<mnw-screen-inspector> is the panel beside the live screen on the prototype page. From top to bottom: a link back to the gallery, a screen picker (the page's heading, the screen title, is visually hidden), Inspect or Compare, then the view options (theme, system navigation, window, palette, device frame, ads) and the screen's own controls. At the end: Reset state and Capture view.
mountScreenPrototype() renders it and applies everything it reports. Use it directly only for a custom prototype page.
Live demo
Use the panel: its events show here.
<mnw-screen-inspector gallery-href="#live-demo" capture-href="../../demos/marketing-hub/screen.html?id=notes&frame=none&panel=none"></mnw-screen-inspector>
<pre class="demo-log" aria-live="polite">Use the panel: its events show here.</pre>import {
DEFAULT_PROTOTYPE_VIEW,
createScreenRegistry,
} from 'material-next-web-components/marketing.js';
import type {
MaterialNextScreenInspector,
PrototypeView,
ScreenState,
} from 'material-next-web-components/marketing.js';
import {SCREENS} from '../sample-app/screens.js';
const registry = createScreenRegistry(SCREENS);
export default (root: HTMLElement) => {
const inspector = root.querySelector<MaterialNextScreenInspector>(
'mnw-screen-inspector'
)!;
const log = root.querySelector('.demo-log')!;
let screen = registry.screens[0];
let state: ScreenState = {...screen.defaults};
inspector.screens = registry.screens;
inspector.palettes = ['ocean', 'clay'];
inspector.screen = screen;
inspector.state = state;
inspector.view = {...DEFAULT_PROTOTYPE_VIEW, id: screen.id};
// The inspector only reports; the page applies each change and passes it back.
inspector.addEventListener('view-change', (event) => {
const patch = (event as CustomEvent<Partial<PrototypeView>>).detail;
inspector.view = {...inspector.view, ...patch};
log.textContent = `view-change ${JSON.stringify(patch)}`;
});
inspector.addEventListener('screen-select', (event) => {
screen = registry.byId((event as CustomEvent<{id: string}>).detail.id)!;
state = {...screen.defaults};
Object.assign(inspector, {
screen,
state,
view: {...inspector.view, id: screen.id},
});
log.textContent = `screen-select ${screen.id}`;
});
inspector.addEventListener('state-patch', (event) => {
const {patch} = (event as CustomEvent<{patch: ScreenState}>).detail;
state = {...state, ...patch};
inspector.state = state;
log.textContent = `state-patch ${JSON.stringify(patch)}`;
});
inspector.addEventListener('state-reset', () => {
state = {...screen.defaults};
inspector.state = state;
log.textContent = 'state-reset';
});
};Screen controls
A screen's controls become the panel's last section. Each control edits one state key (key), except presets, which apply a whole patch. patch adds more state to every change.
type |
Shows | Fields |
|---|---|---|
'presets' |
Assist chips | label, options: [label, patch][] |
'choice' |
Filter chips | key, label, options: (string | number)[], patch? |
'toggle' |
A switch | key, label, patch? |
'slider' or anything else |
A slider with its value | key, label, min, max, step?, unit?, patch? |
API
The prototype page's side panel: the screen's details, the view options and the screen's own controls and presets.
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
screen | Property only | MarketingScreen | undefined | The screen shown. Nothing renders without it. | |
screens | Property only | readonly MarketingScreen[] | [] | Every screen, for the screen picker. |
view | Property only | PrototypeView | DEFAULT_PROTOTYPE_VIEW | The prototype view: mode, theme, navigation, window, palettes, frame. |
palettes | Property only | readonly string[] | [] | The app's palette names; empty hides the palette selects. |
state | Property only | ScreenState | {} | The live screen's state, for the controls' current values. |
galleryHref | gallery-href | string | './' | Where "All screens" links. |
captureHref | capture-href | string | '' | Opens the bare screen for captures. |
adsToggle | ads-toggle | boolean | false | Offer the ad stand-ins switch (apps with ads only). |
| Event | Description |
|---|---|
view-change | Partial<PrototypeView> to apply. |
screen-select | {id} of the screen to open. |
state-patch | {patch} for the screen's state. |
state-reset | Back to the screen's defaults. |
view is a PrototypeView: {mode, compare, palette, paletteB, theme, navType, deviceFrame, window, showAds, state, preset?, capture, id?}, as parsePrototypeView() reads it from the URL.
Accessibility
- Every group has a visible label; the selects and segmented buttons are named.
- The panel is ordinary content in the page's tab order, before the stage when used in
<mnw-prototype-layout>.
Limitations
- The panel only reports: without a page applying
view-change,screen-select,state-patchandstate-reset, nothing changes. - The "Show ads" switch appears only with
ads-toggle, for apps whose screens draw ad stand-ins.