@hashicorp/react-components 0.0.0-nightly.ed6ac6e → 0.0.0-nightly.edea2ba

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashicorp/react-components",
3
- "version": "0.0.0-nightly.ed6ac6e",
3
+ "version": "0.0.0-nightly.edea2ba",
4
4
  "main": "src/index.ts",
5
5
  "scripts": {
6
6
  "lint": "next-hashicorp lint",
@@ -8,7 +8,7 @@
8
8
  "test:watch": "vitest watch"
9
9
  },
10
10
  "dependencies": {
11
- "@hashicorp/flight-icons": "^3.5.0",
11
+ "@hashicorp/flight-icons": "^3.7.0",
12
12
  "@hashicorp/platform-product-meta": "^0.1.1",
13
13
  "@hashicorp/platform-util": "^0.2.0",
14
14
  "@hashicorp/react-design-system-components": "*",
@@ -56,7 +56,7 @@ describe('<Card />', () => {
56
56
  const metaElement = screen.getByTestId('wpl-card-meta')
57
57
 
58
58
  cardMeta.forEach((item) => {
59
- expect(metaElement).toContainElement(screen.getByText(item))
59
+ expect(metaElement).toHaveTextContent(item)
60
60
  })
61
61
  expect(metaElement).toContainElement(screen.getByText('|'))
62
62
  })
@@ -26,7 +26,7 @@ describe('<NewsroomCard />', () => {
26
26
  const metaElement = screen.getByTestId('wpl-card-meta')
27
27
 
28
28
  expectedMeta.forEach((item) => {
29
- expect(metaElement).toContainElement(screen.getByText(item))
29
+ expect(metaElement).toHaveTextContent(item)
30
30
  })
31
31
 
32
32
  expect(metaElement).toContainElement(screen.queryByText('|'))
@@ -33,6 +33,7 @@ const Card = React.forwardRef<HTMLAnchorElement, CardPrimitiveProps>(
33
33
  hasBorder = true,
34
34
  children,
35
35
  className,
36
+ 'aria-label': ariaLabel,
36
37
  } = props
37
38
 
38
39
  const linkProps = isExternal
@@ -58,7 +59,7 @@ const Card = React.forwardRef<HTMLAnchorElement, CardPrimitiveProps>(
58
59
  href={link}
59
60
  ref={ref}
60
61
  className={s.link}
61
- aria-label={heading}
62
+ aria-label={ariaLabel ?? heading}
62
63
  onClickCapture={clickHandler}
63
64
  {...linkProps}
64
65
  />
@@ -100,23 +101,23 @@ function LogoThumbnail({ src, alt }: ThumbnailProps) {
100
101
 
101
102
  function Meta({ items }: MetaProps) {
102
103
  return (
103
- <ul className={s.meta} data-testid="wpl-card-meta">
104
- {items.map((item, stableIdx) => {
105
- return (
106
- // eslint-disable-next-line react/no-array-index-key
107
- <li key={stableIdx}>
108
- <TextPlus.Label>
104
+ <div className={s.meta} data-testid="wpl-card-meta">
105
+ <TextPlus.Label>
106
+ {items.map((item, stableIdx) => {
107
+ const isLastItem = stableIdx === items.length - 1
108
+ return (
109
+ <>
109
110
  {item}
110
- {stableIdx < items.length - 1 ? (
111
+ {!isLastItem ? (
111
112
  <span className={s.metaSeparator} aria-hidden={true}>
112
113
  |
113
114
  </span>
114
115
  ) : null}
115
- </TextPlus.Label>
116
- </li>
117
- )
118
- })}
119
- </ul>
116
+ </>
117
+ )
118
+ })}
119
+ </TextPlus.Label>
120
+ </div>
120
121
  )
121
122
  }
122
123
 
@@ -26,7 +26,7 @@ describe('<ResourceCard />', () => {
26
26
  const metaElement = screen.getByTestId('wpl-card-meta')
27
27
 
28
28
  expectedMeta.forEach((item) => {
29
- expect(metaElement).toContainElement(screen.getByText(item))
29
+ expect(metaElement).toHaveTextContent(item)
30
30
  })
31
31
 
32
32
  expect(metaElement).toContainElement(screen.getByText('|'))
@@ -10,14 +10,14 @@ import type { PersonCardProps } from './person-card'
10
10
  import type { ResourceCardProps } from './resource-card'
11
11
  import type { UnifiedCardProps } from './unified-card'
12
12
 
13
- export interface BaseCardProps {
13
+ export interface BaseCardProps
14
+ extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
14
15
  withArrow?: boolean
15
16
  heading: string
16
17
  link: string
17
18
  clickHandler?: () => void
18
19
  isExternal?: boolean
19
20
  hasBorder?: boolean
20
- className?: string
21
21
  }
22
22
 
23
23
  export interface CardPrimitiveProps extends BaseCardProps {
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) HashiCorp, Inc.
3
+ * SPDX-License-Identifier: MPL-2.0
4
+ */
5
+
6
+ import { render, screen } from '@testing-library/react'
7
+ import { UnifiedCard, UnifiedCardProps } from '.'
8
+
9
+ const defaultProps: UnifiedCardProps = {
10
+ link: 'https://hashicorp.com',
11
+ heading: 'Example heading',
12
+ thumbnail: {
13
+ src: 'https://www.datocms-assets.com/19447/1648680074-screenshot-2022-03-31-at-00-40-47.png',
14
+ alt: 'HashiConf Europe 2022 Recap',
15
+ },
16
+ } as const
17
+
18
+ describe(`<UnifiedCard />`, () => {
19
+ it('should render the provided meta with a separator if n > 1', () => {
20
+ const expectedMeta = ['Category', 'Hello']
21
+ render(<UnifiedCard {...defaultProps} meta={expectedMeta} />)
22
+
23
+ const metaElement = screen.getByTestId('wpl-card-meta')
24
+
25
+ expectedMeta.forEach((item) => {
26
+ expect(metaElement).toHaveTextContent(item)
27
+ })
28
+
29
+ expect(metaElement).toContainElement(screen.getByText('|'))
30
+ })
31
+
32
+ it('it should not render a separator if n === 1', () => {
33
+ render(<UnifiedCard {...defaultProps} meta={['Category']} />)
34
+ const metaElement = screen.getByTestId('wpl-card-meta')
35
+
36
+ expect(metaElement).toContainElement(screen.getByText('Category'))
37
+
38
+ expect(metaElement).not.toContainElement(screen.queryByText('|'))
39
+ })
40
+ })
@@ -6,18 +6,10 @@
6
6
  import type { ReactNode } from 'react'
7
7
  import Badge from '@hashicorp/react-design-system-components/src/components/badge'
8
8
  import * as CardPrimitives from '../primitives'
9
- import type { CardProps, ThumbnailProps } from '../types'
9
+ import type { CardProps } from '../types'
10
10
 
11
- export interface UnifiedCardProps {
12
- heading: string
13
- meta?: string[]
14
- link: string
15
- productBadges?: CardProps['productBadges']
11
+ export interface UnifiedCardProps extends CardProps {
16
12
  badges?: (string | [ReactNode, string])[]
17
- thumbnail?: ThumbnailProps
18
- withArrow?: boolean
19
- isExternal?: boolean
20
- className?: string
21
13
  }
22
14
 
23
15
  export function UnifiedCard({
@@ -30,6 +22,7 @@ export function UnifiedCard({
30
22
  withArrow = false,
31
23
  isExternal = false,
32
24
  className,
25
+ 'aria-label': ariaLabel,
33
26
  }: UnifiedCardProps) {
34
27
  return (
35
28
  <CardPrimitives.Card
@@ -38,6 +31,7 @@ export function UnifiedCard({
38
31
  withArrow={withArrow}
39
32
  isExternal={isExternal}
40
33
  className={className}
34
+ aria-label={ariaLabel ?? heading}
41
35
  >
42
36
  {thumbnail ? <CardPrimitives.Thumbnail {...thumbnail} /> : null}
43
37
  <CardPrimitives.Content>