Artifact
A panel for something a reply made, like a file, a document or a page: a header with its title, a line about it, actions and a close button, over a body that scrolls.
use-debounce.ts
TypeScript · 11 lines
export function useDebounce<T>(value: T, delay = 300) { const [debounced, setDebounced] = useState(value) useEffect(() => { const timer = setTimeout(() => setDebounced(value), delay) return () => clearTimeout(timer) }, [value, delay]) return debounced}Installation
npx shadcn@latest add "@aiellie/artifact"shadcn needs the @aiellie registry in components.json first. npx aiellie add artifact adds it on its first run, then installs the same way.
Artifact is a panel for something a reply made, like a file, a document or a page, so it can be read and used beside the thread rather than inside it. A header names it, with a line about it, its actions and a close button, over a body that scrolls.
Getting started
Wrap what was made
The body takes anything. Here it's a Code Block's content, which already scrolls sideways and numbers its lines.
components/generated-file.tsximport { Copy01Icon } from "@hugeicons/core-free-icons" import { Artifact, ArtifactAction, ArtifactActions, ArtifactClose, ArtifactContent, ArtifactHeader, ArtifactTitle, } from "@/components/aiellie/artifact" import { CodeBlockContent } from "@/components/aiellie/code-block" export function GeneratedFile({ code, onClose }: { code: string; onClose: () => void }) { return ( <Artifact className="h-full"> <ArtifactHeader> <ArtifactTitle description="TypeScript">use-debounce.ts</ArtifactTitle> <ArtifactActions> <ArtifactAction tooltip="Copy" icon={Copy01Icon} onClick={() => navigator.clipboard.writeText(code)} /> <ArtifactClose onClick={onClose} /> </ArtifactActions> </ArtifactHeader> <ArtifactContent> <CodeBlockContent code={code} language="ts" lineNumbers /> </ArtifactContent> </Artifact> ) }
Anatomy
<section data-slot="artifact">
<header data-slot="artifact-header">
<div data-slot="artifact-title" />
<div data-slot="artifact-actions" role="group">
<button data-slot="artifact-action" />
<button data-slot="artifact-close" />
</div>
</header>
<div data-slot="artifact-content" />
</section>The panel fills the height it's given and only the body scrolls, so give it a height, or a max-h-*, where it sits. Each action is an icon button with its own tooltip.
Examples
A document
Pad the body yourself for prose. Leave out the close button for a panel that stays.
Launch checklist
Edited just now
- Freeze the release branch
- Run the smoke tests on staging
- Post the changelog
API reference
ArtifactTitle
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | Its name. | |
description | ReactNode | A short line under the name. | |
icon | IconSvgElement | A mark before the name. |
ArtifactAction
| Prop | Type | Default | Description |
|---|---|---|---|
tooltip | string | required | Also its accessible name. |
icon | IconSvgElement | Or pass an icon as children. |
All other TooltipIconButton props are forwarded.
ArtifactClose
| Prop | Type | Default | Description |
|---|---|---|---|
tooltip | string | "Close" |
Artifact, ArtifactHeader, ArtifactActions and ArtifactContent forward their element's props.