Replace fixed text length with css line-clamp (#96)

This commit is contained in:
mchev
2024-06-05 14:36:32 +02:00
committed by GitHub
parent bf5a8cdb28
commit 592a537379
15 changed files with 18 additions and 27 deletions

View File

@@ -1,9 +1,10 @@
<template>
<BaseCustomTag :tag="tag" :title="text">
{{ displayText }}
</BaseCustomTag>
<div class="whitespace-normal">
<BaseCustomTag :tag="tag" :title="text" class="line-clamp-1">
{{ displayText }}
</BaseCustomTag>
</div>
</template>
<script setup>
import { computed } from "vue"
@@ -20,12 +21,17 @@ const props = defineProps({
length: {
type: Number,
default: 0,
default: null,
}
})
const displayText = computed(() => {
const { text, length } = props;
const displayText = computed(() => {
if (length) {
return text.length <= length ? text : `${text.substring(0, length)}...`;
}
return text;
});
return props.text.length < props.length ? props.text : `${props.text.substring(0 , props.length)}...`
})
</script>