|
1
|
import React from "react" |
|
2
|
import { Card, CardProps } from "@/components/Card" |
|
3
|
import clsx from "clsx" |
|
4
|
|
|
5
|
type CardListProps = { |
|
6
|
items: CardProps[] |
|
7
|
itemsPerRow?: number |
|
8
|
defaultItemsPerRow?: number |
|
9
|
className?: string |
|
10
|
} |
|
11
|
|
|
12
|
export const CardList = ({ |
|
13
|
items, |
|
14
|
itemsPerRow, |
|
15
|
className, |
|
16
|
defaultItemsPerRow, |
|
17
|
}: CardListProps) => { |
|
18
|
if (!itemsPerRow) { |
|
19
|
// if length of items is even, set to `2`, else set to `3` |
|
20
|
itemsPerRow = |
|
21
|
items.length === 1 |
|
22
|
? 1 |
|
23
|
: defaultItemsPerRow || (items.length % 2 === 0 ? 2 : 3) |
|
24
|
} |
|
25
|
return ( |
|
26
|
<section |
|
27
|
className={clsx( |
|
28
|
"grid gap-x-docs_1 auto-rows-fr gap-y-docs_1", |
|
29
|
itemsPerRow === 1 && "grid-cols-1", |
|
30
|
itemsPerRow === 2 && "md:grid-cols-2 grid-cols-1", |
|
31
|
itemsPerRow === 3 && "lg:grid-cols-3 md:grid-col-2 grid-cols-1", |
|
32
|
className |
|
33
|
)} |
|
34
|
> |
|
35
|
{items.map((item, key) => ( |
|
36
|
<Card {...item} key={key} /> |
|
37
|
))} |
|
38
|
</section> |
|
39
|
) |
|
40
|
} |