manifold/web/components/site-link.tsx
Forrest Wolf 1e0845f4b9
Replace some uses of any with more specific types (#344)
* Add tsconfig.json for common

* Prefer `const` over `let` over `var`

* Kill dead code

* Fix some trivial Typescript issues

* Turn on Typescript linting in common except for no-explicit-any

* Correctly specify tsconfig dir name in functions eslintrc

* Give react children explicit types

* Add explicit types to removeUndefinedProps

* Create StripeSession type

* Give event in Dropdown an explicit type

* Revert "Give event in Dropdown an explicit type"

This reverts commit 80604310f2.

* Give bids in NewBidTable an explicit type

* Cast results of removeUndefinedProps when neccessary

* Fix type of JoinSpans

* Revert "Cast results of removeUndefinedProps when neccessary"

This reverts commit 5541617bc8.

* Revert "Add explicit types to removeUndefinedProps"

This reverts commit ccf8ffb0b5.

* Give React children types everywhere

* Give event a type

* Give event correct type

* Lint

* Standardize React import

Co-authored-by: Marshall Polaris <marshall@pol.rs>
2022-05-26 15:22:44 -07:00

42 lines
989 B
TypeScript

import clsx from 'clsx'
import { ReactNode } from 'react'
import Link from 'next/link'
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(
'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>
)
}