Skip to content

Commit a983ccf

Browse files
committed
migrate ProductCard component to tailwind
1 parent 66100fb commit a983ccf

File tree

3 files changed

+37
-58
lines changed

3 files changed

+37
-58
lines changed

src/components/ProductCard.tsx

Lines changed: 34 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
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

136
import { ButtonLink } from "@/components/Buttons"
14-
import { Image, type ImageProps } from "@/components/Image"
15-
import Text from "@/components/OldText"
167

8+
import { cn } from "@/lib/utils/cn"
9+
10+
import { Center, Flex, HStack } from "./ui/flex"
1711
import GitStars from "./GitStars"
12+
import { TwImage } from "./Image"
1813

1914
type SubjectBadgeProps = {
2015
subject: string
21-
children: React.ReactNode
16+
children: ReactNode
2217
}
2318

2419
const SubjectBadge = ({ subject, children }: SubjectBadgeProps) => {
@@ -56,7 +51,7 @@ const SubjectBadge = ({ subject, children }: SubjectBadgeProps) => {
5651
}
5752

5853
export type ProductCardProps = {
59-
children?: React.ReactNode
54+
children?: ReactNode
6055
url: string
6156
background: string
6257
image: ImageProps["src"]
@@ -87,71 +82,53 @@ const ProductCard = ({
8782
hideStars = false,
8883
}: ProductCardProps) => {
8984
const { t } = useTranslation("common")
90-
const DESCRIPTION_STYLES: TextProps = {
91-
opacity: 0.8,
92-
fontSize: "sm",
93-
mb: 2,
94-
lineHeight: "140%",
95-
}
9685

9786
return (
9887
<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-
}}
88+
className={cn(
89+
"text-text bg-searchBackground flex-col justify-between",
90+
"shadow-product-card",
91+
"rounded-base border border-gray-100 no-underline",
92+
"hover:scale-[1.02] hover:transition-transform"
93+
)}
11294
>
11395
<Center
114-
background={bgProp}
115-
boxShadow="inset 0px -1px 0px rgba(0, 0, 0, 0.1)"
116-
minH="200px"
96+
className="min-h-[200px] shadow-product-card-img-container"
97+
style={{ backgroundColor: bgProp }}
11798
>
118-
<Image
119-
src={image}
120-
alt={alt}
121-
height="100"
122-
alignSelf="center"
123-
maxW={{ base: "311px", sm: "372px" }}
124-
maxH="257px"
125-
/>
99+
<TwImage src={image} alt={alt} className="w-[100px] self-center" />
126100
</Center>
127-
<Flex flexDirection="column" p={6} textAlign="start" height="100%">
101+
<Flex className="h-full flex-col p-6 text-left">
128102
{githubRepoStars > 0 && (
129103
<GitStars
130104
gitHubRepo={{ url: githubUrl, stargazerCount: githubRepoStars }}
131105
hideStars={hideStars}
132106
/>
133107
)}
134-
<Heading
135-
as="h3"
136-
fontSize="2xl"
137-
fontWeight={600}
138-
mt={githubRepoStars > 0 ? 8 : 12}
139-
mb={3}
108+
<h3
109+
className={cn(
110+
"mb-3 text-2xl font-semibold",
111+
githubRepoStars > 0 ? "mt-8" : "mt-12"
112+
)}
140113
>
141114
{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>}
115+
</h3>
116+
{description && (
117+
<p className="mb-2 text-sm leading-xs opacity-80">{description}</p>
118+
)}
119+
{note.length > 0 && (
120+
<p className="mb-2 text-sm leading-xs opacity-80">Note: {note}</p>
121+
)}
122+
{children && <div className="mt-4">{children}</div>}
146123
</Flex>
147-
<HStack mt={5} mb={2} px={6} spacing={3}>
124+
<HStack className="mb-2 mt-5 gap-3 px-6">
148125
{subjects &&
149126
subjects.map((subject, idx) => (
150127
<SubjectBadge key={idx} subject={subject}>
151128
{subject}
152129
</SubjectBadge>
153130
))}
154-
{githubRepoLanguages.length &&
131+
{githubRepoLanguages.length > 0 &&
155132
githubRepoLanguages.map((name, idx: number) => (
156133
<SubjectBadge key={idx} subject={name}>
157134
{name.toUpperCase()}

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
))

tailwind.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ const config = {
247247
var(--shadow-window-box-1), var(--shadow-window-box-2),
248248
var(--shadow-window-box-3), var(--shadow-window-box-4),
249249
var(--shadow-window-box-5)`,
250+
"product-card": "0px 14px 66px rgba(0, 0, 0, 0.07)",
251+
"product-card-img-container": "inset 0px -1px 0px rgba(0, 0, 0, 0.1)",
250252
},
251253
spacing: {
252254
7.5: "1.875rem",

0 commit comments

Comments
 (0)