|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import { makeStyles } from '@material-ui/core/styles'; |
| 4 | +import { red } from '@material-ui/core/colors'; |
| 5 | +import { Link } from 'react-router-dom'; |
| 6 | +import clsx from 'clsx'; |
| 7 | +import Card from '@material-ui/core/Card'; |
| 8 | +import CardHeader from '@material-ui/core/CardHeader'; |
| 9 | +import CardContent from '@material-ui/core/CardContent'; |
| 10 | +import CardActions from '@material-ui/core/CardActions'; |
| 11 | +import IconButton from '@material-ui/core/IconButton'; |
| 12 | +import Typography from '@material-ui/core/Typography'; |
| 13 | +import Collapse from '@material-ui/core/Collapse'; |
| 14 | +import TextareaAutosize from '@material-ui/core/TextareaAutosize'; |
| 15 | +import Button from '@material-ui/core/Button'; |
| 16 | +import MoreVertIcon from '@material-ui/icons/MoreVert'; |
| 17 | +import BookmarkIcon from '@material-ui/icons/Bookmark'; |
| 18 | +import ShareIcon from '@material-ui/icons/Share'; |
| 19 | +import LinkIcon from '@material-ui/icons/Link'; |
| 20 | +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; |
| 21 | + |
| 22 | +const useStyles = makeStyles(theme => ({ |
| 23 | + card: { |
| 24 | + maxWidth: 345, |
| 25 | + }, |
| 26 | + media: { |
| 27 | + height: 0, |
| 28 | + paddingTop: '56.25%', // 16:9 |
| 29 | + }, |
| 30 | + expand: { |
| 31 | + transform: 'rotate(0deg)', |
| 32 | + marginLeft: 'auto', |
| 33 | + transition: theme.transitions.create('transform', { |
| 34 | + duration: theme.transitions.duration.shortest, |
| 35 | + }), |
| 36 | + }, |
| 37 | + expandOpen: { |
| 38 | + transform: 'rotate(180deg)', |
| 39 | + }, |
| 40 | + avatar: { |
| 41 | + backgroundColor: red[500], |
| 42 | + }, |
| 43 | +})); |
| 44 | + |
| 45 | +export const ResourceCard = ({ guid, title, created, description, url }) => { |
| 46 | + const classes = useStyles(); |
| 47 | + const [expanded, setExpanded] = React.useState(false); |
| 48 | + |
| 49 | + const handleExpandClick = () => { |
| 50 | + setExpanded(!expanded); |
| 51 | + }; |
| 52 | + return ( |
| 53 | + <Card className={classes.card}> |
| 54 | + <Link to={`/resources/${guid}`}> |
| 55 | + <CardHeader |
| 56 | + action={ |
| 57 | + <IconButton aria-label="settings"> |
| 58 | + <MoreVertIcon /> |
| 59 | + </IconButton> |
| 60 | + } |
| 61 | + title={title} |
| 62 | + subheader={created} |
| 63 | + /> |
| 64 | + </Link> |
| 65 | + <CardContent> |
| 66 | + <Typography variant="body2" color="textSecondary" component="p"> |
| 67 | + {description} |
| 68 | + </Typography> |
| 69 | + </CardContent> |
| 70 | + <CardActions disableSpacing> |
| 71 | + <IconButton aria-label="add to favorites"> |
| 72 | + <BookmarkIcon /> |
| 73 | + </IconButton> |
| 74 | + <IconButton aria-label="share"> |
| 75 | + <ShareIcon /> |
| 76 | + </IconButton> |
| 77 | + <IconButton aria-label="share"> |
| 78 | + <a href={url} target="_blank" rel="noopener noreferrer"> |
| 79 | + <LinkIcon /> |
| 80 | + </a> |
| 81 | + </IconButton> |
| 82 | + <IconButton |
| 83 | + className={clsx(classes.expand, { |
| 84 | + [classes.expandOpen]: expanded, |
| 85 | + })} |
| 86 | + onClick={handleExpandClick} |
| 87 | + aria-expanded={expanded} |
| 88 | + aria-label="show more" |
| 89 | + > |
| 90 | + <ExpandMoreIcon /> |
| 91 | + </IconButton> |
| 92 | + </CardActions> |
| 93 | + <Collapse in={expanded} timeout="auto" unmountOnExit> |
| 94 | + <CardContent> |
| 95 | + <TextareaAutosize |
| 96 | + aria-label="Review" |
| 97 | + rows={3} |
| 98 | + placeholder="Your review" |
| 99 | + /> |
| 100 | + <Button type="submit" color="primary" variant="contained"> |
| 101 | + Submit |
| 102 | + </Button> |
| 103 | + </CardContent> |
| 104 | + </Collapse> |
| 105 | + </Card> |
| 106 | + ); |
| 107 | +}; |
| 108 | + |
| 109 | +ResourceCard.propTypes = { |
| 110 | + guid: PropTypes.string, |
| 111 | + title: PropTypes.string, |
| 112 | + created: PropTypes.string, |
| 113 | + description: PropTypes.string, |
| 114 | + url: PropTypes.string, |
| 115 | +}; |
0 commit comments