Skip to content

Commit 906ba2c

Browse files
authored
Merge dd8b04a into 5974f08
2 parents 5974f08 + dd8b04a commit 906ba2c

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

.changeset/old-comics-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hashicorp/react-card': minor
3+
---
4+
5+
Makes the `date` prop optional, preventing it and the `|` separator from rendering if not set.

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/card/docs.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ A component used to promote and link to marketing pages, always using a descript
316316
appearance="dark"
317317
heading="Display 5 - 4 lines with character limit of 130. Leo mauris fermentum pharetra blandit tellus"
318318
category="Category"
319-
date="August 15, 2022"
320319
thumbnail={{
321320
src: 'https://www.datocms-assets.com/19447/1648680074-screenshot-2022-03-31-at-00-40-47.png',
322321
alt: 'HashiConf Europe 2022 Recap',

packages/card/resource-card/index.test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaultProps = {
1818
}
1919

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

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

3232
expect(metaElement).toContainElement(screen.getByText('|'))
3333
})
34+
35+
it('should not render the date if no date is provided', () => {
36+
const defaultPropsWithoutDate = { ...defaultProps, date: '' }
37+
38+
render(<ResourceCard {...defaultPropsWithoutDate} />)
39+
40+
const metaElement = screen.getByTestId('wpl-card-meta')
41+
42+
expect(metaElement).toContainElement(
43+
screen.getByText(defaultProps.category)
44+
)
45+
46+
expect(metaElement).not.toContainElement(screen.queryByText('|'))
47+
})
3448
})

packages/card/resource-card/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { CardProps, ThumbnailProps } from '../types'
88

99
export interface ResourceCardProps {
1010
heading: string
11-
date: string
11+
date?: string
1212
category: string
1313
link: string
1414
productBadges?: CardProps['productBadges']
@@ -25,6 +25,8 @@ export function ResourceCard({
2525
thumbnail,
2626
appearance,
2727
}: ResourceCardProps): JSX.Element {
28+
const meta: string[] = date ? [date, category] : [category]
29+
2830
return (
2931
<CardPrimitives.Card
3032
heading={heading}
@@ -34,7 +36,7 @@ export function ResourceCard({
3436
>
3537
<CardPrimitives.Thumbnail {...thumbnail} />
3638
<CardPrimitives.Content>
37-
<CardPrimitives.Meta items={[date, category]} />
39+
<CardPrimitives.Meta items={meta} />
3840
<CardPrimitives.Heading>{heading}</CardPrimitives.Heading>
3941
{productBadges && productBadges?.length > 0 ? (
4042
<CardPrimitives.ProductBadges

0 commit comments

Comments
 (0)