Skip to content

Commit 63a8469

Browse files
committed
Make tables fixed on smaller screens
1 parent 9211221 commit 63a8469

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

packages/react-renderer-demo/src/components/mdx/mdx-components.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ export const Heading = ({ level, children, component }) => {
5959
);
6060
};
6161

62+
const tableStyles = makeStyles((theme) => ({
63+
table: {
64+
[theme.breakpoints.down('sm')]: {
65+
tableLayout: 'fixed'
66+
}
67+
},
68+
cell: {
69+
[theme.breakpoints.down('sm')]: {
70+
overflow: 'overlay'
71+
}
72+
}
73+
}));
74+
75+
const StyledCell = (props) => {
76+
const { cell } = tableStyles();
77+
78+
return <TableCell {...props} className={cell} />;
79+
};
80+
81+
const StyledTable = (props) => {
82+
const { table } = tableStyles();
83+
84+
return <Table {...props} className={table} />;
85+
};
86+
6287
const MdLink = ({ href, children }) => {
6388
const classes = useHeadingStyles();
6489
return href.startsWith('/') ? (
@@ -94,15 +119,15 @@ const MdxComponents = {
94119
),
95120
table: ({ children }) => (
96121
<Paper style={{ marginBottom: 10, marginTop: 10 }} className="DocTable">
97-
<Table>
122+
<StyledTable>
98123
<TableHead>{children[0].props.children}</TableHead>
99124
<TableBody>{children[1].props.children}</TableBody>
100-
</Table>
125+
</StyledTable>
101126
</Paper>
102127
),
103128
tr: ({ children }) => <TableRow>{children}</TableRow>,
104-
td: ({ children }) => <TableCell>{children}</TableCell>,
105-
th: ({ children }) => <TableCell>{children}</TableCell>,
129+
td: ({ children }) => <StyledCell>{children}</StyledCell>,
130+
th: ({ children }) => <StyledCell>{children}</StyledCell>,
106131
inlineCode: ({ children }) => (
107132
<code style={{ background: 'white', borderRadius: 3, fontFamily: 'courier, monospace', padding: '3px' }}>{children}</code>
108133
)

0 commit comments

Comments
 (0)