File size: 2,795 Bytes
8b105ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React from "react";
import styled from "styled-components";
import { Link } from 'react-router-dom';
import blogPosts from '../data/blogdata'; // Import the blog data

const BlogCardContainer = styled.div`
  align-self: center;
  width: 100%;  // Makes the card flexible to take full width of its container
  max-width: 320px; // Limits the width for cards (fixed size max)
  margin: 10px; // Consistent margin for even spacing between cards
  border-radius: 12px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  background-color: #2d3748;  // Dark background
  cursor: pointer;
  border: 3px solid #3267B9; // Blue border
  
  // Prevent the card from expanding beyond its max width
  box-sizing: border-box; // Ensure padding doesn't increase width

  // On larger screens, the cards may need to adjust themselves more dynamically
  @media (min-width: 768px) {
    margin: 10px;  // Ensure margin is consistent
  }

  @media (min-width: 1024px) {
    margin: 10px;  // Ensure margin is consistent on larger screens
  }
`;

const BlogImage = styled.img`
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-bottom: 1px solid #e0e0e0;
  // Ensure that the image doesn't stretch out of bounds
  object-position: center;
`;

const BlogContent = styled.div`
  padding: 15px;
  text-align: left;
  flex-grow: 1;
`;

const BlogTitle = styled.h3`
  font-size: 1.2rem;
  color: #e2e8f0;
  font-weight: 600;
  margin-bottom: 10px;
`;

const BlogMeta = styled.div`
  font-size: 0.9rem;
  color: #3f7ad3;
  margin-bottom: 10px;
`;

const BlogExcerpt = styled.p`
  font-size: 1rem;
  color: #e2e8f0;
  margin-bottom: 20px;
  line-height: 1.5;
`;

const ReadMore = styled(Link)`
  font-size: 1rem;
  color: #fff;
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
  padding: 10px 20px;
  margin-top: 10px;
  border-radius: 25px;
  background-color: #3267B9;
  transition: all 0.3s ease-in-out;

  &:hover {
    text-decoration: none;
    box-shadow: 0 0 10px rgba(63, 122, 211, 0.8);
    transform: translateY(-3px);
  }
`;

const BlogCard = ({ blog }) => {
  return (
    <BlogCardContainer data-testid="blog-card">
      <BlogImage src={blog.imageUrl} alt={blog.title} />
      <BlogContent>
        <BlogTitle>{blog.title}</BlogTitle>
        <BlogMeta>
          <span>{blog.author}</span> | <span>{blog.date}</span> | <span>{blog.readTime} min read</span>
        </BlogMeta>
        <BlogExcerpt>{blog.excerpt}</BlogExcerpt>
        
        {/* Pass post as state to the route */}
        <center>
          <ReadMore to={`/blog/${blog.id}`} state={{ post: blogPosts.find(post=>post.id===blog.id) }}>
            Read more →
          </ReadMore>
        </center>
      </BlogContent>
    </BlogCardContainer>
  );
};

export default BlogCard;