PreviewFrame
The live preview of a page beside its editor: a phone, tablet or desktop width drawn at its real size and scaled, zoom, rotate, the address, reload and open in a new tab. usePreviewBridge sends the draft to the page and hears which block was clicked. For the preview of a development server use BrowserBar and DeviceFrame. The address must be http, https or a relative path: javascript:, data: and other schemes show the refused message instead of the frame and the open link. A page on the origin of the editor, like this demo, loses allow-same-origin when the sandbox also allows scripts, so it cannot reach the editor or lift its sandbox; serve the preview from its own origin when it needs the bridge.
- PreviewFrame
- Status
- Stable
- axe:
- Light, Dark, High contrast
- Unit tests:
- yes
- Keyboard pass:
- not yet
- Screen reader pass:
- not yet
- Used in:
- no app yet
PreviewLink to the section Preview
Live in all three themes. Everything here is interactive.
Light theme, PreviewFrame
Dark theme, PreviewFrame
High contrast theme, PreviewFrame
UsageLink to the section Usage
import { PreviewFrame } from '@skribly/ui/content'const bridge = usePreviewBridge<Draft, Selected>({
allowedOrigins: ['https://shop.example'],
isMessage: isSelected,
onMessage: (message) => select(message.block)
})
useEffect(() => bridge.post({ type: 'preview:draft', document }), [bridge, document])
<PreviewFrame src={previewUrl} title={t('preview.title')} labels={labels}
frameRef={bridge.frameRef} toolbarEnd={<LocaleSwitch />} />Every label is a prop, so the app passes its own words in its own language. See no built-in text.
AccessibilityLink to the section Accessibility
- The tools are a named group: the device and zoom choices are radio groups whose options have names even when only icons show, rotate is a toggle button, the address is a read-only field that can be selected and copied, and open says it opens a new tab.
- The frame has a title, and the box around it is a region named by that title in the tab order, so the keyboard can scroll a device wider or taller than the box.
- While the page loads the box is busy and shows a named spinner.
- The bridge posts only to the frame origin when it is allowed and accepts only typed messages from the frame window and an allowed origin, never from an opaque one, and runs nothing it receives.
This demo runs through axe in all three themes on every test run. See what the tests check.