aiellie

Search

Find a component, template or page

GitHub
Components

Response

A reply written in Markdown, set as prose: headings, lists, quotes, links, tables and inline code, with fenced code in a code block, and each word fading in while it streams.

fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/response"

shadcn needs the @aiellie registry in components.json first. npx aiellie add response adds it on its first run, then installs the same way.

Response renders a reply written in Markdown and sets it as prose: headings, lists, quotes, links, tables and inline code, with GitHub's extensions like tables and strikethrough. Fenced code becomes a CodeBlock, named by its language and copyable. While the reply streams, each word fades in as it arrives and a caret follows the last one.

Getting started

  1. Render the reply

    Pass the Markdown as the child.

    components/reply.tsx
    import { Response } from "@/components/aiellie/response"
    
    export function Reply({ text }: { text: string }) {
      return <Response>{text}</Response>
    }
  2. Stream it from the AI SDK

    Join the message's text parts and set streaming while the reply is still coming. Only the words that just arrived fade in, so the text already on screen holds still.

    components/reply.tsx
    import type { UIMessage } from "ai"
    
    import { Response } from "@/components/aiellie/response"
    
    export function Reply({
      message,
      streaming,
    }: {
      message: UIMessage
      streaming: boolean
    }) {
      const text = message.parts
        .map((part) => (part.type === "text" ? part.text : ""))
        .join("")
    
      return <Response streaming={streaming}>{text}</Response>
    }

Anatomy

<div data-slot="response" data-streaming>
  <p /> <h2 /> <ul /> <blockquote /> {/* the reply's own elements */}
  <figure data-slot="response-code-block" /> {/* fenced code */}
  <div data-slot="response-table"><table /></div>
  <span data-slot="response-caret" /> {/* while streaming, after the last word */}
</div>

The styles live on the root and reach the elements the Markdown makes, so it needs no typography plugin. Blocks sit 16px apart, the reply's type is 14px on 24px leading, nothing is heavier than medium, and a table scrolls in its own box rather than widening the page.

Links open in a new tab and rest in the ink around them, underlining on hover.

Examples

Cite sources inline

components replaces how any element renders. Here a link to a listed source becomes an InlineCitation with its number.

Container queries style an element by its parent's width (1), and every major browser has supported them since 2023 (2).

Without the fade

Leave streaming off and the reply renders as plain elements, which is also how a finished reply renders.

<Response>{text}</Response>

API reference

Response

PropTypeDefaultDescription
childrenstringrequiredThe reply, as Markdown.
streamingbooleanfalseFades in each word as it arrives, with a caret after the last.
componentsComponentsreact-markdown renderers of your own, merged over the defaults.
classNamestringMerged onto the root.

All other div props are forwarded.