generated from cfpb/open-source-project-template
-
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.
[Links] Show external-link icon where applicable (#768)
Close #765 ## Changes - feat: [Link] Programmatically determine `internal vs external` links and add icon where appropriate - Links to specific iRegs open in new tab - Links to specific FIG sections open in new tab - `mailto:` links are treated as `internal` - task: Ensure all instances of `<Link>` use the SBL Link for consistent styling and functionality - task: [Link] Refactor to simplify implied usage of RouterLink - task: [Link] Remove unnecessary usages of the `isRouterLink` prop - task: Overrides DS Notification styles to ensure icon colors consistently match link's status-based (visited, hover) styles --------- Co-authored-by: Tanner Ricks <182143365+tanner-ricks@users.noreply.github.com> Co-authored-by: S T <shindigira@gmail.com>
- Loading branch information
1 parent
84b452f
commit 267d021
Showing
13 changed files
with
117 additions
and
70 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
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,51 @@ | ||
import { Icon } from 'design-system-react'; | ||
import type { ReactElement } from 'react'; | ||
|
||
// Link to specific regulation | ||
// Ex: /rules-policy/regulations/1002/109/#a-1-ii | ||
const regsLinkPattern = /\/rules-policy\/regulations\/\d+\/\d+\/#.+/; | ||
|
||
// Link to specific FIG subsection | ||
// Ex: /small-business-lending/filing-instructions-guide/2024-guide/#4.4.1 | ||
const figLinkPattern = /\/filing-instructions-guide\/\d{4}-guide\/#.+/; | ||
|
||
/** | ||
* Programmatically determine if a link is external to the CFPB sphere of websites | ||
*/ | ||
export const isExternalLinkImplied = (targetUrl: string): boolean => { | ||
let parsed; | ||
|
||
try { | ||
parsed = new URL(targetUrl); | ||
} catch { | ||
return false; // Relative targets will fail parsing (ex. '/home') | ||
} | ||
|
||
const externalProtocols = ['http', 'tel:', 'sms:', 'ftp:']; | ||
if (externalProtocols.includes(parsed.protocol)) return true; | ||
|
||
const internalProtocols = ['mailto:']; | ||
if (internalProtocols.includes(parsed.protocol)) return false; | ||
|
||
// Any subdomain of consumerfinance.gov or the current host | ||
const isInternalDomain = new RegExp( | ||
`([\\S]*\\.)?(consumerfinance\\.gov|${window.location.host})`, | ||
).test(parsed.host); | ||
|
||
return !isInternalDomain; | ||
}; | ||
|
||
// External link icon w/ spacing | ||
export function IconExternalLink(): ReactElement { | ||
return ( | ||
<> | ||
{' '} | ||
<Icon name='external-link' className='link-icon-override-color' /> | ||
</> | ||
); | ||
} | ||
|
||
export function isNewTabImplied(href: string | undefined): boolean { | ||
if (!href) return false; | ||
return regsLinkPattern.test(href) || figLinkPattern.test(href); | ||
} |
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
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
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
3 changes: 2 additions & 1 deletion
3
src/pages/Filing/FilingApp/FilingErrors/FilingErrorsAlerts.tsx
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
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
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
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
3 changes: 2 additions & 1 deletion
3
src/pages/Filing/ViewInstitutionProfile/FinancialInstitutionDetails.tsx
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
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
3 changes: 2 additions & 1 deletion
3
src/pages/ProfileForm/Step1Form/AssociatedFinancialInstitutions.tsx
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
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