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

Migrated ActionCard.js to TS #6512

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
98 changes: 0 additions & 98 deletions src/components/ActionCard.js

This file was deleted.

112 changes: 112 additions & 0 deletions src/components/ActionCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import React from "react"
import styled from "styled-components"
import { GatsbyImage } from "gatsby-plugin-image"

import Link from "./Link"

const Content = styled.div`
padding: 1.5rem;
`

const Description = styled.p`
opacity: 0.8;
margin-bottom: 0rem;
`

const ChildrenContainer = styled.div`
margin-top: 2rem;
`

const ImageWrapper = styled.div<{
isRight: boolean | undefined
isBottom: boolean | undefined
}>`
display: flex;
flex-direction: row;
justify-content: ${(props) => (props.isRight ? `flex-end` : `center`)};
align-items: ${(props) => (props.isBottom ? `flex-end` : `center`)};
background: ${(props) => props.theme.colors.cardGradient};
box-shadow: inset 0px -1px 0px rgba(0, 0, 0, 0.1);
min-height: 260px;
`

const Title = styled.h3`
margin-top: 0.5rem;
margin-bottom: 1rem;
`

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

const Card = styled(Link)`
text-decoration: none;
flex: 1 1 372px;
color: ${(props) => props.theme.colors.text};
box-shadow: 0px 14px 66px rgba(0, 0, 0, 0.07),
0px 10px 17px rgba(0, 0, 0, 0.03), 0px 4px 7px rgba(0, 0, 0, 0.05);
margin: 1rem;

&:hover,
&:focus {
border-radius: 4px;
box-shadow: 0px 8px 17px rgba(0, 0, 0, 0.15);
background: ${(props) => props.theme.colors.tableBackgroundHover};
transition: transform 0.1s;
transform: scale(1.02);
}
`

export interface IProps {
Copy link
Member

Choose a reason for hiding this comment

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

You made everything optional but there are some props that we do want to make them as required.
How about this?

export interface IProps {
  to: string
  alt?: string
  image: string
  title: string
  description: string
  className?: string
  isRight?: boolean
  isBottom?: boolean
}

to: string
alt?: string
image: string
title: string
description: string
className?: string
isRight?: boolean
isBottom?: boolean
}

const ActionCard: React.FC<IProps> = ({
to,
alt,
image,
title,
description,
children,
className,
isRight,
isBottom = true
}) => {
hursittarcan marked this conversation as resolved.
Show resolved Hide resolved
const isImageURL = typeof image === "string" && image.includes("http")
return (
<Card to={to} className={className} hideArrow={true}>
<ImageWrapper
isRight={isRight}
isBottom={isBottom}
className="action-card-image-wrapper"
>
{!isImageURL && <Image image={image} alt={alt} />}
{isImageURL && (
<img src={image} alt={alt} className="action-card-image" />
)}
</ImageWrapper>
<Content className="action-card-content">
<Title>{title}</Title>
<Description>{description}</Description>
{children && <ChildrenContainer>{children}</ChildrenContainer>}
</Content>
</Card>
)
}

export default ActionCard