{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message",
  "type": "registry:ui",
  "title": "Message",
  "description": "One message in a conversation, from the person, the assistant or the system, with parts for an avatar, the words, the time and sending state, a toolbar of actions, and suggested replies.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react",
    "radix-ui"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/chip",
    "@rivier-ui/cn"
  ],
  "files": [
    {
      "path": "registry/ui/message.tsx",
      "type": "registry:ui",
      "target": "components/ui/message.tsx",
      "content": "\"use client\";\n/**\n * @name message\n * @category ui\n * @description One message in a conversation, from the person, the assistant or the system, with parts for an avatar, the words, the time and sending state, a toolbar of actions, and suggested replies.\n * @when Inside a thread, one per message. The person's own messages sit at the end side in a bubble; the assistant's read as plain text at the start. For words that are still arriving put streaming-text inside MessageContent; for a structured piece of a reply (a plan, a form) use part-frame beside it. Not for comments under an article or a notification list: those are plain lists.\n * @example\n * <Message from=\"user\">\n *   <MessageBody>\n *     <MessageContent>Somewhere quiet for lunch on Saturday?</MessageContent>\n *     <MessageMeta time={sentAt} status=\"failed\" />\n *   </MessageBody>\n * </Message>\n *\n * <Message from=\"assistant\">\n *   <MessageAvatar><Avatar size=\"sm\"><AvatarFallback>AI</AvatarFallback></Avatar></MessageAvatar>\n *   <MessageBody>\n *     <MessageContent>Three places are open then.</MessageContent>\n *     <MessageActions aria-label=\"Actions for this reply\">\n *       <MessageAction aria-label=\"Copy\" onClick={copy}><Copy /></MessageAction>\n *       <MessageAction aria-label=\"Try again\" onClick={retry}><RotateCcw /></MessageAction>\n *     </MessageActions>\n *     <MessageSuggestions aria-label=\"Suggested replies\">\n *       <MessageSuggestion onClick={() => send(\"Only outdoors\")}>Only outdoors</MessageSuggestion>\n *     </MessageSuggestions>\n *   </MessageBody>\n * </Message>\n */\nimport { Toolbar as ToolbarPrimitive } from \"radix-ui\";\nimport { CircleAlert } from \"lucide-react\";\nimport { createContext, use, type ComponentProps, type ReactNode } from \"react\";\nimport { ChipButton, type ChipButtonProps } from \"@/components/ui/chip\";\nimport { cn } from \"@/lib/cn\";\n\nexport type MessageFrom = \"user\" | \"assistant\" | \"system\";\n\nconst MessageContext = createContext<MessageFrom>(\"assistant\");\n\nexport type MessageProps = ComponentProps<\"div\"> & {\n  /** Who it is from. \"user\" is the person using the product; \"system\" is a note in the conversation (a date, \"the plan changed\"). */\n  from: MessageFrom;\n};\n\n/**\n * The row. The person's messages run from the end side, everyone else's from the start, by the reading\n * direction (nothing here is left or right). Who is speaking is said by the ThreadTurn around it.\n */\nexport function Message({ className, from, ...props }: MessageProps) {\n  return (\n    <MessageContext value={from}>\n      <div\n        data-slot=\"message\"\n        data-from={from}\n        className={cn(\"group/message flex min-w-0 gap-3 data-[from=system]:justify-center data-[from=user]:flex-row-reverse\", className)}\n        {...props}\n      />\n    </MessageContext>\n  );\n}\n\n/** A slot for the speaker's picture (an Avatar). Decorative when the turn already names the speaker: give the image alt=\"\". */\nexport function MessageAvatar({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"message-avatar\" className={cn(\"shrink-0\", className)} {...props} />;\n}\n\n/** The column that stacks the words, the meta line, the actions and the suggestions. */\nexport function MessageBody({ className, ...props }: ComponentProps<\"div\">) {\n  return (\n    <div\n      data-slot=\"message-body\"\n      className={cn(\n        \"flex min-w-0 flex-col gap-1.5 group-data-[from=assistant]/message:flex-1 group-data-[from=system]/message:items-center group-data-[from=user]/message:max-w-[85%] group-data-[from=user]/message:items-end\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type MessageContentProps = ComponentProps<\"div\">;\n\n/**\n * The words. A person's own words get `dir=\"auto\"`, so a message typed in a right-to-left language reads\n * correctly in a left-to-right page and the other way round; pass `dir` to override. Long words and links\n * wrap rather than widen the page.\n */\nexport function MessageContent({ className, dir, ...props }: MessageContentProps) {\n  const from = use(MessageContext);\n  return (\n    <div\n      data-slot=\"message-content\"\n      dir={dir ?? (from === \"user\" ? \"auto\" : undefined)}\n      className={cn(\n        \"max-w-full min-w-0 text-base leading-relaxed wrap-anywhere whitespace-pre-wrap text-foreground\",\n        from === \"user\" && \"rounded-surface bg-muted px-4 py-2.5 text-start\",\n        from === \"system\" && \"text-center text-sm text-muted-foreground\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type MessageStatus = \"sending\" | \"sent\" | \"failed\";\n\nexport type MessageMetaProps = ComponentProps<\"div\"> & {\n  /** When it was sent: shown as a time of day in `locale`. */\n  time?: Date | number | string;\n  /** A BCP 47 language tag for the time. Default: the runtime's. */\n  locale?: string;\n  /** How the time is written. Default: hour and minute. */\n  timeFormat?: Intl.DateTimeFormatOptions;\n  /** \"sending\" and \"failed\" are said in words; \"sent\" (default) shows only the time. */\n  status?: MessageStatus;\n  /** The words for the states. Translate them with the interface. */\n  labels?: { sending?: string; failed?: string };\n  children?: ReactNode;\n};\n\n/**\n * The small line under a message: the time, and a state said in words (and a mark, for \"not sent\"), never by\n * colour alone. Put a retry button in its children when sending failed.\n */\nexport function MessageMeta({ className, time, locale, timeFormat, status = \"sent\", labels, children, ...props }: MessageMetaProps) {\n  const date = time === undefined ? null : new Date(time);\n  const valid = date !== null && !Number.isNaN(date.getTime());\n  return (\n    <div\n      data-slot=\"message-meta\"\n      data-status={status}\n      className={cn(\"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground\", className)}\n      {...props}\n    >\n      {valid ? (\n        // The server and the browser may be in different time zones: the browser's reading wins.\n        <time dateTime={date.toISOString()} suppressHydrationWarning>\n          {new Intl.DateTimeFormat(locale, timeFormat ?? { hour: \"numeric\", minute: \"2-digit\" }).format(date)}\n        </time>\n      ) : null}\n      {status === \"sending\" ? <span data-slot=\"message-status\">{labels?.sending ?? \"Sending\"}</span> : null}\n      {status === \"failed\" ? (\n        <span data-slot=\"message-status\" className=\"inline-flex items-center gap-1 font-medium text-destructive\">\n          <CircleAlert aria-hidden=\"true\" strokeWidth={1.5} className=\"size-3.5 shrink-0\" />\n          {labels?.failed ?? \"Not sent\"}\n        </span>\n      ) : null}\n      {children}\n    </div>\n  );\n}\n\nexport type MessageActionsProps = ComponentProps<typeof ToolbarPrimitive.Root> & {\n  /** \"hover\" (default): shown when the message is hovered or holds focus, and always on touch screens. \"always\": always shown (the latest reply). */\n  visible?: \"hover\" | \"always\";\n};\n\n/**\n * A toolbar of small actions on one message (copy, try again, rate). One Tab stop; Left and Right arrows move\n * between the buttons. It is in the page even when faint, so the keyboard reaches it, and it shows itself\n * on hover, on focus, and always where there is no hover. Name it with `aria-label`.\n */\nexport function MessageActions({ className, visible = \"hover\", \"aria-label\": ariaLabel = \"Message actions\", ...props }: MessageActionsProps) {\n  return (\n    <ToolbarPrimitive.Root\n      data-slot=\"message-actions\"\n      aria-label={ariaLabel}\n      className={cn(\n        \"-ms-2 flex max-w-full flex-wrap items-center gap-0.5 transition-opacity duration-instant ease-out group-data-[from=user]/message:ms-0 group-data-[from=user]/message:-me-2 motion-reduce:transition-none\",\n        visible === \"hover\" && \"opacity-0 group-focus-within/message:opacity-100 group-hover/message:opacity-100 pointer-coarse:opacity-100\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type MessageActionProps = ComponentProps<typeof ToolbarPrimitive.Button>;\n\n/** One action: an icon button. It needs an `aria-label` (\"Copy\"), or visible text beside the icon. */\nexport function MessageAction({ className, ...props }: MessageActionProps) {\n  return (\n    <ToolbarPrimitive.Button\n      data-slot=\"message-action\"\n      className={cn(\n        \"inline-flex h-control-sm min-w-(--control-h-sm) shrink-0 items-center justify-center gap-1.5 rounded-control px-2 text-sm text-muted-foreground transition-[background-color,color] duration-instant ease-out hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50 motion-reduce:transition-none pointer-coarse:h-control pointer-coarse:min-w-(--control-h) [&_svg]:size-4 [&_svg]:shrink-0\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** Suggested replies under a message: a named group of chips that wrap. Name it with `aria-label`. */\nexport function MessageSuggestions({ className, \"aria-label\": ariaLabel = \"Suggested replies\", ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"message-suggestions\" role=\"group\" aria-label={ariaLabel} className={cn(\"flex max-w-full flex-wrap gap-2 pt-1\", className)} {...props} />;\n}\n\n/** One suggested reply: a chip that is a button. Its text is what pressing it sends. */\nexport function MessageSuggestion({ variant = \"soft\", ...props }: ChipButtonProps) {\n  return <ChipButton data-slot=\"message-suggestion\" variant={variant} {...props} />;\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "Inside a thread, one per message. The person's own messages sit at the end side in a bubble; the assistant's read as plain text at the start. For words that are still arriving put streaming-text inside MessageContent; for a structured piece of a reply (a plan, a form) use part-frame beside it. Not for comments under an article or a notification list: those are plain lists.",
    "example": "<Message from=\"user\">\n  <MessageBody>\n    <MessageContent>Somewhere quiet for lunch on Saturday?</MessageContent>\n    <MessageMeta time={sentAt} status=\"failed\" />\n  </MessageBody>\n</Message>\n\n<Message from=\"assistant\">\n  <MessageAvatar><Avatar size=\"sm\"><AvatarFallback>AI</AvatarFallback></Avatar></MessageAvatar>\n  <MessageBody>\n    <MessageContent>Three places are open then.</MessageContent>\n    <MessageActions aria-label=\"Actions for this reply\">\n      <MessageAction aria-label=\"Copy\" onClick={copy}><Copy /></MessageAction>\n      <MessageAction aria-label=\"Try again\" onClick={retry}><RotateCcw /></MessageAction>\n    </MessageActions>\n    <MessageSuggestions aria-label=\"Suggested replies\">\n      <MessageSuggestion onClick={() => send(\"Only outdoors\")}>Only outdoors</MessageSuggestion>\n    </MessageSuggestions>\n  </MessageBody>\n</Message>",
    "client": true
  }
}
