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

38 wiersze
917 B
Vue
Czysty Zwykły widok Historia

2022-05-02 15:06:44 +00:00
<script setup lang="ts">
import { computed } from 'vue'
2022-05-02 15:06:44 +00:00
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>
2022-11-26 23:16:46 +00:00
<span v-if="expanded">
{{ $t('components.common.ExpandableDiv.button.less') }}
</span>
<span v-else>
{{ $t('components.common.ExpandableDiv.button.more') }}
</span>
</a>
</div>
</template>