Skip to content

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

TypeScript

fix(docsite): full-width section-style code blocks in examples & playground (#2518)

Ernest8c95a59aade7
diff --git a/apps/docsite/src/components/component-detail/ExampleBlock.tsx b/apps/docsite/src/components/component-detail/ExampleBlock.tsx
index c2ae5d5748..082adbb595 100644
--- a/apps/docsite/src/components/component-detail/ExampleBlock.tsx
+++ b/apps/docsite/src/components/component-detail/ExampleBlock.tsx
@@ -102,13 +102,19 @@ export function ExampleBlock({entry}: ExampleBlockProps) {
)}
</XDSHStack>
</XDSSection>
- <XDSSection variant="muted">
+ <XDSSection variant="muted" padding={tab === 'code' ? 0 : 4}>
{tab === 'description' ? (
<XDSText type="body">
{entry.description || 'No description available.'}
</XDSText>
) : (
- <XDSCodeBlock code={entry.source} language="tsx" hasCopyButton />
+ <XDSCodeBlock
+ code={entry.source}
+ language="tsx"
+ hasCopyButton
+ container="section"
+ width="100%"
+ />
)}
</XDSSection>
</XDSCard>
diff --git a/apps/docsite/src/components/component-detail/InteractivePreview.tsx b/apps/docsite/src/components/component-detail/InteractivePreview.tsx
index ea75b16183..8b1c3a5050 100644
--- a/apps/docsite/src/components/component-detail/InteractivePreview.tsx
+++ b/apps/docsite/src/components/component-detail/InteractivePreview.tsx
@@ -290,9 +290,14 @@ export function InteractivePreviewStage({
style={{
minHeight: 200,
overflow: 'auto',
- padding: 'var(--spacing-4)',
}}>
- <XDSCodeBlock code={code} language="tsx" hasCopyButton />
+ <XDSCodeBlock
+ code={code}
+ language="tsx"
+ hasCopyButton
+ container="section"
+ width="100%"
+ />
</div>
) : (
<XDSTheme theme={neutralTheme} mode={mode}>
diff --git a/packages/core/src/CodeBlock/CodeBlock.doc.mjs b/packages/core/src/CodeBlock/CodeBlock.doc.mjs
index d271f1cf96..8805bca711 100644
--- a/packages/core/src/CodeBlock/CodeBlock.doc.mjs
+++ b/packages/core/src/CodeBlock/CodeBlock.doc.mjs
@@ -27,7 +27,7 @@ export const docs = {
{name: 'maxHeight', type: 'number | string', description: 'Max height before the block scrolls vertically.'},
{name: 'size', type: "'sm' | 'md'", description: 'Text size variant.', default: "'md'"},
{name: 'width', type: "string", description: "Width of the code block. Any CSS width value. 'fit-content' (default) shrinks to longest line. '100%' fills parent width.", default: "'fit-content'"},
- {name: 'container', type: "'card' | 'section'", description: "Container presentation style. 'card' (default): border and radius for standalone card look. 'section': no border or radius — for embedding inside cards or panels.", default: "'card'"},
+ {name: 'container', type: "'card' | 'section'", description: "Container presentation style. 'card' (default): border and radius with the muted syntax background for a standalone card look. 'section': no border or radius and a transparent background so the block blends into the card or panel it's embedded in.", default: "'card'"},
{name: 'tokenizer', type: '(code: string, language: string) => Array<{type: string; start: number; end: number}>', description: 'Custom tokenizer override for unsupported languages.'},
{name: 'isCollapsible', type: 'boolean', description: 'Allow collapsing the code body into just the header bar. Starts expanded; the header becomes clickable to toggle. Only shows the toggle when the code exceeds collapsibleThreshold lines.', default: 'false'},
{name: 'collapsibleThreshold', type: 'number', description: 'Minimum number of lines before the collapse toggle appears. Below this threshold the code block renders normally even when isCollapsible is true.', default: '10'},
@@ -111,7 +111,7 @@ export const docsZh = {
maxHeight: '代码块垂直滚动前的最大高度。',
size: '文字大小变体。',
width: "代码块宽度。接受任何CSS宽度值。'fit-content'(默认)适应最长行宽度;'100%' 填满父容器宽度。",
- container: "容器展示样式。'card'(默认)=带边框和圆角;'section'=无边框和圆角——适用于嵌入卡片或面板。",
+ container: "容器展示样式。'card'(默认)=带边框和圆角及柔和背景;'section'=无边框圆角且背景透明——融入所嵌入的卡片或面板。",
tokenizer: '用于不支持语言的自定义分词器。',
isCollapsible: '允许将代码折叠为仅标题栏。当代码超过 collapsibleThreshold 行时显示切换按钮。',
collapsibleThreshold: '折叠切换出现前的最小行数。低于此阈值时即使 isCollapsible 为 true 也正常渲染。',
@@ -167,7 +167,7 @@ export const docsDense = {
maxHeight: 'max height before vertical scroll',
size: 'text size variant',
width: "any CSS width value; fit-content (default) or 100% to fill parent",
- container: "card=border+radius (default); section=no border/radius (embed in cards)",
+ container: "card=border+radius+muted bg (default); section=no border/radius, transparent bg (embed in cards)",
tokenizer: 'custom tokenizer for unsupported languages',
isCollapsible: 'Collapse code to header bar. Toggle appears when lines > collapsibleThreshold. Default: false.',
collapsibleThreshold: 'Min lines before collapse toggle shows. Default: 10.',
diff --git a/packages/core/src/CodeBlock/XDSCodeBlock.tsx b/packages/core/src/CodeBlock/XDSCodeBlock.tsx
index 9d80f99112..d8ada65d43 100644
--- a/packages/core/src/CodeBlock/XDSCodeBlock.tsx
+++ b/packages/core/src/CodeBlock/XDSCodeBlock.tsx
@@ -59,6 +59,12 @@ const containerStyles = stylex.create({
borderWidth: 0,
borderStyle: 'none',
borderColor: 'transparent',
+ // Transparent background so the block blends into the surface it's
+ // embedded in (a card or panel) instead of painting its own muted layer,
+ // which would compound with a muted parent into a darker grey. Override
+ // the syntax-background var so both the root and the sticky header inherit
+ // it. Consumers can still set an explicit background via xstyle.
+ '--color-syntax-background': 'transparent',
},
});
@@ -349,8 +355,11 @@ export interface XDSCodeBlockProps extends XDSBaseProps<HTMLPreElement> {
width?: string;
/**
* Container presentation style.
- * - `'card'` (default): border-radius and border — standalone card look.
- * - `'section'`: no border-radius, no border — for embedding inside cards or panels.
+ * - `'card'` (default): border-radius and border with the muted syntax
+ * background — standalone card look.
+ * - `'section'`: no border-radius, no border, and a transparent background
+ * so the block blends into the card or panel it's embedded in. Set an
+ * explicit background via `xstyle` if you need one.
* @default 'card'
*/
container?: 'card' | 'section';