funkwhale/front/src/components/common/ExpandableDiv.vue

42 wiersze
970 B
Vue
Czysty Zwykły widok Historia

2022-05-02 15:06:44 +00:00
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useToggle } from '@vueuse/core'
interface Props {
content: string
length?: number
}
const props = withDefaults(defineProps<Props>(), {
length: 150
})
const [expanded, toggleExpanded] = useToggle(false)
const truncated = computed(() => props.content.slice(0, props.length))
</script>
<template>
<div class="expandable-wrapper">
2022-05-02 15:06:44 +00:00
<div :class="['expandable-content', { expandable: truncated.length < content.length, expanded }]">
<slot>{{ content }}</slot>
</div>
2021-12-06 10:35:20 +00:00
<a
v-if="truncated.length < content.length"
role="button"
2022-05-02 15:06:44 +00:00
@click.prevent="toggleExpanded()"
2021-12-06 10:35:20 +00:00
>
<br>
2021-12-06 10:35:20 +00:00
<translate
2022-05-02 15:06:44 +00:00
v-if="expanded"
2021-12-06 10:35:20 +00:00
key="1"
translate-context="*/*/Button,Label"
>Show less</translate>
<translate
v-else
key="2"
translate-context="*/*/Button,Label"
>Show more</translate>
</a>
</div>
</template>