refactor SiteLink to not repeat (#125)
This commit is contained in:
parent
f8601af45c
commit
1bf2073e61
|
@ -9,24 +9,8 @@ export const SiteLink = (props: {
|
||||||
}) => {
|
}) => {
|
||||||
const { href, children, onClick, className } = props
|
const { href, children, onClick, className } = props
|
||||||
|
|
||||||
return href.startsWith('http') ? (
|
return (
|
||||||
<a
|
<MaybeLink href={href}>
|
||||||
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}>
|
|
||||||
<a
|
<a
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
'z-10 break-words hover:underline hover:decoration-indigo-400 hover:decoration-2',
|
||||||
|
@ -40,6 +24,15 @@ export const SiteLink = (props: {
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</a>
|
</a>
|
||||||
</Link>
|
</MaybeLink>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function MaybeLink(props: { href: string; children: React.ReactNode }) {
|
||||||
|
const { href, children } = props
|
||||||
|
return href.startsWith('http') ? (
|
||||||
|
<>{children}</>
|
||||||
|
) : (
|
||||||
|
<Link href={href}>{children}</Link>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user