Skip to content

Commit b7fcc90

Browse files
authored
Merge pull request #14000 from saurabhburade/shadcn-migrate/BugBountyCards
Shadcn migrate - BugBountyCards
2 parents cd1e25f + 1fb841a commit b7fcc90

File tree

1 file changed

+50
-102
lines changed

1 file changed

+50
-102
lines changed

src/components/BugBountyCards.tsx

Lines changed: 50 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,102 @@
1+
import { BaseHTMLAttributes } from "react"
12
import { useTranslation } from "next-i18next"
2-
import {
3-
Box,
4-
type BoxProps,
5-
Center,
6-
type CenterProps,
7-
Divider,
8-
Flex,
9-
type FlexProps,
10-
Heading,
11-
type HeadingProps,
12-
type TextProps,
13-
useToken,
14-
} from "@chakra-ui/react"
153

164
import type { ChildOnlyProp, TranslationKey } from "@/lib/types"
175

18-
import { ButtonLink, type ButtonLinkProps } from "@/components/Buttons"
19-
import Text from "@/components/OldText"
6+
import { cn } from "@/lib/utils/cn"
7+
8+
import { ButtonLink, ButtonLinkProps } from "./ui/buttons/Button"
9+
import { Center, Flex, Stack } from "./ui/flex"
10+
11+
type FlexProps = BaseHTMLAttributes<HTMLDivElement>
2012

2113
const CardRow = ({ children }: ChildOnlyProp) => (
22-
<Flex justifyContent="space-between" my="16" mx="4" flexWrap="wrap">
23-
{children}
24-
</Flex>
14+
<Flex className="mx-4 my-16 flex-wrap justify-between">{children}</Flex>
2515
)
2616

2717
const SubmitBugBountyButton = ({ children, ...props }: ButtonLinkProps) => (
28-
<ButtonLink m="4" href="https://forms.gle/Gnh4gzGh66Yc3V7G8" {...props}>
18+
<ButtonLink
19+
className="m-4"
20+
href="https://forms.gle/Gnh4gzGh66Yc3V7G8"
21+
{...props}
22+
>
2923
{children}
3024
</ButtonLink>
3125
)
3226

3327
const Card = ({ children, ...props }: FlexProps) => {
34-
const tableBoxShadow = useToken("colors", "tableBoxShadow")
35-
3628
return (
37-
<Flex
38-
flexDir="column"
39-
flex={{ base: "1 1 412px", xl: "1 1 260px" }}
40-
justifyContent="space-between"
41-
bg="background.base"
42-
borderRadius="2px"
43-
borderRad
44-
boxShadow={tableBoxShadow}
45-
border="1px solid"
46-
borderColor="border"
47-
m="4"
48-
_hover={{
49-
borderRadius: "base",
50-
boxShadow: "tableBoxHover",
51-
background: "tableBackgroundHover",
52-
transition: "transform 0.1s",
53-
transform: "scale(1.02)",
54-
}}
29+
<Stack
30+
className={cn(
31+
"flex-[1_1_412px] gap-0 xl:flex-[1_1_216px]",
32+
"m-4 justify-between bg-background",
33+
"rounded-sm border shadow-table-box",
34+
"hover:scale-[1.02] hover:rounded hover:bg-background-highlight hover:shadow-table-box-hover hover:transition-transform hover:duration-100"
35+
)}
5536
{...props}
5637
>
5738
{children}
58-
</Flex>
39+
</Stack>
5940
)
6041
}
6142

6243
type LabelVariant = "low" | "medium" | "high" | "critical"
6344

64-
type LabelProps = CenterProps & {
45+
type LabelProps = FlexProps & {
6546
variant: LabelVariant
6647
}
6748

68-
const stylePropsByVariant = {
69-
low: {
70-
bg: "lowBug",
71-
color: "black300",
72-
},
73-
medium: {
74-
bg: "mediumBug",
75-
color: "black300",
76-
},
77-
high: {
78-
bg: "fail400",
79-
color: "white",
80-
},
81-
critical: {
82-
bg: "fail600",
83-
color: "white",
84-
},
49+
const classNameByVariant = {
50+
low: "bg-red-100 text-black",
51+
medium: "bg-red-300 text-black",
52+
high: "bg-red-700 text-white",
53+
critical: "bg-red-900 text-white",
8554
}
8655

8756
const Label = ({ children, variant = "medium", ...props }: LabelProps) => {
88-
const variantStyleProps = stylePropsByVariant[variant]
57+
const variantClassName = classNameByVariant[variant]
8958

9059
return (
9160
<Center
92-
borderTopEndRadius="1px"
93-
borderTopStartRadius="1px"
94-
borderBottomEndRadius={0}
95-
borderBottomStartRadius={0}
96-
borderBottom="1px solid"
97-
borderColor="border"
98-
fontSize="sm"
99-
px="0"
100-
py="1"
101-
textTransform="uppercase"
102-
{...variantStyleProps}
61+
className={cn(
62+
"rounded-t-[1px] border-b px-0 py-1 text-sm uppercase",
63+
variantClassName
64+
)}
10365
{...props}
10466
>
10567
{children}
10668
</Center>
10769
)
10870
}
10971

110-
const H2 = ({ children, ...props }: HeadingProps) => (
111-
<Heading
112-
fontSize="2xl"
113-
fontStyle="normal"
114-
fontWeight="bold"
115-
lineHeight="22px"
116-
letterSpacing="normal"
117-
p="4"
118-
textAlign="start"
119-
mb="-2"
120-
mt="2"
72+
const H2 = ({ children, ...props }) => (
73+
<h2
74+
className={cn("-mb-2 mt-2 p-4", "text-start text-2xl font-bold leading-6")}
12175
{...props}
12276
>
12377
{children}
124-
</Heading>
78+
</h2>
12579
)
12680

127-
const Description = ({ children, ...props }: TextProps) => (
128-
<Text as="p" fontSize="xl" px="4" py="0" opacity="0.6" {...props}>
81+
const Description = ({ children, ...props }) => (
82+
<p className="mb-6 px-4 py-0 text-xl opacity-60" {...props}>
12983
{children}
130-
</Text>
84+
</p>
13185
)
13286

133-
const SubHeader = ({ children, ...props }: TextProps) => (
134-
<Text
135-
as="p"
136-
textTransform="uppercase"
137-
fontSize="sm"
138-
ms="4"
139-
mt="4"
140-
mb="2"
141-
opacity="0.6"
142-
{...props}
143-
>
87+
const SubHeader = ({ children, ...props }) => (
88+
<p className="mb-2 ms-4 mt-4 text-sm uppercase opacity-60" {...props}>
14489
{children}
145-
</Text>
90+
</p>
14691
)
14792

148-
const TextBox = ({ children, ...props }: BoxProps) => (
149-
<Box m="4" mt="2" {...props}>
93+
const TextBox = ({
94+
children,
95+
...props
96+
}: BaseHTMLAttributes<HTMLDivElement>) => (
97+
<div className="m-4 mt-2" {...props}>
15098
{children}
151-
</Box>
99+
</div>
152100
)
153101

154102
export interface BugBountyCardInfo {
@@ -246,7 +194,7 @@ const BugBountyCards = () => {
246194
<H2>{t(card.h2TranslationId)}</H2>
247195
<Description>{t(card.descriptionTranslationId)}</Description>
248196
<SubHeader>{t(card.subDescriptionTranslationId)}</SubHeader>
249-
<Divider opacity="1" />
197+
250198
<SubHeader>{t(card.subHeader1TranslationId)}</SubHeader>
251199
<TextBox>
252200
<ul>
@@ -258,7 +206,7 @@ const BugBountyCards = () => {
258206
))}
259207
</ul>
260208
</TextBox>
261-
<Divider opacity="1" />
209+
262210
<SubHeader>{t(card.subHeader2TranslationId)}</SubHeader>
263211
<TextBox>{t(card.textTranslationId)}</TextBox>
264212
<SubmitBugBountyButton>

0 commit comments

Comments
 (0)