-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: small changes + custom anchor element
- Loading branch information
Showing
5 changed files
with
44 additions
and
11 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
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,32 @@ | ||
import { cn, openExternalLink } from "@/lib/utils"; | ||
import { ExternalLinkIcon } from "lucide-react"; | ||
import { useLocation } from "wouter"; | ||
|
||
export default function TxAnchor({ children, href, className, rel, ...rest }: React.AnchorHTMLAttributes<HTMLAnchorElement>) { | ||
const setLocation = useLocation()[1]; | ||
const isExternal = href?.startsWith('http'); | ||
const onClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => { | ||
if (!href) return; | ||
e.preventDefault(); | ||
if (isExternal) { | ||
openExternalLink(href); | ||
} else { | ||
setLocation(href ?? '/'); | ||
} | ||
} | ||
return ( | ||
<a | ||
{...rest} | ||
rel={rel ?? 'noopener noreferrer'} | ||
href={href} | ||
className={cn("text-accent no-underline hover:underline ml-1 mr-0 cursor-pointer", className)} | ||
onClick={onClick} | ||
> | ||
{children} | ||
{isExternal && | ||
<ExternalLinkIcon | ||
className="inline ml-1 mb-1 h-5 [.text-sm_&]:h-4 [.text-sm_&]:ml-0" | ||
/>} | ||
</a> | ||
); | ||
} |
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