2021-12-30 20:03:32 +00:00
|
|
|
import clsx from 'clsx'
|
2022-05-26 21:41:24 +00:00
|
|
|
import { ReactNode } from 'react'
|
2021-12-30 20:03:32 +00:00
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
export const SiteLink = (props: {
|
|
|
|
href: string
|
2022-05-26 22:22:44 +00:00
|
|
|
children?: ReactNode
|
2022-04-19 05:16:08 +00:00
|
|
|
onClick?: () => void
|
2021-12-30 20:03:32 +00:00
|
|
|
className?: string
|
|
|
|
}) => {
|
2022-04-19 05:16:08 +00:00
|
|
|
const { href, children, onClick, className } = props
|
2021-12-30 20:03:32 +00:00
|
|
|
|
2022-05-17 17:36:36 +00:00
|
|
|
return (
|
|
|
|
<MaybeLink href={href}>
|
2021-12-30 20:03:32 +00:00
|
|
|
<a
|
|
|
|
className={clsx(
|
2022-02-18 01:16:58 +00:00
|
|
|
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
2021-12-30 20:03:32 +00:00
|
|
|
className
|
|
|
|
)}
|
2022-05-17 21:11:15 +00:00
|
|
|
href={href}
|
|
|
|
target={href.startsWith('http') ? '_blank' : undefined}
|
2022-02-15 02:27:43 +00:00
|
|
|
style={{ /* For iOS safari */ wordBreak: 'break-word' }}
|
2022-04-19 05:16:08 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation()
|
|
|
|
if (onClick) onClick()
|
|
|
|
}}
|
2021-12-30 20:03:32 +00:00
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</a>
|
2022-05-17 17:36:36 +00:00
|
|
|
</MaybeLink>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-26 21:41:24 +00:00
|
|
|
function MaybeLink(props: { href: string; children: ReactNode }) {
|
2022-05-17 17:36:36 +00:00
|
|
|
const { href, children } = props
|
|
|
|
return href.startsWith('http') ? (
|
|
|
|
<>{children}</>
|
|
|
|
) : (
|
|
|
|
<Link href={href}>{children}</Link>
|
2021-12-30 20:03:32 +00:00
|
|
|
)
|
|
|
|
}
|