Skip to content

Commit 7338e04

Browse files
authored
feat: improve markdown table styling (#244)
**Summary** Improves markdown table styling in chat messages by reusing components from `ui/table.tsx`. This provides consistency with the data visualization tool. **Before** <img width="759" height="385" alt="image" src="https://github.com/user-attachments/assets/d140af01-57d2-4a1f-951a-c81bbc456bb7" /> **After** <img width="744" height="529" alt="image" src="https://github.com/user-attachments/assets/567101bd-06f1-40d5-b11c-044997aa4b91" />
1 parent b5bb3dc commit 7338e04

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/components/markdown.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { PreBlock } from "./pre-block";
55
import { isJson, isString, toAny } from "lib/utils";
66
import JsonView from "ui/json-view";
77
import { LinkIcon } from "lucide-react";
8+
import {
9+
Table,
10+
TableHeader,
11+
TableBody,
12+
TableRow,
13+
TableHead,
14+
TableCell,
15+
} from "ui/table";
816

917
const FadeIn = memo(({ children }: PropsWithChildren) => {
1018
return <span className="fade-in animate-in duration-1000">{children} </span>;
@@ -21,6 +29,36 @@ export const WordByWordFadeIn = memo(({ children }: PropsWithChildren) => {
2129
});
2230
WordByWordFadeIn.displayName = "WordByWordFadeIn";
2331
const components: Partial<Components> = {
32+
table: ({ node, children, ...props }) => {
33+
return (
34+
<div className="my-4">
35+
<Table {...props}>{children}</Table>
36+
</div>
37+
);
38+
},
39+
thead: ({ node, children, ...props }) => {
40+
return <TableHeader {...props}>{children}</TableHeader>;
41+
},
42+
tbody: ({ node, children, ...props }) => {
43+
return <TableBody {...props}>{children}</TableBody>;
44+
},
45+
tr: ({ node, children, ...props }) => {
46+
return <TableRow {...props}>{children}</TableRow>;
47+
},
48+
th: ({ node, children, ...props }) => {
49+
return (
50+
<TableHead {...props}>
51+
<WordByWordFadeIn>{children}</WordByWordFadeIn>
52+
</TableHead>
53+
);
54+
},
55+
td: ({ node, children, ...props }) => {
56+
return (
57+
<TableCell {...props}>
58+
<WordByWordFadeIn>{children}</WordByWordFadeIn>
59+
</TableCell>
60+
);
61+
},
2462
code: ({ children }) => {
2563
return (
2664
<code className="text-sm rounded-md bg-accent text-primary py-1 px-2 mx-0.5">

0 commit comments

Comments
 (0)