laguagu/claude-code-nextjs-skills / skills/ai-elements
ai-elements
VerifiedMaintains AI chat UI built from elements.ai-sdk.dev AI Elements components already copied into the project. Use when changing or debugging those components (conversations, messages, prompt inputs, attachments, reasoning, tool output, sources). New chat UI uses the shadcn/ui AI Elements patterns (`shadcn` skill).
scripts/prompt-input.tsx
View on GitHub"use client";
import {
Attachment,
AttachmentPreview,
AttachmentRemove,
Attachments,
} from "@/components/ai-elements/attachments";
import {
ModelSelector,
ModelSelectorContent,
ModelSelectorEmpty,
ModelSelectorGroup,
ModelSelectorInput,
ModelSelectorItem,
ModelSelectorList,
ModelSelectorLogo,
ModelSelectorLogoGroup,
ModelSelectorName,
ModelSelectorTrigger,
} from "@/components/ai-elements/model-selector";
import type { PromptInputMessage } from "@/components/ai-elements/prompt-input";
import {
PromptInput,
PromptInputActionAddAttachments,
PromptInputActionAddScreenshot,
PromptInputActionMenu,
PromptInputActionMenuContent,
PromptInputActionMenuTrigger,
PromptInputBody,
PromptInputButton,
PromptInputFooter,
PromptInputProvider,
PromptInputSubmit,
PromptInputTextarea,
PromptInputTools,
usePromptInputAttachments,
} from "@/components/ai-elements/prompt-input";
import { CheckIcon, GlobeIcon } from "lucide-react";
import { memo, useCallback, useState } from "react";
const models = [
{
chef: "OpenAI",
chefSlug: "openai",
id: "gpt-6.1-sol",
name: "GPT-6.1 Sol",
providers: ["openai", "azure"],
},
{
chef: "OpenAI",
chefSlug: "openai",
id: "gpt-6-luna",
name: "GPT-6 Luna",
providers: ["openai", "azure"],
},
{
chef: "Anthropic",
chefSlug: "anthropic",
id: "claude-opus-5",
name: "Claude Opus 5",
providers: ["anthropic", "azure", "google", "amazon-bedrock"],
},
{
chef: "Anthropic",
chefSlug: "anthropic",
id: "claude-sonnet-5",
name: "Claude Sonnet 5",
providers: ["anthropic", "azure", "google", "amazon-bedrock"],
},
{
chef: "Google",
chefSlug: "google",
id: "gemini-2.0-flash-exp",
name: "Gemini 2.0 Flash",
providers: ["google"],
},
];
const SUBMITTING_TIMEOUT = 200;
const STREAMING_TIMEOUT = 2000;
interface AttachmentItemProps {
attachment: {
id: string;
type: "file";
filename?: string;
mediaType?: string;
url: string;
};
onRemove: (id: string) => void;
}
const AttachmentItem = memo(({ attachment, onRemove }: AttachmentItemProps) => {
const handleRemove = useCallback(
() => onRemove(attachment.id),
[onRemove, attachment.id]
);
return (
<Attachment data={attachment} key={attachment.id} onRemove={handleRemove}>
<AttachmentPreview />
<AttachmentRemove />
</Attachment>
);
});
AttachmentItem.displayName = "AttachmentItem";
interface ModelItemProps {
m: (typeof models)[0];
selectedModel: string;
onSelect: (id: string) => void;
}
const ModelItem = memo(({ m, selectedModel, onSelect }: ModelItemProps) => {
const handleSelect = useCallback(() => onSelect(m.id), [onSelect, m.id]);
return (
<ModelSelectorItem key={m.id} onSelect={handleSelect} value={m.id}>
<ModelSelectorLogo provider={m.chefSlug} />
<ModelSelectorName>{m.name}</ModelSelectorName>
<ModelSelectorLogoGroup>
{m.providers.map((provider) => (
<ModelSelectorLogo key={provider} provider={provider} />
))}
</ModelSelectorLogoGroup>
{selectedModel === m.id ? (
<CheckIcon className="ml-auto size-4" />
) : (
<div className="ml-auto size-4" />
)}
</ModelSelectorItem>
);
});
ModelItem.displayName = "ModelItem";
const PromptInputAttachmentsDisplay = () => {
const attachments = usePromptInputAttachments();
const handleRemove = useCallback(
(id: string) => attachments.remove(id),
[attachments]
);
if (attachments.files.length === 0) {
return null;
}
return (
<Attachments variant="inline">
{attachments.files.map((attachment) => (
<AttachmentItem
attachment={attachment}
key={attachment.id}
onRemove={handleRemove}
/>
))}
</Attachments>
);
};
const Example = () => {
const [model, setModel] = useState<string>(models[0].id);
const [modelSelectorOpen, setModelSelectorOpen] = useState(false);
const [status, setStatus] = useState<
"submitted" | "streaming" | "ready" | "error"
>("ready");
const selectedModelData = models.find((m) => m.id === model);
const handleModelSelect = useCallback((id: string) => {
setModel(id);
setModelSelectorOpen(false);
}, []);
const handleSubmit = useCallback((message: PromptInputMessage) => {
const hasText = Boolean(message.text);
const hasAttachments = Boolean(message.files?.length);
if (!(hasText || hasAttachments)) {
return;
}
setStatus("submitted");
// eslint-disable-next-line no-console
console.log("Submitting message:", message);
setTimeout(() => {
setStatus("streaming");
}, SUBMITTING_TIMEOUT);
setTimeout(() => {
setStatus("ready");
}, STREAMING_TIMEOUT);
}, []);
return (
<div className="size-full">
<PromptInputProvider>
<PromptInput globalDrop multiple onSubmit={handleSubmit}>
<PromptInputAttachmentsDisplay />
<PromptInputBody>
<PromptInputTextarea />
</PromptInputBody>
<PromptInputFooter>
<PromptInputTools>
<PromptInputActionMenu>
<PromptInputActionMenuTrigger />
<PromptInputActionMenuContent>
<PromptInputActionAddAttachments />
<PromptInputActionAddScreenshot />
</PromptInputActionMenuContent>
</PromptInputActionMenu>
<PromptInputButton>
<GlobeIcon size={16} />
<span>Search</span>
</PromptInputButton>
<ModelSelector
onOpenChange={setModelSelectorOpen}
open={modelSelectorOpen}
>
<ModelSelectorTrigger asChild>
<PromptInputButton>
{selectedModelData?.chefSlug && (
<ModelSelectorLogo
provider={selectedModelData.chefSlug}
/>
)}
{selectedModelData?.name && (
<ModelSelectorName>
{selectedModelData.name}
</ModelSelectorName>
)}
</PromptInputButton>
</ModelSelectorTrigger>
<ModelSelectorContent>
<ModelSelectorInput placeholder="Search models..." />
<ModelSelectorList>
<ModelSelectorEmpty>No models found.</ModelSelectorEmpty>
{["OpenAI", "Anthropic", "Google"].map((chef) => (
<ModelSelectorGroup heading={chef} key={chef}>
{models
.filter((m) => m.chef === chef)
.map((m) => (
<ModelItem
key={m.id}
m={m}
onSelect={handleModelSelect}
selectedModel={model}
/>
))}
</ModelSelectorGroup>
))}
</ModelSelectorList>
</ModelSelectorContent>
</ModelSelector>
</PromptInputTools>
<PromptInputSubmit status={status} />
</PromptInputFooter>
</PromptInput>
</PromptInputProvider>
</div>
);
};
export default Example;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |