Files

27 lines
555 B
TypeScript
Raw Permalink Normal View History

2021-08-20 17:06:26 +02:00
import React from 'react';
2021-09-05 18:25:49 +02:00
import styled from 'styled-components';
2021-08-20 17:06:26 +02:00
type EnrichedLinkProps = {
href: string;
children: React.ReactNode
}
2021-09-05 18:25:49 +02:00
const Link = styled.a`
font-weight: 600;
text-decoration: underline;
`;
const EnrichedLink = (props: EnrichedLinkProps) => {
2021-08-20 17:06:26 +02:00
// Is external URL or is a media URL
const isExternalUrl = /(^http(s)?:\/\/)|(\.(png|svg|jpeg|jpg)$)/.test(props.href);
return (
2021-09-05 18:25:49 +02:00
<Link href={props.href} target={isExternalUrl ? '_blank' : '_self'}>
2021-08-20 17:06:26 +02:00
{props.children}
</Link>
);
};
2021-09-05 18:25:49 +02:00
export default EnrichedLink;