Skip to content

Commit 0cb030a

Browse files
authored
Merge pull request #14018 from yashtotla/yt/migrate-product-card
migrate ProductCard component to tailwind
2 parents 6ba7382 + 220c329 commit 0cb030a

File tree

2 files changed

+34
-62
lines changed

2 files changed

+34
-62
lines changed

src/components/ProductCard.tsx

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import React, { ReactNode } from "react"
1+
import type { ImageProps } from "next/image"
22
import { useTranslation } from "next-i18next"
3-
import {
4-
Badge,
5-
Box,
6-
Center,
7-
Flex,
8-
Heading,
9-
HStack,
10-
TextProps,
11-
} from "@chakra-ui/react"
3+
import type { ReactNode } from "react"
4+
import { Badge } from "@chakra-ui/react"
125

13-
import { ButtonLink } from "@/components/Buttons"
14-
import { Image, type ImageProps } from "@/components/Image"
15-
import Text from "@/components/OldText"
6+
import { cn } from "@/lib/utils/cn"
167

8+
import { ButtonLink } from "./ui/buttons/Button"
9+
import { Center, Flex, HStack } from "./ui/flex"
1710
import GitStars from "./GitStars"
11+
import { TwImage } from "./Image"
1812

1913
type SubjectBadgeProps = {
2014
subject: string
21-
children: React.ReactNode
15+
children: ReactNode
2216
}
2317

2418
const SubjectBadge = ({ subject, children }: SubjectBadgeProps) => {
@@ -56,7 +50,7 @@ const SubjectBadge = ({ subject, children }: SubjectBadgeProps) => {
5650
}
5751

5852
export type ProductCardProps = {
59-
children?: React.ReactNode
53+
children?: ReactNode
6054
url: string
6155
background: string
6256
image: ImageProps["src"]
@@ -87,78 +81,56 @@ const ProductCard = ({
8781
hideStars = false,
8882
}: ProductCardProps) => {
8983
const { t } = useTranslation("common")
90-
const DESCRIPTION_STYLES: TextProps = {
91-
opacity: 0.8,
92-
fontSize: "sm",
93-
mb: 2,
94-
lineHeight: "140%",
95-
}
9684

9785
return (
9886
<Flex
99-
flexDirection="column"
100-
justifyContent="space-between"
101-
color="text"
102-
background="searchBackground"
103-
boxShadow="0px 14px 66px rgba(0, 0, 0, 0.07)"
104-
borderRadius="base"
105-
border="1px"
106-
borderColor="lightBorder"
107-
textDecoration="none"
108-
_hover={{
109-
transition: "transform 0.1s",
110-
transform: "scale(1.02)",
111-
}}
87+
className={cn(
88+
"flex-col justify-between bg-background-highlight",
89+
"rounded-base border no-underline",
90+
"hover:scale-[1.02] hover:transition-transform"
91+
)}
11292
>
113-
<Center
114-
background={bgProp}
115-
boxShadow="inset 0px -1px 0px rgba(0, 0, 0, 0.1)"
116-
minH="200px"
117-
>
118-
<Image
119-
src={image}
120-
alt={alt}
121-
height="100"
122-
alignSelf="center"
123-
maxW={{ base: "311px", sm: "372px" }}
124-
maxH="257px"
125-
/>
93+
<Center className="min-h-[200px]" style={{ backgroundColor: bgProp }}>
94+
<TwImage src={image} alt={alt} height="100" className="self-center" />
12695
</Center>
127-
<Flex flexDirection="column" p={6} textAlign="start" height="100%">
96+
<Flex className="h-full flex-col p-6 text-left">
12897
{githubRepoStars > 0 && (
12998
<GitStars
13099
gitHubRepo={{ url: githubUrl, stargazerCount: githubRepoStars }}
131100
hideStars={hideStars}
132101
/>
133102
)}
134-
<Heading
135-
as="h3"
136-
fontSize="2xl"
137-
fontWeight={600}
138-
mt={githubRepoStars > 0 ? 8 : 12}
139-
mb={3}
103+
<h3
104+
className={cn(
105+
"mb-3 text-2xl font-semibold",
106+
githubRepoStars > 0 ? "mt-8" : "mt-12"
107+
)}
140108
>
141109
{name}
142-
</Heading>
143-
{description && <Text {...DESCRIPTION_STYLES}>{description}</Text>}
144-
{note.length > 0 && <Text {...DESCRIPTION_STYLES}>Note: {note}</Text>}
145-
{children && <Box mt={4}>{children}</Box>}
110+
</h3>
111+
{description && (
112+
<p className="mb-2 text-sm leading-xs opacity-80">{description}</p>
113+
)}
114+
{note.length > 0 && (
115+
<p className="mb-2 text-sm leading-xs opacity-80">Note: {note}</p>
116+
)}
117+
{children && <div className="mt-4">{children}</div>}
146118
</Flex>
147-
<HStack mt={5} mb={2} px={6} spacing={3}>
119+
<HStack className="mb-2 mt-5 gap-3 px-6">
148120
{subjects &&
149121
subjects.map((subject, idx) => (
150122
<SubjectBadge key={idx} subject={subject}>
151123
{subject}
152124
</SubjectBadge>
153125
))}
154-
{githubRepoLanguages.length &&
126+
{githubRepoLanguages.length > 0 &&
155127
githubRepoLanguages.map((name, idx: number) => (
156128
<SubjectBadge key={idx} subject={name}>
157129
{name.toUpperCase()}
158130
</SubjectBadge>
159131
))}
160132
</HStack>
161-
<ButtonLink href={url} m={4} height={20}>
133+
<ButtonLink href={url} className="m-4 h-20">
162134
{t("open")} {name}
163135
</ButtonLink>
164136
</Flex>

src/components/ui/command.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const CommandSeparator = React.forwardRef<
123123
>(({ className, ...props }, ref) => (
124124
<CommandPrimitive.Separator
125125
ref={ref}
126-
className={cn("bg-border -mx-1 h-px", className)}
126+
className={cn("-mx-1 h-px bg-border", className)}
127127
{...props}
128128
/>
129129
))

0 commit comments

Comments
 (0)