chat-input-demo-mentions
simple-ai/chat-input-demo-mentionsFreeExample
simple-ai publishes no description for this item.
Install it
npx shadcn@latest add https://simple-ai.dev/r/chat-input-demo-mentions.jsonSource
1"use client";23import { FileIcon } from "lucide-react";4import { useEffect, useState } from "react";5import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";6import { Badge } from "@/components/ui/badge";7import { highlightCode } from "@/lib/highlight-code";8import {9 ChatInput,10 ChatInputEditor,11 ChatInputGroupAddon,12 ChatInputMention,13 ChatInputMentionButton,14 ChatInputSubmitButton,15 createMentionConfig,16 useChatInput,17} from "@/registry/ui/chat-input";1819type MemberItem = {20 id: string;21 name: string;22 image?: string;23 type: string;24};2526type FileItem = {27 id: string;28 name: string;29};3031const members: MemberItem[] = [32 { id: "1", name: "Alice", image: "/avatar-1.png", type: "agent" },33 { id: "2", name: "Bob", type: "user" },34 { id: "3", name: "Charlie", image: "/avatar-2.png", type: "bot" },35 { id: "4", name: "Dave", type: "user" },36];3738const files: FileItem[] = [39 { id: "f1", name: "report.pdf" },40 { id: "f2", name: "image.png" },41 { id: "f3", name: "notes.txt" },42];4344export default function ChatInputWithMentions() {45 const [highlightedOutput, setHighlightedOutput] = useState<string>("");4647 const { value, onChange, parsed, handleSubmit, mentionConfigs } =48 useChatInput({49 mentions: {50 member: createMentionConfig<MemberItem>({51 type: "member",52 trigger: "@",53 items: members,54 }),55 file: createMentionConfig<FileItem>({56 type: "file",57 trigger: "/",58 items: files,59 }),60 },61 onSubmit: (parsedValue) => {62 console.log("Submitted parsed:", parsedValue);63 console.log("Members mentioned:", parsedValue.member);64 console.log("Files mentioned:", parsedValue.file);65 },66 });6768 useEffect(() => {69 highlightCode(JSON.stringify(parsed, null, 2), "json").then(70 setHighlightedOutput,71 );72 }, [parsed]);7374 return (75 <div className="w-full h-full flex justify-center items-center">76 <div className="w-full max-w-md space-y-4">77 <ChatInput78 onSubmit={handleSubmit}79 value={value}80 onChange={onChange}81 >82 <ChatInputMention83 type={mentionConfigs.member.type}84 trigger={mentionConfigs.member.trigger}85 items={mentionConfigs.member.items}86 >87 {(item) => (88 <>89 <Avatar className="h-6 w-6">90 <AvatarImage91 src={item.image ?? "/placeholder.jpg"}92 alt={item.name}93 />94 <AvatarFallback>95 {item.name[0].toUpperCase()}96 </AvatarFallback>97 </Avatar>9899 <span100// … truncated
What it pulls in
Other registry items
Files it writes
More from simple-ai
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| chat-input-demo-simplechat-input-demo-simple | simple-ai | Examples | Free | no deps | |
| chat-input-with-addonschat-input-with-addons | simple-ai | Examples | Free | no deps | |
| chat-message-area-demochat-message-area-demo | simple-ai | Examples | Free | no deps | |
| chat-message-area-demo-alignmentchat-message-area-demo-alignment | simple-ai | Examples | Free | no deps | |
| chat-message-area-demo-streamingchat-message-area-demo-streaming | simple-ai | Examples | Free | no deps | |
| chat-message-demochat-message-demo | simple-ai | Examples | Free | no deps | |
| chat-message-demo-avatar-imagechat-message-demo-avatar-image | simple-ai | Examples | Free | no deps | |
| chat-message-demo-simplechat-message-demo-simple | simple-ai | Examples | Free | no deps |
