Skip to content
WorkspaceArtifact versionsMenu

Artifact versions

Step through artifact versions or pick one from a list, with edit times and line diff counts to the previous version.

Step through versions or pick one, with the diff to the previous.

Installation

$ pnpm dlx shadcn@latest add https://chatcn.dev/r/artifact-versions.json

Usage

tsx
import { ArtifactVersions } from "@/components/ui/chatcn/artifact-versions"

<ArtifactVersions
  versions={[
    { id: "v1", content: first, createdAt: firstAt, summary: "First draft" },
    { id: "v2", content: second, createdAt: secondAt, summary: "Added filters" },
  ]}
  value={versionId}
  onValueChange={setVersionId}
  showMeta
/>

Give each version its content and the +12 −3 counts are computed with a line diff. Pass additions and deletions instead when your backend already knows them. An uncontrolled switcher moves to a new version when it arrives, if the reader was on the latest.

Props

PropTypeNotes
versionsArtifactVersion[]Oldest first: id, label?, createdAt?, summary?, content?, additions?, deletions?
value, defaultValue, onValueChangestringVersion id. Defaults to the latest
showMetabooleanEdited 2 min ago and the diff next to the switcher
disabledbooleanThe panel disables it while streaming

Also exported: diffLines(previous, next) for the counts and formatRelative(time, now) for the edit time.

Keyboard

KeyAction
Enter, Space on the triggerOpen the version list
↑ ↓, Home, EndMove through versions
EnterChoose a version
EscClose the list

Accessibility

  • The list is a Base UI menu with radio items, so the current version is announced as checked.
  • Diff counts read as 12 lines added and 3 lines removed, not plus and minus signs.
  • Relative times refresh every 30 seconds without visible ticking.

Motion

  • The list opens from its trigger with scale 0.96 and opacity, 180 ms, and closes in 140 ms. Opened by keyboard it appears at once.