visual-riffs

A floating version switcher for coded prototypes.

Customize

Every option applies to this page's widget as you change it.

A menu above the coin, or a full-height panel.

Auto follows the OS setting. This black page keeps it dark.

Filters by number, label and note. On by default in sidepanel.

Docks the current version's links beside the coin.

Actions

Buttons below the list. Here they only close the menu.

Prompt

Your settings as instructions. Paste them into your coding assistant to set up the same widget.

Prompt
Add visual-riffs to this project. It is a floating version switcher for coded prototypes (npm: visual-riffs, docs: https://www.npmjs.com/package/visual-riffs).

1. Install it with the project's package manager: npm i visual-riffs. For a page without a build step, load <script src="https://unpkg.com/visual-riffs@0.2"></script> instead; it defines one global, riffs.

2. Mount it once, on every page. riffs(config) reads location and document, so it must run in the browser after mount. In React or Next.js, call it from a client component's effect in the root layout and return its destroy function: useEffect(() => riffs(config).destroy, [pathname]). Re-running on pathname changes keeps the current-version marker right after client-side navigation.

3. Register the current design as version 1: a short label, a one-line note saying what it is, and the url of the route or folder it lives at. Keep the versions array in one shared file (for example src/riffs/versions.ts or /versions.js).

4. Configure it with these properties:
- title: leave it out, or set a short name for this prototype's riffs. It is the widget's accessible name and is never shown.
- theme: "auto". Follows the OS light or dark setting.
- mode: "popover". The version list pops up above the coin.
- search: false (the default for this mode, so it can be left out). No search field.
- quickLinks: false. Links show only inside the menu.
- versions: one entry per design version, in order. The last entry is marked latest.
- actions: none.

riffs({
  versions, // see step 3
})

5. From now on, when I ask for a new riff or version: copy the latest version's route or folder, append it to versions with a short label, a one-line note and its url, and make the change only in the copy. Never edit existing versions; they are the archive. Do not use git branches or commits to represent versions. Add this workflow to AGENTS.md or CLAUDE.md so later sessions follow it.

Install & usage

Each riff is a folder, a URL and an optional one-line note. List them in order; the last one is the latest. Mount the widget once, on every page.

$ npm i visual-riffs
"use client"
import { useEffect } from "react"
import riffs from "visual-riffs"

const versions = [
  { label: "One column", url: "/signup-1" },
  { label: "Split hero", url: "/signup-2" },
]

export function Riffs() {
  useEffect(() => riffs({ versions }).destroy, [])
  return null
}

For agents

The whole reference as one Markdown file. Copy it into your agent's context.

visual-riffs.md
# visual-riffs

> A floating version switcher for coded prototypes. Each riff (version) is a folder or route, a URL and an optional one-line note. A small coin floats over every page; opening it lists the versions in order, marks the one being viewed, and switches between them by plain navigation. No dependencies, about 14 KB gzipped, rendered in a shadow root so page CSS cannot collide with it.

- npm: https://www.npmjs.com/package/visual-riffs
- Version: 0.2.0 (ESM via npm, IIFE via CDN)

## Install

```sh
npm i visual-riffs
```

Without a build step, load the pinned IIFE. It defines one global, `riffs`, and renders nothing until called:

```html
<script src="https://unpkg.com/visual-riffs@0.2"></script>
```

## Mount

`riffs(config)` reads `location` and touches `document` when called, so it must run in the browser, never during a server render. Mount it once for the whole site and destroy it on unmount. It appends its own `<riffs-widget>` to `document.body`.

React or Next.js (render `<Riffs />` once in the root layout):

```tsx
"use client"
import { useEffect } from "react"
import { usePathname } from "next/navigation"
import riffs from "visual-riffs"
import { versions } from "./versions"

export function Riffs() {
  const pathname = usePathname()
  useEffect(() => riffs({ versions }).destroy, [pathname])
  return null
}
```

The widget matches the current version once, when called. After a client-side route change, destroy it and call `riffs()` again, as the `pathname` dependency above does.

Script tag (the same two tags on every version's page):

```html
<script src="https://unpkg.com/visual-riffs@0.2"></script>
<script src="/versions.js"></script>
```

## Config

`riffs(config: RiffsConfig): RiffsInstance`

### RiffsConfig

| Field | Type | Default | Notes |
| --- | --- | --- | --- |
| versions | RiffVersion[] | required | Order is the numbering (001, 002, …). The last entry is marked LATEST. |
| title | string | "Versions" | Accessible name only, never rendered. |
| theme | "auto" \| "light" \| "dark" | "auto" | Auto follows prefers-color-scheme. |
| mode | "popover" \| "sidepanel" | "popover" | A 326px menu above the coin, or a full-height panel down the coin's edge. |
| search | boolean | on in sidepanel, off in popover | A field that matches number, label and note. |
| quickLinks | boolean | false | Docks the current version's links beside the coin. |
| actions | RiffAction[] | none | Buttons below a separator, such as resetting prototype state. |

### RiffVersion

| Field | Type | Notes |
| --- | --- | --- |
| label | string | Version name. |
| url | string | Where the version lives, such as "/signup-1/". Used to detect the current version and to navigate. |
| note | string? | What the riff explores. Clamps to two lines; a longer note gets a Read more panel. |
| links | RiffLink[]? | Chips on the version's row. |

### RiffLink

| Field | Type | Notes |
| --- | --- | --- |
| type | "figma" \| "paper" \| "shaders" \| "github" \| "notion" \| "linear" \| "slack" \| "loom" \| "supercut" \| string | Known types get their brand mark; any other string gets a generic arrow and a tooltip naming the host. |
| url | string | Opens in a new tab. |
| label | string? | Chip text. Defaults to the brand name, or the capitalized type. |

### RiffAction

| Field | Type | Notes |
| --- | --- | --- |
| label | string | Button text. |
| onClick | (event: MouseEvent) => void | The menu closes after it runs. |
| danger | boolean? | Red hover treatment. |
| icon | string? | Inline SVG before the label, injected as raw HTML. Only pass markup you control. |

### RiffsInstance

`riffs()` returns `{ el, open(), close(), toggle(), destroy() }`. `el` is the mounted `<riffs-widget>`; `destroy()` removes it and every listener it registered.

## Theming

Colors are CSS custom properties on the `riffs-widget` host and inherit into the shadow root, so page CSS can set any of them:

```css
riffs-widget {
  --r-surface: #fffdf8;
  --r-text: #101014;
}
```

Tokens: --r-surface, --r-surface-hover, --r-border, --r-text, --r-text-secondary, --r-text-muted, --r-chip-bg, --r-chip-bg-hover, --r-chip-text, --r-chip-icon, --r-chip-grad, --r-chip-shadow, --r-current-bg, --r-current-num, --r-current-chip-bg, --r-current-chip-bg-hover, --r-danger, --r-danger-bg, --r-shadow-coin, --r-shadow-menu, --r-coin-emboss (a filter) and --r-inset (the sidepanel's inset, 12px). There is no accent token.

## Positioning

The coin is a 40px circle fixed 20px from the bottom left. Page CSS on `riffs-widget` overrides it without !important:

```css
riffs-widget { left: auto; right: 20px; }
```

Menus, quick links and the sidepanel open toward the middle of the viewport, whichever side the coin is on.

## URL matching

A version is current when its url's path segments are a suffix of location.pathname's, so "/signup-1/", "signup-1" and "/signup-1/index.html" are equivalent. The longest match wins; on a tie, the earlier version wins. Whatever precedes the match is kept as the base, so a prototype deployed under a subpath keeps working. Query strings and hashes are ignored when matching. When no version matches, none is marked as viewing.

## Workflow for agents

Add this to the prototype's AGENTS.md or CLAUDE.md:

```md
## Design versions (riffs)

This prototype uses the riffs switcher (npm: visual-riffs). Each version is
its own folder or route. One shared versions file lists them all and is
passed to riffs({ versions }) on every page.

When asked for a new riff or version:
1. Copy the folder of the version being riffed on (usually the latest).
   Never edit existing version folders; they are the archive.
2. Append it to the versions array: a short label, a one-line note saying
   what this riff explores, and its url. Numbering and the LATEST marker
   come from array order, so new riffs go last.
3. Make the requested design change inside the new folder only.
4. To attach a share link, add it to that version's links array:
   { type: "loom" | "slack" | "figma" | "notion" | "linear" | "github" | "shaders", url: "..." }.
   Any other type string renders with a generic icon.
5. Versions are folders plus this config. Do not use git branches or
   commits to represent versions.
```