-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-card): add custom cards for faceted search (#848)
* 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
Showing
16 changed files
with
635 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hashicorp/react-card": minor | ||
--- | ||
|
||
Add custom cards for faceted search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('|')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('|')) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
Oops, something went wrong.
7fc9e70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-components – ./
react-components.vercel.app
react-components-git-main-hashicorp.vercel.app
react-components-hashicorp.vercel.app