1
0
Fork 0
This commit is contained in:
Moritz Ruth 2020-04-07 15:52:52 +02:00
parent 82447b6a92
commit e55d5feced
No known key found for this signature in database
GPG key ID: FE38A0B03AA331BA
28 changed files with 2006 additions and 1543 deletions

View file

@ -0,0 +1,74 @@
<template>
<a
class="external-link link"
rel="noopener"
target="_blank"
:href="href"
>
<template v-if="this.$slots.default && this.$slots.default[0] && this.$slots.default[0].text">
<slot/>
</template>
<template v-else>
{{ label }}
</template>
<ExternalIcon class="external-link__icon"/>
</a>
</template>
<style scoped lang="scss">
.external-link {
padding-right: 2px;
overflow-wrap: break-word;
}
.external-link__icon {
margin-left: 3px;
width: 15px;
position: relative;
top: 2px;
}
</style>
<script>
import ExternalIcon from "@/assets/icons/external.svg";
export default {
name: "ExternalLink",
components: { ExternalIcon },
props: {
href: {
type: String,
required: true
},
showProtocol: {
type: Boolean,
default: false
},
showQuery: {
type: Boolean,
default: false
}
},
computed: {
label() {
// eslint-disable-next-line import/no-extraneous-dependencies
const url = new (process.server ? require("url").URL : window.URL)(this.href);
let label = "";
if (this.showProtocol) {
label += url.protocol;
label += "//";
}
label += url.host + url.pathname;
if (this.showQuery) {
label += url.search;
}
return label;
}
}
};
</script>