Skip to content

Commit

Permalink
[docs] Add some Card TypeScript demos (#15011)
Browse files Browse the repository at this point in the history
* Add card demos in ts

* Fix createStyles imported from the wrong package

* Fix order of the import to match the ones in the JS files.
  • Loading branch information
Dudrie authored and eps1lon committed Mar 23, 2019
1 parent f9896bc commit be9a959
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docs/src/pages/demos/cards/MediaCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyles, WithStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardActionArea from '@material-ui/core/CardActionArea';
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 = createStyles({
card: {
maxWidth: 345,
},
media: {
height: 140,
},
});

export interface Props extends WithStyles<typeof styles> {}

function MediaCard(props: Props) {
const { classes } = props;
return (
<Card className={classes.card}>
<CardActionArea>
<CardMedia
className={classes.media}
image="/static/images/cards/contemplative-reptile.jpg"
title="Contemplative Reptile"
/>
<CardContent>
<Typography gutterBottom variant="h5" 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>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}

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

export default withStyles(styles)(MediaCard);
82 changes: 82 additions & 0 deletions docs/src/pages/demos/cards/MediaControlCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, Theme, createStyles, WithStyles, WithTheme } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import SkipPreviousIcon from '@material-ui/icons/SkipPrevious';
import PlayArrowIcon from '@material-ui/icons/PlayArrow';
import SkipNextIcon from '@material-ui/icons/SkipNext';

const styles = (theme: Theme) =>
createStyles({
card: {
display: 'flex',
},
details: {
display: 'flex',
flexDirection: 'column',
},
content: {
flex: '1 0 auto',
},
cover: {
width: 151,
},
controls: {
display: 'flex',
alignItems: 'center',
paddingLeft: theme.spacing(1),
paddingBottom: theme.spacing(1),
},
playIcon: {
height: 38,
width: 38,
},
});

type Props = WithStyles<typeof styles> & WithTheme;

function MediaControlCard(props: Props) {
const { classes, theme } = props;

return (
<Card className={classes.card}>
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography component="h5" variant="h5">
Live From Space
</Typography>
<Typography variant="subtitle1" 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>
</div>
<CardMedia
className={classes.cover}
image="/static/images/cards/live-from-space.jpg"
title="Live from space album cover"
/>
</Card>
);
}

MediaControlCard.propTypes = {
classes: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
} as any;

export default withStyles(styles, { withTheme: true })(MediaControlCard);
131 changes: 131 additions & 0 deletions docs/src/pages/demos/cards/RecipeReviewCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import React from 'react';
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles';
import clsx from 'clsx';
import Card from '@material-ui/core/Card';
import CardHeader from '@material-ui/core/CardHeader';
import CardMedia from '@material-ui/core/CardMedia';
import CardContent from '@material-ui/core/CardContent';
import CardActions from '@material-ui/core/CardActions';
import Collapse from '@material-ui/core/Collapse';
import Avatar from '@material-ui/core/Avatar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import red from '@material-ui/core/colors/red';
import FavoriteIcon from '@material-ui/icons/Favorite';
import ShareIcon from '@material-ui/icons/Share';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import MoreVertIcon from '@material-ui/icons/MoreVert';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
card: {
maxWidth: 400,
},
media: {
height: 0,
paddingTop: '56.25%', // 16:9
},
actions: {
display: 'flex',
},
expand: {
transform: 'rotate(0deg)',
marginLeft: 'auto',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
}),
},
expandOpen: {
transform: 'rotate(180deg)',
},
avatar: {
backgroundColor: red[500],
},
}),
);

function RecipeReviewCard() {
const classes = useStyles();
const [expanded, setExpanded] = React.useState(false);

function handleExpandClick() {
setExpanded(!expanded);
}

return (
<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="Paella dish"
/>
<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={clsx(classes.expand, {
[classes.expandOpen]: expanded,
})}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="Show more"
>
<ExpandMoreIcon />
</IconButton>
</CardActions>
<Collapse in={expanded} timeout="auto" unmountOnExit>
<CardContent>
<Typography paragraph>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>
);
}

export default RecipeReviewCard;
66 changes: 66 additions & 0 deletions docs/src/pages/demos/cards/SimpleCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles, createStyles, 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 Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';

const styles = createStyles({
card: {
minWidth: 275,
},
bullet: {
display: 'inline-block',
margin: '0 2px',
transform: 'scale(0.8)',
},
title: {
fontSize: 14,
},
pos: {
marginBottom: 12,
},
});

export interface Props extends WithStyles<typeof styles> {}

function SimpleCard(props: Props) {
const { classes } = props;
const bull = <span className={classes.bullet}></span>;

return (
<Card className={classes.card}>
<CardContent>
<Typography className={classes.title} color="textSecondary" gutterBottom>
Word of the Day
</Typography>
<Typography variant="h5" 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>
);
}

SimpleCard.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(SimpleCard);

0 comments on commit be9a959

Please sign in to comment.