{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "chat-widget", "title": "Chat Widget", "description": "Simple chat display with message list, avatars, timestamps, and message input.", "registryDependencies": [ "https://raw.githubusercontent.com/dnachavez/adminlte-next/master/public/r/adminlte-theme.json" ], "files": [ { "path": "registry/new-york/chat-widget/components/chat-widget.tsx", "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"@/registry/new-york/adminlte-theme/lib/cn\"\n\n/* ---------------------------------------------------------------------------\n * Types\n * -------------------------------------------------------------------------- */\n\ninterface ChatMessage {\n id: string\n name: string\n avatarUrl: string\n text: string\n time: string\n isOwn?: boolean\n}\n\n/* ---------------------------------------------------------------------------\n * ChatWidget\n * -------------------------------------------------------------------------- */\n\ninterface ChatWidgetProps extends React.HTMLAttributes {\n messages?: ChatMessage[]\n onSend?: (text: string) => void\n height?: number\n}\n\nconst ChatWidget = React.forwardRef(\n ({ className, messages = [], onSend, height = 250, ...props }, ref) => {\n const [inputValue, setInputValue] = React.useState(\"\")\n const messagesEndRef = React.useRef(null)\n\n const scrollToBottom = React.useCallback(() => {\n messagesEndRef.current?.scrollIntoView({ behavior: \"smooth\" })\n }, [])\n\n React.useEffect(() => {\n scrollToBottom()\n }, [messages, scrollToBottom])\n\n const handleSend = () => {\n if (inputValue.trim() && onSend) {\n onSend(inputValue.trim())\n setInputValue(\"\")\n }\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === \"Enter\") {\n e.preventDefault()\n handleSend()\n }\n }\n\n return (\n \n {/* Messages container */}\n \n {messages.map((msg) => (\n \n {/* Avatar */}\n \n\n {/* Message content */}\n
\n {/* Name and time */}\n \n {msg.name}\n {msg.time}\n
\n\n {/* Message bubble */}\n \n {msg.text}\n \n \n \n ))}\n
\n
\n\n {/* Input area */}\n
\n
\n setInputValue(e.target.value)}\n onKeyDown={handleKeyDown}\n />\n \n Send\n \n
\n
\n \n )\n }\n)\nChatWidget.displayName = \"ChatWidget\"\n\nexport { ChatWidget }\nexport type { ChatWidgetProps, ChatMessage }\n", "type": "registry:component" } ], "type": "registry:component" }