add telephone link
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<component
|
||||
:is="href ? 'a' : 'span'"
|
||||
v-if="displayText"
|
||||
:href="href || undefined"
|
||||
class="telephone-link"
|
||||
:class="{ clickable: !!href }"
|
||||
@click.stop
|
||||
>
|
||||
<span v-text="displayText" />
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { buildTelephoneURL, canDialTelephone } from "@/utils/telephone";
|
||||
|
||||
defineOptions({
|
||||
name: "TelephoneLink"
|
||||
});
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
placeholder?: string;
|
||||
value?: string;
|
||||
}>(), {
|
||||
placeholder: ""
|
||||
});
|
||||
|
||||
const textValue = computed(() => props.value?.trim() || "");
|
||||
const displayText = computed(() => textValue.value || props.placeholder);
|
||||
const href = computed(() => canDialTelephone(textValue.value) ? buildTelephoneURL(textValue.value) : "");
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.telephone-link {
|
||||
color: inherit;
|
||||
word-break: break-all;
|
||||
text-decoration: none;
|
||||
|
||||
&.clickable {
|
||||
text-decoration: underline;
|
||||
text-underline-offset: .16rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user