An open source design system that's fully customizable and agent ready
TypeScript
fix(Chat): add minWidth:0 to childrenWrap to prevent overflow, add table example (#1303)
Cindy Zhang8137036d2f79
diff --git a/apps/storybook/stories/Chat.stories.tsx b/apps/storybook/stories/Chat.stories.tsxindex 13e70f1ad1..2a228732af 100644--- a/apps/storybook/stories/Chat.stories.tsx+++ b/apps/storybook/stories/Chat.stories.tsx@@ -26,7 +26,7 @@ export default meta;export const Default: StoryObj = {name: 'Default',render: () => (- <div style={{height: 600, display: 'flex', flexDirection: 'column'}}>+ <div style={{display: 'flex', flexDirection: 'column'}}><XDSChatMessageList><XDSChatMessage sender="user"><XDSChatMessageBubble@@ -108,7 +108,15 @@ Avoid global state managers unless you have a genuine need for cross-cutting staconst [state, dispatch] = useReducer(reducer, initialState);`}language="tsx"/>- <XDSMarkdown density="compact">{`This keeps all your form logic in one place. The reducer is pure and easy to test — just pass in state and action, assert on the output.`}</XDSMarkdown>+ <XDSMarkdown density="compact">{`This keeps all your form logic in one place. The reducer is pure and easy to test — just pass in state and action, assert on the output.++| Hook | Use case | Re-renders | Complexity | Best for |+|------|----------|------------|------------|----------|+| \`useState\` | Simple values | On every set | Low | Toggles, inputs, counters |+| \`useReducer\` | Complex state logic | On dispatch | Medium | Forms, multi-field state |+| \`useContext\` | Shared subtree state | All consumers | Low | Theme, auth, locale |+| \`useSyncExternalStore\` | External stores | On snapshot change | High | Redux, Zustand, signals |+| \`useRef\` | Mutable values | Never | Low | DOM refs, timers, previous values |`}</XDSMarkdown><XDSChatMessageMetadatatimestamp={<XDSTimestamp value="2026-03-15T14:31:30" format="time" />}footer={diff --git a/apps/storybook/stories/ChatLayout.stories.tsx b/apps/storybook/stories/ChatLayout.stories.tsxindex 7f8097b4fe..aee58eb26c 100644--- a/apps/storybook/stories/ChatLayout.stories.tsx+++ b/apps/storybook/stories/ChatLayout.stories.tsx@@ -4,6 +4,7 @@ import {XDSChatMessageList,XDSChatMessage,XDSChatMessageBubble,+ XDSChatMessageMetadata,XDSChatSystemMessage,XDSChatComposer,XDSChatComposerAttachments,@@ -19,6 +20,9 @@ import {import {XDSMarkdown} from '@xds/core/Markdown';import {XDSToken} from '@xds/core/Token';import {XDSButton} from '@xds/core/Button';+import {XDSTimestamp} from '@xds/core/Timestamp';+import {HandThumbUpIcon, HandThumbDownIcon} from '@heroicons/react/24/outline';+import {ClipboardDocumentIcon} from '@heroicons/react/24/outline';import {XDSCodeBlock} from '@xds/core/CodeBlock';import {XDSProgressBar} from '@xds/core/ProgressBar';import {XDSAvatar} from '@xds/core/Avatar';@@ -105,11 +109,14 @@ type Message =text: string;files?: string[];tokens?: XDSChatComposerToken[];+ isSending?: boolean;+ sentAt?: Date;}| {id: number;role: 'assistant';text: string;+ introText?: string;toolCalls?: XDSChatToolCallItem[];isStreaming?: boolean;}@@ -121,11 +128,13 @@ const SEED_MESSAGES: Message[] = [id: 2,role: 'user',text: 'Can you review the Button component and fix the focus ring?',+ sentAt: new Date('2026-03-15T14:30:00'),},{id: 3,role: 'assistant',- text: "I'll read the Button component and check the focus styles.",+ introText: "I'll read the Button component and check the focus styles.",+ text: "I'll read the Button component and check the focus styles.\n\nAdded a `:focus-visible` style with a 2px solid outline and 2px offset. All 24 Button tests pass.\n\n```css\n:focus-visible {\n outline: 2px solid var(--color-ring-focus);\n outline-offset: 2px;\n}\n```\n\nHere's the test breakdown:\n\n| Suite | Tests | Duration | Status |\n|-------|-------|----------|--------|\n| XDSButton.test.tsx | 18 | 1.2s | ✓ Pass |\n| XDSButton.a11y.test.tsx | 4 | 0.8s | ✓ Pass |\n| XDSButton.snapshot.test.tsx | 2 | 0.3s | ✓ Pass |\n\nThe focus ring meets **WCAG 2.4.7** requirements and uses the theme's focus color token.",toolCalls: [{key: '1',@@ -167,12 +176,7 @@ const SEED_MESSAGES: Message[] = [},],},- {- id: 4,- role: 'assistant',- text: "Added a `:focus-visible` style with a 2px solid outline and 2px offset. All 24 Button tests pass.\n\n```css\n:focus-visible {\n outline: 2px solid var(--color-ring-focus);\n outline-offset: 2px;\n}\n```\n\nHere's the test breakdown:\n\n| Suite | Tests | Duration | Status |\n|-------|-------|----------|--------|\n| XDSButton.test.tsx | 18 | 1.2s | ✓ Pass |\n| XDSButton.a11y.test.tsx | 4 | 0.8s | ✓ Pass |\n| XDSButton.snapshot.test.tsx | 2 | 0.3s | ✓ Pass |\n\nThe focus ring meets **WCAG 2.4.7** requirements and uses the theme's focus color token.",- },- {id: 5, role: 'user', text: 'Nice, can you also check the Card component?'},+ {id: 4, role: 'user', text: 'Nice, can you also check the Card component?', sentAt: new Date('2026-03-15T14:35:00')},];// =============================================================================@@ -224,7 +228,7 @@ export const FullAIChat: StoryObj = {setMessages(prev => [...prev,- {id: msgId, role: 'assistant', text: '', isStreaming: true},+ {id: msgId, role: 'assistant', text: '', introText, isStreaming: true},]);let i = 0;@@ -321,19 +325,29 @@ export const FullAIChat: StoryObj = {const handleSubmit = useCallback((value: string) => {+ const userMsgId = Date.now();setMessages(prev => [...prev,{- id: Date.now(),+ id: userMsgId,role: 'user',text: value,files: files.length ? [...files] : undefined,tokens: resolveTokens(value),+ isSending: true,},]);setFiles([]);+ // After 2s, mark as sent and start streamingsetTimeout(() => {+ setMessages(prev =>+ prev.map(m =>+ m.id === userMsgId && m.role === 'user'+ ? {...m, isSending: false, sentAt: new Date()}+ : m,+ ),+ );streamResponse("I'll check the Card component for the same issue.",'The border radius was hardcoded. I replaced it with the theme token:\n\n```css\n/* before */\nborder-radius: 12px;\n\n/* after */\nborder-radius: var(--radius-element);\n```\n\nCards now adapt across themes. All tests pass.',@@ -366,7 +380,7 @@ export const FullAIChat: StoryObj = {},],);- }, 800);+ }, 2000);},[files, streamResponse],);@@ -484,7 +498,15 @@ export const FullAIChat: StoryObj = {))}</XDSChatComposerAttachments>)}- <XDSChatMessageBubble>+ <XDSChatMessageBubble+ metadata={+ <XDSChatMessageMetadata+ timestamp={+ <XDSTimestamp value={msg.sentAt ?? new Date(msg.id)} format="time" />+ }+ status={msg.isSending ? 'sending' : undefined}+ />+ }><XDSChatTokenizedText tokens={mentionTokens}>{msg.text}</XDSChatTokenizedText>@@ -492,14 +514,56 @@ export const FullAIChat: StoryObj = {</XDSChatMessage>);}+ {/* Assistant: intro text → tool calls → rest of text */}+ const introEnd = msg.introText?.length ?? 0;+ const hasToolCalls = msg.toolCalls && msg.toolCalls.length > 0;+ const introContent = introEnd > 0 ? msg.text.slice(0, introEnd) : null;+ const restContent = introEnd > 0 && msg.text.length > introEnd+ ? msg.text.slice(introEnd).replace(/^\n+/, '')+ : !introEnd ? msg.text : null;return (<XDSChatMessage key={msg.id} sender="assistant">- {msg.text && (- <XDSMarkdown density="compact">{msg.text}</XDSMarkdown>+ {introContent && (+ <XDSMarkdown density="compact">{introContent}</XDSMarkdown>)}- {msg.toolCalls && msg.toolCalls.length > 0 && (+ {hasToolCalls && (<XDSChatToolCalls calls={msg.toolCalls ?? []} />)}+ {restContent && (+ <XDSMarkdown density="compact">{restContent}</XDSMarkdown>+ )}+ {!msg.isStreaming && msg.text && (+ <XDSChatMessageMetadata+ timestamp={<XDSTimestamp value={new Date(msg.id)} format="time" />}+ footer={+ <>+ <span>Claude Opus 4.6</span>+ <span>·</span>+ <XDSButton+ label="Thumbs up"+ icon={<HandThumbUpIcon style={{width: 14, height: 14}} />}+ variant="ghost"+ size="sm"+ isIconOnly+ />+ <XDSButton+ label="Thumbs down"+ icon={<HandThumbDownIcon style={{width: 14, height: 14}} />}+ variant="ghost"+ size="sm"+ isIconOnly+ />+ <XDSButton+ label="Copy"+ icon={<ClipboardDocumentIcon style={{width: 14, height: 14}} />}+ variant="ghost"+ size="sm"+ isIconOnly+ />+ </>+ }+ />+ )}</XDSChatMessage>);})}diff --git a/packages/core/src/Chat/XDSChatMessage.tsx b/packages/core/src/Chat/XDSChatMessage.tsxindex eb56405999..820648e848 100644--- a/packages/core/src/Chat/XDSChatMessage.tsx+++ b/packages/core/src/Chat/XDSChatMessage.tsx@@ -95,8 +95,8 @@ const styles = stylex.create({contentColumn: {display: 'flex',flexDirection: 'column',+ flex: 1,minWidth: 0,- maxWidth: '80%',},contentColumnSystem: {maxWidth: '90%',@@ -118,6 +118,7 @@ const styles = stylex.create({childrenWrap: {display: 'flex',flexDirection: 'column',+ minWidth: 0,width: '100%',},childrenAssistant: {diff --git a/packages/core/src/Chat/XDSChatMessageBubble.tsx b/packages/core/src/Chat/XDSChatMessageBubble.tsxindex 60da6368eb..176d67f72a 100644--- a/packages/core/src/Chat/XDSChatMessageBubble.tsx+++ b/packages/core/src/Chat/XDSChatMessageBubble.tsx@@ -98,7 +98,7 @@ const styles = stylex.create({content: {display: 'flex',flexDirection: 'column',- maxWidth: '100%',+ maxWidth: 'max(80%, 280px)',borderRadius: radiusVars['--radius-page'],fontFamily: typographyVars['--font-family-body'],fontSize: typeScaleVars['--text-body-size'],@@ -135,10 +135,10 @@ const styles = stylex.create({paddingInline: spacingVars['--spacing-5'],},metadataReducedGap: {- marginBlockStart: `calc(-1 * ${spacingVars['--spacing-1']})`,+ marginBlockStart: `calc(-1 * ${spacingVars['--spacing-1-5']})`,},headerReducedGap: {- marginBlockEnd: `calc(-1 * ${spacingVars['--spacing-1']})`,+ marginBlockEnd: `calc(-1 * ${spacingVars['--spacing-1-5']})`,},nameRow: {height: spacingVars['--spacing-5'],diff --git a/packages/core/src/CodeBlock/XDSCodeBlock.tsx b/packages/core/src/CodeBlock/XDSCodeBlock.tsxindex 615d276f19..72b5cecd98 100644--- a/packages/core/src/CodeBlock/XDSCodeBlock.tsx+++ b/packages/core/src/CodeBlock/XDSCodeBlock.tsx@@ -54,6 +54,9 @@ const styles = stylex.create({display: 'flex',flexDirection: 'column',margin: 0,+ width: 'fit-content',+ minWidth: 'min(100%, 400px)',+ maxWidth: '100%',borderRadius: radiusVars['--radius-element'],backgroundColor: 'var(--color-syntax-background)',border: `${borderVars['--border-width']} solid ${colorVars['--color-border']}`,diff --git a/packages/core/src/Markdown/XDSMarkdown.tsx b/packages/core/src/Markdown/XDSMarkdown.tsxindex 2a2a8cbfb6..a84adb5efa 100644--- a/packages/core/src/Markdown/XDSMarkdown.tsx+++ b/packages/core/src/Markdown/XDSMarkdown.tsx@@ -9,6 +9,7 @@import {useMemo, useRef} from 'react';import type React from 'react';+import {Fragment} from 'react';import type {StyleXStyles} from '@stylexjs/stylex';import * as stylex from '@stylexjs/stylex';import {@@ -130,8 +131,8 @@ const dynamicStyles = stylex.create({proseAlign: (marginInline: string) => ({marginInline,}),- tableMinWidth: (minWidth: string) => ({- minWidth,+ blockWidth: (minWidth: string) => ({+ minWidth: `min(${minWidth}, 100%)`,}),blockAlign: (marginInline: string) => ({marginInline,@@ -144,6 +145,8 @@ const styles = stylex.create({color: colorVars['--color-text-primary'],lineHeight: typeScaleVars['--text-body-leading'],fontSize: typeScaleVars['--text-body-size'],+ width: '100%',+ maxWidth: '100%',minWidth: 0,overflowWrap: 'break-word',},@@ -273,16 +276,19 @@ const styles = stylex.create({marginInlineEnd: 0,},// Table+ codeBlockWrapper: {+ maxWidth: '100%',+ },tableWrapper: {overflowX: 'auto',- minWidth: 0,+ maxWidth: '100%',},blockIndent: {marginInline: `calc(-1 * ${spacingVars['--spacing-2']})`,},table: {borderCollapse: 'collapse',- width: 'auto',+ width: 'fit-content',maxWidth: '100%',},th: {@@ -569,14 +575,13 @@ function wrapTextWithFade(// Split: some old, some newconst splitAt = cursor.boundary - startOffset;return (- <>+ <Fragment key={`fade-${key}-split`}>{content.slice(0, splitAt)}<span- key={`fade-${key}-${cursor.boundary}`}{...stylex.props(streamingStyles.fadeIn)}>{content.slice(splitAt)}</span>- </>+ </Fragment>);}@@ -895,6 +900,7 @@ function renderBlock(key={index}{...stylex.props(spacing,+ styles.codeBlockWrapper,isFirst && styles.noMarginBlockStart,isLast && styles.noMarginBlockEnd,)}>@@ -902,6 +908,14 @@ function renderBlock(code={node.content}language={node.language}isCollapsible+ xstyle={[+ contentWidthValue != null+ ? dynamicStyles.blockWidth(contentWidthValue)+ : undefined,+ BLOCK_ALIGN_MARGIN[contentAlign] != null+ ? dynamicStyles.blockAlign(BLOCK_ALIGN_MARGIN[contentAlign]!)+ : undefined,+ ]}/></div>);@@ -1115,7 +1129,7 @@ function renderBlock(styles.table,styles.blockIndent,contentWidthValue != null- ? dynamicStyles.tableMinWidth(contentWidthValue)+ ? dynamicStyles.blockWidth(contentWidthValue): null,BLOCK_ALIGN_MARGIN[contentAlign] != null? dynamicStyles.blockAlign(BLOCK_ALIGN_MARGIN[contentAlign]!)