Docs menu

Guides


Primitives
Forms
Layout
Feedback
Overlays
Navigation
Data Display
AI

Artifact Panel

The panel an AI app opens beside the chat to show what it made: a page preview, a document, the code behind it. A title, a version switcher, your own actions, a close button and Preview/Code views, around a body you fill with anything.

Make me a landing page for a coffee shop.
Added opening hours. It's open beside the chat.

Docked or overlay

On a wide screen the panel is an <aside> in the page flow, named by its title, so it drops into aResizable pane or a grid column and fills it. Below overlayBelow (768px by default) it becomes a<dialog> opened with showModal(): a full-height sheet from the inline end, with the focus trap, Escape, backdrop and focus return all coming from the browser, likeDialog andSheet.

The switch is a viewport media query, not a container query, because it changes the element and how focus behaves, which CSS can't do. It's also the right question: whether there's room beside the chat on this screen. A narrow Resizable pane on a desktop stays docked. Passpresentation="docked" or "overlay" to choose yourself. Crossing the breakpoint swaps the element, so an iframe preview reloads once.

Status and versions

status="streaming" shows a small pulsing dot and "Generating…" beside the title, and marks the panelaria-busy; "error" shows "Generation failed". The text sits in a polite live region that's there from the start, so the change is announced. With versionCount above 1 the header gets previous/next buttons and a "v3 of 5" readout. Every built-in string goes through labels.

Usage

Usage
<Resizable defaultSplit={38}>
  <Chat />
  <ArtifactPanel
    title="coffee-landing.html"
    open={open}
    onOpenChange={setOpen}
    status={streaming ? "streaming" : "ready"}
    version={version}
    versionCount={versions.length}
    onVersionChange={setVersion}
    actions={<Button variant="ghost" size="sm" aria-label="Copy code" iconStart={<CopyIcon />} onClick={copy} />}
    views={[
      { value: "preview", label: "Preview", content: <iframe title="Preview" sandbox="" srcDoc={html} /> },
      { value: "code", label: "Code", content: <CodeBlock language="html" code={html} /> },
    ]}
  />
</Resizable>

Playground

Toggle every adjustable prop and watch the component, and the code, update live.

Unstyled

Same component — Kernel look stripped. See Platforms.

presentation
status
views
showCloseButton
Usage
<ArtifactPanel
  title="quarterly-report.md"
  presentation="docked"
  open={open}
  onOpenChange={setOpen}
  version={version}
  versionCount={3}
  onVersionChange={setVersion}
  views={[
    { value: "preview", label: "Preview", content: <Preview /> },
    { value: "source", label: "Source", content: <CodeBlock code={source} /> },
  ]}
/>

Props

Props for ArtifactPanel. Also accepts every native HTML attribute except title, children.
PropTypeDefaultNotes
titleReactNodeRequiredThe artifact's name. Rendered as a real heading and used as the panel's accessible name in both presentations.
headingLevel2 | 3 | 42Level of the title heading in docked mode. Defaults to 2. A modal overlay is its own document context, so it always uses h2.
openbooleantrueWhether the panel is showing. Defaults to true, the usual case for a docked panel the host mounts and unmounts itself.
onOpenChange(open: boolean) => void—Close button, Escape and backdrop clicks (overlay) ask for false.
presentation"auto" | "docked" | "overlay""auto""docked": an <aside> in the page flow — put it in a Resizable pane or a grid column. "overlay": a modal <dialog> sliding in from the inline end. "auto" (default) is docked, and overlay when the viewport is narrower than overlayBelow.
overlayBelownumber768Viewport width in px below which "auto" becomes an overlay. Defaults to 768.
status"ready" | "streaming" | "error""ready""streaming" while the model is still writing the artifact, "error" when it failed. Shown as a small dot and a short line of text by the title, announced politely.
versionnumber—The version on show, 1-based. With versionCount above 1 the header gets previous/next buttons and a "v3 of 5" readout.
versionCountnumber——
onVersionChange(version: number) => void——
actionsReactNode—Your own header controls — copy, download, open in a new window. Rendered before the built-in close button.
viewsArtifactPanelView[]—Views of the artifact ("Preview", "Code"), switched with Kernel's Tabs. Without views, children is the body.
viewstring——
defaultViewstring——
onViewChange(view: string) => void——
childrenReactNode——
showCloseButtonbooleantrueHide the built-in close button. Escape still closes an overlay.
labelsPartial<ArtifactPanelLabels>——
classNameClassNameValue<ArtifactPanelState>—A class string, or a function of the component's state that returns one.

Web Components

Attributes and events of the Custom Elements in @kernelui-lib/elements.
TagAttributesEvents
<kernel-artifact-panel>title, heading-level, open, presentation, overlay-below, status, version, version-count, view, label-close, label-previous-version, label-next-version, label-version, label-versions, label-views, label-streaming, label-errorviewchange, versionchange
<kernel-artifact-view>——

Accessibility

  • Docked, it's a complementary landmark (<aside>) named by its title heading, which is a real h2 (set headingLevel to fit your outline).
  • As an overlay, it's a modal <dialog>: the page behind is inert, focus is trapped inside, Escape and the close button close it, and focus returns to whatever opened it.
  • Views are Kernel's Tabs: arrow keys move between tabs and inactive panels are hidden.
  • An iframe preview needs its own title. Give it sandbox too: generated code shouldn't run with your page's permissions.
  • The status dot keeps moving, slower, under reduced motion; it's the only sign that generation is still running. The overlay fades instead of sliding.