420ea9e90e
* Import React a lot * Fix misc. linting concerns * Turn on many recommended lints for `web` package
42 lines
983 B
TypeScript
42 lines
983 B
TypeScript
import clsx from 'clsx'
|
|
import { ReactNode } from 'react'
|
|
import Link from 'next/link'
|
|
|
|
export const SiteLink = (props: {
|
|
href: string
|
|
children?: any
|
|
onClick?: () => void
|
|
className?: string
|
|
}) => {
|
|
const { href, children, onClick, className } = props
|
|
|
|
return (
|
|
<MaybeLink href={href}>
|
|
<a
|
|
className={clsx(
|
|
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
|
className
|
|
)}
|
|
href={href}
|
|
target={href.startsWith('http') ? '_blank' : undefined}
|
|
style={{ /* For iOS safari */ wordBreak: 'break-word' }}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
if (onClick) onClick()
|
|
}}
|
|
>
|
|
{children}
|
|
</a>
|
|
</MaybeLink>
|
|
)
|
|
}
|
|
|
|
function MaybeLink(props: { href: string; children: ReactNode }) {
|
|
const { href, children } = props
|
|
return href.startsWith('http') ? (
|
|
<>{children}</>
|
|
) : (
|
|
<Link href={href}>{children}</Link>
|
|
)
|
|
}
|