Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Migrate ProductCard to Chakra #8685

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 120 additions & 134 deletions src/components/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,118 +5,17 @@ import { useQuery, gql } from "@apollo/client"

import GitStars from "./GitStars"
import ButtonLink from "./ButtonLink"

const ImageWrapper = styled.div<{
background: string
}>`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background: ${(props) => props.background};
box-shadow: inset 0px -1px 0px rgba(0, 0, 0, 0.1);
min-height: 200px;
`

const Image = styled(GatsbyImage)`
width: 100%;
align-self: center;
max-width: 372px;
max-height: 257px;
@media (max-width: ${(props) => props.theme.breakpoints.s}) {
max-width: 311px;
}
`

const Card = styled.div`
color: ${(props) => props.theme.colors.text};
box-shadow: 0px 14px 66px rgba(0, 0, 0, 0.07);
display: flex;
flex-direction: column;
justify-content: space-between;
background: ${(props) => props.theme.colors.searchBackground};
border-radius: 4px;
border: 1px solid ${(props) => props.theme.colors.lightBorder};
text-decoration: none;
&:hover {
transition: transform 0.1s;
transform: scale(1.02);
}
`

const Content = styled.div`
padding: 1.5rem;
text-align: left;
height: 100%;
display: flex;
flex-direction: column;
`

const Title = styled.h3<{
gitHidden: boolean
}>`
margin-top: ${(props) => (props.gitHidden ? "2rem" : "3rem")};
margin-bottom: 0.75rem;
`

const Description = styled.p`
opacity: 0.8;
font-size: ${(props) => props.theme.fontSizes.s};
margin-bottom: 0.5rem;
line-height: 140%;
`

const SubjectContainer = styled.div`
margin-top: 1.25rem;
padding: 0 1.5rem;
`

const SubjectPill = styled.div<{
subject: string
}>`
text-align: center;
padding: 0 0.5rem;
margin: 0 0.75rem 0.5rem 0;
color: ${(props) => props.theme.colors.black300};
float: left;
background: ${({ theme, subject }) => {
switch (subject) {
case "Solidity":
return theme.colors.tagYellow
case "Vyper":
return theme.colors.tagBlue
case "web3":
return theme.colors.tagTurquoise
case "JavaScript":
return theme.colors.tagRed
case "TypeScript":
return theme.colors.tagBlue
case "Go":
return theme.colors.tagTurquoise
case "Python":
return theme.colors.tagMint
case "Rust":
return theme.colors.tagOrange
case "C#":
return theme.colors.tagBlue
case "Java":
return theme.colors.tagPink
default:
return theme.colors.tagGray
}
}};
font-size: ${(props) => props.theme.fontSizes.xs};
border: 1px solid ${(props) => props.theme.colors.lightBorder};
border-radius: 4px;
`

const StyledButtonLink = styled(ButtonLink)`
margin: 1rem;
`

const Children = styled.div`
margin-top: 1rem;
`
import {
Box,
Center,
Flex,
Heading,
HStack,
Image,
Img,
Text,
TextProps,
} from "@chakra-ui/react"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip curious to know if ESLint has ever been considered with a config that includes import/order to enforce a specific order of the different import types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a useful addition, yes. Hasn't been discussed/considered before AFAIK.


const REPO_DATA = gql`
query RepoData(
Expand All @@ -139,6 +38,53 @@ const REPO_DATA = gql`
}
`

const SubjectPill: React.FC<{ subject: string; children: ReactNode }> = ({
subject,
children,
}) => {
const bgColor = () => {
switch (subject) {
case "Solidity":
return "tagYellow"
case "Vyper":
return "tagBlue"
case "web3":
return "tagTurquoise"
case "JavaScript":
return "tagRed"
case "TypeScript":
return "tagBlue"
case "Go":
return "tagTurquoise"
case "Python":
return "tagMint"
case "Rust":
return "tagOrange"
case "C#":
return "tagBlue"
case "Java":
return "tagPink"
default:
return "tagGray"
}
}
return (
<Box
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be Badges in the upcoming refactor, right?

Copy link
Contributor Author

@TylerAPfledderer TylerAPfledderer Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pettinarip Yes! I have made a note in #8601

background={bgColor()}
border="1px"
borderColor="lightBorder"
borderRadius="base"
color="black300"
fontSize="xs"
textAlign="center"
px={2}
mb={2}
>
{children}
</Box>
)
}

export interface IProps {
children?: React.ReactNode
url: string
Expand All @@ -156,7 +102,7 @@ export interface IProps {

const ProductCard: React.FC<IProps> = ({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a TODO regarding adding loading state. What is the desired loading visual?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure 😆 wouldn't worry too much since that comment is 20 months old and probably we are going to refactor this with the DS.

url,
background,
background: bgProp,
image,
name,
description,
Expand Down Expand Up @@ -186,46 +132,86 @@ const ProductCard: React.FC<IProps> = ({

const isImgSrc = typeof image === "string"

const DESCRIPTION_STYLES: TextProps = {
opacity: 0.8,
fontSize: "sm",
mb: 2,
lineHeight: "140%",
}

return (
<Card>
<ImageWrapper background={background}>
<Flex
flexDirection="column"
justifyContent="space-between"
color="text"
background="searchBackground"
boxShadow="0px 14px 66px rgba(0, 0, 0, 0.07)"
borderRadius="base"
border="1px"
borderColor="lightBorder"
textDecoration="none"
_hover={{
transition: "transform 0.1s",
transform: "scale(1.02)",
}}
>
<Center
background={bgProp}
boxShadow="inset 0px -1px 0px rgba(0, 0, 0, 0.1)"
minH="200px"
>
{isImgSrc ? (
<img src={image} alt={alt} />
) : (
<Image image={image} alt={alt} objectFit="contain" />
<Img
as={GatsbyImage}
image={image}
alt={alt}
objectFit="contain"
width="100%"
alignSelf="center"
maxW={{ base: "311px", sm: "372px" }}
maxH="257px"
/>
)}
</ImageWrapper>
<Content className="hover">
<div>
{hasRepoData && (
<GitStars gitHubRepo={data.repository} hideStars={hideStars} />
)}
<Title gitHidden={!hasRepoData}>{name}</Title>
<Description>{description}</Description>
{note.length > 0 && <Description>Note: {note}</Description>}
</div>
{children && <Children>{children}</Children>}
</Content>
<SubjectContainer>
</Center>
<Flex flexDirection="column" p={6} textAlign="left" height="100%">
{hasRepoData && (
<GitStars gitHubRepo={data.repository} hideStars={hideStars} />
)}
<Heading
as="h3"
fontSize="2xl"
fontWeight={600}
mt={!hasRepoData ? 8 : 12}
mb={3}
>
{name}
</Heading>
{description && <Text {...DESCRIPTION_STYLES}>{description}</Text>}
{note.length > 0 && <Text {...DESCRIPTION_STYLES}>Note: {note}</Text>}
{children && <Box mt={4}>{children}</Box>}
</Flex>
<HStack mt={5} px={6} spacing={3}>
{subjects &&
subjects.map((subject, idx) => (
<SubjectPill key={idx} subject={subject}>
{subject}
</SubjectPill>
))}
{hasRepoData &&
data.repository.languages.nodes.map(
data.repository.language.nodes.map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering why this has changed 🤔

Currently I see an error breaking some pages. These two pages are loading but breaking after a second:

({ name }: { name: string }, idx: number) => (
<SubjectPill key={idx} subject={name}>
{name.toUpperCase()}
</SubjectPill>
)
)}
</SubjectContainer>
<StyledButtonLink h={20} to={url}>
</HStack>
<ButtonLink to={url} m={4} height={20}>
Open {name}
</StyledButtonLink>
</Card>
</ButtonLink>
</Flex>
)
}

Expand Down