Skip to content

Commit

Permalink
add cards component
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman committed Oct 22, 2024
1 parent 50a0e3a commit 5d7d1de
Show file tree
Hide file tree
Showing 7 changed files with 506 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/AspectRatio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const EmbedAspectRatio = styled.div<{ $aspectRatio: string }>(
)

export const ImageAspectRatio = styled(EmbedAspectRatio)<{ $url: string }>(
({ $url }) => ({
({ theme, $url }) => ({
borderRadius: theme.borderRadiuses.large,
border: theme.borders['fill-three'],
backgroundSize: 'cover',
backgroundPosition: 'center',
backgroundImage: `url(${$url})`,
Expand Down
5 changes: 3 additions & 2 deletions src/components/custom-page/BlogCards.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type BlogCardsComponentFragment } from '@src/generated/graphqlDirectus'

export function BlogCards({ spacing }: BlogCardsComponentFragment) {
return <div>BlogCards</div>
export function BlogCards({ spacing: _spacing }: BlogCardsComponentFragment) {
// TODO
return null
}
2 changes: 1 addition & 1 deletion src/components/custom-page/CallToAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function CallToAction({
<section
className={cn(
getSpacingClassName(spacing),
'm-auto flex w-1/2 flex-col items-center gap-medium text-center'
'mx-auto flex w-1/2 flex-col items-center gap-medium text-center'
)}
>
<Hero2>{heading}</Hero2>
Expand Down
75 changes: 72 additions & 3 deletions src/components/custom-page/Cards.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
import { type CardsComponentFragment } from '@src/generated/graphqlDirectus'
import { Card } from '@pluralsh/design-system'

export function Cards({ spacing }: CardsComponentFragment) {
return <div>Cards</div>
import styled from 'styled-components'

import { getImageUrl } from '@src/consts/routes'
import {
type CardFragment,
type CardsComponentFragment,
} from '@src/generated/graphqlDirectus'
import { cn } from '@src/utils/cn'

import { ImageAspectRatio } from '../AspectRatio'
import { Body2, OverlineLabel } from '../Typography'

import { getSpacingClassName } from './common'

export function Cards({ spacing, cards }: CardsComponentFragment) {
return (
<section
className={cn(
getSpacingClassName(spacing),
'flex gap-xxlarge px-xxxlarge'
)}
>
{cards?.map((c) => c?.card_id && <CardComponent {...c?.card_id} />)}
</section>
)
}

export function CardComponent({
image,
heading,
body_text: bodyText,
url,
}: CardFragment) {
return (
<CardComponentWrapperSC
{...(url
? {
forwardedAs: 'a',
href: url,
target: '_blank',
rel: 'noopener noreferrer',
$clickable: true,
}
: {})}
>
<ImageAspectRatio
$aspectRatio="16/10"
$url={getImageUrl(image) ?? ''}
/>
<OverlineLabel>{heading}</OverlineLabel>
<Body2 $color="text">{bodyText}</Body2>
</CardComponentWrapperSC>
)
}

const CardComponentWrapperSC = styled(Card)<{ $clickable: boolean }>(
({ theme, $clickable }) => ({
display: 'flex',
flexDirection: 'column',
padding: theme.spacing.xlarge,
gap: theme.spacing.medium,
transition: 'border 0.16s ease-in-out',
...($clickable
? {
cursor: 'pointer',
'&:hover': {
border: theme.borders.selected,
},
}
: {}),
})
)
2 changes: 1 addition & 1 deletion src/components/custom-page/SectionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function SectionHeader({
<section
className={cn(
getSpacingClassName(spacing),
'm-auto flex w-1/2 flex-col items-center gap-medium text-center'
'mx-auto flex w-1/2 flex-col items-center gap-medium text-center'
)}
>
{overline && <OverlineLabel>{overline}</OverlineLabel>}
Expand Down
Loading

0 comments on commit 5d7d1de

Please sign in to comment.