Ghost Text

PreviousNext

A text suggestion system that displays AI-generated content after the cursor.

Preview

Loading preview…
registry/ui/ghost-text.tsx
'use client';

import * as React from 'react';

import { CopilotPlugin } from '@platejs/ai/react';
import { useElement, usePluginOption } from 'platejs/react';

export function GhostText() {
  const element = useElement();

  const isSuggested = usePluginOption(
    CopilotPlugin,
    'isSuggested',
    element.id as string
  );

  if (!isSuggested) return null;

  return <GhostTextContent />;
}

function GhostTextContent() {
  const suggestionText = usePluginOption(CopilotPlugin, 'suggestionText');

  return (
    <span
      className="pointer-events-none text-muted-foreground/70 max-sm:hidden"
      contentEditable={false}
    >
      {suggestionText && suggestionText}
    </span>
  );
}

Installation

npx shadcn@latest add @plate/ghost-text

Usage

import { GhostText } from "@/components/ui/ghost-text"
<GhostText />