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
|
||||
|
||||
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 +24,15 @@ export const SiteLink = (props: {
|
|||
>
|
||||
{children}
|
||||
</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