summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkLink.vue
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/components/MkLink.vue')
-rw-r--r--packages/frontend/src/components/MkLink.vue47
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/frontend/src/components/MkLink.vue b/packages/frontend/src/components/MkLink.vue
new file mode 100644
index 0000000000..6148ec6195
--- /dev/null
+++ b/packages/frontend/src/components/MkLink.vue
@@ -0,0 +1,47 @@
+<template>
+<component
+ :is="self ? 'MkA' : 'a'" ref="el" class="xlcxczvw _link" :[attr]="self ? url.substr(local.length) : url" :rel="rel" :target="target"
+ :title="url"
+>
+ <slot></slot>
+ <i v-if="target === '_blank'" class="ti ti-external-link icon"></i>
+</component>
+</template>
+
+<script lang="ts" setup>
+import { defineAsyncComponent } from 'vue';
+import { url as local } from '@/config';
+import { useTooltip } from '@/scripts/use-tooltip';
+import * as os from '@/os';
+
+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();
+
+useTooltip($$(el), (showing) => {
+ os.popup(defineAsyncComponent(() => import('@/components/MkUrlPreviewPopup.vue')), {
+ showing,
+ url: props.url,
+ source: el,
+ }, {}, 'closed');
+});
+</script>
+
+<style lang="scss" scoped>
+.xlcxczvw {
+ word-break: break-all;
+
+ > .icon {
+ padding-left: 2px;
+ font-size: .9em;
+ }
+}
+</style>