Create EmLink.vue

This commit is contained in:
syuilo 2024-08-27 13:22:35 +09:00
parent db2b9d2669
commit 7bac106538
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<component
:is="self ? EmA : 'a'" ref="el" style="word-break: break-all;" class="_link" :[attr]="self ? url.substring(local.length) : url" :rel="rel ?? 'nofollow noopener'" :target="target"
:title="url"
>
<slot></slot>
<i v-if="target === '_blank'" class="ti ti-external-link" :class="$style.icon"></i>
</component>
</template>
<script lang="ts" setup>
import { defineAsyncComponent, ref } from 'vue';
import EmA from './EmA.vue';
import { url as local } from '@/config.js';
const props = withDefaults(defineProps<{
url: string;
rel?: null | string;
}>(), {
});
const self = props.url.startsWith(local);
const attr = self ? 'to' : 'href';
const target = self ? null : '_blank';
const el = ref<HTMLElement | { $el: HTMLElement }>();
</script>
<style lang="scss" module>
.icon {
padding-left: 2px;
font-size: .9em;
}
</style>