manifold/web/components/site-link.tsx
Sinclair Chen 8903b1ef95
Replace style props with tailwind classes (#800)
* add utility class for `word-break: break-word`

* refactor visuallyHidden style out of Page

* refactor out ref sizing hack in sidebar

* replace style props with tailwind classes
2022-08-26 14:23:06 -07:00

41 lines
935 B
TypeScript

import clsx from 'clsx'
import { ReactNode } from 'react'
import Link from 'next/link'
export const linkClass =
'z-10 break-anywhere hover:underline hover:decoration-indigo-400 hover:decoration-2'
export const SiteLink = (props: {
href: string
children?: ReactNode
onClick?: () => void
className?: string
}) => {
const { href, children, onClick, className } = props
return (
<MaybeLink href={href}>
<a
className={clsx(linkClass, className)}
href={href}
target={href.startsWith('http') ? '_blank' : undefined}
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>
)
}