From 8ac899b3f0b58b2ad99816c710102b56153507e9 Mon Sep 17 00:00:00 2001 From: Avior Date: Sat, 1 May 2021 23:34:45 +0200 Subject: [PATCH] Added HideExternal to links Signed-off-by: Avior --- src/dzeio/Footer/index.tsx | 2 +- src/dzeio/Link/Link.stories.tsx | 4 +++- src/dzeio/Link/index.tsx | 23 ++++++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/dzeio/Footer/index.tsx b/src/dzeio/Footer/index.tsx index e7635cb..ffc2757 100644 --- a/src/dzeio/Footer/index.tsx +++ b/src/dzeio/Footer/index.tsx @@ -34,7 +34,7 @@ export default class Footer extends React.Component { )} {this.props.socials && (
    {this.props.socials.map((l, index) => ( -
  • +
  • {typeof l.icon === 'string' ? ( ) : ( diff --git a/src/dzeio/Link/Link.stories.tsx b/src/dzeio/Link/Link.stories.tsx index 261e27a..3a19a07 100644 --- a/src/dzeio/Link/Link.stories.tsx +++ b/src/dzeio/Link/Link.stories.tsx @@ -7,7 +7,9 @@ export default { component: Component, argTypes: { href: {control: 'text', defaultValue: 'https://www.dzeio.com'}, - text: {control: 'text', defaultValue: 'Dzeio'} + text: {control: 'text', defaultValue: 'Dzeio'}, + external: {control: 'boolean'}, + hideIcon: {control: 'boolean'} } } as Meta diff --git a/src/dzeio/Link/index.tsx b/src/dzeio/Link/index.tsx index 701a34c..ac8cc6c 100644 --- a/src/dzeio/Link/index.tsx +++ b/src/dzeio/Link/index.tsx @@ -19,23 +19,35 @@ interface Props { * Override external detection system */ external?: boolean + + /** + * force hiding the icon + */ + hideIcon?: boolean } export default class Link extends React.Component { public render() { - const external = this.props.external ?? this.props.href.startsWith('http') - if (external) { + const isExternal = this.props.href.startsWith('http') + const externalProps = this.props.external ? { + rel: 'noreferrer nofollow', + target: '_blank' + } : {} + + if (isExternal) { // external link return ( - {this.props.children} + {this.props.children} + {(this.props.external !== false && !this.props.hideIcon) && ( + + )} ) } @@ -43,6 +55,7 @@ export default class Link extends React.Component { {this.props.children}