-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[docs] Add Grid List TypeScript demos #15118
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles, createStyles, Theme, WithStyles } from '@material-ui/core/styles'; | ||
import GridList from '@material-ui/core/GridList'; | ||
import GridListTile from '@material-ui/core/GridListTile'; | ||
import GridListTileBar from '@material-ui/core/GridListTileBar'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import StarBorderIcon from '@material-ui/icons/StarBorder'; | ||
import tileData from './tileData'; | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
root: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-around', | ||
overflow: 'hidden', | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
gridList: { | ||
width: 500, | ||
height: 450, | ||
// Promote the list into his own layer on Chrome. This cost memory but helps keeping high FPS. | ||
transform: 'translateZ(0)', | ||
}, | ||
titleBar: { | ||
background: | ||
'linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, ' + | ||
'rgba(0,0,0,0.3) 70%, rgba(0,0,0,0) 100%)', | ||
}, | ||
icon: { | ||
color: 'white', | ||
}, | ||
}); | ||
|
||
/** | ||
* The example data is structured as follows: | ||
* | ||
* import image from 'path/to/image.jpg'; | ||
* [etc...] | ||
* | ||
* const tileData = [ | ||
* { | ||
* img: image, | ||
* title: 'Image', | ||
* author: 'author', | ||
* featured: true, | ||
* }, | ||
* { | ||
* [etc...] | ||
* }, | ||
* ]; | ||
*/ | ||
function AdvancedGridList(props: WithStyles<typeof styles>) { | ||
const { classes } = props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<GridList cellHeight={200} spacing={1} className={classes.gridList}> | ||
{tileData.map(tile => ( | ||
<GridListTile key={tile.img} cols={tile.featured ? 2 : 1} rows={tile.featured ? 2 : 1}> | ||
<img src={tile.img} alt={tile.title} /> | ||
<GridListTileBar | ||
title={tile.title} | ||
titlePosition="top" | ||
actionIcon={ | ||
<IconButton className={classes.icon}> | ||
<StarBorderIcon /> | ||
</IconButton> | ||
} | ||
actionPosition="left" | ||
className={classes.titleBar} | ||
/> | ||
</GridListTile> | ||
))} | ||
</GridList> | ||
</div> | ||
); | ||
} | ||
|
||
AdvancedGridList.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
} as any; | ||
|
||
export default withStyles(styles)(AdvancedGridList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles'; | ||
import GridList from '@material-ui/core/GridList'; | ||
import GridListTile from '@material-ui/core/GridListTile'; | ||
import tileData from './tileData'; | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
root: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-around', | ||
overflow: 'hidden', | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
gridList: { | ||
width: 500, | ||
height: 450, | ||
}, | ||
}); | ||
|
||
/** | ||
* The example data is structured as follows: | ||
* | ||
* import image from 'path/to/image.jpg'; | ||
* [etc...] | ||
* | ||
* const tileData = [ | ||
* { | ||
* img: image, | ||
* title: 'Image', | ||
* author: 'author', | ||
* cols: 2, | ||
* }, | ||
* { | ||
* [etc...] | ||
* }, | ||
* ]; | ||
*/ | ||
function ImageGridList(props: WithStyles<typeof styles>) { | ||
const { classes } = props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<GridList cellHeight={160} className={classes.gridList} cols={3}> | ||
{tileData.map(tile => ( | ||
<GridListTile key={tile.img} cols={tile.cols || 1}> | ||
<img src={tile.img} alt={tile.title} /> | ||
</GridListTile> | ||
))} | ||
</GridList> | ||
</div> | ||
); | ||
} | ||
|
||
ImageGridList.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
} as any; | ||
|
||
export default withStyles(styles)(ImageGridList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles'; | ||
import GridList from '@material-ui/core/GridList'; | ||
import GridListTile from '@material-ui/core/GridListTile'; | ||
import GridListTileBar from '@material-ui/core/GridListTileBar'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import StarBorderIcon from '@material-ui/icons/StarBorder'; | ||
import tileData from './tileData'; | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
root: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-around', | ||
overflow: 'hidden', | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
gridList: { | ||
flexWrap: 'nowrap', | ||
// Promote the list into his own layer on Chrome. This cost memory but helps keeping high FPS. | ||
transform: 'translateZ(0)', | ||
}, | ||
title: { | ||
color: theme.palette.primary.light, | ||
}, | ||
titleBar: { | ||
background: | ||
'linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.3) 70%, rgba(0,0,0,0) 100%)', | ||
}, | ||
}); | ||
|
||
/** | ||
* The example data is structured as follows: | ||
* | ||
* import image from 'path/to/image.jpg'; | ||
* [etc...] | ||
* | ||
* const tileData = [ | ||
* { | ||
* img: image, | ||
* title: 'Image', | ||
* author: 'author', | ||
* }, | ||
* { | ||
* [etc...] | ||
* }, | ||
* ]; | ||
*/ | ||
function SingleLineGridList(props: WithStyles<typeof styles>) { | ||
const { classes } = props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<GridList className={classes.gridList} cols={2.5}> | ||
{tileData.map(tile => ( | ||
<GridListTile key={tile.img}> | ||
<img src={tile.img} alt={tile.title} /> | ||
<GridListTileBar | ||
title={tile.title} | ||
classes={{ | ||
root: classes.titleBar, | ||
title: classes.title, | ||
}} | ||
actionIcon={ | ||
<IconButton> | ||
<StarBorderIcon className={classes.title} /> | ||
</IconButton> | ||
} | ||
/> | ||
</GridListTile> | ||
))} | ||
</GridList> | ||
</div> | ||
); | ||
} | ||
|
||
SingleLineGridList.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
} as any; | ||
|
||
export default withStyles(styles)(SingleLineGridList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { withStyles, Theme, createStyles, WithStyles } from '@material-ui/core/styles'; | ||
import GridList from '@material-ui/core/GridList'; | ||
import GridListTile from '@material-ui/core/GridListTile'; | ||
import GridListTileBar from '@material-ui/core/GridListTileBar'; | ||
import ListSubheader from '@material-ui/core/ListSubheader'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import InfoIcon from '@material-ui/icons/Info'; | ||
import tileData from './tileData'; | ||
|
||
const styles = (theme: Theme) => | ||
createStyles({ | ||
root: { | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
justifyContent: 'space-around', | ||
overflow: 'hidden', | ||
backgroundColor: theme.palette.background.paper, | ||
}, | ||
gridList: { | ||
width: 500, | ||
height: 450, | ||
}, | ||
icon: { | ||
color: 'rgba(255, 255, 255, 0.54)', | ||
}, | ||
}); | ||
|
||
/** | ||
* The example data is structured as follows: | ||
* | ||
* import image from 'path/to/image.jpg'; | ||
* [etc...] | ||
* | ||
* const tileData = [ | ||
* { | ||
* img: image, | ||
* title: 'Image', | ||
* author: 'author', | ||
* }, | ||
* { | ||
* [etc...] | ||
* }, | ||
* ]; | ||
*/ | ||
function TitlebarGridList(props: WithStyles<typeof styles>) { | ||
const { classes } = props; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<GridList cellHeight={180} className={classes.gridList}> | ||
<GridListTile key="Subheader" cols={2} style={{ height: 'auto' }}> | ||
<ListSubheader component="div">December</ListSubheader> | ||
</GridListTile> | ||
{tileData.map(tile => ( | ||
<GridListTile key={tile.img}> | ||
<img src={tile.img} alt={tile.title} /> | ||
<GridListTileBar | ||
title={tile.title} | ||
subtitle={<span>by: {tile.author}</span>} | ||
actionIcon={ | ||
<IconButton className={classes.icon}> | ||
<InfoIcon /> | ||
</IconButton> | ||
} | ||
/> | ||
</GridListTile> | ||
))} | ||
</GridList> | ||
</div> | ||
); | ||
} | ||
|
||
TitlebarGridList.propTypes = { | ||
classes: PropTypes.object.isRequired, | ||
} as any; | ||
|
||
export default withStyles(styles)(TitlebarGridList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface TileDataItem { | ||
img: string; | ||
title: string; | ||
author: string; | ||
cols: number; | ||
featured: boolean; | ||
} | ||
|
||
declare const tileData: TileDataItem[]; | ||
|
||
export default tileData; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../tslint.json", | ||
"rules": { | ||
"no-relative-import-in-test": false | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.