Skip to content

Commit

Permalink
Organize and DRY React link component
Browse files Browse the repository at this point in the history
  • Loading branch information
kangaree committed Oct 25, 2024
1 parent b10322e commit da3e417
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions playbook/app/pb_kits/playbook/pb_link/_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const Link = (props: LinkProps): React.ReactElement => {
globalProps(props),
className
)
const Tag: keyof JSX.IntrinsicElements = `${tag}`
const Tag = tag as keyof JSX.IntrinsicElements

const content = (
const renderContent = () => (
<>
{icon && (
<Icon
Expand All @@ -76,32 +76,30 @@ const Link = (props: LinkProps): React.ReactElement => {
</>
)

const commonProps = {
...ariaProps,
...dataProps,
...htmlProps,
className: classes,
id,
}

if (tag === 'a') {
return (
<Tag
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
<a
{...commonProps}
href={href}
id={id}
>
{content}
</Tag>
{renderContent()}
</a>
)
} else {
return (
<a
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
{...commonProps}
href={href}
id={id}
>
<Tag>
{content}
</Tag>
<Tag>{renderContent()}</Tag>
</a>
)
}
Expand Down

0 comments on commit da3e417

Please sign in to comment.