refactor SiteLink to not repeat
This commit is contained in:
parent
abf23a1462
commit
cf62711c24
|
@ -1,5 +1,6 @@
|
|||
import clsx from 'clsx'
|
||||
import Link from 'next/link'
|
||||
import { Children } from 'react'
|
||||
|
||||
export const SiteLink = (props: {
|
||||
href: string
|
||||
|
@ -9,24 +10,8 @@ export const SiteLink = (props: {
|
|||
}) => {
|
||||
const { href, children, onClick, className } = props
|
||||
|
||||
return href.startsWith('http') ? (
|
||||
<a
|
||||
href={href}
|
||||
className={clsx(
|
||||
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
||||
className
|
||||
)}
|
||||
style={{ /* For iOS safari */ wordBreak: 'break-word' }}
|
||||
target="_blank"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (onClick) onClick()
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
) : (
|
||||
<Link href={href}>
|
||||
return (
|
||||
<MaybeLink href={href}>
|
||||
<a
|
||||
className={clsx(
|
||||
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
||||
|
@ -40,6 +25,15 @@ export const SiteLink = (props: {
|
|||
>
|
||||
{children}
|
||||
</a>
|
||||
</Link>
|
||||
</MaybeLink>
|
||||
)
|
||||
}
|
||||
|
||||
function MaybeLink(props: { href: string; children: any }) {
|
||||
const { href, children } = props
|
||||
return href.startsWith('http') ? (
|
||||
children
|
||||
) : (
|
||||
<Link href={href}>{children}</Link>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user