Skip to content

Commit

Permalink
feat: add support for generic links for PersonCard (#876)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley committed Mar 8, 2023
1 parent 236e903 commit a5be4e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-walls-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/react-card': minor
---

Add support for generic links for PersonCard
7 changes: 7 additions & 0 deletions packages/card/person-card/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('<PersonCard />', () => {
github: 'https://github.com',
twitter: 'https://twitter.com',
linkedin: 'https://linkedin.com',
link: 'https://example.com',
}

render(
Expand All @@ -60,4 +61,10 @@ describe('<PersonCard />', () => {
screen.getByTestId(`wpl-personcard-${platform}-icon`)
})
})

it('should not render a thumbnail icon when link is on hashicorp.com', () => {
render(<PersonCard {...defaultProps} link="https://hashicorp.com" />)

expect(screen.queryByTestId('wpl-personcard-link-icon')).toBeNull()
})
})
11 changes: 8 additions & 3 deletions packages/card/person-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as CardPrimitives from '../primitives'
import { IconGithub16 } from '@hashicorp/flight-icons/svg-react/github-16'
import { IconTwitter16 } from '@hashicorp/flight-icons/svg-react/twitter-16'
import { IconLinkedin16 } from '@hashicorp/flight-icons/svg-react/linkedin-16'
import { IconLink16 } from '@hashicorp/flight-icons/svg-react/link-16'
import s from './style.module.css'

export interface PersonCardProps {
Expand All @@ -20,8 +21,12 @@ export interface PersonCardProps {
productBadges?: ProductBadgesProps['badges']
}

function Icon({ url }) {
let icon
function Icon({ url }: { url: string }) {
if (url.includes('hashicorp.com')) {
return null
}

let icon = <IconLink16 data-testid={'wpl-personcard-link-icon'} />
if (url.includes('twitter')) {
icon = <IconTwitter16 data-testid={'wpl-personcard-twitter-icon'} />
}
Expand All @@ -32,7 +37,7 @@ function Icon({ url }) {
icon = <IconLinkedin16 data-testid={'wpl-personcard-linkedin-icon'} />
}

return icon ? <div className={s.thumbnailIcon}>{icon}</div> : null
return <div className={s.thumbnailIcon}>{icon}</div>
}

export function PersonCard({
Expand Down

1 comment on commit a5be4e8

@vercel
Copy link

@vercel vercel bot commented on a5be4e8 Mar 8, 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.