From f10acd517288693bfe52161546d131487a46eb76 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Wed, 25 Nov 2026 11:45:36 -0800 Subject: [PATCH] refactor(playground): clean up hooks and label the toolbar buttons --- e2e/playground.e2e.ts | 33 +- src/components/global/Playground/README.md | 2 +- src/components/global/Playground/index.tsx | 422 ++++++------------ .../global/Playground/playground.types.ts | 105 ++++- static/usage/v8/app/set-focus/index.mdx | 2 +- static/usage/v9/app/set-focus/index.mdx | 2 +- 6 files changed, 262 insertions(+), 304 deletions(-) diff --git a/e2e/playground.e2e.ts b/e2e/playground.e2e.ts index 493991dd73e..78241b8d413 100644 --- a/e2e/playground.e2e.ts +++ b/e2e/playground.e2e.ts @@ -80,11 +80,12 @@ test.describe('file tabs', () => { 'src/app/child.component.html', 'src/app/child.component.ts', ]); - await expect(playground.locator('#playground_angular_src_app_example_component_html')).toBeVisible(); + const panels = playground.getByRole('tabpanel', { includeHidden: true }); + await expect(panels.nth(0)).toBeVisible(); await fileTabs.getByRole('tab', { name: 'src/app/child.component.ts' }).click(); - await expect(playground.locator('#playground_angular_src_app_child_component_ts')).toBeVisible(); - await expect(playground.locator('#playground_angular_src_app_example_component_html')).toBeHidden(); + await expect(panels.nth(3)).toBeVisible(); + await expect(panels.nth(0)).toBeHidden(); }); test('select the first file after switching frameworks', async ({ page }) => { @@ -98,7 +99,7 @@ test.describe('file tabs', () => { 'aria-selected', 'true' ); - await expect(playground.locator('#playground_vue_src_components_Example_vue')).toBeVisible(); + await expect(playground.getByRole('tabpanel', { includeHidden: true }).nth(0)).toBeVisible(); }); test('move focus with the arrow keys and select with Enter', async ({ page }) => { @@ -128,8 +129,7 @@ test('StackBlitz receives every file of a multi-file example', async ({ page, co const playground = await openChildStatePlayground(page); await expect(playground.locator('.playground__tabs')).toBeVisible(); - // The StackBlitz button is the first icon button, and has no accessible name to find it by. - await playground.locator('.playground__control-group--end button').first().click(); + await playground.getByRole('button', { name: 'Open in StackBlitz' }).click(); const form = await request; for (const [file, source] of [ @@ -151,6 +151,8 @@ test.describe('mode', () => { const last = playgrounds.last(); await first.getByRole('button', { name: 'MD', exact: true }).click(); + await expect(first.getByRole('button', { name: 'MD', exact: true })).toHaveAttribute('aria-pressed', 'true'); + await expect(first.getByRole('button', { name: 'iOS', exact: true })).toHaveAttribute('aria-pressed', 'false'); await expect(first.locator('iframe[src*="ionic:mode=md"]')).toBeVisible(); await expect(first.locator('iframe[src*="ionic:mode=ios"]')).toBeHidden(); @@ -184,3 +186,22 @@ test.describe('mode', () => { await expect(playground.getByRole('button', { name: 'MD', exact: true })).toBeFocused(); }); }); + +test('the demo follows the site theme, including after a reset', async ({ page }) => { + await page.addInitScript(() => localStorage.setItem('theme', 'dark')); + // `docusaurus serve` redirects `demo.html` to a clean URL without the base path, which loads the home page instead. + await page.route('**/demo.html*', (route) => + route.fulfill({ path: `build${new URL(route.request().url()).pathname.replace(/^\/docs/, '')}` }) + ); + await page.goto('api/alert'); + const playground = page.locator('.playground').first(); + const demo = playground.frameLocator('iframe[src*="ionic:mode=ios"]').locator('html'); + + await expect(demo).toHaveClass(/ion-theme-dark/); + + // Marks the demo, so the check below waits for the reloaded one. + await demo.evaluate((html) => html.setAttribute('data-before-reset', '')); + await playground.getByRole('button', { name: 'Reset demo' }).click(); + await expect(demo).not.toHaveAttribute('data-before-reset'); + await expect(demo).toHaveClass(/ion-theme-dark/); +}); diff --git a/src/components/global/Playground/README.md b/src/components/global/Playground/README.md index 5ed3fdd06c9..f846ba4037d 100644 --- a/src/components/global/Playground/README.md +++ b/src/components/global/Playground/README.md @@ -39,7 +39,7 @@ import angular_example_component_ts from './angular/example_component_ts.md'; | Option | Description | | --- | --- | -| `size` | Height of the demo: `xsmall`, `small` (default), `medium`, `large`, `xlarge`, or any CSS height such as `300px`. | +| `size` | Height of the demo: `xsmall`, `small` (default), `medium`, `large`, `xlarge`, or a pixel value such as `300px`. | | `mode` | Locks the demo to `ios` or `md` and disables the button for the other mode. | | `devicePreview` | Renders the demo inside a device frame. Refer to [Device Frame](#show-example-within-a-device-frame-iphonepixel-5). | | `showConsole` | Shows a console below the demo with anything the demo logs through `console.log`, `console.warn`, or `console.error`. | diff --git a/src/components/global/Playground/index.tsx b/src/components/global/Playground/index.tsx index c69f0f67512..8769bcea171 100644 --- a/src/components/global/Playground/index.tsx +++ b/src/components/global/Playground/index.tsx @@ -18,14 +18,15 @@ * For the props and how to write a playground, refer to the README. */ -import React, { type FocusEvent, type ReactElement, type ReactNode, useEffect, useRef, useState } from 'react'; +import React, { type FocusEvent, useEffect, useRef, useState } from 'react'; import Link from '@docusaurus/Link'; import useBaseUrl from '@docusaurus/useBaseUrl'; +import useIsBrowser from '@docusaurus/useIsBrowser'; import './playground.css'; import { EditorOptions, openAngularEditor, openHtmlEditor, openReactEditor, openVueEditor } from './stackblitz.utils'; import { useColorMode } from '@docusaurus/theme-common'; -import { CodeSnippets, ConsoleItem, Mode, UsageTarget } from './playground.types'; +import { ConsoleItem, FRAME_SIZES, FrameSize, Mode, PlaygroundProps, UsageTarget } from './playground.types'; import { FRAMEWORKS, useFrameworkChoice } from '@site/src/utils/frameworks'; import Tooltip from '../Tooltip'; @@ -36,10 +37,6 @@ import TabItem from '@theme/TabItem'; import { IconDots } from './icons'; -import useIsBrowser from '@docusaurus/useIsBrowser'; - -type MdxContent = () => ReactNode; - /** * Reads the source of a rendered Docusaurus code block back out of the DOM. * @@ -62,58 +59,27 @@ function getCodeBlockText(codeBlock: HTMLElement) { .join('\n'); } -/** - * The advanced configuration of options when creating a - * playground example with multiple files for a single usage target - * or if needing to modify the generated StackBlitz example code. - */ -interface UsageTargetOptions { - /** - * The list of the file names to use in the StackBlitz example - * and their associated MDX content. - * - * ```ts - * files: { - * 'src/app/app.component.html': app_component_html, - * 'src/app/app.component.ts': app_component_ts, - * } - * ``` - */ - files: { - [key: string]: MdxContent; - }; - /** - * The list of dependencies to use in the StackBlitz example. - * The key is the package name and the value is the version. - * The version must be a valid semver range. - * - * For example: - * ```ts - * dependencies: { - * '@maskito/core': '^0.11.0', - * } - * ``` - */ - dependencies?: { - [key: string]: string; - }; +export default function Playground(props: PlaygroundProps) { + const { code, mode, version } = props; + + // Checked before any hook runs, so an invalid playground renders nothing without changing the hooks between renders. + if (!code || Object.keys(code).length === 0) { + console.warn('No code usage examples provided for this Playground example.'); + return null; + } + if (typeof mode !== 'undefined' && mode !== 'ios' && mode !== 'md') { + console.warn(`Invalid mode provided: ${mode}. Accepted values are: "ios" or "md".`); + return null; + } + if (typeof version === 'undefined') { + console.warn('You must specify a `version` for the Playground example. For example: '); + return null; + } + + return ; } -/** - * @param code The code snippets for each supported framework target. - * @param title Optional title of the generated playground example. Specify to customize the StackBlitz title. - * @param description Optional description of the generated playground example. Specify to customize the StackBlitz description. - * @param src The absolute path to the playground demo. For example: `/usage/button/basic/demo.html` - * @param size The height of the playground. Supports `xsmall`, `small`, `medium`, `large`, 'xlarge' or any string value. - * @param mode Restricts the playground to a single specified mode. Acceptable values are: `ios` or `md`. - * @param devicePreview `true` if the playground example should render in a device frame (iOS/MD). - * @param showConsole `true` if the playground should render a console UI that reflects console logs, warnings, and errors. - * @param includeIonContent Whether to include the `ion-app` and `ion-content` elements in the generated StackBlitz example. - * @param version The major version of Ionic to use in the generated StackBlitz example. - * @param defaultFramework The framework to select by default when no user preference is stored. - * @returns The generated StackBlitz example. - */ -export default function Playground({ +function PlaygroundExample({ code, title, description, @@ -125,52 +91,9 @@ export default function Playground({ includeIonContent = true, version, defaultFramework, -}: { - code: { [key in UsageTarget]?: MdxContent | UsageTargetOptions }; - title?: string; - src: string; - size: string; - /** - * Restricts the playground to a single specified mode. - * If not specified, the user can toggle between modes. - * Acceptable values are: `ios` or `md`. - */ - mode?: 'ios' | 'md'; - description?: string; - devicePreview?: boolean; - showConsole?: boolean; - includeIonContent: boolean; - /** - * The major version of Ionic to use in the generated StackBlitz examples. - * This will also load assets for StackBlitz from the specified version directory. - */ - version: string; - /** - * The framework to select by default when no user preference is stored. - * If not specified, defaults to Angular when available, then the first available framework. - */ - defaultFramework?: UsageTarget; -}) { - if (!code || Object.keys(code).length === 0) { - console.warn('No code usage examples provided for this Playground example.'); - return; - } - if (typeof mode !== 'undefined' && mode !== 'ios' && mode !== 'md') { - console.warn(`Invalid mode provided: ${mode}. Accepted values are: "ios" or "md".`); - return; - } - if (typeof version === 'undefined') { - console.warn('You must specify a `version` for the Playground example. For example: '); - return; - } - +}: PlaygroundProps) { const { colorMode } = useColorMode(); - - /** - * When deploying, Docusaurus builds the app in an SSR environment. - * We need to check whether we're in a browser so we know if we can - * use the window or localStorage objects. - */ + const isDarkTheme = colorMode === 'dark'; const isBrowser = useIsBrowser(); const hostRef = useRef(null); @@ -178,27 +101,14 @@ export default function Playground({ const frameiOS = useRef(null); const frameMD = useRef(null); const consoleBodyRef = useRef(null); + /** The element holding each file's code block, for a multi-file example. */ + const fileRefs = useRef>({}); - const getDefaultMode = () => { - /** - * If a custom mode was specified, use that. - */ - if (mode) return mode; - - /** - * Otherwise, if there is a saved mode from previously clicking - * the mode button, use that. - */ - if (isBrowser) { - const storedMode = localStorage.getItem(MODE_STORAGE_KEY) as Mode | null; - if (storedMode) return storedMode; - } - - /** - * Default to iOS mode as a fallback. - */ - return Mode.iOS; - }; + /** + * The mode a playground restricted to one uses, else the mode last picked + * with a mode button, else iOS. Only call it in the browser. + */ + const getStoredMode = () => mode ?? (localStorage.getItem(MODE_STORAGE_KEY) as Mode | null) ?? Mode.iOS; /** * The framework is shared with the docs' framework tabs. Picking a framework @@ -239,13 +149,12 @@ export default function Playground({ * Developers can set a predefined size * or an explicit pixel value. */ - const frameSize = FRAME_SIZES[size] || size; + const frameSize = size in FRAME_SIZES ? FRAME_SIZES[size as FrameSize] : size; const usageTarget = getUsageTarget(); - const [ionicMode, setIonicMode] = useState(getDefaultMode()); - const [codeSnippets, setCodeSnippets] = useState({}); + // The server can't read the stored mode, so it is applied once the playground scrolls into view. + const [ionicMode, setIonicMode] = useState(mode ?? Mode.iOS); const [renderIframes, setRenderIframes] = useState(false); const [iframesLoaded, setIframesLoaded] = useState(false); - const [isDarkTheme, setIsDarkTheme] = useState(colorMode === 'dark'); const [mdConsoleItems, setMDConsoleItems] = useState([]); const [iosConsoleItems, setiOSConsoleItems] = useState([]); @@ -264,20 +173,17 @@ export default function Playground({ const setAndSaveMode = (mode: Mode) => { setIonicMode(mode); + localStorage.setItem(MODE_STORAGE_KEY, mode); - if (isBrowser) { - localStorage.setItem(MODE_STORAGE_KEY, mode); - - /** - * Tell other playgrounds on the page that the mode has - * updated, so they can sync up if they're in view. - */ - window.dispatchEvent( - new CustomEvent(MODE_UPDATED_EVENT, { - detail: mode, - }) - ); - } + /** + * Tell other playgrounds on the page that the mode has + * updated, so they can sync up if they're in view. + */ + window.dispatchEvent( + new CustomEvent(MODE_UPDATED_EVENT, { + detail: mode, + }) + ); }; /** @@ -311,35 +217,17 @@ export default function Playground({ } }; - const handleFrameRef = (ref: HTMLIFrameElement | null, frameMode: 'ios' | 'md') => { - if (frameMode === 'ios') { - frameiOS.current = ref; - } else { - frameMD.current = ref; - } - - /** - * If both frames are loaded, init the dark theme for the first page load. - * When dark mode is toggled after the fact, that's handled by the - * useEffect below. - */ - if (frameiOS.current && frameMD.current) { - postDarkThemeMessage(); - } - }; - - useEffect(() => { - setIsDarkTheme(colorMode === 'dark'); - }, [colorMode]); - + /** + * Sends the dark mode when the frames first load, when it changes, and when + * a reset reloads them. + * + * Note that we can't just do useEffect(postDarkThemeMessage) + * because useEffect callbacks cannot return a Promise, as + * async functions do. + */ useEffect(() => { - /** - * Note that we can't just do useEffect(postDarkThemeMessage) - * because useEffect callbacks cannot return a Promise, as - * async functions do. - */ postDarkThemeMessage(); - }, [isDarkTheme]); + }, [isDarkTheme, renderIframes, resetCount]); /** * The source of the iframe takes a moment to @@ -351,6 +239,10 @@ export default function Playground({ * callbacks cannot return a Promise, as async functions do. */ useEffect(() => { + if (!renderIframes) { + return; + } + const setFramesLoaded = async () => { await Promise.all([waitForFrame(frameiOS.current), waitForFrame(frameMD.current)]); setIframesLoaded(true); @@ -384,8 +276,10 @@ export default function Playground({ * Using a dynamic import here to avoid SSR errors when trying to extend `HTMLElement` * to create the custom element. */ - import('./device-preview.js').then((comp) => comp.defineCustomElement()); - }); + if (devicePreview) { + import('./device-preview.js').then((comp) => comp.defineCustomElement()); + } + }, [devicePreview]); /** * By default, we do not render the iframe content as it could @@ -400,28 +294,26 @@ export default function Playground({ */ useEffect(() => { const io = new IntersectionObserver( - (entries: IntersectionObserverEntry[]) => { - const event = entries[0]; - setIsInView(event.isIntersecting); - if (!event.isIntersecting) return; + ([entry]) => { + setIsInView(entry.isIntersecting); + if (!entry.isIntersecting) return; /** * Load the stored mode, if present from previously being toggled. */ - setIonicMode(getDefaultMode()); + setIonicMode(getStoredMode()); /** - * If the iframes weren't already loaded, load them now. + * Load the iframes, if they weren't already. */ - if (!renderIframes) { - setRenderIframes(true); - } + setRenderIframes(true); }, { threshold: 0 } ); io.observe(hostRef.current!); - }); + return () => io.disconnect(); + }, []); const handleModeUpdated = (e: WindowEventMap['playground-event-updated']) => { const mode = e.detail; @@ -436,29 +328,18 @@ export default function Playground({ * sync up to the same setting. This is needed because if the * playground is already in view, the IntersectionObserver doesn't * fire until the playground is scrolled off and back on the screen. - * - * Sometimes, the app isn't fully hydrated on the first render, - * causing isBrowser to be set to false even if running the app - * in a browser (vs. SSR). isBrowser is then updated on the next - * render cycle. This means we need to re-run this hook when - * isBrowser changes to handle playgrounds that were in view - * from the start of the page load. - * - * We also re-run when isInView changes because otherwise, a stale - * state value would be captured. Since we need to listen for these - * events only when the playground is in view, we check the state - * before adding the listeners at all, rather than within the - * callbacks. */ useEffect(() => { - if (isBrowser && isInView) { - window.addEventListener(MODE_UPDATED_EVENT, handleModeUpdated); + if (!isInView) { + return; } + window.addEventListener(MODE_UPDATED_EVENT, handleModeUpdated); + return () => { window.removeEventListener(MODE_UPDATED_EVENT, handleModeUpdated); }; - }, [isBrowser, isInView]); + }, [isInView]); const isIOS = ionicMode === Mode.iOS; const isMD = ionicMode === Mode.MD; @@ -474,7 +355,8 @@ export default function Playground({ copyButton?.click(); } - const hasUsageTargetOptions = (code[usageTarget] as UsageTargetOptions)?.files !== undefined; + const usage = code[usageTarget]; + const hasUsageTargetOptions = typeof usage === 'object'; /** * Reloads the iOS and MD iframe sources back to their original state. */ @@ -504,18 +386,14 @@ export default function Playground({ const codeBlock = getCodeBlockText(codeRef.current!.querySelector('code')!); - if (hasUsageTargetOptions) { - editorOptions.files = Object.keys((codeSnippets[usageTarget] ?? {}) as Record) - .map((fileName) => { - const codeBlock = hostRef.current!.querySelector( - `#${getCodeSnippetId(usageTarget, fileName)} code` - ); - return { - [fileName]: getCodeBlockText(codeBlock!), - }; - }) - .reduce((acc, curr) => ({ ...acc, ...curr }), {}); - editorOptions.dependencies = (code[usageTarget] as UsageTargetOptions).dependencies; + if (typeof usage === 'object') { + editorOptions.files = Object.fromEntries( + Object.keys(usage.files).map((fileName) => [ + fileName, + getCodeBlockText(fileRefs.current[fileName]!.querySelector('code')!), + ]) + ); + editorOptions.dependencies = usage.dependencies; } switch (usageTarget) { @@ -534,39 +412,6 @@ export default function Playground({ } } - useEffect(() => { - const codeSnips: CodeSnippets = {}; - (Object.keys(code) as UsageTarget[]).forEach((key) => { - if (typeof code[key] === 'function') { - /** - * Instantiates the React component from the MDX content for - * single-file playground examples. - */ - const DynamicComponent = code[key]; - codeSnips[key] = ; - } else if (typeof code[key] === 'object') { - /** - * Instantiates the list of React components from the MDX content for - * multi-file playground examples. - */ - const fileSnippets: Record = {}; - for (const fileName of Object.keys(code[key].files)) { - const DynamicFileComponent = code[key].files[fileName]; - fileSnippets[`${fileName}`] = ; - } - codeSnips[key] = fileSnippets; - } - }); - setCodeSnippets(codeSnips); - }, []); - - function getCodeSnippetId(usageTarget: string, fileName: string) { - let fileNameId = fileName; - // replace all non-alphanumeric characters with underscores - fileNameId = fileNameId.replace(/[^a-zA-Z0-9]/g, '_'); - return `playground_${usageTarget}_${fileNameId}`; - } - /** * The file type that picks a tab's icon in `playground.css`. Docusaurus tab * labels are text only, so the icon is drawn by CSS rather than rendered here. @@ -587,41 +432,47 @@ export default function Playground({ } function renderCodeSnippets() { - if (code[usageTarget]) { - /** - * `hasUsageTargetOptions` is what decides which shape this holds, and it is - * computed from the props rather than the value, so the narrowing has to be - * asserted. - */ - const snippets = codeSnippets[usageTarget]; - if (!hasUsageTargetOptions) { - return snippets as ReactElement | undefined; - } - if (snippets == null) { - return null; - } - const fileSnippets = snippets as Record; - return ( - // Each framework has its own files, so remounting on a switch selects its first file. - - {Object.keys(fileSnippets).map((fileName) => ( - ) => - event.currentTarget.scrollIntoView({ block: 'nearest', inline: 'nearest' }), + /** + * The code renders in the browser only, so the server HTML is an empty + * shell, which the llms.txt plugin relies on when it adds each framework's + * code to the page's markdown. + */ + if (usage === undefined || !isBrowser) { + return null; + } + + // A single-file example's code, rendered from its MDX. + if (typeof usage === 'function') { + const Snippet = usage; + return ; + } + + return ( + // Each framework has its own files, so remounting on a switch selects its first file. + + {Object.entries(usage.files).map(([fileName, FileSnippet]) => ( + ) => + event.currentTarget.scrollIntoView({ block: 'nearest', inline: 'nearest' }), + }} + > +
{ + fileRefs.current[fileName] = element; }} > -
{fileSnippets[fileName]}
- - ))} - - ); - } + +
+
+ ))} +
+ ); } function renderLoadingScreen() { @@ -684,6 +535,7 @@ export default function Playground({ setAndSaveMode(Mode.iOS)} title="iOS mode" label="iOS" @@ -691,6 +543,7 @@ export default function Playground({ setAndSaveMode(Mode.MD)} title="MD mode" label="MD" @@ -698,7 +551,11 @@ export default function Playground({
- -
,
- +
, ] @@ -822,7 +680,7 @@ export default function Playground({ key="ios-iframe" height={frameSize} className={!isIOS ? 'frame-hidden' : ''} - ref={(ref) => handleFrameRef(ref, 'ios')} + ref={frameiOS} src={sourceiOS} aria-hidden={!isIOS ? 'true' : undefined} >, @@ -830,7 +688,7 @@ export default function Playground({ key="md-iframe" height={frameSize} className={!isMD ? 'frame-hidden' : ''} - ref={(ref) => handleFrameRef(ref, 'md')} + ref={frameMD} src={sourceMD} aria-hidden={!isMD ? 'true' : undefined} >, @@ -847,14 +705,6 @@ export default function Playground({ ); } -const FRAME_SIZES: Record = { - xsmall: '100px', - small: '200px', - medium: '400px', - large: '600px', - xlarge: '800px', -}; - const waitForFrame = (frame: HTMLIFrameElement | null) => { if (isFrameReady(frame)) return Promise.resolve(); diff --git a/src/components/global/Playground/playground.types.ts b/src/components/global/Playground/playground.types.ts index 6e0ab4d3955..dd8a055e1a8 100644 --- a/src/components/global/Playground/playground.types.ts +++ b/src/components/global/Playground/playground.types.ts @@ -1,4 +1,4 @@ -import type { ReactElement } from 'react'; +import type { ReactNode } from 'react'; import type { Framework } from '@site/src/utils/frameworks'; /** @@ -14,6 +14,101 @@ export const UsageTarget = { export type UsageTarget = (typeof UsageTarget)[keyof typeof UsageTarget]; +/** A code snippet's rendered MDX. */ +export type MdxContent = () => ReactNode; + +/** + * The advanced configuration of options when creating a + * playground example with multiple files for a single usage target + * or if needing to modify the generated StackBlitz example code. + */ +export interface UsageTargetOptions { + /** + * The list of the file names to use in the StackBlitz example + * and their associated MDX content. + * + * ```ts + * files: { + * 'src/app/app.component.html': app_component_html, + * 'src/app/app.component.ts': app_component_ts, + * } + * ``` + */ + files: { + [key: string]: MdxContent; + }; + /** + * The list of dependencies to use in the StackBlitz example. + * The key is the package name and the value is the version. + * The version must be a valid semver range. + * + * For example: + * ```ts + * dependencies: { + * '@maskito/core': '^0.11.0', + * } + * ``` + */ + dependencies?: { + [key: string]: string; + }; +} + +/** The named heights a playground can use instead of a pixel value. */ +export const FRAME_SIZES = { + xsmall: '100px', + small: '200px', + medium: '400px', + large: '600px', + xlarge: '800px', +} as const; + +export type FrameSize = keyof typeof FRAME_SIZES; + +export interface PlaygroundProps { + /** The code snippets for each supported framework target. */ + code: { [key in UsageTarget]?: MdxContent | UsageTargetOptions }; + /** Optional title of the generated playground example. Specify to customize the StackBlitz title. */ + title?: string; + /** The absolute path to the playground demo. For example: `/usage/button/basic/demo.html` */ + src: string; + /** + * The height of the playground: `xsmall`, `small`, `medium`, `large`, `xlarge`, or a pixel value + * such as `300px`. Defaults to `small`. + */ + size: FrameSize | `${number}px`; + /** + * Restricts the playground to a single specified mode. + * If not specified, the user can toggle between modes. + * Acceptable values are: `ios` or `md`. + */ + mode?: 'ios' | 'md'; + /** Optional description of the generated playground example. Specify to customize the StackBlitz description. */ + description?: string; + /** `true` if the playground example should render in a device frame (iOS/MD). Defaults to `false`. */ + devicePreview?: boolean; + /** + * `true` if the playground should render a console UI that reflects console logs, warnings, and errors. + * Defaults to `false`. + */ + showConsole?: boolean; + /** + * Whether to include the `ion-app` and `ion-content` elements in the generated StackBlitz example. + * Defaults to `true`. + */ + includeIonContent: boolean; + /** + * The major version of Ionic to use in the generated StackBlitz examples. + * This will also load assets for StackBlitz from the specified version directory. + */ + version: string; + /** + * The framework to select by default when no user preference is stored. + * If not specified, defaults to Angular when available, then the first available framework. + */ + defaultFramework?: UsageTarget; +} + export enum Mode { iOS = 'ios', MD = 'md', @@ -24,14 +119,6 @@ export interface ConsoleItem { message: string; } -/** - * The rendered MDX for each framework the playground has code for. - * - * A single-file example holds one element. A multi-file example holds one per file, - * keyed by file name. - */ -export type CodeSnippets = Partial>>; - /** * Custom events the playground listens for on a `Window`. * diff --git a/static/usage/v8/app/set-focus/index.mdx b/static/usage/v8/app/set-focus/index.mdx index 8f33bf88f40..46dd952378a 100644 --- a/static/usage/v8/app/set-focus/index.mdx +++ b/static/usage/v8/app/set-focus/index.mdx @@ -21,5 +21,5 @@ import angular_example_component_ts from './angular/example_component_ts.md'; }, }} src="usage/v8/app/set-focus/demo.html" - size="sm" + size="150px" /> diff --git a/static/usage/v9/app/set-focus/index.mdx b/static/usage/v9/app/set-focus/index.mdx index 0736bf6437a..e174ad67569 100644 --- a/static/usage/v9/app/set-focus/index.mdx +++ b/static/usage/v9/app/set-focus/index.mdx @@ -21,5 +21,5 @@ import angular_example_component_ts from './angular/example_component_ts.md'; }, }} src="usage/v9/app/set-focus/demo.html" - size="sm" + size="150px" />