Skip to content

Commit c8c6b38

Browse files
committed
feat(Button): Show indicator icon for external URLs
1 parent ce9ab04 commit c8c6b38

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/components/ui/button/button.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "react"
77

88
import { cva, type VariantProps } from "class-variance-authority"
9+
import { ExternalLink } from "lucide-react"
910
import { Link } from "wouter"
1011

1112
import { Slot } from "components/utility/slot"
@@ -22,6 +23,9 @@ import { interactive, InteractiveProps } from "utils/styles"
2223
import { Icon, IconProps } from "../icon"
2324
import { Spinner } from "../spinner"
2425

26+
const isExternalLink = (href?: string) =>
27+
href && URL.canParse(href) && !href.includes(window.location.origin)
28+
2529
const button = cva(
2630
cn(
2731
"relative inline-flex shrink-0 items-center justify-center rounded-md text-sm font-medium whitespace-nowrap"
@@ -105,6 +109,14 @@ export const Button = ({
105109
/>
106110
) : null}
107111
{children}
112+
{isExternalLink(props.href) && (
113+
<Icon
114+
icon={ExternalLink}
115+
size="xs"
116+
color="muted"
117+
className="absolute top-0.5 right-0.5 size-2.5!"
118+
/>
119+
)}
108120
</Comp>
109121
)
110122
}

0 commit comments

Comments
 (0)