hippofish/packages/frontend/src/components/MkOmit.vue

87 lines
1.8 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div ref="content" :class="[$style.content, { [$style.omitted]: omitted }]">
<slot></slot>
<button v-if="omitted" :class="$style.fade" class="_button" @click="() => { ignoreOmit = true; omitted = false; }">
2023-04-01 07:01:57 +02:00
<span :class="$style.fadeLabel">{{ i18n.ts.showMore }}</span>
</button>
</div>
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted } from 'vue';
2023-09-19 09:37:43 +02:00
import { i18n } from '@/i18n.js';
const props = withDefaults(defineProps<{
2023-04-04 03:45:01 +02:00
maxHeight?: number;
}>(), {
maxHeight: 200,
});
let content = $shallowRef<HTMLElement>();
let omitted = $ref(false);
let ignoreOmit = $ref(false);
const calcOmit = () => {
if (omitted || ignoreOmit) return;
omitted = content.offsetHeight > props.maxHeight;
};
const omitObserver = new ResizeObserver((entries, observer) => {
calcOmit();
});
onMounted(() => {
calcOmit();
omitObserver.observe(content);
});
onUnmounted(() => {
omitObserver.disconnect();
});
</script>
<style lang="scss" module>
.content {
--stickyTop: 0px;
&.omitted {
position: relative;
max-height: v-bind("props.maxHeight + 'px'");
overflow: hidden;
> .fade {
display: block;
position: absolute;
z-index: 10;
bottom: 0;
left: 0;
width: 100%;
height: 64px;
2023-10-16 01:39:02 +02:00
--mix: color-mix(in srgb, var(--panel) 10%, transparent);
background: linear-gradient(0deg, var(--mix), transparent);
backdrop-filter: blur(1px);
> .fadeLabel {
display: inline-block;
background: var(--panel);
padding: 6px 10px;
font-size: 0.8em;
2023-10-01 01:20:20 +02:00
border-radius: 4px;
box-shadow: 0 2px 6px rgb(0 0 0 / 20%);
}
&:hover {
> .fadeLabel {
background: var(--panelHighlight);
}
}
}
}
}
</style>