Guest User

Untitled

a guest
Feb 17th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import React from 'react';
  2. import {connect} from 'react-redux';
  3. import {Card, CardTitle, CardMedia} from 'material-ui';
  4. import {openMovieModal} from '../movie-modal/movie-modal.actions';
  5.  
  6. // These are inline styles
  7. // You can pass styles as objects using this convention
  8. const styles = {
  9. cardMedia: {
  10. maxHeight: 394,
  11. overflow: 'hidden'
  12. },
  13. card: {
  14. cursor: 'pointer',
  15. height: 400,
  16. overflow: 'hidden'
  17. },
  18. bgImage: {
  19. width: '100%'
  20. }
  21. };
  22.  
  23. class MovieCardComponent extends React.Component {
  24. constructor(props) {
  25. super(props);
  26. // Track if the mouse hovering over the movie card
  27. this.state = {
  28. isMouseOver: false
  29. };
  30. }
  31.  
  32. render() {
  33. const {movie, openMovieModal} = this.props;
  34. // The CardTitle.subtitle won't render if it's null
  35. const subtitle = this.state.isMouseOver ? movie.overview : null;
  36.  
  37. return (
  38. <Card
  39. style={styles.card}
  40. onMouseOver={() => this.setState({isMouseOver: true})}
  41. onMouseLeave={() => this.setState({isMouseOver: false})}
  42. onClick= {() => openMovieModal(movie.id)}
  43. >
  44. <CardMedia
  45. style={styles.cardMedia}
  46. overlay={
  47. <CardTitle
  48. title={movie.title}
  49. subtitle={subtitle}
  50. />
  51. }
  52. >
  53. <img style={styles.bgImage} src={movie.poster_path} />
  54. </CardMedia>
  55. </Card>
  56. );
  57. }
  58. }
  59.  
  60. export default connect(
  61. () => ({}),
  62. { openMovieModal }
  63. )(MovieCardComponent);
Add Comment
Please, Sign In to add comment