组件

Message

The row of a chat message: an avatar, a column with a header, the bubbles and a footer, aligned to the start or the end. Also MessageText, which sets a reply word by word so streaming text soaks in like wet ink.

安装

terminal
npx shadcn@latest add @wobko/message

第一次使用?先把 registry 加进 components.json。 如何安装

示例

A thread

Two speakers. The footer of the first message rides above the avatar, so the avatar keeps standing beside the last bubble.

Streaming text

MessageText keeps the words already on the page and soaks each new word in as it arrives: dark and blurred at first, then dry. A felt-tip caret rides after the last word.

Names, times and receipts

Header and footer are quiet hand notes. A reaction chip and a tick make a message look lived in.

In your own hand

`pen="you"` sets a bubble in blue felt and the script face. MessageText keeps its words plain inline text with a baseline offset and a lighter ink, so the tall last letters of a script face (d, l, e, !) are whole.

A Friday deploy

shadcn's `message-demo`: two speakers, avatars on the side of their message, a delivery note under the last of mine, a pair of muted bubbles with a reaction chip, and a typing marker to end. The photo avatars of the original are initials on marker here.

Avatar

shadcn's `message-avatar`: MessageAvatar sits at the bottom of the row, on the side the message is aligned to (`align="end"` moves it to the right). In a BubbleGroup the avatar stays beside the last bubble.

Group

shadcn's `message-group`: consecutive messages from one sender. The earlier ones carry an empty MessageAvatar to hold the column, so the words line up and the face appears once, on the last.

Header and footer

shadcn's `message-header-footer`: MessageHeader names the sender above the bubble, MessageFooter holds a receipt below it. The header stays at the start whatever the alignment; the footer follows the message.

Actions

shadcn's `message-actions`: icon buttons in MessageFooter (copy, like, dislike), each with an `aria-label`, and a failed send with a retry. The thumbs are not drawn yet, so like and dislike wear a tick and a cross-out.

Attachment

shadcn's `message-attachment`: an image attachment above the bubble that sent it (a polaroid under tape), and a PDF the reply hands back (a slip with a paper clip and a download button). The photograph is a sticker so the page needs no network.

Rich replies

shadcn's `message-markdown`: the user's message stays plain text in a bubble; the assistant's reply goes in a `ghost` bubble, which has no frame, so rendered markdown (a list, bold, inline code) reads as a page. shadcn's docs render it with their own Markdown component, which is not part of the registry; the markup below is what such a renderer produces.

API 参考

Message

One message row. `align="end"` reverses it and tells the bubbles inside to put their tail on that side.

属性类型默认值说明
align"start" | "end""start"Which end of the row the message sits on.

MessageText

The words of a message as real text, set like a person wrote them: each word sits a hair off the baseline, some a shade lighter. While `streaming`, every word that arrives after the first render soaks in (dark and blurred, then dry in half a second) and a felt-tip caret rides after the last word.

属性类型默认值说明
childrenstring-The text so far. Newlines are kept.
streamingbooleanfalseSoak new words in and show the caret.
jitterbooleantrueThe per-word wobble (zero in calm density and with reduced motion).
seedstring | number-Pins the wobble.

无障碍

  • All parts are plain divs (as upstream). Put the transcript in a `role="log"` region, which MessageScrollerContent does for you.
  • MessageText renders one span per word with normal spaces between them, so copy, paste, find-in-page and screen readers read it as ordinary text. The animation is a CSS one that reduced motion turns off; the words and the caret stay.
  • Text in a right-to-left script (Hebrew, Arabic...) is not split into words. Such text is one plain span with `dir="auto"`, so the browser orders, joins and shapes it itself (no per-word wobble or soak; the caret stays).
  • Header and footer are 14 px muted text (8.9:1 on paper).

源码

CLI 会复制进你项目的文件。

正在加载源码