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

feat(card): Make date optional on <ResourceCard /> #1001

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/old-comics-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-card': minor
---

Makes the `date` prop optional, preventing it and the `|` separator from rendering if not set.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/card/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ A component used to promote and link to marketing pages, always using a descript
appearance="dark"
heading="Display 5 - 4 lines with character limit of 130. Leo mauris fermentum pharetra blandit tellus"
category="Category"
date="August 15, 2022"
thumbnail={{
src: 'https://www.datocms-assets.com/19447/1648680074-screenshot-2022-03-31-at-00-40-47.png',
alt: 'HashiConf Europe 2022 Recap',
Expand Down
16 changes: 15 additions & 1 deletion packages/card/resource-card/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const defaultProps = {
}

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

render(<ResourceCard {...defaultProps} />)
Expand All @@ -31,4 +31,18 @@ describe('<ResourceCard />', () => {

expect(metaElement).toContainElement(screen.getByText('|'))
})

it('should not render the date if no date is provided', () => {
const defaultPropsWithoutDate = { ...defaultProps, date: '' }

render(<ResourceCard {...defaultPropsWithoutDate} />)

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

expect(metaElement).toContainElement(
screen.getByText(defaultProps.category)
)

expect(metaElement).not.toContainElement(screen.queryByText('|'))
})
})
6 changes: 4 additions & 2 deletions packages/card/resource-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { CardProps, ThumbnailProps } from '../types'

export interface ResourceCardProps {
heading: string
date: string
date?: string
category: string
link: string
productBadges?: CardProps['productBadges']
Expand All @@ -25,6 +25,8 @@ export function ResourceCard({
thumbnail,
appearance,
}: ResourceCardProps): JSX.Element {
const meta: string[] = date ? [date, category] : [category]

return (
<CardPrimitives.Card
heading={heading}
Expand All @@ -34,7 +36,7 @@ export function ResourceCard({
>
<CardPrimitives.Thumbnail {...thumbnail} />
<CardPrimitives.Content>
<CardPrimitives.Meta items={[date, category]} />
<CardPrimitives.Meta items={meta} />
<CardPrimitives.Heading>{heading}</CardPrimitives.Heading>
{productBadges && productBadges?.length > 0 ? (
<CardPrimitives.ProductBadges
Expand Down
Loading