-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(link): implement link component for utah design system
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PropTypes from 'prop-types'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import Icon from './Icon'; | ||
|
||
export default function Link({ className, href, external, children }) { | ||
return ( | ||
<a | ||
href={href} | ||
target={external ? '_blank' : '_self'} | ||
rel={external ? 'noopener noreferrer' : ''} | ||
className={twMerge( | ||
'inline-flex cursor-pointer items-center text-sky-600 hover:bg-slate-100 hover:text-sky-800', | ||
className | ||
)} | ||
> | ||
<span className="underline">{children}</span> | ||
{external ? ( | ||
<Icon | ||
className="ml-1" | ||
name={Icon.Names.externalLink} | ||
label="more info" | ||
size="xs" | ||
/> | ||
) : null} | ||
</a> | ||
); | ||
} | ||
|
||
Link.propTypes = { | ||
className: PropTypes.string, | ||
href: PropTypes.string.isRequired, | ||
external: PropTypes.bool, | ||
children: PropTypes.node.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Link from './Link'; | ||
|
||
export default { | ||
title: 'Utah Design System/Link', | ||
component: Link, | ||
}; | ||
|
||
export const Default = () => ( | ||
<> | ||
This is an external link{' '} | ||
<Link href="https://www.google.com" external> | ||
</Link> | ||
. Internal links <Link href="./test.html">look like this</Link>. | ||
</> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters