Skip to content

Commit

Permalink
feat(react-card): add custom cards for faceted search (#848)
Browse files Browse the repository at this point in the history
* update: add blog card

* update: add career card

* update: add customer story card

* update: add newsroom card

* update: add partner card

* update: add resource card

* feat: start adding cards to docs

* update: add all card tpyes to docs

* update: date prop type

* feat: add tests

* fix: export types

* Create thick-mice-rule.md

* fix: remove bottom class and add appearance prop

* update card wpl color
  • Loading branch information
pbortnick committed Dec 16, 2022
1 parent f7c31b7 commit 7fc9e70
Show file tree
Hide file tree
Showing 16 changed files with 635 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-mice-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashicorp/react-card": minor
---

Add custom cards for faceted search
30 changes: 30 additions & 0 deletions packages/card/blog-card/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render, screen } from '@testing-library/react'
import { BlogCard } from '.'

const defaultProps = {
link: 'https://hashicorp.com',
heading: 'Example heading',
description: 'Example Description',
date: 'August 15, 2022',
category: 'Category',
thumbnail: {
src: 'https://www.datocms-assets.com/19447/1648680074-screenshot-2022-03-31-at-00-40-47.png',
alt: 'HashiConf Europe 2022 Recap',
},
}

describe('<BlogCard />', () => {
it('should render the provided metadata correctly', () => {
const expectedMeta = [defaultProps.date, defaultProps.category]

render(<BlogCard {...defaultProps} />)

const metaElement = screen.getByTestId('wpl-card-meta')

expectedMeta.forEach((item) => {
expect(metaElement).toContainElement(screen.getByText(item))
})

expect(metaElement).toContainElement(screen.getByText('|'))
})
})
43 changes: 43 additions & 0 deletions packages/card/blog-card/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as CardPrimitives from '../primitives'
import type { CardProps } from '../types'

export interface BlogCardProps {
heading: string
description: string
date: string
category: string
link: string
productBadges?: CardProps['productBadges']
appearance?: CardProps['appearance']
}

export function BlogCard({
heading,
description,
date,
category,
link,
productBadges,
appearance,
}: BlogCardProps): JSX.Element {
return (
<CardPrimitives.Card
heading={heading}
link={link}
withArrow={false}
appearance={appearance}
>
<CardPrimitives.Content>
<CardPrimitives.Meta items={[date, category]} />
<CardPrimitives.Heading>{heading}</CardPrimitives.Heading>
<CardPrimitives.Description>{description}</CardPrimitives.Description>
{productBadges && productBadges?.length > 0 ? (
<CardPrimitives.ProductBadges
badges={productBadges}
appearance={appearance}
/>
) : null}
</CardPrimitives.Content>
</CardPrimitives.Card>
)
}
29 changes: 29 additions & 0 deletions packages/card/career-card/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render, screen } from '@testing-library/react'
import { CareerCard } from '.'

const defaultProps = {
link: 'https://hashicorp.com',
heading: 'Example heading',
workplaceType: 'Remote',
location: 'Example Location',
thumbnail: {
src: 'https://www.datocms-assets.com/19447/1648680074-screenshot-2022-03-31-at-00-40-47.png',
alt: 'HashiConf Europe 2022 Recap',
},
}

describe('<CareerCard />', () => {
it('should render the provided metadata correctly', () => {
const expectedMeta = [defaultProps.workplaceType]

render(<CareerCard {...defaultProps} />)

const metaElement = screen.getByTestId('wpl-card-meta')

expectedMeta.forEach((item) => {
expect(metaElement).toContainElement(screen.getByText(item))
})

expect(metaElement).not.toContainElement(screen.queryByText('|'))
})
})
42 changes: 42 additions & 0 deletions packages/card/career-card/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as CardPrimitives from '../primitives'
import type { CardProps } from '../types'
import s from './style.module.css'

export interface CareerCardProps {
heading: string
workplaceType: string
location: string
link: string
productBadges?: CardProps['productBadges']
appearance?: CardProps['appearance']
}

export function CareerCard({
heading,
workplaceType,
location,
link,
productBadges,
appearance,
}: CareerCardProps) {
return (
<CardPrimitives.Card
heading={heading}
link={link}
withArrow={false}
appearance={appearance}
>
<CardPrimitives.Content>
<CardPrimitives.Meta items={[workplaceType]} />
<p className={s.subHeading}>{location}</p>
<CardPrimitives.Heading>{heading}</CardPrimitives.Heading>
{productBadges && productBadges?.length > 0 ? (
<CardPrimitives.ProductBadges
badges={productBadges}
appearance={appearance}
/>
) : null}
</CardPrimitives.Content>
</CardPrimitives.Card>
)
}
11 changes: 11 additions & 0 deletions packages/card/career-card/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.bottom {
display: flex;
align-items: flex-end;
height: 100%;
}

.subHeading {
composes: g-type-body-small-x-strong from global;
margin: 0;
color: var(--secondary-text-color);
}
41 changes: 41 additions & 0 deletions packages/card/customer-story-card/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as CardPrimitives from '../primitives'
import type { CardProps, ThumbnailProps } from '../types'

export interface CustomerStoryCardProps {
heading: string
category: string
link: string
productBadges?: CardProps['productBadges']
thumbnail: ThumbnailProps
appearance?: CardProps['appearance']
}

export function CustomerStoryCard({
heading,
category,
link,
thumbnail,
productBadges,
appearance,
}: CustomerStoryCardProps): JSX.Element {
return (
<CardPrimitives.Card
heading={heading}
link={link}
withArrow={false}
appearance={appearance}
>
<CardPrimitives.Thumbnail {...thumbnail} />
<CardPrimitives.Content>
<CardPrimitives.Meta items={[category]} />
<CardPrimitives.Heading>{heading}</CardPrimitives.Heading>
{productBadges && productBadges?.length > 0 ? (
<CardPrimitives.ProductBadges
badges={productBadges}
appearance={appearance}
/>
) : null}
</CardPrimitives.Content>
</CardPrimitives.Card>
)
}
Loading

1 comment on commit 7fc9e70

@vercel
Copy link

@vercel vercel bot commented on 7fc9e70 Dec 16, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.