Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
fix: improve table styling on mobile / tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Aug 3, 2020
1 parent 1ba2f9d commit b005982
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/MdxComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ const Header = (level, props) => {
});
};

const Table = ({...props}) => (
<div css={{ display: 'grid' }}>
<div css={{ overflowX: 'auto' }}>
<table css={table(useTheme())} {...props} />
</div>
</div>
);

const Section = (props) => {
let header = '';
if (Array.isArray(props.children)) {
Expand Down Expand Up @@ -61,7 +69,7 @@ export default {
blockquote: (props) => <blockquote css={blockquote(useTheme())} {...props} />,
p: (props) => <p className="paragraph" {...props} />,
pre: (props) => <pre css={pre} {...props} />,
table: (props) => <table css={table(useTheme())} {...props} />,
table: (props) => <Table {...props}/>,
em: emphasis,
img: (props) => (
<a href={props.src} target="_blank" rel="noopener noreferrer">
Expand Down
8 changes: 8 additions & 0 deletions src/styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const table = (theme) => css`
border-radius: 4px;
border-spacing: 0;
overflow-wrap: normal;
${onMobile} {
white-space: pre;
}
thead {
background-color: ${theme.table.header.background};
color: ${theme.table.header.font};
Expand All @@ -112,6 +115,7 @@ export const table = (theme) => css`
}
tbody tr {
transition: ${theme.transitions.hover};
border-top: 1px solid ${theme.table.primary};
margin: 0;
padding: 0;
Expand Down Expand Up @@ -139,6 +143,10 @@ export const table = (theme) => css`
}
}
tbody tr:hover {
background-color: ${theme.table.rowHover};
}
th :first-child,
td :first-child {
margin-top: 0;
Expand Down
1 change: 1 addition & 0 deletions src/theme/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const table = (colors) => ({
},
oddRow: colors.mainBackground,
evenRow: colors.background,
rowHover: colors.hover + '3d',
border: colors.border,
});

Expand Down

0 comments on commit b005982

Please sign in to comment.