Skip to content

Commit 06967ec

Browse files
[docs] Set the infrastructure for a full page demo (mui#13314)
1 parent 79444f1 commit 06967ec

25 files changed

+1105
-557
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = [
2828
name: 'The main docs bundle',
2929
webpack: false,
3030
path: main.path,
31-
limit: '177 KB',
31+
limit: '178 KB',
3232
},
3333
{
3434
name: 'The docs home page',

docs/src/modules/components/AppDrawer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { pageToTitle } from 'docs/src/modules/utils/helpers';
1616
const styles = theme => ({
1717
paper: {
1818
width: 240,
19-
backgroundColor: theme.palette.background.paper,
2019
},
2120
title: {
2221
color: theme.palette.text.secondary,

docs/src/modules/components/Demo.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Tooltip from '@material-ui/core/Tooltip';
1515
import Github from '@material-ui/docs/svgIcons/GitHub';
1616
import MarkdownElement from '@material-ui/docs/MarkdownElement';
1717
import { getDependencies } from 'docs/src/modules/utils/helpers';
18+
import DemoFrame from 'docs/src/modules/components/DemoFrame';
1819

1920
function compress(object) {
2021
return LZString.compressToBase64(JSON.stringify(object))
@@ -266,7 +267,13 @@ class Demo extends React.Component {
266267
[classes.demoHiddenHeader]: demoOptions.hideHeader,
267268
})}
268269
>
269-
<DemoComponent />
270+
{demoOptions.iframe ? (
271+
<DemoFrame>
272+
<DemoComponent />
273+
</DemoFrame>
274+
) : (
275+
<DemoComponent />
276+
)}
270277
</div>
271278
</div>
272279
);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { create } from 'jss';
4+
import {
5+
withStyles,
6+
createGenerateClassName,
7+
jssPreset,
8+
MuiThemeProvider,
9+
} from '@material-ui/core/styles';
10+
import rtl from 'jss-rtl';
11+
import Frame from 'react-frame-component';
12+
import JssProvider from 'react-jss/lib/JssProvider';
13+
14+
const styles = theme => ({
15+
root: {
16+
backgroundColor: theme.palette.background.default,
17+
flexGrow: 1,
18+
height: 400,
19+
border: 'none',
20+
boxShadow: theme.shadows[1],
21+
},
22+
});
23+
24+
const generateClassName = createGenerateClassName();
25+
26+
class DemoFrame extends React.Component {
27+
state = {
28+
ready: false,
29+
};
30+
31+
handleRef = ref => {
32+
this.contentDocument = ref ? ref.node.contentDocument : null;
33+
};
34+
35+
onContentDidMount = () => {
36+
this.setState({
37+
ready: true,
38+
jss: create({
39+
plugins: [...jssPreset().plugins, rtl()],
40+
insertionPoint: this.contentDocument.querySelector('#demo-frame-jss'),
41+
}),
42+
sheetsManager: new Map(),
43+
container: this.contentDocument.body,
44+
});
45+
};
46+
47+
onContentDidUpdate = () => {
48+
this.contentDocument.body.dir = this.props.theme.direction;
49+
};
50+
51+
render() {
52+
const { children, classes, theme } = this.props;
53+
54+
const inIframe = this.state.ready ? (
55+
<JssProvider jss={this.state.jss} generateClassName={generateClassName}>
56+
<MuiThemeProvider theme={theme} sheetsManager={this.state.sheetsManager}>
57+
{React.cloneElement(children, {
58+
container: this.state.container,
59+
})}
60+
</MuiThemeProvider>
61+
</JssProvider>
62+
) : null;
63+
64+
return (
65+
<Frame
66+
ref={this.handleRef}
67+
className={classes.root}
68+
contentDidMount={this.onContentDidMount}
69+
contentDidUpdate={this.onContentDidUpdate}
70+
>
71+
<div id="demo-frame-jss" />
72+
{inIframe}
73+
</Frame>
74+
);
75+
}
76+
}
77+
78+
DemoFrame.propTypes = {
79+
children: PropTypes.node.isRequired,
80+
classes: PropTypes.object.isRequired,
81+
theme: PropTypes.object.isRequired,
82+
};
83+
84+
export default withStyles(styles, { withTheme: true })(DemoFrame);

docs/src/pages/demos/app-bar/BottomAppBar.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { Fragment } from 'react';
22
import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
44
import AppBar from '@material-ui/core/AppBar';
5+
import CssBaseline from '@material-ui/core/CssBaseline';
56
import Toolbar from '@material-ui/core/Toolbar';
67
import Typography from '@material-ui/core/Typography';
78
import IconButton from '@material-ui/core/IconButton';
@@ -18,25 +19,23 @@ import SearchIcon from '@material-ui/icons/Search';
1819
import MoreIcon from '@material-ui/icons/MoreVert';
1920

2021
const styles = theme => ({
21-
container: {
22-
position: 'relative',
23-
maxWidth: 500,
24-
},
2522
text: {
26-
paddingTop: theme.spacing.unit,
23+
paddingTop: theme.spacing.unit * 2,
2724
paddingLeft: theme.spacing.unit * 2,
2825
paddingRight: theme.spacing.unit * 2,
2926
},
30-
main: {
31-
height: 400,
32-
overflowY: 'auto',
33-
position: 'relative',
27+
paper: {
28+
paddingBottom: 50,
3429
},
3530
list: {
3631
marginBottom: theme.spacing.unit * 2,
3732
},
3833
subHeader: {
39-
backgroundColor: '#fff',
34+
backgroundColor: theme.palette.background.paper,
35+
},
36+
appBar: {
37+
top: 'auto',
38+
bottom: 0,
4039
},
4140
toolbar: {
4241
alignItems: 'center',
@@ -61,7 +60,7 @@ const messages = [
6160
{
6261
id: 2,
6362
primary: 'Birthday Gift',
64-
secondary: `Do you have a suggestion for a good present for John on his work
63+
secondary: `Do you have a suggestion for a good present for John on his work
6564
anniversary. I am really confused & would love your thoughts on it.`,
6665
person: '/static/images/uxceo-128.jpg',
6766
},
@@ -86,8 +85,8 @@ const messages = [
8685
{
8786
id: 6,
8887
primary: 'Discussion',
89-
secondary: `Menus that are generated by the bottom app bar (such as a bottom
90-
navigation drawer or overflow menu) open as bottom sheets at a higher elevation
88+
secondary: `Menus that are generated by the bottom app bar (such as a bottom
89+
navigation drawer or overflow menu) open as bottom sheets at a higher elevation
9190
than the bar.`,
9291
person: '/static/images/remy.jpg',
9392
},
@@ -103,8 +102,9 @@ const messages = [
103102
function BottomAppBar(props) {
104103
const { classes } = props;
105104
return (
106-
<div className={classes.container}>
107-
<Paper square className={classes.main}>
105+
<React.Fragment>
106+
<CssBaseline />
107+
<Paper square className={classes.paper}>
108108
<Typography className={classes.text} variant="h5" gutterBottom>
109109
Inbox
110110
</Typography>
@@ -121,7 +121,7 @@ function BottomAppBar(props) {
121121
))}
122122
</List>
123123
</Paper>
124-
<AppBar position="sticky" color="primary">
124+
<AppBar position="fixed" color="primary" className={classes.appBar}>
125125
<Toolbar className={classes.toolbar}>
126126
<IconButton color="inherit" aria-label="Open drawer">
127127
<MenuIcon />
@@ -139,7 +139,7 @@ function BottomAppBar(props) {
139139
</div>
140140
</Toolbar>
141141
</AppBar>
142-
</div>
142+
</React.Fragment>
143143
);
144144
}
145145

docs/src/pages/demos/app-bar/app-bar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ A primary searchbar.
4141

4242
## Bottom App Bar
4343

44-
{{"demo": "pages/demos/app-bar/BottomAppBar.js"}}
44+
{{"demo": "pages/demos/app-bar/BottomAppBar.js", "iframe": true}}

docs/src/pages/demos/drawers/ClippedDrawer.js

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,36 @@ import PropTypes from 'prop-types';
33
import { withStyles } from '@material-ui/core/styles';
44
import Drawer from '@material-ui/core/Drawer';
55
import AppBar from '@material-ui/core/AppBar';
6+
import CssBaseline from '@material-ui/core/CssBaseline';
67
import Toolbar from '@material-ui/core/Toolbar';
78
import List from '@material-ui/core/List';
89
import Typography from '@material-ui/core/Typography';
910
import Divider from '@material-ui/core/Divider';
10-
import { mailFolderListItems, otherMailFolderListItems } from './tileData';
11+
import ListItem from '@material-ui/core/ListItem';
12+
import ListItemIcon from '@material-ui/core/ListItemIcon';
13+
import ListItemText from '@material-ui/core/ListItemText';
14+
import InboxIcon from '@material-ui/icons/MoveToInbox';
15+
import MailIcon from '@material-ui/icons/Mail';
1116

1217
const drawerWidth = 240;
1318

1419
const styles = theme => ({
1520
root: {
16-
flexGrow: 1,
17-
height: 440,
18-
zIndex: 1,
19-
overflow: 'hidden',
20-
position: 'relative',
2121
display: 'flex',
2222
},
2323
appBar: {
2424
zIndex: theme.zIndex.drawer + 1,
2525
},
26+
drawer: {
27+
width: drawerWidth,
28+
flexShrink: 0,
29+
},
2630
drawerPaper: {
27-
position: 'relative',
2831
width: drawerWidth,
2932
},
3033
content: {
3134
flexGrow: 1,
32-
backgroundColor: theme.palette.background.default,
3335
padding: theme.spacing.unit * 3,
34-
minWidth: 0, // So the Typography noWrap works
3536
},
3637
toolbar: theme.mixins.toolbar,
3738
});
@@ -41,27 +42,65 @@ function ClippedDrawer(props) {
4142

4243
return (
4344
<div className={classes.root}>
44-
<AppBar position="absolute" className={classes.appBar}>
45+
<CssBaseline />
46+
<AppBar position="fixed" className={classes.appBar}>
4547
<Toolbar>
4648
<Typography variant="h6" color="inherit" noWrap>
4749
Clipped drawer
4850
</Typography>
4951
</Toolbar>
5052
</AppBar>
5153
<Drawer
54+
className={classes.drawer}
5255
variant="permanent"
5356
classes={{
5457
paper: classes.drawerPaper,
5558
}}
5659
>
5760
<div className={classes.toolbar} />
58-
<List>{mailFolderListItems}</List>
61+
<List>
62+
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
63+
<ListItem button key={text}>
64+
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
65+
<ListItemText primary={text} />
66+
</ListItem>
67+
))}
68+
</List>
5969
<Divider />
60-
<List>{otherMailFolderListItems}</List>
70+
<List>
71+
{['All mail', 'Trash', 'Spam'].map((text, index) => (
72+
<ListItem button key={text}>
73+
<ListItemIcon>{index % 2 === 0 ? <InboxIcon /> : <MailIcon />}</ListItemIcon>
74+
<ListItemText primary={text} />
75+
</ListItem>
76+
))}
77+
</List>
6178
</Drawer>
6279
<main className={classes.content}>
6380
<div className={classes.toolbar} />
64-
<Typography noWrap>{'You think water moves fast? You should see ice.'}</Typography>
81+
<Typography paragraph>
82+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
83+
ut labore et dolore magna aliqua. Rhoncus dolor purus non enim praesent elementum
84+
facilisis leo vel. Risus at ultrices mi tempus imperdiet. Semper risus in hendrerit
85+
gravida rutrum quisque non tellus. Convallis convallis tellus id interdum velit laoreet id
86+
donec ultrices. Odio morbi quis commodo odio aenean sed adipiscing. Amet nisl suscipit
87+
adipiscing bibendum est ultricies integer quis. Cursus euismod quis viverra nibh cras.
88+
Metus vulputate eu scelerisque felis imperdiet proin fermentum leo. Mauris commodo quis
89+
imperdiet massa tincidunt. Cras tincidunt lobortis feugiat vivamus at augue. At augue eget
90+
arcu dictum varius duis at consectetur lorem. Velit sed ullamcorper morbi tincidunt. Lorem
91+
donec massa sapien faucibus et molestie ac.
92+
</Typography>
93+
<Typography paragraph>
94+
Consequat mauris nunc congue nisi vitae suscipit. Fringilla est ullamcorper eget nulla
95+
facilisi etiam dignissim diam. Pulvinar elementum integer enim neque volutpat ac
96+
tincidunt. Ornare suspendisse sed nisi lacus sed viverra tellus. Purus sit amet volutpat
97+
consequat mauris. Elementum eu facilisis sed odio morbi. Euismod lacinia at quis risus sed
98+
vulputate odio. Morbi tincidunt ornare massa eget egestas purus viverra accumsan in. In
99+
hendrerit gravida rutrum quisque non tellus orci ac. Pellentesque nec nam aliquam sem et
100+
tortor. Habitant morbi tristique senectus et. Adipiscing elit duis tristique sollicitudin
101+
nibh sit. Ornare aenean euismod elementum nisi quis eleifend. Commodo viverra maecenas
102+
accumsan lacus vel facilisis. Nulla posuere sollicitudin aliquam ultrices sagittis orci a.
103+
</Typography>
65104
</main>
66105
</div>
67106
);

0 commit comments

Comments
 (0)