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 3895785
Show file tree
Hide file tree
Showing 4 changed files with 501 additions and 9 deletions.
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
}
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,
},
}
: {}),
})
)
Loading

0 comments on commit 3895785

Please sign in to comment.