Skip to content

Commit

Permalink
feat(react-card): add isExternal prop (#997)
Browse files Browse the repository at this point in the history
* feat: add isExternal prop to card component

* update: remove legacy behavior

* add prop to live component

* Create forty-paws-tease.md

* fix: pass prop down to component
  • Loading branch information
pbortnick committed Aug 16, 2023
1 parent c83f31a commit 33ace01
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/forty-paws-tease.md
@@ -0,0 +1,5 @@
---
"@hashicorp/react-card": minor
---

feat(react-card): add isExternal prop to allow card link to open in new tab
8 changes: 7 additions & 1 deletion packages/card/card.tsx
Expand Up @@ -14,9 +14,15 @@ function Card({
meta,
description,
productBadges,
isExternal,
}: CardProps) {
return (
<CardPrimitive.Card appearance={appearance} heading={heading} link={link}>
<CardPrimitive.Card
appearance={appearance}
heading={heading}
link={link}
isExternal={isExternal}
>
{thumbnail ? (
<CardPrimitive.Thumbnail src={thumbnail.src} alt={thumbnail.alt} />
) : null}
Expand Down
1 change: 1 addition & 0 deletions packages/card/docs.mdx
Expand Up @@ -20,6 +20,7 @@ A component used to promote and link to marketing pages, always using a descript
]}
heading="Display 5 - 4 lines with character limit of 130. Leo mauris fermentum pharetra blandit tellus euismod…"
description="Body small - 4 lines with character limit of 170. Leo mauris fermentum pharetra blandit tellus euismod pharetra. Duis egestas volutpat dolor…"
isExternal
/>
<Card
appearance="dark"
Expand Down
17 changes: 13 additions & 4 deletions packages/card/primitives.tsx
Expand Up @@ -27,8 +27,14 @@ const Card = React.forwardRef<HTMLAnchorElement, CardPrimitiveProps>(
withArrow = true,
heading,
link,
isExternal,
children,
} = props

const linkProps = isExternal
? { target: '_blank', rel: 'noopener noreferrer' }
: {}

return (
<div className={classNames(s.card, s[appearance])} data-testid="wpl-card">
<div className={s.contentContainer}>
Expand All @@ -38,10 +44,13 @@ const Card = React.forwardRef<HTMLAnchorElement, CardPrimitiveProps>(
{withArrow ? <IconArrowRight24 /> : null}
</div>

<Link href={link} legacyBehavior>
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a ref={ref} className={s.link} aria-label={heading} />
</Link>
<Link
href={link}
ref={ref}
className={s.link}
aria-label={heading}
{...linkProps}
/>
</div>
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions packages/card/props.js
Expand Up @@ -73,6 +73,11 @@ const baseProps = {
required: true,
testValue: 'https://hashicorp.com',
},
isExternal: {
type: 'boolean',
description: 'If true, card link opens in new tab',
required: false,
},
}

const thumbnailProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/card/types.ts
Expand Up @@ -19,6 +19,7 @@ export interface BaseCardProps {
withArrow?: boolean
heading: string
link: string
isExternal?: boolean
}

export interface CardPrimitiveProps extends BaseCardProps {
Expand Down

1 comment on commit 33ace01

@vercel
Copy link

@vercel vercel bot commented on 33ace01 Aug 16, 2023

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.