Skip to content

Commit 14c7710

Browse files
committed
Conditionally apply word breaks to card text.
1 parent 2bc3f0f commit 14c7710

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

src/components/cards.tsx

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,31 @@ export function Cards({
1515
}) {
1616
return (
1717
<div className="grid grid-cols-2 mt-6 gap-4">
18-
{items.map(
19-
({
20-
icon: Icon,
21-
title,
22-
link,
23-
description = link.replace(/^https?:\/\//, ""),
24-
}) => {
25-
const isExternal = link.startsWith("https://")
26-
return (
27-
<Card
28-
key={title}
29-
as={isExternal ? "a" : NextLink}
30-
// @ts-expect-error
31-
href={link}
32-
className={clsx(
33-
"flex flex-col items-center",
34-
isExternal &&
35-
"relative after:content-['_↗'] after:font-sans after:absolute after:right-4 after:top-4",
36-
)}
18+
{items.map(({ icon: Icon, title, link, description }) => {
19+
const isExternal = link.startsWith("https://")
20+
return (
21+
<Card
22+
key={title}
23+
as={isExternal ? "a" : NextLink}
24+
// @ts-expect-error
25+
href={link}
26+
className={clsx(
27+
"flex flex-col items-center",
28+
isExternal &&
29+
"relative after:content-['_↗'] after:font-sans after:absolute after:right-4 after:top-4",
30+
)}
31+
>
32+
{/* @ts-expect-error */}
33+
{typeof Icon === "function" ? <Icon className="h-6" /> : Icon}
34+
<b className="mt-4 mb-2 text-lg text-center">{title}</b>
35+
<span
36+
className={`text-xs md:text-sm text-center${description ? "" : " break-all"}`}
3737
>
38-
{/* @ts-expect-error */}
39-
{typeof Icon === "function" ? <Icon className="h-6" /> : Icon}
40-
<b className="mt-4 mb-2 text-lg text-center">{title}</b>
41-
<span className="text-xs md:text-sm text-center break-all">
42-
{description}
43-
</span>
44-
</Card>
45-
)
46-
},
47-
)}
38+
{description ? description : link.replace(/^https?:\/\//, "")}
39+
</span>
40+
</Card>
41+
)
42+
})}
4843
</div>
4944
)
5045
}

0 commit comments

Comments
 (0)