A text suggestion system that displays AI-generated content after the cursor.
'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>
);
}
npx shadcn@latest add @plate/ghost-textimport { GhostText } from "@/components/ui/ghost-text"<GhostText />