Skip to content
kitn AI/UI

Artifact

kai-artifact

Show an AI-generated deliverable beside the conversation — a web page, doc, image, or PDF — in a sandboxed iframe with a nav toolbar and a switchable Code view.

  • Shadow DOM
  • Sandboxed iframe
  • Preview + Code tabs
  • Configurable toolbar
  • 4 events

Point src at your hosted artifact and set files in JavaScript (it’s an array, so it can’t be an HTML attribute) for the Code tab.

<kai-artifact src="https://your.app/artifacts/abc/index.html" style="display:block;height:520px"></kai-artifact>
<script type="module">
import '@kitn.ai/ui/elements';
const el = document.querySelector('kai-artifact');
el.files = [
{ path: 'index.html', url: '…/index.html', type: 'html', code: '<!DOCTYPE …>' },
{ path: 'styles.css', url: '…/styles.css', type: 'other', language: 'css', code: '' },
];
el.addEventListener('kai-navigate', (e) => console.log(e.detail.url));
</script>
  • files — each entry needs a path; add url for the preview, code + language for the Code tab, and type (html | pdf | image | other). Folders come from the / in paths.
  • Toolbar — hide any default control with its no-* flag (no-nav, no-reload, no-home, no-path-field, no-tabs); expandable and open-in-tab are opt-in.
  • Sandbox defaults to allow-scripts allow-forms. Widen it only for trusted content.

Hide the whole toolbar for a chrome-free embedded tile.

Rounded, bordered chrome for an artifact rendered outside a panel — a modal or inline tile.

An expand-to-fill button that fires kai-maximize-change, plus the open-in-tab control.

PropertyTypeDefaultNotes
src URL the preview iframe frames. Consumer-controlled.
files [] Files for the Code tab tree + each file's preview `url`. Set as a JS property (array).
tab 'preview' Active tab: `preview` (default) or `code`.
activeFile Selected file path — syncs the tree highlight, Code source, and preview.
sandbox 'allow-scripts allow-forms' iframe `sandbox` override. Secure default `allow-scripts allow-forms` (NOT `allow-same-origin`).
iframeTitle Accessible title for the preview iframe.
maximized false Reflects the artifact's own maximized view-state (usually driven by the protocol).
expandable false Show the expand-to-fill button (OPT-IN).
openInTab false Show the open-in-new-tab button (OPT-IN).
noNav false Hide back/forward.
noReload false Hide reload.
noHome false Hide home.
noPathField false Hide the address field.
noTabs false Hide the Preview|Code toggle.
standalone false Standalone chrome: rounded corners + border (else square, borderless in-panel).
readonlyPath false Show the address but make it read-only (visible, nav-tracking, non-editable).
EventDetailNotes
Fired when a file is selected. `detail.path`.
Artifact's own maximize button toggled (consumer-observable; non-bubbling).
Fired when the preview navigates. `detail.url` = the new location.
Fired when the Preview|Code tab changes. `detail.tab`.

This element wraps these SolidJS components — reach for them directly when you need finer control than the props expose.

Artifact