InlineLink.tsx44 lines · main
1import Link from 'next/link'
2import { type MouseEvent, type PropsWithChildren } from 'react'
3import { cn } from 'ui'
4
5interface InlineLinkProps {
6 href: string
7 className?: string
8 target?: string
9 rel?: string
10 title?: string
11 onClick?: (e: MouseEvent<HTMLAnchorElement>) => void
12}
13
14export const InlineLinkClassName =
15 'underline transition underline-offset-2 decoration-foreground-lighter hover:decoration-foreground text-inherit hover:text-foreground'
16
17export const InlineLink = ({
18 href,
19 className: _className,
20 children,
21 title,
22 ...props
23}: PropsWithChildren<InlineLinkProps>) => {
24 const className = cn(InlineLinkClassName, _className)
25 if (href.startsWith('http')) {
26 return (
27 <a
28 title={title}
29 className={className}
30 href={href}
31 target="_blank"
32 rel="noreferrer noopener"
33 {...props}
34 >
35 {children}
36 </a>
37 )
38 }
39 return (
40 <Link className={className} href={href} title={title} {...props}>
41 {children}
42 </Link>
43 )
44}