Skip to content

Commit

Permalink
[docs] Add CSSGrid comparison example (mui#10433)
Browse files Browse the repository at this point in the history
* [docs] Add CSSGrid comparison example

* add flexbox
  • Loading branch information
caub authored and oliviertassinari committed Feb 25, 2018
1 parent e0a8fbd commit ea179a1
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 28 deletions.
62 changes: 34 additions & 28 deletions docs/src/pages/layout/grid/AutoGridNoWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import Typography from 'material-ui/Typography';

const styles = theme => ({
root: {
width: 400,
overflow: 'hidden',
padding: `0 ${theme.spacing.unit * 3}px`,
},
wrapper: {
maxWidth: 400,
},
paper: {
margin: theme.spacing.unit,
Expand All @@ -23,36 +27,38 @@ function AutoGridNoWrap(props) {

return (
<div className={classes.root}>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs zeroMinWidth>
<Typography noWrap>{message}</Typography>
</Grid>
</Grid>
</Paper>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs>
<Typography noWrap>{message}</Typography>
<div className={classes.wrapper}>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs zeroMinWidth>
<Typography noWrap>{message}</Typography>
</Grid>
</Grid>
</Grid>
</Paper>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Paper>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs>
<Typography noWrap>{message}</Typography>
</Grid>
</Grid>
<Grid item xs>
<Typography>{message}</Typography>
</Paper>
<Paper className={classes.paper}>
<Grid container wrap="nowrap">
<Grid item>
<Avatar>W</Avatar>
</Grid>
<Grid item xs>
<Typography>{message}</Typography>
</Grid>
</Grid>
</Grid>
</Paper>
</Paper>
</div>
</div>
);
}
Expand Down
87 changes: 87 additions & 0 deletions docs/src/pages/layout/grid/CSSGrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from 'material-ui/styles';
import Typography from 'material-ui/Typography';
import Paper from 'material-ui/Paper';
import Divider from 'material-ui/Divider';
import Grid from 'material-ui/Grid';

const styles = theme => ({
container: {
display: 'grid',
gridTemplateColumns: 'repeat(12, 1fr)',
gridGap: `${theme.spacing.unit * 3}px`,
},
paper: {
padding: theme.spacing.unit,
textAlign: 'center',
color: theme.palette.text.secondary,
whiteSpace: 'nowrap',
marginBottom: theme.spacing.unit,
},
divider: {
margin: `${theme.spacing.unit * 2}px 0`,
},
});

function CSSGrid(props) {
const { classes } = props;

return (
<div>
<Typography variant="subheading" gutterBottom>
Material-UI Grid:
</Typography>
<Grid container spacing={24}>
<Grid item xs={3}>
<Paper className={classes.paper}>xs=3</Paper>
</Grid>
<Grid item xs={3}>
<Paper className={classes.paper}>xs=3</Paper>
</Grid>
<Grid item xs={3}>
<Paper className={classes.paper}>xs=3</Paper>
</Grid>
<Grid item xs={3}>
<Paper className={classes.paper}>xs=3</Paper>
</Grid>
<Grid item xs={8}>
<Paper className={classes.paper}>xs=8</Paper>
</Grid>
<Grid item xs={4}>
<Paper className={classes.paper}>xs=4</Paper>
</Grid>
</Grid>
<Divider className={classes.divider} />
<Typography variant="subheading" gutterBottom>
CSS Grid Layout:
</Typography>
<div className={classes.container}>
<div style={{ gridColumnEnd: 'span 3' }}>
<Paper className={classes.paper}>xs=3</Paper>
</div>
<div style={{ gridColumnEnd: 'span 3' }}>
<Paper className={classes.paper}>xs=3</Paper>
</div>
<div style={{ gridColumnEnd: 'span 3' }}>
<Paper className={classes.paper}>xs=3</Paper>
</div>
<div style={{ gridColumnEnd: 'span 3' }}>
<Paper className={classes.paper}>xs=3</Paper>
</div>
<div style={{ gridColumnEnd: 'span 8' }}>
<Paper className={classes.paper}>xs=8</Paper>
</div>
<div style={{ gridColumnEnd: 'span 4' }}>
<Paper className={classes.paper}>xs=4</Paper>
</div>
</div>
</div>
);
}

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

export default withStyles(styles)(CSSGrid);
7 changes: 7 additions & 0 deletions docs/src/pages/layout/grid/grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ That also means you can set the width of one *item* and the others will automati

{{"demo": "pages/layout/grid/AutoGrid.js"}}

## CSS Grid Layout

**CSS Grid Layout** excels at dividing a page into major regions, or defining the relationship in terms of size, position, and layer, between parts of a control built from HTML primitives.
Unfortunately, CSS grid is only supported by the most recent browsers.

{{"demo": "pages/layout/grid/CSSGrid.js"}}

## Limitations

### Negative margin
Expand Down
7 changes: 7 additions & 0 deletions pages/layout/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/layout/grid/AutoGrid'), 'utf8')
`,
},
'pages/layout/grid/CSSGrid.js': {
js: require('docs/src/pages/layout/grid/CSSGrid').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/layout/grid/CSSGrid'), 'utf8')
`,
},
'pages/layout/grid/AutoGridNoWrap.js': {
Expand Down

0 comments on commit ea179a1

Please sign in to comment.