File size: 1,439 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 |
import React from "react";
import BlogCard from "../../components/BlogCard"; // Importing BlogCard component
import blog from "../../data/blogcardsdata"; // Importing blog data directly
import styled from "styled-components";
// Styled component for the grid layout
const BlogGridWrapper = styled.div`
justify-items: center; // Center the grid items
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); // Dynamic columns
gap: 2rem; // Spacing between cards
padding: 0 1rem; // Padding to ensure no cards are at the edges
max-width: 1200px; // Constrain grid to a max-width
margin: 0 auto; // Center the grid horizontally
// Prevent horizontal overflow
overflow-x: hidden;
@media (min-width: 768px) {
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); // Ensure flexibility for medium screens
}
@media (min-width: 1024px) {
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); // Three columns for larger screens
}
`;
const Blogsection = () => {
return (
<div >
{blog && Array.isArray(blog) && blog.length > 0 ? (
<BlogGridWrapper data-testid='grid-wrapper'>
{blog.slice().reverse().map((blogItem) => (
<BlogCard key={blogItem.id} blog={blogItem} />
))}
</BlogGridWrapper>
) : (
<p>No blogs available at the moment.</p>
)}
</div>
);
};
export default Blogsection; |