AI Artifact
Things an agent makes: a file card that builds itself, a preview pane with a code toggle, and a version strip of generated results.
"use client"
import * as React from "react"
import { ArrowUpRight, Code, Eye, FileCode, RefreshCw } from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Mark,
Pill,
Roll,
} from "@/lib/ai-kit"
const CSS = `
.aik-ar-file{position:relative;display:flex;align-items:center;gap:12px;width:min(100%,380px);padding:12px;border-radius:16px;background:var(--aik-card);box-shadow:var(--aik-sh-card);overflow:hidden}
.aik-ar-ico{display:grid;place-items:center;width:40px;height:40px;flex:none;border-radius:10px;background:var(--aik-raised);color:var(--aik-text-2);transition:color var(--aik-d-state),background var(--aik-d-state)}
.aik-ar-file[data-s="done"] .aik-ar-ico{color:var(--aik-green);background:color-mix(in oklab,var(--aik-green) 12%,transparent)}
.aik-ar-meta{display:grid;gap:1px;flex:1;min-width:0}
.aik-ar-meta b{font:500 13.5px/20px var(--aik-mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-ar-meta span{font-size:12.5px;line-height:18px;color:var(--aik-text-2);font-variant-numeric:tabular-nums;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-ar-end{display:flex;flex:none}
.aik-ar-bar{position:absolute;inset:auto 0 0 0;height:2px;background:var(--aik-line);transition:opacity var(--aik-d-panel) var(--aik-ease-out)}
.aik-ar-bar i{display:block;height:100%;background:var(--aik-blue);transform-origin:0 50%;transition:transform var(--aik-d-panel) var(--aik-ease-out)}
.aik-ar-file[data-s="done"] .aik-ar-bar{opacity:0}
.aik-ar-pane{display:grid;width:min(100%,420px);border-radius:18px;background:var(--aik-card);box-shadow:var(--aik-sh-card);overflow:hidden}
.aik-ar-top{display:flex;align-items:center;gap:10px;height:48px;padding:0 8px 0 14px;border-bottom:1px solid var(--aik-line)}
.aik-ar-top b{flex:1;min-width:0;font:500 13px/20px var(--aik-mono);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-ar-toggle{position:relative;display:grid;grid-template-columns:1fr 1fr;flex:none;padding:2px;border-radius:10px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-ar-thumb{position:absolute;left:2px;top:2px;bottom:2px;width:calc(50% - 2px);border-radius:8px;background:var(--aik-card);box-shadow:var(--aik-sh-card);transition:transform var(--aik-d-panel) var(--aik-ease-move)}
.aik-ar-toggle[data-view="code"] .aik-ar-thumb{transform:translateX(100%)}
.aik-ar-toggle button{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:6px;height:28px;padding:0 10px;border-radius:8px;font-size:12.5px;font-weight:500;color:var(--aik-text-3);transition:color var(--aik-d-state)}
.aik-ar-toggle button[aria-selected="true"]{color:var(--aik-text)}
.aik-ar-body{display:grid;height:216px;background:var(--aik-panel)}
.aik-ar-view{grid-area:1/1;min-width:0;min-height:0;opacity:0;transform:translateY(6px);visibility:hidden;transition:opacity var(--aik-d-exit) var(--aik-ease-in),transform var(--aik-d-exit) var(--aik-ease-in),visibility 0s var(--aik-d-exit)}
.aik-ar-view[data-on]{opacity:1;transform:none;visibility:visible;transition:opacity var(--aik-d-enter) var(--aik-ease-out) 80ms,transform var(--aik-d-enter) var(--aik-ease-out) 80ms}
.aik-ar-show{display:grid;place-items:center;padding:16px;overflow:hidden}
.aik-ar-code{margin:0;padding:12px 0;overflow:auto;font:12px/20px var(--aik-mono);color:var(--aik-text-2);scrollbar-width:thin}
.aik-ar-code span{display:block;padding-right:16px;white-space:pre}
.aik-ar-code i{display:inline-block;width:38px;padding-right:12px;text-align:right;font-style:normal;color:var(--aik-text-3);user-select:none}
@container (max-width:340px){.aik-ar-toggle button span{display:none}.aik-ar-toggle button{padding:0 9px}}
.aik-ar-vers{display:grid;gap:10px;width:min(100%,400px)}
.aik-ar-stage{position:relative;aspect-ratio:16/9;border-radius:16px;overflow:hidden;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-ar-big{position:absolute;inset:0;display:grid;animation:aik-ar-big var(--aik-d-panel) var(--aik-ease-out) both}
.aik-ar-big > *,.aik-ar-tn > *{width:100%;height:100%;min-width:0;min-height:0}
@keyframes aik-ar-big{from{opacity:0;transform:scale(1.03)}}
.aik-ar-stage::after{content:"";position:absolute;inset:0;opacity:0;pointer-events:none;background:linear-gradient(100deg,transparent 30%,color-mix(in oklab,var(--aik-panel) 70%,transparent) 50%,transparent 70%) 0 0/260% 100%;transition:opacity var(--aik-d-state)}
.aik-ar-vers[data-busy] .aik-ar-stage::after{opacity:1;animation:aik-shimmer 1.4s linear infinite}
.aik-ar-vers[data-busy] .aik-ar-big{opacity:.45;transition:opacity var(--aik-d-state)}
.aik-ar-foot{display:flex;align-items:center;gap:10px;min-height:28px}
.aik-ar-cap{display:flex;align-items:baseline;gap:8px;flex:1;min-width:0;font-size:13.5px}
.aik-ar-cap .aik-roll{font-weight:600;min-width:0}
.aik-ar-cap > span:last-child{font:11.5px/16px var(--aik-mono);color:var(--aik-text-3);white-space:nowrap;font-variant-numeric:tabular-nums}
.aik-ar-vers[data-busy] .aik-ar-spin{animation:aik-spin .9s linear infinite}
.aik-ar-strip{display:grid;grid-template-columns:repeat(var(--n,4),minmax(0,1fr));gap:8px}
.aik-ar-tn{display:grid;aspect-ratio:16/10;border-radius:10px;overflow:hidden;opacity:.62;box-shadow:0 0 0 1px var(--aik-line-2);transition:opacity var(--aik-d-state),box-shadow var(--aik-d-state),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-ar-tn:hover{opacity:.9}
.aik-ar-tn:active{transform:scale(.96)}
.aik-ar-tn[aria-checked="true"]{opacity:1;box-shadow:0 0 0 2px var(--aik-panel),0 0 0 3.5px var(--aik-text)}
.aik-ar-tn[data-new]{animation:aik-pop var(--aik-d-enter) var(--aik-ease-out) both}
@media (prefers-reduced-motion: reduce){.aik-ar-vers[data-busy] .aik-ar-stage::after,.aik-ar-vers[data-busy] .aik-ar-spin{animation:none}}
`
export interface AiArtifactFileProps extends React.HTMLAttributes<HTMLDivElement> {
/** The file name, shown in mono. */
name: string
/** Lines written so far. */
lines: number
/** Build progress from 0 to 1. */
progress: number
/** `ready` swaps the building pill for an Open button. */
status?: "building" | "ready"
/** A short qualifier after the line count, such as the language. */
detail?: string
/** Replaces the default file icon. */
icon?: React.ReactNode
onOpen?: () => void
}
/** A file card that builds itself: the line count climbs, a progress line fills, then it offers Open. */
export function AiArtifactFile({
name,
lines,
progress,
status = "building",
detail,
icon,
onOpen,
className,
...rest
}: AiArtifactFileProps) {
const ready = status === "ready"
const amount = Math.min(1, Math.max(0, progress))
return (
<div
{...rest}
className={cx("aik aik-ar-file", className)}
data-s={ready ? "done" : "run"}
>
<AiKitStyles />
<AiStyle id="ai-artifact" css={CSS} />
<span className="aik-ar-ico">{icon ?? <FileCode size={18} />}</span>
<span className="aik-ar-meta">
<b>{name}</b>
<span>
{lines} {lines === 1 ? "line" : "lines"}
{detail ? ` · ${detail}` : ""}
</span>
</span>
<span className="aik-ar-end" role="status">
{ready ? (
<button
type="button"
className="aik-btn sm pri aik-in"
onClick={onOpen}
>
Open
<ArrowUpRight size={14} />
</button>
) : (
<Pill status="run">
<Mark status="run" />
Building
</Pill>
)}
</span>
<i className="aik-ar-bar" aria-hidden="true">
<i style={{ transform: `scaleX(${ready ? 1 : amount})` }} />
</i>
</div>
)
}
export type AiArtifactView = "preview" | "code"
export interface AiArtifactPreviewProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"title"
> {
/** The artifact's name, shown in the header. */
title: string
view: AiArtifactView
onViewChange: (view: AiArtifactView) => void
/** The source shown on the Code side, one line per row. */
code: string
/** The rendered result shown on the Preview side. */
children: React.ReactNode
}
/** A result pane with a Preview and Code toggle whose thumb slides between the two. */
export function AiArtifactPreview({
title,
view,
onViewChange,
code,
children,
className,
...rest
}: AiArtifactPreviewProps) {
const id = React.useId()
const tabs = React.useRef<Record<AiArtifactView, HTMLButtonElement | null>>({
preview: null,
code: null,
})
const flip = (next: AiArtifactView) => {
onViewChange(next)
tabs.current[next]?.focus()
}
const tab = (key: AiArtifactView, label: string, icon: React.ReactNode) => (
<button
ref={(node) => {
tabs.current[key] = node
}}
type="button"
role="tab"
id={`${id}-tab-${key}`}
aria-selected={view === key}
aria-controls={`${id}-${key}`}
tabIndex={view === key ? 0 : -1}
onClick={() => onViewChange(key)}
onKeyDown={(event) => {
if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
event.preventDefault()
flip(key === "preview" ? "code" : "preview")
}
}}
>
{icon}
<span>{label}</span>
</button>
)
return (
<div {...rest} className={cx("aik aik-ar-pane", className)}>
<AiKitStyles />
<AiStyle id="ai-artifact" css={CSS} />
<div className="aik-ar-top">
<b>{title}</b>
<div
className="aik-ar-toggle"
role="tablist"
aria-label="View"
data-view={view}
>
<i className="aik-ar-thumb" aria-hidden="true" />
{tab("preview", "Preview", <Eye size={14} />)}
{tab("code", "Code", <Code size={14} />)}
</div>
</div>
<div className="aik-ar-body">
<div
className="aik-ar-view aik-ar-show"
role="tabpanel"
id={`${id}-preview`}
aria-labelledby={`${id}-tab-preview`}
data-on={view === "preview" ? "" : undefined}
>
{children}
</div>
<pre
className="aik-ar-view aik-ar-code"
role="tabpanel"
id={`${id}-code`}
aria-labelledby={`${id}-tab-code`}
data-on={view === "code" ? "" : undefined}
tabIndex={view === "code" ? 0 : -1}
>
{code.split("\n").map((line, index) => (
<span key={index}>
<i>{index + 1}</i>
{line}
</span>
))}
</pre>
</div>
</div>
)
}
export interface AiArtifactVersion {
id: string
/** Named in the caption and read out for the thumbnail. */
label: string
/** The result itself: an image, SVG or any node. It fills its frame. */
art: React.ReactNode
}
export interface AiArtifactVersionsProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onChange"
> {
versions: AiArtifactVersion[]
/** The selected version's id. */
value: string
onValueChange: (id: string) => void
onRegenerate?: () => void
/** True while a new version is being made: the stage shimmers and the button spins. */
regenerating?: boolean
}
/** A strip of generated results. Pick one to see it large, or regenerate for another. */
export function AiArtifactVersions({
versions,
value,
onValueChange,
onRegenerate,
regenerating = false,
className,
...rest
}: AiArtifactVersionsProps) {
const thumbs = React.useRef<Array<HTMLButtonElement | null>>([])
const found = versions.findIndex((version) => version.id === value)
const index = found < 0 ? 0 : found
const current = versions[index]
const move = (step: number) => {
const next = (index + step + versions.length) % versions.length
const target = versions[next]
if (!target) return
onValueChange(target.id)
thumbs.current[next]?.focus()
}
return (
<div
{...rest}
className={cx("aik aik-ar-vers", className)}
data-busy={regenerating ? "" : undefined}
>
<AiKitStyles />
<AiStyle id="ai-artifact" css={CSS} />
<div className="aik-ar-stage">
{current ? (
<div key={current.id} className="aik-ar-big">
{current.art}
</div>
) : null}
</div>
<div className="aik-ar-foot">
<span className="aik-ar-cap" aria-live="polite">
<Roll>
{regenerating ? "Making another" : (current?.label ?? "")}
</Roll>
<span>
{index + 1} of {versions.length}
</span>
</span>
<button
type="button"
className="aik-btn sm line"
disabled={regenerating}
onClick={onRegenerate}
>
<RefreshCw size={14} className="aik-ar-spin" />
Regenerate
</button>
</div>
<div
className="aik-ar-strip"
role="radiogroup"
aria-label="Versions"
style={{ "--n": Math.max(versions.length, 1) } as React.CSSProperties}
>
{versions.map((version, at) => (
<button
key={version.id}
ref={(node) => {
thumbs.current[at] = node
}}
type="button"
role="radio"
className="aik-ar-tn"
aria-checked={at === index}
aria-label={version.label}
tabIndex={at === index ? 0 : -1}
onClick={() => onValueChange(version.id)}
onKeyDown={(event) => {
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
event.preventDefault()
move(1)
} else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
event.preventDefault()
move(-1)
}
}}
>
{version.art}
</button>
))}
</div>
</div>
)
}
Installation
One command adds ai-artifact and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/ai-artifact.json
ai-artifact-demo
"use client"
import * as React from "react"
import { Check } from "lucide-react"
import { AiDemo } from "@/lib/ai-demo"
import { AiStyle, useAiLoop } from "@/lib/ai-kit"
import {
AiArtifactFile,
AiArtifactPreview,
AiArtifactVersions,
type AiArtifactVersion,
type AiArtifactView,
} from "@/registry/tween/ai-artifact"
const CSS = `
.aik-ard-price{display:grid;gap:10px;width:min(100%,228px);padding:14px;border-radius:14px;background:var(--aik-card);box-shadow:var(--aik-sh-pop);text-align:left}
.aik-ard-price header{display:flex;align-items:center;justify-content:space-between;gap:8px}
.aik-ard-price header b{font-size:12.5px;font-weight:600}
.aik-ard-price header span{height:18px;padding:0 6px;border-radius:6px;font:500 10px/18px var(--aik-mono);letter-spacing:.04em;text-transform:uppercase;color:var(--aik-blue);background:color-mix(in oklab,var(--aik-blue) 12%,transparent)}
.aik-ard-amt{display:flex;align-items:baseline;gap:4px}
.aik-ard-amt b{font-size:28px;line-height:30px;font-weight:600;letter-spacing:-.03em}
.aik-ard-amt span{font-size:11.5px;color:var(--aik-text-3)}
.aik-ard-price ul{display:grid;gap:5px}
.aik-ard-price li{display:flex;align-items:center;gap:6px;font-size:11.5px;line-height:16px;color:var(--aik-text-2)}
.aik-ard-price li svg{color:var(--aik-green)}
.aik-ard-cta{display:grid;place-items:center;height:28px;border-radius:9px;background:var(--aik-pri);color:var(--aik-pri-ink);font-size:12px;font-weight:500}
.aik-ard-art{position:relative;display:block;overflow:hidden}
.aik-ard-art svg{position:absolute;inset:0;width:100%;height:100%}
.aik-ard-art[data-v="dawn"]{background:radial-gradient(90% 120% at 12% 100%,#ff9a5a 0%,transparent 58%),radial-gradient(80% 110% at 92% 8%,#ff5f8f 0%,transparent 60%),linear-gradient(160deg,#3a1d6e,#7a3fd0)}
.aik-ard-art[data-v="tide"]{background:radial-gradient(80% 100% at 80% 0%,#7fe3d4 0%,transparent 62%),linear-gradient(170deg,#0b3a66,#1273a8 60%,#18a7a7)}
.aik-ard-art[data-v="grid"]{background:radial-gradient(60% 80% at 50% 110%,#5b7cff 0%,transparent 64%),#0c0d16;background-blend-mode:screen}
.aik-ard-art[data-v="grid"]::before{content:"";position:absolute;inset:0;background:linear-gradient(#ffffff14 1px,transparent 1px) 0 0/100% 12.5%,linear-gradient(90deg,#ffffff14 1px,transparent 1px) 0 0/8.33% 100%}
.aik-ard-art[data-v="paper"]{background:radial-gradient(70% 90% at 18% 22%,#ffd9a8 0%,transparent 60%),#f6efe4}
.aik-ard-art[data-v="moss"]{background:radial-gradient(80% 110% at 100% 100%,#c9f27a 0%,transparent 60%),linear-gradient(150deg,#0f3d2a,#1f7a4c)}
`
const Bars = ({ ink }: { ink: string }) => (
<svg viewBox="0 0 160 100" preserveAspectRatio="none" aria-hidden="true">
<rect x="14" y="58" width="74" height="9" rx="4.5" fill={ink} />
<rect
x="14"
y="72"
width="48"
height="5"
rx="2.5"
fill={ink}
opacity=".55"
/>
<rect x="14" y="83" width="26" height="8" rx="4" fill={ink} opacity=".9" />
</svg>
)
function Art({ kind }: { kind: "dawn" | "tide" | "grid" | "paper" | "moss" }) {
return (
<span className="aik-ard-art" data-v={kind}>
{kind === "tide" ? (
<svg
viewBox="0 0 160 100"
preserveAspectRatio="none"
aria-hidden="true"
>
<path
d="M0 44 C30 30 50 56 82 42 S134 28 160 40 V100 H0Z"
fill="#ffffff"
opacity=".12"
/>
<path
d="M0 56 C34 44 58 66 92 54 S138 44 160 52 V100 H0Z"
fill="#ffffff"
opacity=".1"
/>
</svg>
) : null}
{kind === "paper" ? (
<svg
viewBox="0 0 160 100"
preserveAspectRatio="xMidYMid slice"
aria-hidden="true"
>
<circle cx="122" cy="34" r="22" fill="#ff7a45" />
<circle cx="104" cy="50" r="13" fill="#1d1d24" />
</svg>
) : null}
{kind === "grid" ? (
<svg
viewBox="0 0 160 100"
preserveAspectRatio="xMidYMid slice"
aria-hidden="true"
>
<circle cx="118" cy="30" r="12" fill="#9db1ff" opacity=".9" />
</svg>
) : null}
{kind === "moss" ? (
<svg
viewBox="0 0 160 100"
preserveAspectRatio="xMidYMid slice"
aria-hidden="true"
>
<rect
x="100"
y="14"
width="40"
height="40"
rx="13"
fill="#eaffc2"
opacity=".9"
/>
</svg>
) : null}
<Bars ink={kind === "paper" ? "#1d1d24" : "#ffffff"} />
</span>
)
}
function File() {
const root = React.useRef<HTMLDivElement>(null)
const [lines, setLines] = React.useState(148)
const [ready, setReady] = React.useState(true)
const total = 148
useAiLoop(
root,
async ({ sleep }) => {
setReady(false)
setLines(0)
await sleep(600)
for (let count = 0; count <= total; count += 4) {
setLines(count)
await sleep(count % 36 === 0 ? 240 : 46)
}
setLines(total)
await sleep(350)
setReady(true)
await sleep(2200)
},
{ gap: 700 }
)
return (
<div ref={root} style={{ display: "grid", width: "min(100%, 380px)" }}>
<AiArtifactFile
name="pricing-section.tsx"
detail="React"
lines={lines}
progress={lines / total}
status={ready ? "ready" : "building"}
/>
</div>
)
}
const CODE = `export function PricingCard() {
const [yearly, setYearly] = useState(false)
return (
<Card className="w-56">
<Badge>Popular</Badge>
<Price value={yearly ? 19 : 24} />
<FeatureList items={FEATURES} />
<Button>Start free</Button>
</Card>
)
}`
function Preview() {
const root = React.useRef<HTMLDivElement>(null)
const [view, setView] = React.useState<AiArtifactView>("preview")
const [hands, setHands] = React.useState(false)
useAiLoop(
root,
async ({ sleep }) => {
setView("preview")
await sleep(2400)
setView("code")
await sleep(2600)
setView("preview")
},
{ gap: 600, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 420px)" }}
onPointerDown={() => setHands(true)}
onKeyDown={() => setHands(true)}
>
<AiArtifactPreview
title="pricing-card.tsx"
view={view}
onViewChange={setView}
code={CODE}
>
<div className="aik-ard-price">
<header>
<b>Pro</b>
<span>Popular</span>
</header>
<div className="aik-ard-amt">
<b>$24</b>
<span>per month</span>
</div>
<ul>
<li>
<Check size={12} />
Every component
</li>
<li>
<Check size={12} />
Templates and updates
</li>
</ul>
<span className="aik-ard-cta">Start free</span>
</div>
</AiArtifactPreview>
</div>
)
}
const BASE: AiArtifactVersion[] = [
{ id: "dawn", label: "Dawn gradient", art: <Art kind="dawn" /> },
{ id: "tide", label: "Tide", art: <Art kind="tide" /> },
{ id: "grid", label: "Night grid", art: <Art kind="grid" /> },
]
const EXTRA: AiArtifactVersion[] = [
{ id: "paper", label: "Paper cut", art: <Art kind="paper" /> },
{ id: "moss", label: "Moss", art: <Art kind="moss" /> },
]
function Versions() {
const root = React.useRef<HTMLDivElement>(null)
const [versions, setVersions] = React.useState<AiArtifactVersion[]>([
...BASE,
EXTRA[0]!,
])
const [value, setValue] = React.useState("tide")
const [busy, setBusy] = React.useState(false)
const [hands, setHands] = React.useState(false)
const timer = React.useRef<number | undefined>(undefined)
React.useEffect(() => () => window.clearTimeout(timer.current), [])
useAiLoop(
root,
async ({ sleep }) => {
setVersions(BASE)
setBusy(false)
setValue("dawn")
await sleep(1500)
setValue("tide")
await sleep(1400)
setValue("grid")
await sleep(1400)
setBusy(true)
await sleep(1700)
setVersions([...BASE, EXTRA[0]!])
setValue("paper")
setBusy(false)
await sleep(2400)
},
{ gap: 600, enabled: !hands }
)
const regenerate = () => {
setBusy(true)
window.clearTimeout(timer.current)
timer.current = window.setTimeout(() => {
setVersions((list) => {
const next = [...BASE, ...EXTRA].find(
(item) => !list.some((have) => have.id === item.id)
)
if (!next) return list
setValue(next.id)
return [...list, next]
})
setBusy(false)
}, 1500)
}
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 400px)" }}
onPointerDown={() => setHands(true)}
onKeyDown={() => setHands(true)}
>
<AiArtifactVersions
versions={versions}
value={value}
onValueChange={setValue}
regenerating={busy}
onRegenerate={regenerate}
/>
</div>
)
}
export function AiArtifactDemo({ only }: { only?: string }) {
return (
<>
<AiStyle id="ai-artifact-demo" css={CSS} />
<AiDemo
only={only}
tabs={[
{ name: "File", node: <File /> },
{ name: "Preview", node: <Preview /> },
{ name: "Versions", node: <Versions /> },
]}
/>
</>
)
}
Installation
Usage
import {
AiArtifactFile,
AiArtifactPreview,
AiArtifactVersions,
} from "@/components/ui/ai-artifact"const [view, setView] = useState<"preview" | "code">("preview")
<AiArtifactFile
name="pricing-section.tsx"
lines={96}
progress={0.65}
status="building"
/>
<AiArtifactPreview
title="pricing-card.tsx"
view={view}
onViewChange={setView}
code={source}
>
<PricingCard />
</AiArtifactPreview>Versions
AiArtifactFileis a file being written. The line count climbs, a progress line fills along the bottom edge, and whenstatusisreadythe building pill gives way to an Open button.AiArtifactPreviewshows a result with a Preview and Code toggle. The thumb slides between the two, the arrow keys switch sides, and the panes cross over in place so the frame never changes size.AiArtifactVersionsis a strip of generated results. Pick a thumbnail to see it large, or regenerate: the stage shimmers whileregeneratingis true and the new version pops into the strip.
The demo's pictures are drawn in CSS and inline SVG. art and children accept any node, so pass real images or a live component.
Props
AiArtifactFile
| Prop | Type | Default | Description |
|---|---|---|---|
name | string | The file name. | |
lines | number | Lines written so far. | |
progress | number | Build progress from 0 to 1. | |
status | "building" | "ready" | "building" | Ready swaps the pill for an Open button. |
detail | string | A qualifier after the line count, such as a language. | |
icon | ReactNode | Replaces the default file icon. | |
onOpen | () => void | Called by the Open button. |
AiArtifactPreview
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | The artifact's name in the header. | |
view | "preview" | "code" | Which side is showing. | |
onViewChange | (view) => void | Called by the toggle. | |
code | string | The source, one line per row. | |
children | ReactNode | The rendered result. |
AiArtifactVersions
| Prop | Type | Default | Description |
|---|---|---|---|
versions | { id, label, art }[] | The results. art fills its frame. | |
value | string | The selected version's id. | |
onValueChange | (id: string) => void | Called when a thumbnail is picked. | |
onRegenerate | () => void | Called by the regenerate button. | |
regenerating | boolean | false | Shimmers the stage and spins the button. |