externalLink.tsx 563 B

123456789101112131415161718192021
  1. import {forwardRef} from 'react';
  2. import Anchor from './anchor';
  3. export interface ExternalLinkProps
  4. extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'target'> {
  5. disabled?: boolean;
  6. openInNewTab?: boolean;
  7. }
  8. const ExternalLink = forwardRef<HTMLAnchorElement, ExternalLinkProps>(
  9. ({openInNewTab = true, ...props}, ref) => {
  10. const anchorProps = openInNewTab
  11. ? {target: '_blank', rel: 'noreferrer noopener'}
  12. : {href: props.href};
  13. return <Anchor ref={ref} {...anchorProps} {...props} />;
  14. }
  15. );
  16. export default ExternalLink;