Plate № 14 · Meta-pattern · documentation primitive

A pattern from the gf.cx specimen book

Pattern preview · live demo + tabbed code

Source · Dan, 2026-06-08

"How could we put in real-code examples of the elements — so that we can see it, like how CodePen does it? Visual + code to the side. It's a preview pattern, for pattern library."

The problem

A pattern entry that documents interactive behaviour — a tooltip, a pulse, a hover-zone guard — earns one <pre><code> block in the prose and asks the reader to imagine what it looks like. The reader can either trust the description or open a new browser tab and rebuild it themselves. Either way, the learning loop is broken: the page tells you about the behaviour without letting you feel it.

The shape

A reusable block that pairs an isolated live demo with the source that produced it. Demo runs in an iframe sandbox so its styles never leak into the host page. Source is shown in a tabbed dark panel (HTML / CSS / JS) with a Copy button. Side-by-side at desktop, stacked at mobile.

PieceWhat it does
<template data-tab="html|css|js">Author writes raw source inside <template> elements. data-tab names the language for the tab label + iframe assembly.
data-external-css / data-external-jsComma-separated URLs of external assets to load inside the iframe head (e.g. assets.gf.cx/tooltip/tooltip.css). Lets a demo depend on the portfolio's primitive CSS without redefining it.
pattern-preview.js assembles srcdocReads each template, dedents the source, builds a single <iframe srcdoc="…"> with external assets in <head> + inline code in <body>. Iframe is sandbox="allow-scripts allow-popups".
Tabs + Copy buttonClick a tab to switch the source pane (HTML default). Copy button copies the currently-shown source to clipboard with a 1.6s "Copied ✓" confirmation.

The element, in-page

This block is itself a pattern-preview — the primitive documenting itself. It demos the simplest possible interactive case: a button that increments a counter. Inspect the three tabs to see how HTML / CSS / JS compose into the live iframe on the left. Every other pattern entry on this site uses exactly this block for its own live demos.

The trap — host-page style leak

The naive version inlines the demo HTML directly into the patterns.gf.cx body. The host page's serif fonts, link styles, code styles, and CSS variables apply to the demo — the demo no longer looks like the surface where it'll actually run, and any aggressive demo CSS (e.g. body { background: black }) leaks back into the host page. The iframe sandbox is non-negotiable: each demo gets its own document scope, its own root element, its own stylesheet origin.

Why srcdoc over a separate file

Where it applies

A pattern library that only describes its patterns is a glossary. A pattern library that lets you feel them is a workbook.

Reusable elements

Reference

Source
Dan, 2026-06-08 · "How could we put in real-code examples of the elements — so that we can see it, like how CodePen does it?" Split from patterns.gf.cx/index.html 2026-06-22.
In use / example
patterns.gf.cx/timeline-overlap-zone-card/ — the canonical in-use entry. Its gate-hero + UTC timeline demo runs inside a pattern-preview block. Copy it as a starting template for any new pattern entry that needs a live demo.
Reusable elements
/assets/pattern-preview.js · /assets/pattern-preview.css · <template data-tab> authoring contract · data-external-css / data-external-js attributes.
Origin
Every pattern that shows interactive behaviour needs a "see it first, read the why second" loop. A static <pre><code> block breaks that loop. This primitive closes it without requiring a separate file or a third-party embed.