Skip to content

Commit d3e15e4

Browse files
committed
feat(Link): external links now have an icon
1 parent d0ac435 commit d3e15e4

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

workspaces/core/scss/components/_link.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@
3131
pointer-events: none;
3232
text-decoration: line-through;
3333
}
34+
35+
&[target="_blank"]:not(&.#{$shale}-no-icon),
36+
&.#{$shale}-external {
37+
&::after {
38+
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'%3E%3C!--! Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --%3E%3Cpath d='M256 64C256 46.33 270.3 32 288 32H415.1C415.1 32 415.1 32 415.1 32C420.3 32 424.5 32.86 428.2 34.43C431.1 35.98 435.5 38.27 438.6 41.3C438.6 41.35 438.6 41.4 438.7 41.44C444.9 47.66 447.1 55.78 448 63.9C448 63.94 448 63.97 448 64V192C448 209.7 433.7 224 416 224C398.3 224 384 209.7 384 192V141.3L214.6 310.6C202.1 323.1 181.9 323.1 169.4 310.6C156.9 298.1 156.9 277.9 169.4 265.4L338.7 96H288C270.3 96 256 81.67 256 64V64zM0 128C0 92.65 28.65 64 64 64H160C177.7 64 192 78.33 192 96C192 113.7 177.7 128 160 128H64V416H352V320C352 302.3 366.3 288 384 288C401.7 288 416 302.3 416 320V416C416 451.3 387.3 480 352 480H64C28.65 480 0 451.3 0 416V128z'/%3E%3C/svg%3E")
39+
no-repeat center;
40+
background-color: currentColor;
41+
color: currentColor;
42+
content: "(opens in new tab)";
43+
display: inline;
44+
font-size: 0;
45+
padding: var(--#{$shale}font--3) var(--#{$shale}font--2);
46+
vertical-align: bottom;
47+
}
48+
}
3449
}

workspaces/react/reports/react.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface BaseHeaderProps {
3434

3535
// @alpha (undocumented)
3636
export interface BaseLinkProps {
37+
isExternal?: boolean;
3738
state?: StateVariant;
3839
}
3940

workspaces/react/src/components/Link.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import { css } from "../utils/css";
66
export interface BaseLinkProps {
77
/** The initial state of the link (if you want to force a specific state) */
88
state?: StateVariant;
9+
/** Shows an external link icon */
10+
isExternal?: boolean;
911
}
1012

1113
/**
1214
* A link component.
1315
*
16+
* External links (links with `target="_blank"`) will automatically show an external link icon, but you can also
17+
* explicitly set `isExternal` to `true` to show the icon, or set it to `false` to hide the icon.
18+
*
1419
* @example Basic link
1520
*
1621
* ```tsx
@@ -20,23 +25,34 @@ export interface BaseLinkProps {
2025
* @example Link with forced state
2126
*
2227
* ```tsx
23-
* <Link href="/page" state="hover">
28+
* <Link href="/" state="hover">
2429
* Hovered Link
2530
* </Link>;
2631
* ```
2732
*
33+
* @example External link
34+
*
35+
* ```tsx
36+
* <Link href="https://example.com" state="hover" target="_blank" rel="noopener noreferrer">
37+
* Go to Example
38+
* </Link>;
39+
* ```
40+
*
2841
* @alpha
2942
*/
3043
export const Link: PolymorphicComponent<"a", BaseLinkProps> = ({
3144
Component = "a",
3245
state,
46+
isExternal,
3347
...props
3448
}) => (
3549
<Component
3650
{...props}
3751
className={css(
3852
"shale-v1-link",
3953
{ [`shale-v1--${state}`]: state },
54+
{ "shale-v1--external": isExternal === true },
55+
{ "shale-v1--no-icon": isExternal === false },
4056
props?.className,
4157
)}
4258
/>

0 commit comments

Comments
 (0)