Command Palette

Search for a command to run...

Suggestion

shadcn/ui

Horizontal scrollable row of one-click prompt suggestions for the user.

Suggestion
Click a suggestion to populate

import { useState } from "react";import {	PromptInput,	PromptInputSubmit,	PromptInputTextarea,	PromptInputToolbar,	PromptInputTools,} from "@/components/optics/ai-elements/prompt-input";import { Suggestion, Suggestions } from "@/components/optics/ai-elements/suggestion";import { Button } from "@/components/optics/button";const SUGGESTIONS = [	"Explain the auth middleware flow",	"Write unit tests for rate limiting",	"Find unused exports in components",	"Optimize database query latency",	"Add keyboard navigation to menu",	"Summarize recent PR feedback",];function SuggestionDemo() {	const [prompt, setPrompt] = useState("");	const [submitted, setSubmitted] = useState<string[]>([]);	function handleSubmit(text: string) {		setSubmitted((prev) => [...prev, text]);		setPrompt("");	}	return (		<div className="flex w-full max-w-lg flex-col gap-3">			{submitted.length > 0 ? (				<div className="flex flex-col gap-2 rounded-xl border bg-background p-3">					<div className="flex items-center justify-between gap-2">						<span className="text-xs font-medium text-muted-foreground">Submitted prompts</span>						<Button type="button" size="xs" variant="ghost" onClick={() => setSubmitted([])}>							Clear						</Button>					</div>					<div className="flex flex-col gap-1.5">						{submitted.map((entry, index) => (							<div								key={`${index}-${entry}`}								className="rounded-lg bg-muted/60 px-3 py-2 text-xs text-foreground"							>								{entry}							</div>						))}					</div>				</div>			) : null}			<Suggestions>				{SUGGESTIONS.map((item) => (					<Suggestion						key={item}						suggestion={item}						variant={prompt === item ? "secondary" : "outline"}						onSelect={setPrompt}					/>				))}			</Suggestions>			<PromptInput				value={prompt}				onValueChange={setPrompt}				onSubmitMessage={handleSubmit}				inputGroupClassName="rounded-xl bg-background dark:bg-background"			>				<PromptInputTextarea placeholder="Ask anything or pick a suggestion above..." />				<PromptInputToolbar>					<PromptInputTools>						<span className="px-2 text-xs text-muted-foreground">							{prompt.trim().length > 0								? "Press Enter or click Send to submit"								: "Click a suggestion to populate"}						</span>					</PromptInputTools>					<PromptInputSubmit disabled={prompt.trim().length === 0} />				</PromptInputToolbar>			</PromptInput>		</div>	);}<SuggestionDemo />

Installation

pnpm dlx shadcn@latest add @optics/ai-suggestion

Props

<Suggestion />
Name
Type
suggestion
string
variant
"link" | "outline" | "default"(default: outline)
render
React.ReactElement
nativeButton
boolean
animation
"none" | "all" | "colors" | "only-scale"
focusableWhenDisabled
boolean