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] Add TS demos for SimpleNoSsr and FrameDeferring #17913

Merged
merged 6 commits into from
Oct 19, 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
34 changes: 19 additions & 15 deletions docs/src/pages/components/no-ssr/FrameDeferring.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import NoSsr from '@material-ui/core/NoSsr';

const useStyles = makeStyles({
container: {
maxWidth: 300,
wordBreak: 'break-all',
width: 300,
display: 'flex',
flexWrap: 'wrap',
},
});

function LargeTree() {
return Array.from(new Array(3000)).map((_, index) => <span key={index}>.</span>);
return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>);
}

function FrameDeferring() {
export default function FrameDeferring() {
const classes = useStyles();
const [state, setState] = React.useState({ open: false, defer: false });

Expand All @@ -30,6 +31,7 @@ function FrameDeferring() {
>
{'Render NoSsr defer="false"'}
</button>
<br />
<button
type="button"
onClick={() =>
Expand All @@ -41,17 +43,19 @@ function FrameDeferring() {
>
{'Render NoSsr defer="true"'}
</button>
{state.open ? (
<div className={classes.container}>
<span>Outside NoSsr</span>
<NoSsr defer={state.defer}>
....Inside NoSsr
<LargeTree />
</NoSsr>
</div>
) : null}
<br />
<br />
<div className={classes.container}>
{state.open ? (
<React.Fragment>
<div>Outside NoSsr</div>
<NoSsr defer={state.defer}>
.....Inside NoSsr
<LargeTree />
</NoSsr>
</React.Fragment>
) : null}
</div>
</div>
);
}

export default FrameDeferring;
61 changes: 61 additions & 0 deletions docs/src/pages/components/no-ssr/FrameDeferring.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import NoSsr from '@material-ui/core/NoSsr';

const useStyles = makeStyles({
container: {
width: 300,
display: 'flex',
flexWrap: 'wrap',
},
});

function LargeTree(): any {
return Array.from(new Array(5000)).map((_, index) => <span key={index}>.</span>);
}

export default function FrameDeferring() {
const classes = useStyles();
const [state, setState] = React.useState({ open: false, defer: false });

return (
<div>
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: false,
})
}
>
{'Render NoSsr defer="false"'}
</button>
<br />
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: true,
})
}
>
{'Render NoSsr defer="true"'}
</button>
<br />
<br />
<div className={classes.container}>
{state.open ? (
<React.Fragment>
<div>Outside NoSsr</div>
<NoSsr defer={state.defer}>
.....Inside NoSsr
<LargeTree />
</NoSsr>
</React.Fragment>
) : null}
</div>
</div>
);
}
31 changes: 7 additions & 24 deletions docs/src/pages/components/no-ssr/SimpleNoSsr.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import NoSsr from '@material-ui/core/NoSsr';
import Button from '@material-ui/core/Button';

const styles = theme => ({
button: {
display: 'block',
margin: theme.spacing(2),
},
});

function SimpleNoSsr(props) {
const { classes } = props;
import Box from '@material-ui/core/Box';

export default function SimpleNoSsr() {
return (
<div>
<Button className={classes.button} variant="contained" color="primary">
Server & Client
</Button>
<Box p={2} bgcolor="primary.main" color="primary.contrastText">
Server and Client
</Box>
<NoSsr>
<Button className={classes.button} variant="contained" color="secondary">
<Box p={2} bgcolor="secondary.main" color="primary.contrastText">
Client only
</Button>
</Box>
</NoSsr>
</div>
);
}

SimpleNoSsr.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(SimpleNoSsr);
18 changes: 18 additions & 0 deletions docs/src/pages/components/no-ssr/SimpleNoSsr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import NoSsr from '@material-ui/core/NoSsr';
import Box from '@material-ui/core/Box';

export default function SimpleNoSsr() {
return (
<div>
<Box p={2} bgcolor="primary.main" color="primary.contrastText">
Server and Client
</Box>
<NoSsr>
<Box p={2} bgcolor="secondary.main" color="primary.contrastText">
Client only
</Box>
</NoSsr>
</div>
);
}