Skip to content

Commit

Permalink
New components "BlogGrid"
Browse files Browse the repository at this point in the history
  • Loading branch information
nkokla committed Aug 27, 2024
1 parent 93460f5 commit 72e36af
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/BlogGrid/BlogGrid.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import styled, { css } from 'styled-components'

import CardWrapperAPP from '@/components/CardWrapper'

export const BlogPostWrapper = styled.div`
display: grid;
grid-template-columns: repeat(auto-fill, minmax(calc(30% - 1rem), 1fr));
grid-gap: 1rem;
gap: 1rem;
`

export const BlogGridFooter = styled.footer`
padding: 3rem 0 1rem;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 1rem;
`

export const CardWrapper = styled(CardWrapperAPP)<{ $loading?: boolean }>`
filter: grayscale(0) blur(0px);
filter: ${
({ $loading }) => $loading
? css`grayscale(1) blur(5px)`
: css`grayscale(0) blur(0px)`
};
transition: filter ease;
transition-duration: .6s;
`
50 changes: 50 additions & 0 deletions src/components/BlogGrid/BlogGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use client'

import { ReactNode, useEffect, useState } from 'react'

import Section from '@/components/Section'
import BlogCard, { PostItem } from '@/components/BlogCard'

import { BlogGridFooter, CardWrapper } from './BlogGrid.styles'

interface BlogGridProps {
title?: string
header?: ReactNode
footer?: ReactNode
posts?: PostItem[]
nbPost?: number
isLoading?: boolean
isVisible?: boolean
}

function BlogGrid({ title, header, footer, posts, nbPost, isLoading, isVisible }: BlogGridProps) {
const [loading, setLoading] = useState(isLoading ?? true)

useEffect(() => {
if (posts && posts.length) {
setLoading(false)
}
}, [posts])

return (
<Section title={title} isVisible={isVisible}>
{header}

<CardWrapper $loading={isLoading}>
{
!posts || loading
? 'Chargement en cours...'
: posts.slice(0, nbPost).map(post =>
<BlogCard key={post.title} post={post} />
)
}
</CardWrapper>

{footer && (
<BlogGridFooter>{footer}</BlogGridFooter>
)}
</Section>
)
}

export default BlogGrid
1 change: 1 addition & 0 deletions src/components/BlogGrid/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './BlogGrid'

0 comments on commit 72e36af

Please sign in to comment.