Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mermaid-diagram-sizing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"streamdown": patch
---

Improve Mermaid diagram sizing so SVGs scale to fill the container. Add `w-full`, `[&_svg]:w-full`, `[&_svg]:h-auto`, and `[&_svg]:max-w-full` to the chart wrapper for responsive scaling. Increase default container min-height from `min-h-28` to `min-h-48` for better visibility.
29 changes: 29 additions & 0 deletions packages/streamdown/__tests__/mermaid-component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,35 @@ describe("Mermaid Component", () => {
});
});

it("should apply responsive sizing classes to chart container", async () => {
const { container } = renderWithContext(<Mermaid chart={simpleChart} />);

await waitFor(() => {
const chartContainer = container.querySelector(
'[aria-label="Mermaid chart"]'
);
expect(chartContainer).toBeTruthy();
expect(chartContainer?.className).toContain("w-full");
expect(chartContainer?.className).toContain("min-w-0");
expect(chartContainer?.className).toContain("items-start");
});
});

it("should apply fullscreen alignment to chart container", async () => {
const { container } = renderWithContext(
<Mermaid chart={simpleChart} fullscreen={true} />
);

await waitFor(() => {
const chartContainer = container.querySelector(
'[aria-label="Mermaid chart"]'
);
expect(chartContainer).toBeTruthy();
expect(chartContainer?.className).toContain("items-center");
expect(chartContainer?.className).toContain("size-full");
});
});

it("should pass config to mermaid getMermaid", async () => {
const mockPlugin = createMockMermaidPlugin();

Expand Down
5 changes: 3 additions & 2 deletions packages/streamdown/lib/mermaid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ export const Mermaid = ({
<div
aria-label="Mermaid chart"
className={cn(
"flex justify-center",
fullscreen ? "size-full items-center" : null
"flex w-full min-w-0 justify-center",
fullscreen ? "size-full items-center" : "items-start",
"[&_svg]:max-w-full [&_svg]:h-auto [&_svg]:w-full"
)}
// biome-ignore lint/security/noDangerouslySetInnerHtml: "Required for Mermaid"
dangerouslySetInnerHTML={{ __html: displaySvg }}
Expand Down
2 changes: 1 addition & 1 deletion packages/streamdown/lib/mermaid/pan-zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const PanZoom = ({
<div
className={cn(
"relative flex flex-col",
fullscreen ? "h-full w-full" : "min-h-28 w-full",
fullscreen ? "h-full w-full" : "min-h-48 w-full",
className
)}
ref={containerRef}
Expand Down
Loading