Skip to content

Commit

Permalink
[Links] Show external-link icon where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
meissadia committed Oct 9, 2024
1 parent a4aaaac commit ce2d3b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/components/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// this component could potentially be lifted with others into the DSR in a later refactor
// see: https://github.com/cfpb/sbl-frontend/issues/200

import type { LinkProperties as DesignSystemReactLinkProperties } from 'design-system-react';
import {
Link as DesignSystemReactLink,
ListLink as DesignSystemReactListLink,
} from 'design-system-react';
import { Link as DesignSystemReactLink, LinkProperties as DesignSystemReactLinkProperties, ListLink as DesignSystemReactListLink, Icon } from 'design-system-react';

const getIsLinkExternal = (url: string | undefined): boolean => {
if (url === undefined) {
Expand Down Expand Up @@ -59,15 +55,23 @@ export function Link({
const isInternalLink = getIsRouterLink(href, isRouterLink);
const otherProperties: LinkProperties = { ...others };

if (!isInternalLink) otherProperties.target = '_blank'; // Open link in new tab
let icon = null
if (!isInternalLink) {
otherProperties.target = '_blank'; // Open link in new tab
icon =<>
{' '}<Icon name="external-link" className='link-icon-override-color' />
</>
}

return (
<DesignSystemReactLink
href={href}
isRouterLink={isInternalLink}
hasIcon={!isInternalLink}
{...otherProperties}
>
{children}
{icon}
</DesignSystemReactLink>
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ td:last-child{
td {
background-color: white !important;
}

/* Design System overrides */

/* Alerts - all icons in DS Alerts are colored based on the Alert type */
a .link-icon-override-color .cf-icon-svg{
@apply fill-pacific;
}

a:visited .link-icon-override-color .cf-icon-svg {
@apply fill-teal;
}

a:hover .link-icon-override-color .cf-icon-svg {
@apply !fill-pacificDark;
}

0 comments on commit ce2d3b0

Please sign in to comment.