Skip to content

Commit 1a06480

Browse files
authored
Fix/markdown tables (#202)
* Style markdown tables in blog posts Closes "// TODO: Debug tables" that had been sitting in MDStyles since June 2023. Fixes #199. * Use theme tokens for table colors where available
1 parent 36ab58e commit 1a06480

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

src/styles/MDStyles.tsx

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
1-
import { Box, Divider, Flex, Image, Stack, Table, Text } from '@chakra-ui/react'
1+
import {
2+
Box,
3+
Divider,
4+
Flex,
5+
Image,
6+
Stack,
7+
Table,
8+
Tbody,
9+
Td,
10+
Th,
11+
Thead,
12+
Tr,
13+
Text,
14+
useColorModeValue,
15+
} from '@chakra-ui/react'
216
import { Code, HeadingWithAnchor, Link } from '@/components'
3-
// TODO: Debug tables
17+
18+
const MDTable = ({ children }: any) => {
19+
const borderColor = useColorModeValue('purple.300', '#3D35A0')
20+
const headerBg = useColorModeValue('gray.50', '#1a1560')
21+
const tableBg = useColorModeValue('white', 'transparent')
22+
return (
23+
<Box
24+
overflowX="auto"
25+
mb={{ base: 4, md: 6 }}
26+
borderWidth="1px"
27+
borderColor={borderColor}
28+
borderRadius="md"
29+
bg={tableBg}
30+
sx={{
31+
'& table': { borderCollapse: 'collapse', width: '100%' },
32+
'& th, & td': {
33+
border: '1px solid',
34+
borderColor,
35+
},
36+
'& th': { bg: headerBg },
37+
}}
38+
>
39+
<Table variant="simple" size="sm">
40+
{children}
41+
</Table>
42+
</Box>
43+
)
44+
}
445

546
export const MDStyles = {
647
p: ({ children }: any) => (
@@ -94,4 +135,10 @@ export const MDStyles = {
94135
hr: ({ children }: any) => {
95136
return <Divider my={6}>{children}</Divider>
96137
},
138+
table: ({ children }: any) => <MDTable>{children}</MDTable>,
139+
thead: ({ children }: any) => <Thead>{children}</Thead>,
140+
tbody: ({ children }: any) => <Tbody>{children}</Tbody>,
141+
tr: ({ children }: any) => <Tr>{children}</Tr>,
142+
th: ({ children }: any) => <Th>{children}</Th>,
143+
td: ({ children }: any) => <Td>{children}</Td>,
97144
}

0 commit comments

Comments
 (0)