2022-05-02 15:06:44 +00:00
|
|
|
<script setup lang="ts">
|
2022-05-03 00:30:43 +00:00
|
|
|
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>
|
|
|
|
|
2019-08-28 15:13:26 +00:00
|
|
|
<template>
|
|
|
|
<div class="expandable-wrapper">
|
2022-05-02 15:06:44 +00:00
|
|
|
<div :class="['expandable-content', { expandable: truncated.length < content.length, expanded }]">
|
2019-08-28 15:13:26 +00:00
|
|
|
<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
|
|
|
>
|
2019-08-28 15:13:26 +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>
|
2019-08-28 15:13:26 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|