Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(core): add a width prop to ChatMessageBubble so ghost bubbles align custom in-message content with the text column (#3879)

Jiun Shin0ad35c3b63e7
diff --git a/.changeset/chat-chatmessagebubble-width-prop-overrides-cap-l41o.md b/.changeset/chat-chatmessagebubble-width-prop-overrides-cap-l41o.md
new file mode 100644
index 0000000000..5ff3dc76bd
--- /dev/null
+++ b/.changeset/chat-chatmessagebubble-width-prop-overrides-cap-l41o.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Chat: ChatMessageBubble accepts a `width` prop (numbers are pixels, strings pass through, e.g. `width="100%"`), following the sizing convention on Card and other containers. When set it replaces the bubble's default `max(80%, 280px)` width cap; when unset nothing changes. Combined with `variant="ghost"`, custom in-message content (an artifact card, attachment chips, a standalone ChatMessageMetadata) can now align with the bubble's text column at the full message-column width — previously the only workaround was hardcoding the bubble's private padding token at every call site. (#2574)
+@jiunshinn
diff --git a/apps/storybook/stories/Chat.stories.tsx b/apps/storybook/stories/Chat.stories.tsx
index 0251933495..8db0d19b8e 100644
--- a/apps/storybook/stories/Chat.stories.tsx
+++ b/apps/storybook/stories/Chat.stories.tsx
@@ -9,6 +9,8 @@ import {
ChatSystemMessage,
} from '@astryxdesign/core/Chat';
import {Avatar} from '@astryxdesign/core/Avatar';
+import {ClickableCard} from '@astryxdesign/core/ClickableCard';
+import {Text} from '@astryxdesign/core/Text';
import {Markdown} from '@astryxdesign/core/Markdown';
import {Token} from '@astryxdesign/core/Token';
import {HStack} from '@astryxdesign/core/Stack';
@@ -235,6 +237,49 @@ export function Button({ label, variant = 'primary' }) {
),
};
+export const CustomContent: StoryObj = {
+ name: 'Custom Content',
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column'}}>
+ <ChatMessageList style={{maxWidth: 520}}>
+ <ChatMessage sender="user">
+ <ChatMessageBubble>Can you pull up the Q3 report?</ChatMessageBubble>
+ </ChatMessage>
+ <ChatMessage sender="assistant">
+ <ChatMessageBubble name="Navi">
+ Sure, here is the artifact from last quarter.
+ </ChatMessageBubble>
+ {/* A ghost bubble insets custom content to the bubble's text
+ column; width="100%" spans the full message column instead
+ of the default bubble width cap (#2574). */}
+ <ChatMessageBubble
+ variant="ghost"
+ width="100%"
+ metadata={
+ <ChatMessageMetadata
+ timestamp={
+ <Timestamp value="2026-03-15T14:32:00" format="time" />
+ }
+ footer={<span>Claude Opus 4.6</span>}
+ />
+ }>
+ <ClickableCard
+ label="Open Q3 performance report"
+ onClick={() => {}}>
+ <Text type="body" weight="semibold" display="block">
+ Q3 Performance Report
+ </Text>
+ <Text type="supporting" color="secondary" display="block">
+ 12 pages · updated 2 days ago
+ </Text>
+ </ClickableCard>
+ </ChatMessageBubble>
+ </ChatMessage>
+ </ChatMessageList>
+ </div>
+ ),
+};
+
export const ChatConversation: StoryObj = {
name: 'Chat Conversation',
render: () => {
diff --git a/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.doc.mjs b/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.doc.mjs
new file mode 100644
index 0000000000..9363616f24
--- /dev/null
+++ b/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.doc.mjs
@@ -0,0 +1,13 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export const doc = {
+ type: 'block',
+ exampleFor: 'ChatMessageBubble',
+ name: 'ChatMessageBubble — Custom Content',
+ displayName: 'ChatMessageBubble — Custom Content',
+ description: 'Custom in-message content aligned to the bubble text column. An artifact card is wrapped in a ghost bubble with width="100%", so its left edge matches the bubble text and it spans the full message column instead of the default bubble width cap; the timestamp rides the bubble metadata slot.',
+ isReady: true,
+ aspectRatio: 4 / 3,
+ componentsUsed: ['Chat', 'ChatMessage', 'ChatMessageBubble', 'ChatMessageMetadata', 'ClickableCard', 'Text', 'Timestamp'],
+};
diff --git a/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.tsx b/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.tsx
new file mode 100644
index 0000000000..ee7482b4a2
--- /dev/null
+++ b/packages/cli/assets/templates/blocks/components/ChatMessageBubble/ChatMessageBubbleCustomContent.tsx
@@ -0,0 +1,55 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+import {
+ ChatMessageList,
+ ChatMessage,
+ ChatMessageBubble,
+ ChatMessageMetadata,
+} from '@astryxdesign/core/Chat';
+import {ClickableCard} from '@astryxdesign/core/ClickableCard';
+import {Text} from '@astryxdesign/core/Text';
+import {Timestamp} from '@astryxdesign/core/Timestamp';
+
+export default function ChatMessageBubbleCustomContent() {
+ return (
+ <ChatMessageList style={{maxWidth: 520}}>
+ <ChatMessage sender="user">
+ <ChatMessageBubble>Can you pull up the Q3 report?</ChatMessageBubble>
+ </ChatMessage>
+ <ChatMessage sender="assistant">
+ <ChatMessageBubble name="Navi">
+ Sure, here is the artifact from last quarter.
+ </ChatMessageBubble>
+ {/* A ghost bubble aligns custom content with the bubble text column;
+ width="100%" spans the full message column instead of the default
+ bubble width cap. Metadata rides the bubble's metadata slot. */}
+ <ChatMessageBubble
+ variant="ghost"
+ width="100%"
+ metadata={
+ <ChatMessageMetadata
+ timestamp={
+ <Timestamp value="2026-04-28T09:45:00" format="time" />
+ }
+ footer={
+ <Text type="supporting" color="secondary">
+ Claude Opus 4.6
+ </Text>
+ }
+ />
+ }>
+ <ClickableCard label="Open Q3 performance report" onClick={() => {}}>
+ <Text type="body" weight="semibold" display="block">
+ Q3 Performance Report
+ </Text>
+ <Text type="supporting" color="secondary" display="block">
+ 12 pages · updated 2 days ago
+ </Text>
+ </ClickableCard>
+ </ChatMessageBubble>
+ </ChatMessage>
+ </ChatMessageList>
+ );
+}
diff --git a/packages/cli/assets/templates/pages/ai-chat/page.tsx b/packages/cli/assets/templates/pages/ai-chat/page.tsx
index 7665e4c345..3dadc45a41 100644
--- a/packages/cli/assets/templates/pages/ai-chat/page.tsx
+++ b/packages/cli/assets/templates/pages/ai-chat/page.tsx
@@ -70,9 +70,6 @@ const chatLayout: CSSProperties = {
flex: 1,
minHeight: 0,
};
-const artifactCard: CSSProperties = {
- marginBlockStart: 'var(--spacing-2)',
-};
const artifactScroll: CSSProperties = {
flex: 1,
overflowY: 'auto',
@@ -250,8 +247,7 @@ function ArtifactCard({onOpen}: {onOpen: () => void}) {
onClick={onOpen}
variant="muted"
padding={3}
- maxWidth={360}
- style={artifactCard}>
+ maxWidth={360}>
<HStack gap={3} vAlign="center" width="100%">
<Icon icon={DocumentTextIcon} size="md" color="secondary" />
<StackItem size="fill">
@@ -614,15 +610,24 @@ The fix is to catch \`TokenExpiredError\` specifically and attempt a refresh bef
{`I've drafted a design doc covering the problem, the fix, and the test matrix — pulling straight from the changes we just made.\n\nOpen the document below to review it. Want me to expand any section?`}
</Markdown>
</ChatMessageBubble>
- <ArtifactCard onOpen={openArtifact} />
- <ChatMessageMetadata
- timestamp={
- <Timestamp
- value="2026-04-29T10:18:40"
- format="time"
+ {/* Ghost + width="100%" aligns the card with the
+ bubble text column and spans the full message
+ column; metadata rides the bubble slot. */}
+ <ChatMessageBubble
+ variant="ghost"
+ width="100%"
+ metadata={
+ <ChatMessageMetadata
+ timestamp={
+ <Timestamp
+ value="2026-04-29T10:18:40"
+ format="time"
+ />
+ }
/>
- }
- />
+ }>
+ <ArtifactCard onOpen={openArtifact} />
+ </ChatMessageBubble>
</ChatMessage>
{/* User follow-up */}
diff --git a/packages/core/src/Chat/Chat.doc.mjs b/packages/core/src/Chat/Chat.doc.mjs
index 4f60f135b8..2ea4eee788 100644
--- a/packages/core/src/Chat/Chat.doc.mjs
+++ b/packages/core/src/Chat/Chat.doc.mjs
@@ -67,6 +67,7 @@ export const docs = {
{ guidance: true, description: 'Use the group prop on bubbles (first, middle, last) when a single sender sends multiple consecutive messages; it tightens corner radius to visually connect them.' },
{ guidance: true, description: 'Use ChatSystemMessage with variant="divider" for date separators and default for inline status notices like joins, leaves, or topic changes.' },
{ guidance: true, description: 'Put name on the first bubble and metadata on the last bubble in a message so they align with the bubble\'s inline padding.' },
+ { guidance: true, description: 'Wrap custom in-message content (cards, attachments, citations) in a ghost bubble so it aligns with the bubble text column; add width="100%" when it should span the full message column instead of the default bubble width cap.' },
{ guidance: true, description: 'Provide an emptyState prop so new users see a clear prompt to start a conversation instead of a blank screen.' },
{ guidance: true, description: 'Use the ghost bubble variant for AI-style responses that show rich content like code blocks or markdown without a visible boundary.' },
{ guidance: false, description: 'Don\'t use ChatSystemMessage for sender content; it has no avatar, alignment, or bubble. Use ChatMessage with a sender role instead.' },
@@ -84,7 +85,7 @@ export const docs = {
{ name: 'Empty state', required: false, description: 'Centered placeholder shown when no messages exist. Use EmptyState for a consistent look.' },
{ name: 'Avatar', required: false, description: 'A sender avatar rendered beside the message. Typically Avatar with size="md". Hidden for system messages.' },
{ name: 'Name', required: false, description: 'Sender name above the message body. Place on the bubble when using bubbles, or on the message wrapper for raw content.' },
- { name: 'Content', required: true, description: 'The message body: one or more ChatMessageBubble elements, or any free-form ReactNode like images or tool calls.' },
+ { name: 'Content', required: true, description: 'The message body: one or more ChatMessageBubble elements, or any free-form ReactNode like images or tool calls. Wrap non-bubble content in a ghost bubble to align it with the bubble text column.' },
{ name: 'Metadata', required: false, description: 'Timestamp, delivery status, and footer actions below the message. Place on the last bubble or on the message wrapper.' },
],
},
@@ -100,6 +101,7 @@ export const docsZh = {
{ guidance: true, description: '当同一发送者发送多条连续消息时,使用气泡的 group 属性(first、middle、last)来视觉上连接相关消息。' },
{ guidance: true, description: '使用 ChatSystemMessage 的 variant="divider" 作为日期分隔线,使用 default 作为内联状态通知。' },
{ guidance: true, description: '将 name 放在第一个气泡上,metadata 放在最后一个气泡上,使其与气泡的内边距对齐。' },
+ { guidance: true, description: '将自定义消息内容(卡片、附件、引用)包裹在 ghost 变体的气泡中,使其与气泡文本列对齐;需要占满消息列宽度时设置 width="100%"。' },
{ guidance: true, description: '提供 emptyState 属性,让新用户看到开始对话的提示,而不是空白屏幕。' },
{ guidance: true, description: '使用 ghost 气泡变体显示代码块或 Markdown 等富内容,无需可见边界。' },
{ guidance: false, description: '不要将 ChatSystemMessage 用于发送者内容,它没有头像、对齐或气泡。请使用带有发送者角色的 ChatMessage。' },
@@ -131,6 +133,7 @@ export const docsDense = {
{ guidance: true, description: 'Group prop on bubbles (first/middle/last) for consecutive same-sender messages; tightens corner radius.' },
{ guidance: true, description: 'SystemMessage: divider variant for date breaks, default for status notices.' },
{ guidance: true, description: 'Name on first bubble, metadata on last; aligns with bubble inline padding.' },
+ { guidance: true, description: 'Ghost bubble wraps custom content (cards/attachments); width="100%" spans full message column (default cap max(80%,280px)).' },
{ guidance: true, description: 'Provide emptyState so new users see a prompt, not a blank screen.' },
{ guidance: true, description: 'Ghost bubble variant for rich AI content like code/markdown without visible boundary.' },
{ guidance: false, description: 'SystemMessage for sender content: no avatar/alignment/bubble. Use ChatMessage instead.' },
diff --git a/packages/core/src/Chat/ChatMessage.doc.mjs b/packages/core/src/Chat/ChatMessage.doc.mjs
index 951239c126..eb884bce1e 100644
--- a/packages/core/src/Chat/ChatMessage.doc.mjs
+++ b/packages/core/src/Chat/ChatMessage.doc.mjs
@@ -17,7 +17,7 @@ export const docs = {
{
name: 'children',
type: 'ReactNode',
- description: 'Free-form content: bubbles, asset lists, tool calls, images.',
+ description: 'Free-form content: bubbles, asset lists, tool calls, images. Custom (non-bubble) children render flush with the message edge; wrap them in a ghost ChatMessageBubble to align them with the bubble text column.',
required: true,
},
{
@@ -67,7 +67,7 @@ export const docsZh = {
description: '发送者上下文包装器,根据发送者角色处理头像、名称、元数据和对齐方式。',
propDescriptions: {
sender: '消息发送者,控制对齐和布局。',
- children: '自由内容:气泡、资源列表、工具调用、图片。',
+ children: '自由内容:气泡、资源列表、工具调用、图片。非气泡的自定义子内容默认与消息边缘齐平,可用 ghost 变体的 ChatMessageBubble 包裹使其与气泡文本列对齐。',
avatar: '消息旁边渲染的头像元素。通常是 Avatar。',
name: '消息正文上方渲染的发送者名称。当第一个子元素不是气泡时使用。',
metadata: '消息正文下方渲染的元数据。当最后一个子元素不是气泡时使用。',
@@ -81,7 +81,7 @@ export const docsDense = {
description: 'sender context wrapper; handles avatar+name+metadata+alignment by sender role',
propDescriptions: {
sender: 'who sent; controls alignment+layout',
- children: 'free-form: bubbles, assets, tool calls, images',
+ children: 'free-form: bubbles, assets, tool calls, images; wrap non-bubble content in a ghost bubble to align with bubble text column',
avatar: 'avatar element beside msg; typically Avatar',
name: 'sender name above body; use when first child is raw (not bubble)',
displayName: 'sender name above body; use when first child is raw (not bubble)',
diff --git a/packages/core/src/Chat/ChatMessage.tsx b/packages/core/src/Chat/ChatMessage.tsx
index d78752160b..474d26a0e1 100644
--- a/packages/core/src/Chat/ChatMessage.tsx
+++ b/packages/core/src/Chat/ChatMessage.tsx
@@ -41,6 +41,13 @@ import {useTranslator} from '../i18n';
export interface ChatMessageProps extends BaseProps<HTMLElement> {
ref?: React.Ref<HTMLElement>;
sender: ChatMessageSender;
+ /**
+ * Message body — bubbles, tool calls, images, or any free-form content.
+ * Custom (non-bubble) children render flush with the message edge; wrap
+ * them in a ghost bubble (`<ChatMessageBubble variant="ghost">`) to align
+ * them with the bubble's text column, and add `width="100%"` when they
+ * should span the full message column.
+ */
children: ReactNode;
avatar?: ReactNode;
/**
diff --git a/packages/core/src/Chat/ChatMessageBubble.doc.mjs b/packages/core/src/Chat/ChatMessageBubble.doc.mjs
index 2feb58b2c3..5a368faece 100644
--- a/packages/core/src/Chat/ChatMessageBubble.doc.mjs
+++ b/packages/core/src/Chat/ChatMessageBubble.doc.mjs
@@ -45,6 +45,11 @@ export const docs = {
type: "'first' | 'middle' | 'last'",
description: 'Position within a multi-bubble group. Controls corner radius reduction on the sender side. Leave unset for standalone bubbles (full radius).',
},
+ {
+ name: 'width',
+ type: 'SizeValue',
+ description: 'Width of the bubble (number = pixels, string = used as-is). When set, replaces the default max(80%, 280px) width cap. Combine with variant="ghost" to let custom content (an artifact card, attachments) span the full message column.',
+ },
],
};
@@ -59,6 +64,7 @@ export const docsZh = {
name: '气泡上方渲染的发送者名称,与气泡文本内边距对齐。用于消息中的第一个气泡。',
metadata: '气泡下方渲染的元数据内容,与气泡文本内边距对齐。用于消息中的最后一个气泡。',
group: '多气泡组中的位置。控制发送者侧的圆角缩减。',
+ width: '气泡宽度(数字 = 像素,字符串 = 按原样使用)。设置后替代默认的 max(80%, 280px) 宽度上限;与 ghost 变体组合可让自定义内容占满消息列宽度。',
},
};
@@ -74,5 +80,6 @@ export const docsDense = {
displayName: 'sender name above bubble, aligned w/ bubble padding',
metadata: 'metadata below bubble, aligned w/ bubble padding',
group: 'position in multi-bubble group; controls corner radius reduction',
+ width: 'bubble width (number=px, string=as-is); replaces default max(80%,280px) cap; ghost+width="100%" spans full message column',
},
};
diff --git a/packages/core/src/Chat/ChatMessageBubble.test.tsx b/packages/core/src/Chat/ChatMessageBubble.test.tsx
index 0a23e3ccb7..741b046966 100644
--- a/packages/core/src/Chat/ChatMessageBubble.test.tsx
+++ b/packages/core/src/Chat/ChatMessageBubble.test.tsx
@@ -7,6 +7,16 @@ import {ChatMessageBubble} from './ChatMessageBubble';
import {ChatMessageList} from './ChatMessageList';
import {ChatMessageMetadata} from './ChatMessageMetadata';
+/**
+ * Classes shared between two elements. StyleX emits one atomic class per
+ * style declaration, so two elements share a class exactly when they share
+ * a declaration — e.g. the same density paddingInline.
+ */
+function sharedClasses(a: Element, b: Element): string[] {
+ const bClasses = new Set(Array.from(b.classList));
+ return Array.from(a.classList).filter(c => bClasses.has(c));
+}
+
describe('ChatMessageBubble', () => {
it('renders children', () => {
render(
@@ -29,9 +39,7 @@ describe('ChatMessageBubble', () => {
it('defaults to assistant when no context', () => {
render(
- <ChatMessageBubble data-testid="bubble">
- Standalone
- </ChatMessageBubble>,
+ <ChatMessageBubble data-testid="bubble">Standalone</ChatMessageBubble>,
);
const el = screen.getByTestId('bubble');
expect(el.className).toContain('assistant');
@@ -41,9 +49,7 @@ describe('ChatMessageBubble', () => {
render(
<ChatMessageList density="compact">
<ChatMessage sender="assistant">
- <ChatMessageBubble data-testid="bubble">
- Compact
- </ChatMessageBubble>
+ <ChatMessageBubble data-testid="bubble">Compact</ChatMessageBubble>
</ChatMessage>
</ChatMessageList>,
);
@@ -59,6 +65,89 @@ describe('ChatMessageBubble', () => {
);
expect(screen.getByTestId('my-bubble')).toBeTruthy();
});
+
+ it('ghost variant aligns custom content with the bubble text column (#2574)', () => {
+ // Repro from the issue: a raw child renders flush with the message
+ // edge — it carries none of the inset the bubble's name slot gets.
+ const {container} = render(
+ <ChatMessage sender="assistant">
+ <ChatMessageBubble name="Navi">Hello</ChatMessageBubble>
+ <div data-testid="raw">Artifact card</div>
+ <ChatMessageBubble variant="ghost" data-testid="ghost">
+ Artifact card
+ </ChatMessageBubble>
+ </ChatMessage>,
+ );
+ const nameSlot = container.querySelector('[data-chat-name]')!;
+ expect(nameSlot).toBeTruthy();
+
+ // Unwrapped custom content: no shared inset — the misalignment case.
+ expect(sharedClasses(screen.getByTestId('raw'), nameSlot)).toEqual([]);
+
+ // Ghost-wrapped content: shares the bubble slot's paddingInline
+ // declaration, so its text column matches the filled bubble exactly.
+ expect(
+ sharedClasses(screen.getByTestId('ghost'), nameSlot).length,
+ ).toBeGreaterThan(0);
+ });
+
+ it('ghost inset tracks message density', () => {
+ const renderAtDensity = (density: 'balanced' | 'spacious') => {
+ const {container} = render(
+ <ChatMessage sender="assistant" density={density}>
+ <ChatMessageBubble name="Navi">Hello</ChatMessageBubble>
+ <ChatMessageBubble variant="ghost" data-testid={`ghost-${density}`}>
+ Card
+ </ChatMessageBubble>
+ </ChatMessage>,
+ );
+ return sharedClasses(
+ screen.getByTestId(`ghost-${density}`),
+ container.querySelector('[data-chat-name]')!,
+ );
+ };
+
+ const balancedInset = renderAtDensity('balanced');
+ const spaciousInset = renderAtDensity('spacious');
+
+ // Both densities align with their own bubble's slot padding...
+ expect(balancedInset.length).toBeGreaterThan(0);
+ expect(spaciousInset.length).toBeGreaterThan(0);
+ // ...and spacious uses a wider inset than balanced.
+ expect(spaciousInset).not.toEqual(balancedInset);
+ });
+
+ it('width prop replaces the default width cap', () => {
+ render(
+ <ChatMessage sender="assistant">
+ <ChatMessageBubble data-testid="capped">Text</ChatMessageBubble>
+ <ChatMessageBubble variant="ghost" width="100%" data-testid="full">
+ Card
+ </ChatMessageBubble>
+ </ChatMessage>,
+ );
+ const capped = screen.getByTestId('capped');
+ const full = screen.getByTestId('full');
+
+ // Default bubbles keep the cap; a width bubble replaces it with none.
+ expect(getComputedStyle(capped).maxWidth).toMatch(/^max\(80%,\s*280px\)$/);
+ expect(getComputedStyle(full).maxWidth).toBe('none');
+ // The dynamic width value is set on the element (string passes through).
+ expect(full.getAttribute('style')).toContain('100%');
+ });
+
+ it('numeric width is treated as pixels', () => {
+ render(
+ <ChatMessage sender="assistant">
+ <ChatMessageBubble width={420} data-testid="fixed">
+ Artifact
+ </ChatMessageBubble>
+ </ChatMessage>,
+ );
+ expect(screen.getByTestId('fixed').getAttribute('style')).toContain(
+ '420px',
+ );
+ });
});
describe('ChatMessageMetadata', () => {
diff --git a/packages/core/src/Chat/ChatMessageBubble.tsx b/packages/core/src/Chat/ChatMessageBubble.tsx
index b33e45e19d..fc35a76d86 100644
--- a/packages/core/src/Chat/ChatMessageBubble.tsx
+++ b/packages/core/src/Chat/ChatMessageBubble.tsx
@@ -15,6 +15,9 @@
* - If you use bubbles on one side (e.g. assistant), use them consistently
* for all messages on that side. Use `ghost` variant for content that
* needs alignment without a visual boundary.
+ * - For custom content (cards, attachments, citations) that should span
+ * the full message column instead of the default width cap, combine
+ * `ghost` with `width="100%"` (#2574).
* - Put `name` on the first bubble in a message, `metadata` on the last.
* - For unbubbled messages, use ChatMessage's `name` and `metadata`
* props instead.
@@ -36,6 +39,7 @@ import {
} from '../theme/tokens.stylex';
import {useChatMessageContext} from './ChatContext';
import {mergeProps} from '../utils';
+import type {SizeValue} from '../utils/types';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
@@ -83,6 +87,15 @@ export interface ChatMessageBubbleProps extends BaseProps<HTMLDivElement> {
* Leave unset for standalone bubbles (full radius).
*/
group?: 'first' | 'middle' | 'last';
+
+ /**
+ * Width of the bubble.
+ * Numbers are treated as pixels, strings are used as-is (e.g. "100%").
+ * When set, replaces the default `max(80%, 280px)` width cap; leave unset
+ * to keep the cap. Combine with `variant="ghost"` to let custom content
+ * (an artifact card, attachments) span the full message column.
+ */
+ width?: SizeValue;
}
// =============================================================================
@@ -189,6 +202,16 @@ const styles = stylex.create({
},
});
+// Dynamic styles for sizing props
+const dynamicStyles = stylex.create({
+ sizing: (width: SizeValue) => ({
+ width,
+ // An explicit width replaces the default cap — a full-column or
+ // fixed-width bubble shouldn't also be clamped by max(80%, 280px).
+ maxWidth: 'none',
+ }),
+});
+
// =============================================================================
// Component
// =============================================================================
@@ -216,6 +239,7 @@ export function ChatMessageBubble({
name,
metadata,
group,
+ width,
xstyle,
className,
style: styleProp,
@@ -292,6 +316,7 @@ export function ChatMessageBubble({
paddingStyle,
variant === 'ghost' && styles.paddingBlockNone,
groupStyle,
+ width != null && dynamicStyles.sizing(width),
xstyle,
),
className,