Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update <KExternalLink> with icon and noopener noreferrer attr #142

Merged
merged 13 commits into from
Jan 5, 2021
Merged
5 changes: 4 additions & 1 deletion lib/KIcon/iconDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ const KolibriIcons = {
icon: require('./precompiled-icons/material-icons/keyboard_arrow_right/baseline.vue').default,
},
pdf: { icon: require('./precompiled-icons/material-icons/picture_as_pdf/baseline.vue').default },
openNewTab: { icon: require('./precompiled-icons/material-icons/launch/baseline.vue').default },
openNewTab: {
icon: require('./precompiled-icons/material-icons/launch/baseline.vue').default,
rtlFlip: true,
},
history: { icon: require('./precompiled-icons/material-icons/restore/baseline.vue').default },
myLocation: {
icon: require('./precompiled-icons/material-icons/gps_fixed/baseline.vue').default,
Expand Down
49 changes: 21 additions & 28 deletions lib/buttons-and-links/KExternalLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@
:class="buttonClasses"
:href="href"
:download="download"
:openInNewTab="openInNewTab"
:target="openInNewTab ? '_blank' : false"
rel="noopener noreferrer"
dir="auto"
@mouseenter="hovering = true"
@mouseleave="hovering = false"
>
<slot name="icon">
<KIcon
v-if="icon"
:icon="icon"
style="top: 4px;"
:color="hovering ? $themeTokens.primaryDark : $themeTokens.primary"
/>
</slot>
<span class="link-text" :style="spanStyle">{{ text }}</span>
<slot name="iconAfter">
<slot name="openInNewTab">
<KIcon
v-if="iconAfter"
:icon="iconAfter"
v-if="openInNewTab"
icon="openNewTab"
style="top: 4px;"
:color="hovering ? $themeTokens.primaryDark : $themeTokens.primary"
/>
Expand Down Expand Up @@ -57,18 +52,11 @@
required: false,
},
/**
* If provided, shows a KIcon in front of the text
*/
icon: {
type: String,
required: false,
},
/**
* If provided, shows a KIcon after the text
* If provided, opens link in new tab and displays a "pop out" icon
*/
iconAfter: {
type: String,
required: false,
openInNewTab: {
type: Boolean,
default: false,
},
},
data() {
Expand All @@ -78,18 +66,23 @@
},
computed: {
/**
* If icon is provided, add 8px margin between the icon and the text
* If link opens in new tab, add 8px margin between the icon and the text
*/
spanStyle() {
if (this.icon) {
sairina marked this conversation as resolved.
Show resolved Hide resolved
let styles = {};
if (this.openInNewTab) {
if (this.isRtl) {
return { marginRight: '8px' };
// If RTL-language, but English link, displays correct margins
styles['marginRight'] = '8px';
if (this.text !== this.href) {
styles['marginRight'] = '0px';
styles['marginLeft'] = '8px';
}
} else {
return { marginLeft: '8px' };
styles['marginLeft'] = '8px';
}
} else {
return {};
}
return { ...styles };
},
},
};
Expand Down