-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcards.tsx
45 lines (44 loc) · 1.27 KB
/
cards.tsx
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
import { ReactElement } from "react"
import { Card } from "./card"
import { clsx } from "clsx"
import NextLink from "next/link"
export function Cards({
items,
}: {
items: {
icon: ReactElement
title: string
description?: string
link: string
}[]
}) {
return (
<div className="mt-6 grid grid-cols-2 gap-4">
{items.map(({ icon: Icon, title, link, description }) => {
const isExternal = link.startsWith("https://")
return (
<Card
key={title}
as={isExternal ? "a" : NextLink}
// @ts-expect-error
href={link}
className={clsx(
"flex flex-col items-center",
isExternal &&
"relative after:absolute after:right-4 after:top-4 after:font-sans after:content-['_↗']",
)}
>
{/* @ts-expect-error */}
{typeof Icon === "function" ? <Icon className="h-12" /> : Icon}
<b className="mb-2 mt-4 text-center text-lg">{title}</b>
<span
className={`text-xs md:text-sm text-center${description ? "" : "break-all"}`}
>
{description ? description : link.replace(/^https?:\/\//, "")}
</span>
</Card>
)
})}
</div>
)
}