Skip to content

Commit 124c9f5

Browse files
committed
refactor(stablecoinboxgrid): migrate stablecoinboxgrid component to shadcn/tailwind
1 parent 378fd29 commit 124c9f5

File tree

1 file changed

+21
-101
lines changed

1 file changed

+21
-101
lines changed

src/components/StablecoinBoxGrid.tsx

Lines changed: 21 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import { useState } from "react"
22
import { useRouter } from "next/router"
33
import { useTranslation } from "next-i18next"
4-
import { Box, Flex } from "@chakra-ui/react"
5-
import { useColorModeValue } from "@chakra-ui/react"
64

75
import { ChildOnlyProp } from "@/lib/types"
86

7+
import { Flex } from "@/components/ui/flex"
8+
import InlineLink from "@/components/ui/Link"
9+
910
import { isMobile } from "../lib/utils/isMobile"
1011

1112
import Emoji from "./Emoji"
12-
import InlineLink from "./Link"
13-
import OldHeading from "./OldHeading"
1413

1514
// Represent string as 32-bit integer
1615
const hashCode = (string: string): number => {
@@ -25,12 +24,12 @@ const hashCode = (string: string): number => {
2524

2625
// Theme variables from Theme.js
2726
const colors = [
28-
"gridYellow",
29-
"gridBlue",
30-
"gridGreen",
31-
"gridOrange",
32-
"gridPink",
33-
"gridPurple",
27+
"bg-yellow-300",
28+
"bg-blue-300",
29+
"bg-green-300",
30+
"bg-orange-100",
31+
"bg-pink-300",
32+
"bg-purple-300",
3433
]
3534

3635
interface ILink {
@@ -40,8 +39,6 @@ interface ILink {
4039

4140
type GridItemProps = {
4241
description: string
43-
columnNumber: number
44-
rowNumber: number
4542
emoji: string
4643
index: number
4744
title: string
@@ -54,85 +51,48 @@ type GridItemProps = {
5451
}
5552

5653
const OpenTitle = ({ title }: { title: string }) => {
57-
return (
58-
<OldHeading
59-
as="h3"
60-
fontSize={{ base: "2rem", sm: "2.5rem" }}
61-
fontWeight={700}
62-
marginTop={0}
63-
>
64-
{title}
65-
</OldHeading>
66-
)
54+
return <h3 className="mb-8 mt-0 text-3xl font-bold sm:text-4xl">{title}</h3>
6755
}
6856

6957
const Title = ({ title }: { title: string }) => {
70-
return (
71-
<OldHeading
72-
as="h3"
73-
fontSize={{ base: "2rem", sm: "2.5rem" }}
74-
fontWeight={400}
75-
marginTop={0}
76-
>
77-
{title}
78-
</OldHeading>
79-
)
58+
return <h3 className="mb-8 mt-0 text-3xl font-normal sm:text-4xl">{title}</h3>
8059
}
8160

8261
const Subtitle = ({ children }: ChildOnlyProp) => {
8362
return (
84-
<OldHeading
85-
as="h4"
86-
fontSize={{ base: "2xl", sm: "2rem" }}
87-
fontWeight={600}
88-
marginTop={0}
89-
padding={2}
90-
paddingBottom={4}
91-
borderBottom="1px solid"
92-
borderColor="black300"
93-
>
63+
<h4 className="mb-8 mt-0 border-b border-body-medium p-2 pb-4 text-2xl font-semibold sm:text-3xl">
9464
{children}
95-
</OldHeading>
65+
</h4>
9666
)
9767
}
9868

9969
const Body = ({ children }: ChildOnlyProp) => {
100-
return (
101-
<Box fontSize="xl" lineHeight="140%" color="black300">
102-
{children}
103-
</Box>
104-
)
70+
return <div className="text-xl text-gray-600">{children}</div>
10571
}
10672

10773
const StyledEmoji = ({ emoji }: { emoji: string }) => {
10874
return (
10975
<Emoji
110-
className="order-2 m-2 self-center text-8xl hover:rotate-12 hover:duration-500"
76+
className="order-2 m-2 self-center text-8xl duration-500 hover:rotate-12"
11177
text={emoji}
11278
/>
11379
)
11480
}
11581

11682
const Row = ({ children }: ChildOnlyProp) => {
11783
return (
118-
<Flex
119-
justify="space-between"
120-
marginTop={8}
121-
direction={{ base: "column", md: "row" }}
122-
>
84+
<Flex className="mt-8 flex-col justify-between md:flex-row">
12385
{children}
12486
</Flex>
12587
)
12688
}
12789

12890
const Column = ({ children }: ChildOnlyProp) => {
129-
return <Box width="100%">{children}</Box>
91+
return <div className="w-full">{children}</div>
13092
}
13193

13294
const GridItem = ({
13395
description,
134-
columnNumber,
135-
rowNumber,
13696
emoji,
13797
index,
13898
title,
@@ -146,38 +106,13 @@ const GridItem = ({
146106
const handleClick = (): void => {
147107
callback(index)
148108
}
149-
const shadow = useColorModeValue("tableBox.light", "tableBox.dark")
150109
const { t } = useTranslation("page-stablecoins")
151110

152111
return (
153112
<Flex
154113
id={`type-${index}`}
155114
onClick={() => handleClick()}
156-
gridRowStart={isOpen ? rowNumber : `auto`}
157-
gridRowEnd={isOpen ? `span 3` : `auto`}
158-
gridColumnStart={isOpen ? columnNumber : `auto`}
159-
color={isOpen ? "black300" : "text"}
160-
cursor={isOpen ? `auto` : `pointer`}
161-
background={isOpen ? color : "background.base"}
162-
direction={{
163-
base: "column",
164-
sm: `${isOpen ? "column" : "row"}`,
165-
lg: "column",
166-
}}
167-
justify={{
168-
base: `${isOpen ? "flex-start" : "space-between"}`,
169-
lg: "flex-start",
170-
}}
171-
align={{ base: "center", lg: "flex-start" }}
172-
border="1px solid"
173-
borderColor="text"
174-
padding={6}
175-
_hover={{
176-
background: isOpen ? color : "ednBackground",
177-
transition: isOpen ? "auto" : "transform 0.5s",
178-
transform: isOpen ? "auto" : "skewX(-5deg)",
179-
boxShadow: shadow,
180-
}}
115+
className={`flex-col ${isOpen ? `${color} col-start-1 row-start-1 row-end-[span_3] cursor-auto justify-start text-gray-600 transition sm:flex-col` : "col-start-auto row-start-auto row-end-auto cursor-pointer justify-between bg-background transition-transform duration-500 hover:skew-x-[-5deg] hover:bg-background-highlight sm:flex-row"} items-center border border-body p-6 hover:shadow-table-box lg:flex-col lg:items-start lg:justify-start`}
181116
>
182117
{isOpen ? (
183118
<Emoji className="mb-8 text-8xl" text={emoji} />
@@ -228,10 +163,7 @@ const GridItem = ({
228163
<InlineLink
229164
key={idx}
230165
href={link.url}
231-
color="black300"
232-
_hover={{
233-
color: "black",
234-
}}
166+
className="text-gray-600 hover:text-gray-900"
235167
>
236168
{link.text}
237169
</InlineLink>
@@ -273,18 +205,8 @@ const StablecoinBoxGrid = ({ items }: StablecoinBoxGridProps) => {
273205
}
274206

275207
return (
276-
<Box
277-
gridTemplateColumns="3fr 1fr"
278-
gridTemplateRows="3fr 3fr"
279-
borderRadius="sm"
280-
my={16}
281-
display={{ base: "flex", lg: "grid" }}
282-
flexDirection="column"
283-
maxW="100%"
284-
>
208+
<div className="my-16 flex max-w-full flex-col rounded-sm lg:grid lg:grid-cols-[3fr_1fr] lg:grid-rows-[3fr_3fr]">
285209
{items.map((item, idx) => {
286-
const columnNumber = 1
287-
const rowNumber = 1
288210
const colorIdx = hashCode(item.emoji) % colors.length
289211
const color = colors[colorIdx]
290212
return (
@@ -297,15 +219,13 @@ const StablecoinBoxGrid = ({ items }: StablecoinBoxGridProps) => {
297219
cons={item.cons}
298220
links={item.links}
299221
index={idx}
300-
columnNumber={columnNumber}
301-
rowNumber={rowNumber}
302222
isOpen={idx === indexOpen}
303223
callback={handleSelect}
304224
color={color}
305225
/>
306226
)
307227
})}
308-
</Box>
228+
</div>
309229
)
310230
}
311231

0 commit comments

Comments
 (0)