{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat",
  "type": "registry:ui",
  "title": "Chat",
  "description": "The parts of a chat UI: a message list that follows the newest message, messages with avatars, times and read receipts, bubbles for text, files, images and code, a typing indicator, quick replies and a composer that grows as you type. For AI assistants, support chats, inboxes and help widgets.",
  "author": "DressCode UI <https://dresscodeui.com>",
  "dependencies": [
    "lucide-react@^1.73.0"
  ],
  "registryDependencies": [
    "avatar",
    "button"
  ],
  "files": [
    {
      "path": "registry/dresscode/components/chat/ui/chat.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\n// Chat: the parts of a conversation UI. A message list that keeps to the newest message unless the\n// reader has scrolled up (then a \"New messages\" button jumps back down), messages placed by sender with\n// an avatar, a name, a time and a delivery status, bubbles for text, files, images and code, a typing\n// indicator, quick-reply chips, and a composer whose textarea grows as you type (Enter sends,\n// Shift+Enter adds a line). The list is a polite live region, so new messages are read out.\n// Built for shadcn/ui; reads only the theme's variables.\nimport * as React from \"react\"\nimport { AlertCircle, ArrowDown, ArrowUp, Check, CheckCheck, Clock, Copy, FileText, Loader2, Paperclip, RotateCw, Square, X } from \"lucide-react\"\n\nimport { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from \"@/components/ui/avatar\"\nimport { Button } from \"@/components/ui/button\"\nimport { cn } from \"@/lib/utils\"\n\ntype ChatSide = \"start\" | \"end\"\ntype ChatMessageStatusValue = \"sending\" | \"sent\" | \"delivered\" | \"read\" | \"failed\"\n\n/** A column that holds a header, a ChatMessageList and a ChatInput. Give it a height. */\nfunction Chat({ className, ...props }: React.ComponentProps<\"div\">) {\n  return <div data-slot=\"chat\" className={cn(\"flex min-h-0 flex-col overflow-hidden\", className)} {...props} />\n}\n\n// ---------------------------------------------------------------------------------------------\n// The message list\n\ntype ChatMessageListProps = React.ComponentProps<\"div\"> & {\n  /** Classes for the inner column that holds the messages (padding, gap, max width). */\n  contentClassName?: string\n  /** How near the bottom, in px, still counts as reading the newest message. */\n  threshold?: number\n  /** The jump button's text when the reader has scrolled up. */\n  jumpLabel?: string\n  /** The jump button's text when something new arrived below. */\n  newMessagesLabel?: string\n}\n\n/**\n * The scrolling list of messages. It follows the newest message as messages arrive or stream in,\n * unless the reader has scrolled up; then a button offers to jump back. Takes the remaining height\n * of a flex column (or give it one). It is a log: assistive tech reads out messages as they are added.\n */\nfunction ChatMessageList({\n  className,\n  contentClassName,\n  children,\n  threshold = 48,\n  jumpLabel = \"Jump to latest\",\n  newMessagesLabel = \"New messages\",\n  onScroll,\n  ...props\n}: ChatMessageListProps) {\n  const viewportRef = React.useRef<HTMLDivElement>(null)\n  const contentRef = React.useRef<HTMLDivElement>(null)\n  const following = React.useRef(true)\n  const jumping = React.useRef(false)\n  const lastHeight = React.useRef(0)\n  const [away, setAway] = React.useState(false)\n  const [unseen, setUnseen] = React.useState(false)\n\n  const toBottom = React.useCallback((smooth = false) => {\n    const el = viewportRef.current\n    if (!el) return\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches\n    el.scrollTo({ top: el.scrollHeight, behavior: smooth && !reduce ? \"smooth\" : \"auto\" })\n  }, [])\n\n  React.useLayoutEffect(() => {\n    toBottom()\n  }, [toBottom])\n\n  React.useEffect(() => {\n    const viewport = viewportRef.current\n    const content = contentRef.current\n    if (!viewport || !content) return\n    const onContent = new ResizeObserver(() => {\n      const height = content.offsetHeight\n      const grew = height > lastHeight.current + 1\n      lastHeight.current = height\n      if (following.current) toBottom()\n      else if (grew) setUnseen(true)\n    })\n    const onViewport = new ResizeObserver(() => {\n      if (following.current) toBottom()\n    })\n    // A message you send (side \"end\") always brings you back to the newest message.\n    const onAdded = new MutationObserver((records) => {\n      const mine = records.some((r) => [...r.addedNodes].some((n) => n instanceof HTMLElement && n.matches(\"[data-slot=chat-message][data-side=end]\")))\n      if (!mine) return\n      following.current = true\n      setAway(false)\n      setUnseen(false)\n      toBottom()\n    })\n    onContent.observe(content)\n    onViewport.observe(viewport)\n    onAdded.observe(content, { childList: true })\n    return () => {\n      onContent.disconnect()\n      onViewport.disconnect()\n      onAdded.disconnect()\n    }\n  }, [toBottom])\n\n  const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {\n    onScroll?.(e)\n    const el = e.currentTarget\n    const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight <= threshold\n    if (jumping.current) {\n      if (!atBottom) return\n      jumping.current = false\n    }\n    following.current = atBottom\n    setAway(!atBottom)\n    if (atBottom) setUnseen(false)\n  }\n\n  // The reader took over (wheel, touch, keys): stop treating the scroll as our own jump.\n  const interrupt = () => {\n    jumping.current = false\n  }\n\n  const jump = () => {\n    following.current = true\n    jumping.current = true\n    setAway(false)\n    setUnseen(false)\n    toBottom(true)\n    window.setTimeout(() => {\n      jumping.current = false\n    }, 900)\n  }\n\n  return (\n    <div data-slot=\"chat-message-list\" className={cn(\"relative min-h-0 flex-1\", className)}>\n      <div\n        ref={viewportRef}\n        role=\"log\"\n        aria-label=\"Messages\"\n        aria-live=\"polite\"\n        aria-relevant=\"additions\"\n        tabIndex={0}\n        className=\"absolute inset-0 overflow-x-hidden overflow-y-auto overscroll-contain outline-none focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset\"\n        {...props}\n        onScroll={handleScroll}\n        onWheel={interrupt}\n        onTouchStart={interrupt}\n        onPointerDown={interrupt}\n        onKeyDown={interrupt}\n      >\n        <div\n          ref={contentRef}\n          data-slot=\"chat-message-list-content\"\n          className={cn(\"flex min-h-full flex-col justify-end gap-4 p-4\", contentClassName)}\n        >\n          {children}\n        </div>\n      </div>\n      {away ? (\n        <Button\n          type=\"button\"\n          size=\"sm\"\n          variant={unseen ? \"default\" : \"secondary\"}\n          onClick={jump}\n          data-slot=\"chat-jump\"\n          className=\"absolute bottom-3 left-1/2 z-10 -translate-x-1/2 rounded-full border-border px-3 shadow-md\"\n        >\n          <ArrowDown aria-hidden=\"true\" />\n          {unseen ? newMessagesLabel : jumpLabel}\n        </Button>\n      ) : null}\n    </div>\n  )\n}\n\n/** A centered label between messages: a day (\"Today\"), or an event (\"Maya joined the chat\"). */\nfunction ChatSeparator({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"chat-separator\"\n      className={cn(\n        \"flex items-center gap-3 py-1 text-center text-xs text-muted-foreground before:h-px before:flex-1 before:bg-border after:h-px after:flex-1 after:bg-border\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n// ---------------------------------------------------------------------------------------------\n// One message\n\ntype ChatMessageProps = React.ComponentProps<\"div\"> & {\n  /** \"start\" for the other person, \"end\" for you. */\n  side?: ChatSide\n  /** Follows a message from the same sender: tighter spacing, no avatar or header shown. */\n  grouped?: boolean\n  /** Set while the text is still streaming in, so assistive tech waits for the whole message. */\n  streaming?: boolean\n  /** The delivery status, for styling the bubble while sending or after a failure. */\n  status?: ChatMessageStatusValue\n}\n\nfunction ChatMessage({ className, side = \"start\", grouped = false, streaming, status, ...props }: ChatMessageProps) {\n  return (\n    <div\n      data-slot=\"chat-message\"\n      data-side={side}\n      data-grouped={grouped || undefined}\n      data-status={status}\n      aria-busy={streaming || undefined}\n      className={cn(\"group/chat-message flex w-full items-start gap-2.5\", side === \"end\" && \"flex-row-reverse\", grouped && \"-mt-3\", className)}\n      {...props}\n    />\n  )\n}\n\ntype ChatMessageAvatarProps = Omit<React.ComponentProps<typeof Avatar>, \"children\"> & {\n  src?: string\n  /** Initials or an icon, shown until the image loads (or instead of it). */\n  fallback: React.ReactNode\n  /** Adds a dot for \"online now\". */\n  online?: boolean\n}\n\n/** The sender's picture. Hidden (but still taking its space) on grouped messages. */\nfunction ChatMessageAvatar({ className, src, fallback, online, ...props }: ChatMessageAvatarProps) {\n  return (\n    <Avatar aria-hidden=\"true\" className={cn(\"group-data-[grouped=true]/chat-message:invisible\", className)} {...props}>\n      {src ? <AvatarImage src={src} alt=\"\" /> : null}\n      <AvatarFallback className=\"text-xs font-medium [&_svg]:size-4\">{fallback}</AvatarFallback>\n      {online ? <AvatarBadge /> : null}\n    </Avatar>\n  )\n}\n\n/** The column of header, bubbles, attachments and status. Lines up with the sender's side. */\nfunction ChatMessageContent({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"chat-message-content\"\n      className={cn(\n        \"flex max-w-[min(80%,36rem)] min-w-0 flex-col items-start gap-1 group-data-[side=end]/chat-message:items-end\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** Name and time above the first message of a run. On grouped messages it stays for screen readers only. */\nfunction ChatMessageHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"chat-message-header\"\n      className={cn(\n        \"flex items-baseline gap-2 px-1 text-xs leading-5 group-data-[grouped=true]/chat-message:sr-only group-data-[side=end]/chat-message:flex-row-reverse\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction ChatMessageName({ className, ...props }: React.ComponentProps<\"span\">) {\n  return <span data-slot=\"chat-message-name\" className={cn(\"font-medium text-foreground\", className)} {...props} />\n}\n\nfunction ChatMessageTime({ className, ...props }: React.ComponentProps<\"time\">) {\n  return <time data-slot=\"chat-message-time\" className={cn(\"text-muted-foreground tabular-nums\", className)} {...props} />\n}\n\ntype ChatBubbleProps = React.ComponentProps<\"div\"> & {\n  /** \"default\" is a filled bubble; \"ghost\" is plain text for long, rich answers (lists, code). */\n  variant?: \"default\" | \"ghost\"\n}\n\n/** The message text. Muted for the other person, the primary color for you. */\nfunction ChatBubble({ className, variant = \"default\", ...props }: ChatBubbleProps) {\n  return (\n    <div\n      data-slot=\"chat-bubble\"\n      data-variant={variant}\n      className={cn(\n        \"max-w-full min-w-0 text-sm leading-relaxed [overflow-wrap:anywhere]\",\n        variant === \"default\" &&\n          \"w-fit rounded-xl bg-muted px-3.5 py-2 whitespace-pre-wrap text-foreground group-data-[side=end]/chat-message:bg-primary group-data-[side=end]/chat-message:text-primary-foreground group-data-[status=failed]/chat-message:opacity-70 group-data-[status=sending]/chat-message:opacity-70 [&_a]:underline [&_a]:underline-offset-2\",\n        variant === \"ghost\" && \"w-full text-foreground [&_a]:text-primary [&_a]:underline [&_a]:underline-offset-2\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\ntype ChatAttachmentProps = React.ComponentProps<\"div\"> & {\n  name: string\n  /** A line under the name: the size, the type, or both (\"2.4 MB · PDF\"). */\n  detail?: React.ReactNode\n  /** Replaces the file icon. */\n  icon?: React.ReactNode\n  /** Put a download link or button here. */\n  action?: React.ReactNode\n}\n\n/** A file sent with a message: icon, name, size, and an optional action. */\nfunction ChatAttachment({ className, name, detail, icon, action, ...props }: ChatAttachmentProps) {\n  return (\n    <div\n      data-slot=\"chat-attachment\"\n      className={cn(\"flex w-64 max-w-full items-center gap-3 rounded-lg border bg-background p-2 pr-2.5 text-foreground\", className)}\n      {...props}\n    >\n      <span className=\"flex size-9 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground [&_svg]:size-4\">\n        {icon ?? <FileText />}\n      </span>\n      <span className=\"min-w-0 flex-1\">\n        <span className=\"block truncate text-sm font-medium\">{name}</span>\n        {detail ? <span className=\"block truncate text-xs text-muted-foreground\">{detail}</span> : null}\n      </span>\n      {action}\n    </div>\n  )\n}\n\n/** An image sent with a message. Put an <img> inside, or any preview; `label` names it for screen readers. */\nfunction ChatImage({ className, label, ...props }: React.ComponentProps<\"div\"> & { label: string }) {\n  return (\n    <div\n      data-slot=\"chat-image\"\n      role=\"img\"\n      aria-label={label}\n      className={cn(\"relative w-64 max-w-full overflow-hidden rounded-lg border bg-muted [&_img]:block [&_img]:size-full [&_img]:object-cover\", className)}\n      {...props}\n    />\n  )\n}\n\n/** Copy text and say so for two seconds. Returns [copied, copy]. */\nfunction useCopyToClipboard(timeout = 2000) {\n  const [copied, setCopied] = React.useState(false)\n  const timer = React.useRef<number | undefined>(undefined)\n  React.useEffect(() => () => window.clearTimeout(timer.current), [])\n  const copy = React.useCallback(\n    async (text: string) => {\n      try {\n        await navigator.clipboard.writeText(text)\n      } catch {\n        return false\n      }\n      setCopied(true)\n      window.clearTimeout(timer.current)\n      timer.current = window.setTimeout(() => setCopied(false), timeout)\n      return true\n    },\n    [timeout],\n  )\n  return [copied, copy] as const\n}\n\ntype ChatCodeBlockProps = React.ComponentProps<\"div\"> & {\n  code: string\n  /** Shown in the header, e.g. \"TypeScript\". */\n  language?: string\n  /** Shown instead of the language, e.g. \"app/api/webhooks/route.ts\". */\n  filename?: string\n}\n\n/** Code in a message, with its language and a copy button. Scrolls sideways instead of wrapping. */\nfunction ChatCodeBlock({ className, code, language, filename, ...props }: ChatCodeBlockProps) {\n  const [copied, copy] = useCopyToClipboard()\n  return (\n    <div\n      data-slot=\"chat-code-block\"\n      className={cn(\"w-full min-w-0 overflow-hidden rounded-lg border bg-card text-card-foreground\", className)}\n      {...props}\n    >\n      <div className=\"flex items-center justify-between gap-2 border-b bg-muted/60 py-1 pr-1 pl-3\">\n        <span className=\"truncate text-xs text-muted-foreground\">{filename ?? language ?? \"Code\"}</span>\n        <Button type=\"button\" variant=\"ghost\" size=\"xs\" onClick={() => copy(code)} aria-label={copied ? \"Copied\" : \"Copy code\"}>\n          {copied ? <Check aria-hidden=\"true\" /> : <Copy aria-hidden=\"true\" />}\n          {copied ? \"Copied\" : \"Copy\"}\n        </Button>\n      </div>\n      <pre className=\"overflow-x-auto p-3 text-[13px] leading-relaxed whitespace-pre\">\n        <code className=\"font-mono\">{code}</code>\n      </pre>\n    </div>\n  )\n}\n\nconst STATUS: Record<ChatMessageStatusValue, { icon: typeof Check; label: string }> = {\n  sending: { icon: Clock, label: \"Sending\" },\n  sent: { icon: Check, label: \"Sent\" },\n  delivered: { icon: CheckCheck, label: \"Delivered\" },\n  read: { icon: CheckCheck, label: \"Read\" },\n  failed: { icon: AlertCircle, label: \"Not sent\" },\n}\n\ntype ChatMessageStatusProps = React.ComponentProps<\"div\"> & {\n  status: ChatMessageStatusValue\n  /** Shown after the label, e.g. \"Read 10:42\". */\n  time?: string\n  /** Offers a retry button when the status is \"failed\". */\n  onRetry?: () => void\n}\n\n/** Sending, sent, delivered, read, or not sent with a retry. Goes under your last message. */\nfunction ChatMessageStatus({ className, status, time, onRetry, ...props }: ChatMessageStatusProps) {\n  const { icon: Icon, label } = STATUS[status]\n  return (\n    <div\n      data-slot=\"chat-message-status\"\n      data-status={status}\n      className={cn(\"flex items-center gap-1 px-1 text-xs text-muted-foreground data-[status=failed]:text-destructive\", className)}\n      {...props}\n    >\n      <Icon aria-hidden=\"true\" className={cn(\"size-3.5 shrink-0\", status === \"read\" && \"text-primary\")} />\n      {status === \"failed\" ? (\n        <span role=\"alert\">{label}</span>\n      ) : (\n        <span>\n          {label}\n          {time ? <span className=\"tabular-nums\"> {time}</span> : null}\n        </span>\n      )}\n      {status === \"failed\" && onRetry ? (\n        <button\n          type=\"button\"\n          onClick={onRetry}\n          className=\"ml-1 inline-flex items-center gap-1 rounded-md px-1 font-medium underline-offset-2 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50\"\n        >\n          <RotateCw aria-hidden=\"true\" className=\"size-3\" />\n          Retry\n        </button>\n      ) : null}\n    </div>\n  )\n}\n\n/** Buttons under a message: copy, regenerate, feedback. */\nfunction ChatMessageActions({ className, ...props }: React.ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"chat-message-actions\"\n      role=\"group\"\n      aria-label=\"Message actions\"\n      className={cn(\"flex flex-wrap items-center gap-0.5 text-muted-foreground\", className)}\n      {...props}\n    />\n  )\n}\n\n/** Three pulsing dots in a bubble. `name` makes the screen-reader text \"Maya is typing\". */\nfunction ChatTypingIndicator({ className, name, label, ...props }: React.ComponentProps<\"div\"> & { name?: string; label?: string }) {\n  return (\n    <div\n      data-slot=\"chat-typing-indicator\"\n      role=\"status\"\n      className={cn(\"inline-flex h-9 w-fit items-center gap-1 rounded-xl bg-muted px-3.5\", className)}\n      {...props}\n    >\n      {[0, 1, 2].map((i) => (\n        <span\n          key={i}\n          aria-hidden=\"true\"\n          className=\"size-1.5 animate-pulse rounded-full bg-muted-foreground [animation-duration:1.1s] motion-reduce:animate-none\"\n          style={{ animationDelay: `${i * 0.18}s` }}\n        />\n      ))}\n      <span className=\"sr-only\">{label ?? (name ? `${name} is typing` : \"Typing\")}</span>\n    </div>\n  )\n}\n\n// ---------------------------------------------------------------------------------------------\n// Quick replies\n\nfunction ChatSuggestions({ className, ...props }: React.ComponentProps<\"div\">) {\n  return <div data-slot=\"chat-suggestions\" role=\"group\" aria-label=\"Suggestions\" className={cn(\"flex flex-wrap gap-2\", className)} {...props} />\n}\n\nfunction ChatSuggestion({ className, type = \"button\", ...props }: React.ComponentProps<\"button\">) {\n  return (\n    <button\n      type={type}\n      data-slot=\"chat-suggestion\"\n      className={cn(\n        \"inline-flex min-h-8 items-center gap-1.5 rounded-full border bg-background px-3 py-1.5 text-left text-sm text-foreground transition-colors outline-none hover:bg-muted focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n// ---------------------------------------------------------------------------------------------\n// The composer\n\ntype ChatInputContextValue = {\n  value: string\n  setValue: (value: string) => void\n  submit: () => void\n  ready: boolean\n  busy: boolean\n  disabled: boolean\n  onStop?: () => void\n  textareaRef: React.RefObject<HTMLTextAreaElement | null>\n}\n\nconst ChatInputContext = React.createContext<ChatInputContextValue | null>(null)\n\n/** The composer's state, for parts you build yourself inside a ChatInput. */\nfunction useChatInput() {\n  const ctx = React.useContext(ChatInputContext)\n  if (!ctx) throw new Error(\"useChatInput must be used inside <ChatInput>\")\n  return ctx\n}\n\ntype ChatInputProps = Omit<React.ComponentProps<\"form\">, \"onSubmit\"> & {\n  value: string\n  onValueChange: (value: string) => void\n  /** Called by Enter or the send button, only when there is something to send and nothing is in flight. */\n  onSubmit: (value: string) => void\n  /** A message is sending or an answer is coming in: sending is paused, the button shows progress or Stop. */\n  busy?: boolean\n  /** With busy, the send button becomes a Stop button that calls this. */\n  onStop?: () => void\n  /** The whole composer is off, e.g. the conversation is closed. */\n  disabled?: boolean\n  /** Whether there is something to send. Defaults to \"the text is not blank\"; pass true when files are attached. */\n  canSubmit?: boolean\n  /** A ref to the textarea, to focus it from outside (after picking a suggestion, say). */\n  inputRef?: React.RefObject<HTMLTextAreaElement | null>\n}\n\n/** The box around the textarea, attachments and toolbar. A form: Enter or the send button submits it. */\nfunction ChatInput({ className, value, onValueChange, onSubmit, busy = false, onStop, disabled = false, canSubmit, inputRef, children, ...props }: ChatInputProps) {\n  const ownRef = React.useRef<HTMLTextAreaElement>(null)\n  const textareaRef = inputRef ?? ownRef\n  const ready = (canSubmit ?? value.trim().length > 0) && !busy && !disabled\n  const submit = () => {\n    if (ready) onSubmit(value)\n  }\n  return (\n    <ChatInputContext.Provider value={{ value, setValue: onValueChange, submit, ready, busy, disabled, onStop, textareaRef }}>\n      <form\n        data-slot=\"chat-input\"\n        data-busy={busy || undefined}\n        data-disabled={disabled || undefined}\n        onSubmit={(e) => {\n          e.preventDefault()\n          submit()\n        }}\n        className={cn(\n          \"flex flex-col gap-1 rounded-xl border border-input bg-background p-1.5 text-foreground shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 data-disabled:opacity-60\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </form>\n    </ChatInputContext.Provider>\n  )\n}\n\n/** Grows with its text up to `max-h-48`, then scrolls. Enter sends, Shift+Enter adds a line. */\nfunction ChatInputTextarea({ className, onKeyDown, onChange, rows = 1, ...props }: React.ComponentProps<\"textarea\">) {\n  const { value, setValue, submit, disabled, textareaRef } = useChatInput()\n  React.useLayoutEffect(() => {\n    const el = textareaRef.current\n    if (!el) return\n    el.style.height = \"auto\"\n    el.style.height = `${el.scrollHeight}px`\n  }, [value, textareaRef])\n  return (\n    <textarea\n      ref={textareaRef}\n      data-slot=\"chat-input-textarea\"\n      rows={rows}\n      value={value}\n      disabled={disabled}\n      onChange={(e) => {\n        setValue(e.target.value)\n        onChange?.(e)\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e)\n        if (e.defaultPrevented) return\n        // Enter while an input method is composing (Chinese, Japanese) picks a candidate, not send.\n        if (e.key === \"Enter\" && !e.shiftKey && !e.nativeEvent.isComposing && e.keyCode !== 229) {\n          e.preventDefault()\n          submit()\n        }\n      }}\n      className={cn(\n        \"max-h-48 min-h-10 w-full resize-none bg-transparent px-2.5 py-2 text-base leading-6 outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed md:text-sm\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** The row under the textarea: attach, pickers, then the send button (put a `ml-auto` before it). */\nfunction ChatInputToolbar({ className, ...props }: React.ComponentProps<\"div\">) {\n  return <div data-slot=\"chat-input-toolbar\" className={cn(\"flex items-center gap-1\", className)} {...props} />\n}\n\n/** Opens the file picker; hands back the picked files. */\nfunction ChatInputAttach({\n  className,\n  onFiles,\n  accept,\n  multiple = true,\n  label = \"Attach files\",\n  children,\n  disabled,\n  ...props\n}: Omit<React.ComponentProps<typeof Button>, \"onClick\"> & { onFiles: (files: File[]) => void; accept?: string; multiple?: boolean; label?: string }) {\n  const ctx = React.useContext(ChatInputContext)\n  const fileRef = React.useRef<HTMLInputElement>(null)\n  return (\n    <>\n      <Button\n        type=\"button\"\n        variant=\"ghost\"\n        size=\"icon\"\n        aria-label={label}\n        disabled={disabled ?? ctx?.disabled}\n        onClick={() => fileRef.current?.click()}\n        className={cn(\"text-muted-foreground\", className)}\n        {...props}\n      >\n        {children ?? <Paperclip aria-hidden=\"true\" />}\n      </Button>\n      <input\n        ref={fileRef}\n        type=\"file\"\n        hidden\n        tabIndex={-1}\n        accept={accept}\n        multiple={multiple}\n        data-slot=\"chat-input-file\"\n        onChange={(e) => {\n          const files = Array.from(e.target.files ?? [])\n          e.target.value = \"\"\n          if (files.length) onFiles(files)\n        }}\n      />\n    </>\n  )\n}\n\n/** Send while idle; a spinner while busy; Stop while busy if the ChatInput has onStop. */\nfunction ChatInputSubmit({ className, ...props }: Omit<React.ComponentProps<typeof Button>, \"type\">) {\n  const { ready, busy, disabled, onStop } = useChatInput()\n  if (busy && onStop)\n    return (\n      <Button type=\"button\" size=\"icon\" onClick={onStop} aria-label=\"Stop\" data-slot=\"chat-input-submit\" className={cn(\"rounded-full\", className)} {...props}>\n        <Square aria-hidden=\"true\" className=\"size-3 fill-current\" />\n      </Button>\n    )\n  return (\n    <Button\n      type=\"submit\"\n      size=\"icon\"\n      disabled={!ready || disabled}\n      aria-label={busy ? \"Sending\" : \"Send message\"}\n      data-slot=\"chat-input-submit\"\n      className={cn(\"rounded-full\", className)}\n      {...props}\n    >\n      {busy ? <Loader2 aria-hidden=\"true\" className=\"animate-spin\" /> : <ArrowUp aria-hidden=\"true\" />}\n    </Button>\n  )\n}\n\n/** The files waiting in the composer. */\nfunction ChatInputAttachments({ className, ...props }: React.ComponentProps<\"ul\">) {\n  return <ul data-slot=\"chat-input-attachments\" aria-label=\"Attachments\" className={cn(\"flex flex-wrap gap-2 p-1\", className)} {...props} />\n}\n\ntype ChatInputAttachmentProps = React.ComponentProps<\"li\"> & {\n  name: string\n  /** The size or type, shown under the name. */\n  detail?: React.ReactNode\n  /** An image preview (an <img>, say). Turns the chip into a square thumbnail. */\n  preview?: React.ReactNode\n  /** Upload progress, 0 to 100. Below 100 it shows a bar. */\n  progress?: number\n  /** Why the file can't be sent, e.g. \"Larger than 20 MB\". */\n  error?: string\n  onRemove?: () => void\n}\n\n/** A file or image waiting to be sent, with upload progress, an error, and a remove button. */\nfunction ChatInputAttachment({ className, name, detail, preview, progress, error, onRemove, ...props }: ChatInputAttachmentProps) {\n  const uploading = progress !== undefined && progress < 100 && !error\n  const remove = onRemove ? (\n    <button\n      type=\"button\"\n      onClick={onRemove}\n      aria-label={`Remove ${name}`}\n      className=\"absolute -top-1.5 -right-1.5 z-10 flex size-5 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-xs outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n    >\n      <X aria-hidden=\"true\" className=\"size-3\" />\n    </button>\n  ) : null\n  const bar = uploading ? (\n    <span className=\"absolute inset-x-1.5 bottom-1 h-1 overflow-hidden rounded-full bg-muted\" aria-hidden=\"true\">\n      <span className=\"block h-full rounded-full bg-primary transition-[width] duration-200\" style={{ width: `${progress}%` }} />\n    </span>\n  ) : null\n  const status = error ?? (uploading ? `Uploading, ${progress}%` : null)\n\n  if (preview)\n    return (\n      <li\n        data-slot=\"chat-input-attachment\"\n        data-error={error ? true : undefined}\n        title={error ? `${name}: ${error}` : name}\n        className={cn(\"relative size-16 shrink-0 rounded-lg border bg-muted\", error && \"border-destructive\", className)}\n        {...props}\n      >\n        <span className={cn(\"block size-full overflow-hidden rounded-[inherit] [&_img]:size-full [&_img]:object-cover\", (uploading || error) && \"opacity-60\")}>\n          {preview}\n        </span>\n        <span className=\"sr-only\">\n          {name}\n          {status ? `, ${status}` : \"\"}\n        </span>\n        {error ? (\n          <span className=\"absolute inset-x-0 bottom-0 truncate rounded-b-lg bg-background/90 px-1 text-center text-[10px] font-medium text-destructive\" aria-hidden=\"true\">\n            {error}\n          </span>\n        ) : null}\n        {bar}\n        {remove}\n      </li>\n    )\n\n  return (\n    <li\n      data-slot=\"chat-input-attachment\"\n      data-error={error ? true : undefined}\n      className={cn(\"relative flex h-16 w-56 max-w-full items-center gap-2.5 rounded-lg border bg-card p-2 pr-3 text-sm\", error && \"border-destructive\", className)}\n      {...props}\n    >\n      <span className=\"flex size-10 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground [&_svg]:size-4\">\n        {error ? <AlertCircle aria-hidden=\"true\" className=\"text-destructive\" /> : <FileText aria-hidden=\"true\" />}\n      </span>\n      <span className=\"min-w-0 flex-1\">\n        <span className=\"block truncate font-medium\">{name}</span>\n        <span className={cn(\"block truncate text-xs text-muted-foreground\", error && \"text-destructive\")}>{status ?? detail}</span>\n      </span>\n      {bar}\n      {remove}\n    </li>\n  )\n}\n\n/** \"1.4 MB\", \"820 KB\": a file size for attachment chips. */\nfunction formatFileSize(bytes: number) {\n  if (bytes < 1024) return `${bytes} B`\n  if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`\n  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\nexport {\n  Chat,\n  ChatAttachment,\n  ChatBubble,\n  ChatCodeBlock,\n  ChatImage,\n  ChatInput,\n  ChatInputAttach,\n  ChatInputAttachment,\n  ChatInputAttachments,\n  ChatInputSubmit,\n  ChatInputTextarea,\n  ChatInputToolbar,\n  ChatMessage,\n  ChatMessageActions,\n  ChatMessageAvatar,\n  ChatMessageContent,\n  ChatMessageHeader,\n  ChatMessageList,\n  ChatMessageName,\n  ChatMessageStatus,\n  ChatMessageTime,\n  ChatSeparator,\n  ChatSuggestion,\n  ChatSuggestions,\n  ChatTypingIndicator,\n  formatFileSize,\n  useChatInput,\n  useCopyToClipboard,\n}\nexport type { ChatMessageStatusValue, ChatSide }\n"
    }
  ],
  "docs": "Chat is in components/ui. Examples: https://dresscodeui.com/components/chat"
}
