Skip to content

Commit 9118cc0

Browse files
sleitorShurik
andauthored
docs: clarify that custom components replace default styles (#398)
Document that custom components fully replace default implementations including their built-in Tailwind classes. The className prop only contains classes from the Markdown AST, not Streamdown's default styles. Add a warning callout and a before/after example showing how to preserve default h2 styles when overriding. Fixes #394 Co-authored-by: Shurik <shurik@openclaw.ai>
1 parent 61c251b commit 9118cc0

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

apps/website/content/docs/components.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,37 @@ You can override any of the following standard HTML components:
5959
Custom components receive all the props that the default components would receive, including:
6060

6161
- `children` - The content to render
62-
- `className` - CSS class names (if applicable)
62+
- `className` - CSS class names from the Markdown AST (if applicable)
6363
- `node` - The Markdown AST node (for advanced use cases)
6464
- Element-specific props (e.g., `href` for links, `src` for images)
6565

66+
<Callout type="warn">
67+
Custom components **fully replace** the default implementations, including their built-in Tailwind styles. The `className` prop only contains classes from the Markdown AST (e.g., `language-js` on code elements) — it does **not** include the default styles that Streamdown normally applies.
68+
69+
If you need to preserve the default appearance, you must re-apply the styles yourself. See the [Styling](/docs/styling) documentation for the default classes, or use [CSS selectors with `data-streamdown` attributes](/docs/styling#global-css-targeting) instead of component overrides when you only need visual changes.
70+
</Callout>
71+
72+
For example, the default `h2` component applies `mt-6 mb-2 font-semibold text-2xl`. When you override it, those styles are lost unless you include them:
73+
74+
```tsx title="app/page.tsx"
75+
<Streamdown
76+
components={{
77+
// ❌ Loses default spacing and font styles
78+
h2: ({ children }) => (
79+
<h2 className="text-blue-500">{children}</h2>
80+
),
81+
// ✅ Preserves default styles alongside custom ones
82+
h2: ({ children, className }) => (
83+
<h2 className={`mt-6 mb-2 font-semibold text-2xl text-blue-500 ${className ?? ''}`}>
84+
{children}
85+
</h2>
86+
),
87+
}}
88+
>
89+
{markdown}
90+
</Streamdown>
91+
```
92+
6693
```tsx title="app/page.tsx"
6794
<Streamdown
6895
components={{

0 commit comments

Comments
 (0)