InlineLink.tsx 1.0 KB

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