Material Next
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.
The page applies each event and passes the new view and state back. Here no screen is shown, so the effect is in the panel and the log.
<mnw-screen-inspector gallery-href="#live-demo" capture-href="../../demos/marketing-hub/screen.html?id=notes&amp;frame=none&amp;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.

<mnw-screen-inspector> properties
PropertyAttributeTypeDefaultDescription
screenProperty onlyMarketingScreen | undefinedThe screen shown. Nothing renders without it.
screensProperty onlyreadonly MarketingScreen[][]Every screen, for the screen picker.
viewProperty onlyPrototypeViewDEFAULT_PROTOTYPE_VIEWThe prototype view: mode, theme, navigation, window, palettes, frame.
palettesProperty onlyreadonly string[][]The app's palette names; empty hides the palette selects.
stateProperty onlyScreenState{}The live screen's state, for the controls' current values.
galleryHrefgallery-hrefstring'./'Where "All screens" links.
captureHrefcapture-hrefstring''Opens the bare screen for captures.
adsToggleads-togglebooleanfalseOffer the ad stand-ins switch (apps with ads only).
<mnw-screen-inspector> events
EventDescription
view-changePartial<PrototypeView> to apply.
screen-select{id} of the screen to open.
state-patch{patch} for the screen's state.
state-resetBack 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-patch and state-reset, nothing changes.
  • The "Show ads" switch appears only with ads-toggle, for apps whose screens draw ad stand-ins.
mail