This rune is part of @refrakt-md/design. Install with npm install @refrakt-md/design and add "@refrakt-md/design" to the plugins array in your refrakt.config.json.
Preview
A component showcase wrapper that renders content in a framed environment with a theme toggle toolbar and responsive viewport simulation. Useful for documentation sites, design systems, and theme demonstrations.
Basic usage
Wrap any content in a preview to give it a visual frame with a theme toggle.
{% preview title="Hint variants" %}
{% hint type="note" %}
This is a note inside a preview.
{% /hint %}
{% /preview %}
Theme modes
The toolbar toggle lets users switch between auto (system preference), light, and dark modes. The theme attribute sets the initial mode.
{% preview theme="dark" %}
Content rendered in dark mode by default.
{% /preview %}
The theme toggle scopes CSS custom properties to the preview canvas, so child content inherits the selected theme without affecting the rest of the page.
Responsive viewports
The responsive attribute adds a viewport simulation toolbar that lets users switch between device sizes. Specify a comma-separated list of presets.
Available presets: mobile (375px), tablet (768px), desktop (full width).
{% preview source=true responsive="mobile,tablet,desktop" %}
{% hint type="note" %}
Resize me to see how this looks at different breakpoints.
{% /hint %}
{% /preview %}
The preview starts at the last preset in the list (e.g., desktop above). Switching viewports wraps the canvas in a constrained frame with a dashed border and a width label.
You can include any subset of presets:
{% preview responsive="mobile,tablet" %}
{% hint type="check" %}
Mobile and tablet only -- no desktop option.
{% /hint %}
{% /preview %}
Source code toggle
The preview rune supports two ways to show source code alongside rendered output.
Auto-inferred source
Add source to automatically extract the children's Markdoc text as the code view. No duplication needed -- the preview infers the source from what it renders.
{% preview source=true %}
{% hint type="note" %}
This is a note inside a preview.
{% /hint %}
{% /preview %}
This is ideal for Markdoc documentation sites where the preview content IS the source code.
Explicit source
Add a fenced code block as a direct child for full control over what the code view shows. The fence can be in any language -- JSX, Vue, HTML, or Markdoc. This is useful when documenting external frameworks where the source differs from the rendered preview.
{% preview title="Button" %}
```jsx
<Button variant="primary">Click me</Button>
```

{% /preview %}
If both a fence and source are present, the fence takes priority.
Sandbox embedding
Preview pairs naturally with the sandbox rune. Nest a sandbox inside a preview to get live HTML rendering with theme toggling, responsive viewports, and source code panels -- all in one component.
{% preview source=true responsive="mobile,tablet,desktop" %}
{% sandbox framework="tailwind" %}
<button class="bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
Click me
</button>
{% /sandbox %}
{% /preview %}
The preview toolbar controls the sandbox iframe -- theme toggles propagate into the iframe, and viewport presets constrain its width. Add data-source attributes inside the sandbox to extract specific elements as syntax-highlighted source panels.
{% preview source=true %}
{% sandbox framework="tailwind" %}
<style data-source="CSS">
.card { padding: 1.5rem; border-radius: 0.5rem; }
</style>
<div class="card" data-source="HTML">
<h3>Card Title</h3>
<p>Card content goes here.</p>
</div>
{% /sandbox %}
{% /preview %}
See the sandbox rune docs for full details on framework presets, dependencies, and data-source panels.
Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
title | string | — | Label shown in the preview card header. |
theme | "auto" | "light" | "dark" | — | Background theme for the preview viewport: auto follows the page, light/dark forces a mode. |
source | boolean | — | Enable/disable showing the source code panel alongside the rendered preview. |
responsive | string | — | Comma-separated viewport presets (e.g. "mobile,tablet,desktop") for responsive preview frames. Accepts mobile (375px), tablet (768px), and desktop (full); other values are ignored. |
Universal attributes
bg
The background layer (SPEC-088): image, video, gradient, flat overlay wash and legibility scrim, in a single injected layer behind the rune's content.
| Attribute | Type | Required | Description |
|---|---|---|---|
bg | string | — | Background preset applied to this block |
bg-from | string | — | Gradient start colour — a semantic token name (→ var(--rf-color-*)) |
bg-gradient | "to-t" | "to-b" | "to-l" | "to-r" | "to-tr" | "to-br" | "to-bl" | "to-tl" | — | Gradient direction (bounded named set) |
bg-gradient-type | "linear" | "radial" | "conic" | — | Gradient type |
bg-to | string | — | Gradient end colour — a semantic token name |
bg-via | string | — | Optional middle gradient stop — a semantic token name |
scrim | "top" | "bottom" | "left" | "right" | "none" | — | Scrim direction (heaviest edge); presence turns the scrim on, "none" opts out of the default cover scrim |
scrim-blur | "none" | "sm" | "md" | "lg" | — | Frost scrim blur amount |
scrim-strength | "sm" | "md" | "lg" | — | Gradient scrim strength |
scrim-tone | "dark" | "light" | — | Whether the scrim darkens (for light text) or lightens (for dark text) |
scrim-type | "gradient" | "frost" | — | Scrim treatment: gradient (default) or frost (backdrop blur) |
elevation
The chrome/depth ladder (SPEC-107). The skin maps each rung to a chrome bundle by attribute, so there is no BEM class.
| Attribute | Type | Required | Description |
|---|---|---|---|
elevation | "sunken" | "flush" | "flat" | "raised" | "floating" | "overlay" | "none" | "sm" | "md" | "lg" | — | Surface depth on the SPEC-107 ladder (sunken→overlay); none/sm/md/lg are deprecated aliases |
inset
Internal padding override.
| Attribute | Type | Required | Description |
|---|---|---|---|
inset | "flush" | "tight" | "default" | "loose" | "breathe" | — | Inner padding of this block |
motion
Scroll-reveal entrance (SPEC-105). The author declares the character, the theme owns the choreography, a behaviour owns the timing.
| Attribute | Type | Required | Description |
|---|---|---|---|
reveal | "none" | "fade" | "slide" | "scale" | "blur" | — | Scroll-reveal entrance character (none|fade|slide|scale|blur); the theme owns the choreography |
stagger | boolean | — | Cascade this block's items in as it reveals (no-op on single-child runes) |
spacing
Block-level rhythm override.
| Attribute | Type | Required | Description |
|---|---|---|---|
spacing | "flush" | "tight" | "default" | "loose" | "breathe" | — | Vertical spacing above and below this block |
substrate
Generated pattern fills (SPEC-087). Markers only — the engine sets the attributes and cell/opacity custom properties, CSS draws the pattern.
| Attribute | Type | Required | Description |
|---|---|---|---|
substrate | "dots" | "grid" | "lines" | "cross" | "checker" | "none" | — | Generated surface pattern |
substrate-fill | "inherit" | "inset" | — | Surface fill the pattern sits on (full colour stays with tint) |
substrate-opacity | "sm" | "md" | "lg" | — | Pattern ink strength |
substrate-size | "sm" | "md" | "lg" | — | Pattern cell size |
substrate-target | "self" | "media" | — | Which surface the pattern fills (overrides the rune/theme default) |
tint
Per-rune colour override (SPEC-053): a named tint from the theme registry, with inline per-token overrides layered on top.
| Attribute | Type | Required | Description |
|---|---|---|---|
tint | string | — | Color tint preset applied to this block |
tint-mode | "auto" | "dark" | "light" | — | Whether the tint adapts to auto, dark, or light mode |
width
The track a block rune occupies.
| Attribute | Type | Required | Description |
|---|---|---|---|
width | "compact" | "narrow" | "content" | "wide" | "full" | — | Maximum width constraint for this block |
| Not available | Why |
|---|---|
| dropcap, reading | this rune declares no prose body |
| frame | this rune declares neither a `frameTarget` nor a media section |
| prominence | this rune has no page-section header |