skolplattformen-backup/apps/website/components/ButtonLink.tsx

57 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2021-05-17 05:09:33 +00:00
import classNames from 'classnames'
2021-03-30 09:45:16 +00:00
import Link from 'next/link'
2021-05-17 05:09:33 +00:00
import { AnchorHTMLAttributes, DetailedHTMLProps } from 'react'
2021-03-30 09:45:16 +00:00
type ButtonLinkProps = DetailedHTMLProps<
AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
>
2021-03-30 18:34:40 +00:00
const ButtonLink: React.FC<ButtonLinkProps> = ({
children,
className,
href,
target,
}) => {
const isExternal = href?.indexOf('//') !== -1
2021-05-17 05:09:33 +00:00
const inner = (
<a
2021-05-17 05:09:33 +00:00
href={isExternal ? href : undefined}
className={classNames(
'inline-block py-2 px-4 md:px-8 md:py-4 font-bold text-indigo-800 border-2 border-indigo-800 rounded-full hover:bg-indigo-800 dark:hover:bg-indigo-400 hover:text-white dark:text-indigo-400 dark:border-indigo-400',
className
)}
target={target}
rel={target === '_blank' ? 'noopener noreferrer' : ''}
>
{children}
</a>
)
2021-05-17 05:09:33 +00:00
if (isExternal || !href) {
return inner
}
2021-03-30 18:34:40 +00:00
return (
2021-05-17 05:09:33 +00:00
<Link href={href} passHref>
{inner}
2021-03-30 09:45:16 +00:00
</Link>
)
}
export const ButtonLinkPatreon: React.FC = ({ children }) => {
2021-04-21 17:21:15 +00:00
return (
2021-05-17 05:09:33 +00:00
<ButtonLink
2021-04-21 17:21:15 +00:00
href="https://www.patreon.com/oppnaskolplattformen"
2021-05-17 05:09:33 +00:00
className="!text-white bg-red-500 !border-transparent rounded-full hover:!bg-transparent hover:!border-red-500 hover:!text-red-500"
2021-04-21 17:21:15 +00:00
target="_blank"
rel="noopener noreferrer"
>
{children}
2021-05-17 05:09:33 +00:00
</ButtonLink>
2021-04-21 17:21:15 +00:00
)
}
export default ButtonLink