Skip to content

Commit

Permalink
[CardMedia] Add an example with the component property (#12481)
Browse files Browse the repository at this point in the history
* initial commit

* let's seek the simplest solution
  • Loading branch information
adeelibr authored and oliviertassinari committed Aug 15, 2018
1 parent db5531a commit ed75035
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 188 deletions.
57 changes: 57 additions & 0 deletions docs/src/pages/demos/cards/ImgMediaCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';

const styles = {
card: {
maxWidth: 345,
},
media: {
// ⚠️ object-fit is not supported by IE11.
objectFit: 'cover',
},
};

function ImgMediaCard(props) {
const { classes } = props;
return (
<Card className={classes.card}>
<CardMedia
component="img"
className={classes.media}
height="140"
image="/static/images/cards/contemplative-reptile.jpg"
title="Contemplative Reptile"
/>
<CardContent>
<Typography gutterBottom variant="headline" component="h2">
Lizard
</Typography>
<Typography component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000 species, ranging
across all continents except Antarctica
</Typography>
</CardContent>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}

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

export default withStyles(styles)(ImgMediaCard);
54 changes: 54 additions & 0 deletions docs/src/pages/demos/cards/MediaCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';

const styles = {
card: {
maxWidth: 345,
},
media: {
height: 140,
},
};

function MediaCard(props) {
const { classes } = props;
return (
<Card className={classes.card}>
<CardMedia
className={classes.media}
image="/static/images/cards/contemplative-reptile.jpg"
title="Contemplative Reptile"
/>
<CardContent>
<Typography gutterBottom variant="headline" component="h2">
Lizard
</Typography>
<Typography component="p">
Lizards are a widespread group of squamate reptiles, with over 6,000 species, ranging
across all continents except Antarctica
</Typography>
</CardContent>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}

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

export default withStyles(styles)(MediaCard);
52 changes: 25 additions & 27 deletions docs/src/pages/demos/cards/MediaControlCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,32 @@ function MediaControlCard(props) {
const { classes, theme } = props;

return (
<div>
<Card className={classes.card}>
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography variant="headline">Live From Space</Typography>
<Typography variant="subheading" color="textSecondary">
Mac Miller
</Typography>
</CardContent>
<div className={classes.controls}>
<IconButton aria-label="Previous">
{theme.direction === 'rtl' ? <SkipNextIcon /> : <SkipPreviousIcon />}
</IconButton>
<IconButton aria-label="Play/pause">
<PlayArrowIcon className={classes.playIcon} />
</IconButton>
<IconButton aria-label="Next">
{theme.direction === 'rtl' ? <SkipPreviousIcon /> : <SkipNextIcon />}
</IconButton>
</div>
<Card className={classes.card}>
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography variant="headline">Live From Space</Typography>
<Typography variant="subheading" color="textSecondary">
Mac Miller
</Typography>
</CardContent>
<div className={classes.controls}>
<IconButton aria-label="Previous">
{theme.direction === 'rtl' ? <SkipNextIcon /> : <SkipPreviousIcon />}
</IconButton>
<IconButton aria-label="Play/pause">
<PlayArrowIcon className={classes.playIcon} />
</IconButton>
<IconButton aria-label="Next">
{theme.direction === 'rtl' ? <SkipPreviousIcon /> : <SkipNextIcon />}
</IconButton>
</div>
<CardMedia
className={classes.cover}
image="/static/images/cards/live-from-space.jpg"
title="Live from space album cover"
/>
</Card>
</div>
</div>
<CardMedia
className={classes.cover}
image="/static/images/cards/live-from-space.jpg"
title="Live from space album cover"
/>
</Card>
);
}

Expand Down
144 changes: 71 additions & 73 deletions docs/src/pages/demos/cards/RecipeReviewCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,82 +57,80 @@ class RecipeReviewCard extends React.Component {
const { classes } = this.props;

return (
<div>
<Card className={classes.card}>
<CardHeader
avatar={
<Avatar aria-label="Recipe" className={classes.avatar}>
R
</Avatar>
}
action={
<IconButton>
<MoreVertIcon />
</IconButton>
}
title="Shrimp and Chorizo Paella"
subheader="September 14, 2016"
/>
<CardMedia
className={classes.media}
image="/static/images/cards/paella.jpg"
title="Contemplative Reptile"
/>
<Card className={classes.card}>
<CardHeader
avatar={
<Avatar aria-label="Recipe" className={classes.avatar}>
R
</Avatar>
}
action={
<IconButton>
<MoreVertIcon />
</IconButton>
}
title="Shrimp and Chorizo Paella"
subheader="September 14, 2016"
/>
<CardMedia
className={classes.media}
image="/static/images/cards/paella.jpg"
title="Contemplative Reptile"
/>
<CardContent>
<Typography component="p">
This impressive paella is a perfect party dish and a fun meal to cook together with your
guests. Add 1 cup of frozen peas along with the mussels, if you like.
</Typography>
</CardContent>
<CardActions className={classes.actions} disableActionSpacing>
<IconButton aria-label="Add to favorites">
<FavoriteIcon />
</IconButton>
<IconButton aria-label="Share">
<ShareIcon />
</IconButton>
<IconButton
className={classnames(classes.expand, {
[classes.expandOpen]: this.state.expanded,
})}
onClick={this.handleExpandClick}
aria-expanded={this.state.expanded}
aria-label="Show more"
>
<ExpandMoreIcon />
</IconButton>
</CardActions>
<Collapse in={this.state.expanded} timeout="auto" unmountOnExit>
<CardContent>
<Typography component="p">
This impressive paella is a perfect party dish and a fun meal to cook together with
your guests. Add 1 cup of frozen peas along with the mussels, if you like.
<Typography paragraph variant="body2">
Method:
</Typography>
<Typography paragraph>
Heat 1/2 cup of the broth in a pot until simmering, add saffron and set aside for 10
minutes.
</Typography>
<Typography paragraph>
Heat oil in a (14- to 16-inch) paella pan or a large, deep skillet over medium-high
heat. Add chicken, shrimp and chorizo, and cook, stirring occasionally until lightly
browned, 6 to 8 minutes. Transfer shrimp to a large plate and set aside, leaving
chicken and chorizo in the pan. Add pimentón, bay leaves, garlic, tomatoes, onion,
salt and pepper, and cook, stirring often until thickened and fragrant, about 10
minutes. Add saffron broth and remaining 4 1/2 cups chicken broth; bring to a boil.
</Typography>
<Typography paragraph>
Add rice and stir very gently to distribute. Top with artichokes and peppers, and cook
without stirring, until most of the liquid is absorbed, 15 to 18 minutes. Reduce heat
to medium-low, add reserved shrimp and mussels, tucking them down into the rice, and
cook again without stirring, until mussels have opened and rice is just tender, 5 to 7
minutes more. (Discard any mussels that don’t open.)
</Typography>
<Typography>
Set aside off of the heat to let rest for 10 minutes, and then serve.
</Typography>
</CardContent>
<CardActions className={classes.actions} disableActionSpacing>
<IconButton aria-label="Add to favorites">
<FavoriteIcon />
</IconButton>
<IconButton aria-label="Share">
<ShareIcon />
</IconButton>
<IconButton
className={classnames(classes.expand, {
[classes.expandOpen]: this.state.expanded,
})}
onClick={this.handleExpandClick}
aria-expanded={this.state.expanded}
aria-label="Show more"
>
<ExpandMoreIcon />
</IconButton>
</CardActions>
<Collapse in={this.state.expanded} timeout="auto" unmountOnExit>
<CardContent>
<Typography paragraph variant="body2">
Method:
</Typography>
<Typography paragraph>
Heat 1/2 cup of the broth in a pot until simmering, add saffron and set aside for 10
minutes.
</Typography>
<Typography paragraph>
Heat oil in a (14- to 16-inch) paella pan or a large, deep skillet over medium-high
heat. Add chicken, shrimp and chorizo, and cook, stirring occasionally until lightly
browned, 6 to 8 minutes. Transfer shrimp to a large plate and set aside, leaving
chicken and chorizo in the pan. Add pimentón, bay leaves, garlic, tomatoes, onion,
salt and pepper, and cook, stirring often until thickened and fragrant, about 10
minutes. Add saffron broth and remaining 4 1/2 cups chicken broth; bring to a boil.
</Typography>
<Typography paragraph>
Add rice and stir very gently to distribute. Top with artichokes and peppers, and
cook without stirring, until most of the liquid is absorbed, 15 to 18 minutes.
Reduce heat to medium-low, add reserved shrimp and mussels, tucking them down into
the rice, and cook again without stirring, until mussels have opened and rice is
just tender, 5 to 7 minutes more. (Discard any mussels that don’t open.)
</Typography>
<Typography>
Set aside off of the heat to let rest for 10 minutes, and then serve.
</Typography>
</CardContent>
</Collapse>
</Card>
</div>
</Collapse>
</Card>
);
}
}
Expand Down
52 changes: 25 additions & 27 deletions docs/src/pages/demos/cards/SimpleCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,31 @@ function SimpleCard(props) {
const bull = <span className={classes.bullet}></span>;

return (
<div>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary">
Word of the Day
</Typography>
<Typography variant="headline" component="h2">
be
{bull}
nev
{bull}o{bull}
lent
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
<Typography component="p">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
</div>
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary">
Word of the Day
</Typography>
<Typography variant="headline" component="h2">
be
{bull}
nev
{bull}o{bull}
lent
</Typography>
<Typography className={classes.pos} color="textSecondary">
adjective
</Typography>
<Typography component="p">
well meaning and kindly.
<br />
{'"a benevolent smile"'}
</Typography>
</CardContent>
<CardActions>
<Button size="small">Learn More</Button>
</CardActions>
</Card>
);
}

Expand Down
Loading

0 comments on commit ed75035

Please sign in to comment.