Skip to content

Commit 97acf3b

Browse files
committed
feat: migrate CardList from to tailwind
1 parent c8d0b17 commit 97acf3b

File tree

6 files changed

+62
-81
lines changed

6 files changed

+62
-81
lines changed

src/components/CardList.tsx

Lines changed: 47 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
import Image, { type ImageProps } from "next/image"
1+
import TwImage, { type ImageProps } from "next/image"
22
import type { ReactNode } from "react"
3-
import {
4-
Box,
5-
type BoxProps,
6-
Flex,
7-
HStack,
8-
LinkBox,
9-
LinkOverlay,
10-
type StackProps,
11-
useColorModeValue,
12-
} from "@chakra-ui/react"
133

144
import { BaseLink } from "@/components/Link"
5+
import { LinkBox } from "@/components/ui/link-box"
156

7+
import { cn } from "@/lib/utils/cn"
168
import { MatomoEventOptions, trackCustomEvent } from "@/lib/utils/matomo"
179
import * as url from "@/lib/utils/url"
1810

1911
import { useRtlFlip } from "@/hooks/useRtlFlip"
2012

21-
export type CardListItem = {
13+
export type CardProps = {
2214
title?: ReactNode
2315
description?: ReactNode
2416
caption?: ReactNode
@@ -27,93 +19,80 @@ export type CardListItem = {
2719
image?: ImageProps["src"]
2820
imageWidth?: number
2921
alt?: string
22+
className?: string
23+
onClick?: () => void
3024
}
3125

32-
const CardContainer = (props: StackProps) => (
33-
<HStack
34-
spacing={4}
35-
p={4}
36-
color="text"
37-
border="1px solid"
38-
borderColor="border"
39-
_hover={{
40-
borderRadius: "base",
41-
boxShadow: "0 0 1px var(--eth-colors-primary)",
42-
background: "tableBackgroundHover",
43-
}}
44-
{...props}
45-
/>
46-
)
47-
48-
type CardProps = CardListItem & Omit<StackProps, "title" | "id">
49-
5026
const Card = ({
5127
title,
5228
description,
5329
caption,
5430
link,
5531
image,
56-
imageWidth = 20, // Set 20px as default image width, can be overridden if needed
32+
className,
5733
alt,
34+
onClick,
35+
imageWidth = 20,
5836
...props
5937
}: CardProps) => {
6038
const { flipForRtl } = useRtlFlip()
6139
const isLink = !!link
6240
const isExternal = url.isExternal(link || "")
6341

64-
const descriptionColor = useColorModeValue("gray.500", "gray.400")
65-
6642
return (
67-
<CardContainer {...props}>
68-
{image && <Image src={image} alt={alt ?? ""} width={imageWidth} />}
69-
<Flex flex="1 1 75%" direction="column">
43+
<div
44+
className={cn(
45+
"text-text flex flex-row items-center gap-4 border border-solid border-border p-4",
46+
"transition-all duration-200",
47+
"hover:rounded-base hover:bg-tableBackgroundHover hover:shadow-[0_0_1px_var(--eth-colors-primary)]",
48+
className
49+
)}
50+
onClick={onClick}
51+
{...props}
52+
>
53+
{image && <TwImage src={image} alt={alt ?? ""} width={imageWidth} />}
54+
<div className="flex flex-1 basis-3/4 flex-col">
7055
{isLink ? (
71-
<LinkOverlay
72-
as={BaseLink}
56+
<BaseLink
7357
href={link}
7458
isExternal={isExternal}
7559
hideArrow
76-
color="text"
77-
textDecoration="none"
78-
_hover={{ textDecoration: "none" }}
60+
className="text-text hover:no-underline"
7961
>
8062
{title}
81-
</LinkOverlay>
63+
</BaseLink>
8264
) : (
83-
<Box>{title}</Box>
65+
<div>{title}</div>
8466
)}
8567

86-
<Box fontSize="sm" mb={0} color={descriptionColor}>
87-
{description}
88-
</Box>
89-
</Flex>
68+
<div className="mb-0 text-sm text-body-medium">{description}</div>
69+
</div>
9070
{caption && (
91-
<Flex flex="1 0 25%" align="center" wrap="wrap" me={4}>
92-
<Box fontSize="sm" mb={0} opacity={0.6}>
93-
{caption}
94-
</Box>
95-
</Flex>
71+
<div className="me-4 flex flex-[1_0_25%] flex-wrap items-center">
72+
<div className="mb-0 text-sm opacity-60">{caption}</div>
73+
</div>
9674
)}
97-
{isExternal && <Box transform={flipForRtl}></Box>}
98-
</CardContainer>
75+
{isExternal && <span style={{ transform: flipForRtl }}></span>}
76+
</div>
9977
)
10078
}
10179

102-
export type CardListProps = BoxProps & {
80+
export type CardListProps = {
10381
items: CardProps[]
10482
imageWidth?: number
10583
clickHandler?: (idx: string | number) => void
10684
customEventOptions?: MatomoEventOptions
85+
className?: string
10786
}
10887

10988
const CardList = ({
11089
items,
11190
imageWidth,
11291
clickHandler = () => null,
11392
customEventOptions,
114-
...props
93+
className,
11594
}: CardListProps) => (
116-
<Box bg="background.base" w="full" {...props}>
95+
<div className={cn("w-full bg-background", className)}>
11796
{items.map((listItem, idx) => {
11897
const { link, id } = listItem
11998
const isLink = !!link
@@ -123,18 +102,19 @@ const CardList = ({
123102
<Card {...listItem} imageWidth={imageWidth} />
124103
</LinkBox>
125104
) : (
126-
<Card
127-
key={idx}
128-
onClick={() => {
129-
customEventOptions && trackCustomEvent(customEventOptions)
130-
clickHandler(idx)
131-
}}
132-
mb={4}
133-
{...listItem}
134-
/>
105+
<div key={idx}>
106+
<Card
107+
onClick={() => {
108+
customEventOptions && trackCustomEvent(customEventOptions)
109+
clickHandler(idx)
110+
}}
111+
className="mb-4"
112+
{...listItem}
113+
/>
114+
</div>
135115
)
136116
})}
137-
</Box>
117+
</div>
138118
)
139119

140120
export default CardList

src/components/MergeArticleList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useTranslation } from "next-i18next"
22

3-
import CardList, { type CardListItem } from "@/components/CardList"
3+
import CardList, { type CardProps } from "@/components/CardList"
44

55
const MergeArticleList = () => {
66
const { t } = useTranslation(["page-upgrades", "page-upgrades-index"])
77

8-
const reads: CardListItem[] = [
8+
const reads: CardProps[] = [
99
{
1010
title: t("page-upgrades-index:page-upgrade-article-title-ethmerge"),
1111
description: t(

src/components/StablecoinAccordion/useStablecoinAccordion.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useTranslation } from "next-i18next"
22

3-
import { CardListItem } from "../CardList"
3+
import { type CardProps } from "@/components/CardList"
44

55
import aaveImg from "@/public/images/dapps/aave.png"
66
// -- borrow
@@ -25,7 +25,7 @@ import ethImg from "@/public/images/favicon.png"
2525
export const useStablecoinAccordion = () => {
2626
const { t } = useTranslation("page-stablecoins")
2727

28-
const dapps: Array<CardListItem> = [
28+
const dapps: Array<CardProps> = [
2929
{
3030
title: "Uniswap",
3131
image: uniImg,
@@ -52,7 +52,7 @@ export const useStablecoinAccordion = () => {
5252
},
5353
]
5454

55-
const borrow: Array<CardListItem> = [
55+
const borrow: Array<CardProps> = [
5656
{
5757
title: "Compound",
5858
image: compoundImg,
@@ -73,7 +73,7 @@ export const useStablecoinAccordion = () => {
7373
},
7474
]
7575

76-
const earn: Array<CardListItem> = [
76+
const earn: Array<CardProps> = [
7777
{
7878
title: t("page-stablecoins-accordion-earn-project-bounties"),
7979
image: gitcoinImg,
@@ -90,7 +90,7 @@ export const useStablecoinAccordion = () => {
9090
},
9191
]
9292

93-
const exchanges: Array<CardListItem> = [
93+
const exchanges: Array<CardProps> = [
9494
{
9595
title: "Coinbase",
9696
image: coinbaseImg,

src/components/Staking/StakingGuides.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useTranslation } from "next-i18next"
22

3-
import CardList, { type CardListItem } from "@/components/CardList"
3+
import CardList, { type CardProps } from "@/components/CardList"
44

55
const StakingGuides = () => {
66
const { t } = useTranslation("page-staking")
77

8-
const guides: CardListItem[] = [
8+
const guides: CardProps[] = [
99
{
1010
title: t("page-staking-guide-title-coincashew-ethereum"),
1111
link: "https://www.coincashew.com/coins/overview-eth/guide-or-how-to-setup-a-validator-on-eth2-mainnet",

src/pages/get-eth.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import type { ReactNode } from "react"
66
import type { BasePageProps, ChildOnlyProp, Lang } from "@/lib/types"
77

88
import CalloutBanner from "@/components/CalloutBanner"
9-
import type { CardListItem } from "@/components/CardList"
10-
import CardList from "@/components/CardList"
9+
import CardList, {
10+
type CardProps as CardListCardProps,
11+
} from "@/components/CardList"
1112
import CentralizedExchanges from "@/components/CentralizedExchanges"
1213
import Emoji from "@/components/Emoji"
1314
import EthPriceCard from "@/components/EthPriceCard"
@@ -110,7 +111,7 @@ const GetEthPage = ({
110111
md: "50%",
111112
})
112113

113-
const tokenSwaps: CardListItem[] = [
114+
const tokenSwaps: CardListCardProps[] = [
114115
{
115116
title: "Uniswap",
116117
link: "https://app.uniswap.org/#/swap",
@@ -137,7 +138,7 @@ const GetEthPage = ({
137138
},
138139
]
139140

140-
const safetyArticles: CardListItem[] = [
141+
const safetyArticles: CardListCardProps[] = [
141142
{
142143
title: t("page-get-eth-article-protecting-yourself"),
143144
link: "https://support.mycrypto.com/staying-safe/protecting-yourself-and-your-funds",

src/pages/wallets/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ const WalletsPage = () => {
310310
>
311311
<Text>{t("page-wallets-description")}</Text>
312312
<Text>{t("page-wallets-desc-2")}</Text>
313-
<CardList items={guides} mb={{ base: 6, lg: 0 }} />
313+
<CardList items={guides} className="mb-6 lg:mb-0" />
314314
</Box>
315315
<RightColumn>
316316
<Text>{t("page-wallets-desc-3")}</Text>

0 commit comments

Comments
 (0)