aiellie

Search

Find a component, template or page

GitHub
Components

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}
Open full screen
fig. 01 · open it full screen from the corner

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

  1. 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.tsx
    import { 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

  1. Freeze the release branch
  2. Run the smoke tests on staging
  3. Post the changelog

API reference

ArtifactTitle

PropTypeDefaultDescription
childrenReactNodeIts name.
descriptionReactNodeA short line under the name.
iconIconSvgElementA mark before the name.

ArtifactAction

PropTypeDefaultDescription
tooltipstringrequiredAlso its accessible name.
iconIconSvgElementOr pass an icon as children.

All other TooltipIconButton props are forwarded.

ArtifactClose

PropTypeDefaultDescription
tooltipstring"Close"

Artifact, ArtifactHeader, ArtifactActions and ArtifactContent forward their element's props.