Files
website-astro-stefanimhoff.de/src/components/Link.tsx
2023-04-04 17:40:19 +02:00

28 lines
612 B
TypeScript

import cx from 'classnames';
import type { FunctionalComponent, JSX } from 'preact';
interface Props extends JSX.HTMLAttributes<HTMLAnchorElement> {}
export const Link: FunctionalComponent<Props> = ({
class: className,
children,
href = '#',
...props
}: Props) => {
const isExternal = (href as string).startsWith('http');
const classes = cx('link', { external: isExternal }, className as string);
return (
<a
class={classes}
href={href}
rel={isExternal ? 'nofollow noopener noreferrer' : undefined}
target={isExternal ? '_blank' : undefined}
{...props}
>
{children}
</a>
);
};