Xzero UI
Pro library

Ghost textPro

An inline AI autocomplete where muted ghost text continues your sentence exactly at the caret and Tab turns it solid in place. Cmd+Right takes it one word at a time, Escape fades it away, and a calm chip shows the model behind it.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/ghost-text
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/ghost-text

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { GhostText, ClaudeMark } from "@/components/xzero/ghost-text/ghost-text";

// Stream a continuation from your API route (any model works).
async function* suggest(text: string, signal: AbortSignal) {
  const response = await fetch("/api/autocomplete", { method: "POST", body: JSON.stringify({ text }), signal });
  if (!response.ok || !response.body) throw new Error("Autocomplete is unavailable");
  const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
  for (;;) {
    const { value, done } = await reader.read();
    if (done) return;
    yield value;
  }
}

export function PullRequestDescription() {
  const [body, setBody] = useState("");
  return (
    <GhostText
      value={body}
      onValueChange={setBody}
      suggest={suggest}
      rows={6}
      placeholder="Describe what changed and why"
      label="Description"
      model={{ name: "Claude Haiku 5.5", mark: <ClaudeMark style={{ color: "#D97757" }} /> }}
      onAccept={(text, mode) => track("autocomplete_accept", { mode, chars: text.length })}
    />
  );
}

// Single-line, uncontrolled, whole suggestions from a promise.
<GhostText multiline={false} defaultValue="" aria-label="Subject" suggest={(text, signal) => api.complete(text, { signal })} />

// Flush inside your own card: the card owns the border and focus style.
<div className="compose-card">
  <ComposeHeader />
  <GhostText variant="plain" value={body} onValueChange={setBody} suggest={suggest} aria-label="Message" />
</div>

// With no props it plays the simulated pull request card.
<GhostText />

API reference

GhostText

Inline AI autocomplete for a textarea or a single-line input. When the person pauses, muted ghost text continues their sentence right at the caret, streamed from your suggest(text, signal) function. Tab accepts the whole suggestion, Cmd+Right (Ctrl+Right on Windows, Option or Alt+Right too) accepts one word at a time, Escape dismisses it, and typing the same characters as the ghost keeps it in place instead of asking again. A small chip in the corner shows the model's mark and name, a shimmering Thinking while it waits, a Tab key cap and "to accept" when a suggestion is ready (a tap target on touch screens), Accepted with a check after Tab, and No suggestion with Retry when your function throws. Accepted text settles from ghost ink to text ink in place, with no flicker or movement. Works controlled or uncontrolled, as a bordered field or flush inside your own card (variant="plain"). With no props it plays a simulated pull request card that types, pauses, accepts and loops, and you can take it over by clicking it.

PropTypeDefaultDescription
suggest(text: string, signal: AbortSignal) => string | null | Promise<string | null> | AsyncIterable<string>–Returns a continuation for the text before the caret. Return a string or a promise of one for a whole suggestion, or an async iterable (an async generator over your model's stream) to stream it in chunk by chunk. Return null synchronously to skip without showing Thinking. Abort your request when signal fires: the person kept typing, moved the caret or left the field. A thrown error shows No suggestion with Retry.
valuestring–The text, for a controlled field. Pair with onValueChange. Programmatic changes run through the same logic as typing, so a parent can drive the field.
defaultValuestring""The starting text for an uncontrolled field.
onValueChange(value: string) => void–Called with the new text on every edit and every accepted suggestion or word.
delaynumber450Milliseconds of pause before suggest is called. Every keystroke resets it.
minLengthnumber3Trimmed characters needed before suggestions start.
multilinebooleantrueA growing textarea with a footer row, or a single-line input with the chip inline at its end. Line breaks pasted into a single-line field become spaces.
variant"field" | "plain""field"field draws its own 1px border, hover and keyboard focus ring. plain drops the border, background and ring so the text sits flush inside a card you already have (a compose panel, a PR form); give the card its own focus style.
rowsnumber3Minimum visible lines of a multi-line field.
maxRowsnumber10Lines before a multi-line field stops growing and scrolls, keeping the caret in view.
placeholderstring–Placeholder text for the empty field.
labelReactNode–A quiet row above the text, such as a field name with an icon. It labels the field unless aria-label is set. Multi-line only.
footerReactNode–Content at the start of the footer row, such as a character count, a note or a send button. Multi-line only.
model{ name: string; mark?: ReactNode }{ name: "Autocomplete" }The model behind the suggestions. The name shows in the idle chip and the mark at 12px in every chip state. Give a mono mark its brand color, for example the Claude mark in #D97757.
hintbooleantrueShows the chip, the Cmd+Right and Escape key hints next to it on wide fields, and a screen reader description of the keys.
onAccept(accepted: string, mode: "all" | "word") => void–Called with the text that was accepted: the whole suggestion (all) or the next word (word). Useful for acceptance-rate analytics.
onDismiss(suggestion: string) => void–Called with the suggestion the person dismissed with Escape.
onStatusChange(status: "idle" | "loading" | "ready" | "error") => void–Called when the suggestion status changes.
disabledbooleanfalseDisables the field and stops suggestions.
name, id, autoFocus, aria-labelstring | boolean–Passed to the textarea or input.
noticestring–A one-off message for screen readers, joined to the field's own announcements.
refRef<GhostTextHandle>–Imperative handle: focus(), acceptAll(), acceptWord(), dismiss(), request() to ask now without waiting for a pause, and getState() returning { status, suggestion, streaming }. Use it for an Accept button of your own or for tests.
classNamestring–Class on the root element.

createDemoSuggest

The rule based stand in for a model used by the preview, exported for prototypes and tests. It streams PR writing continuations in 3 to 6 word chunks after a short think, completes partial words from a small vocabulary, and fails with a timeout when the text contains the word timeout so the error state can be seen. Nothing is sent anywhere.

PropTypeDefaultDescription
scriptedOnlybooleanfalseOnly answer the autoplay script's contexts and return null for everything else.

Keyboard interactions

KeysAction
TabAccepts the whole suggestion and keeps the caret at the end. With no suggestion showing, Tab moves focus as usual.
Cmd+Right / Ctrl+RightAccepts the next word of the suggestion; the rest stays. Option+Right and Alt+Right work too. With no suggestion showing, the keys move the caret as usual.
EscapeDismisses the suggestion. With no suggestion showing, Escape is left alone, so a surrounding dialog can still close.
TypingCharacters that match the start of the ghost consume it in place; anything else clears it and a new suggestion is asked for after the next pause.
Arrow keys, clickMoving the caret away from the end of the text clears the suggestion; suggestions only continue from the end.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in ai

Guidance for AI tools

Ghost text: An inline AI autocomplete where muted ghost text continues your sentence exactly at the caret and Tab turns it solid in place. Cmd+Right takes it one word at a time, Escape fades it away, and a calm chip shows the model behind it. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components