Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Prevent layout shift when rendering ads #17893

Merged
merged 4 commits into from
Oct 17, 2019
Merged
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
2 changes: 1 addition & 1 deletion docs/src/modules/components/Ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AdCarbon from 'docs/src/modules/components/AdCarbon';
const styles = theme => ({
root: {
position: 'relative',
minHeight: 116,
minHeight: 124,
maxWidth: 345,
display: 'block',
marginTop: theme.spacing(4),
Expand Down
27 changes: 17 additions & 10 deletions docs/src/modules/components/AppContent.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { withStyles } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/core/styles';
import Container from '@material-ui/core/Container';

const styles = theme => ({
const useStyles = makeStyles(theme => ({
root: {
paddingTop: 80 + 16,
flex: '1 1 100%',
Expand All @@ -21,6 +21,14 @@ const styles = theme => ({
maxWidth: 'calc(100% - 175px - 240px)',
},
},
ad: {
'& .description': {
marginBottom: 196,
},
'& .description.ad': {
marginBottom: 40,
},
},
disableToc: {
[theme.breakpoints.up('sm')]: {
maxWidth: 'calc(100%)',
Expand All @@ -29,17 +37,19 @@ const styles = theme => ({
maxWidth: 'calc(100% - 240px)',
},
},
});
}));

function AppContent(props) {
const { className, classes, children, disableToc } = props;
export default function AppContent(props) {
const { children, disableAd, disableToc } = props;
const classes = useStyles();

return (
<Container
component="main"
id="main-content"
tabIndex={-1}
className={clsx(classes.root, className, {
className={clsx(classes.root, {
[classes.ad]: !disableAd,
[classes.disableToc]: disableToc,
})}
>
Expand All @@ -50,9 +60,6 @@ function AppContent(props) {

AppContent.propTypes = {
children: PropTypes.node.isRequired,
classes: PropTypes.object.isRequired,
className: PropTypes.string,
disableAd: PropTypes.bool.isRequired,
disableToc: PropTypes.bool.isRequired,
};

export default withStyles(styles)(AppContent);
10 changes: 8 additions & 2 deletions docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,17 @@ function MarkdownDocs(props) {
/>
{disableToc ? null : <AppTableOfContents contents={contents} />}
{disableAd ? null : (
<Portal container={() => document.querySelector('.description')}>
<Portal
container={() => {
const container = document.querySelector('.description');
container.classList.add('ad');
return container;
}}
>
<Ad />
</Portal>
)}
<AppContent disableToc={disableToc}>
<AppContent disableAd={disableAd} disableToc={disableToc}>
{!disableEdit ? (
<div className={classes.header}>
<EditPage
Expand Down