2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-06-01 10:19:46 +02:00
|
|
|
<div ref="rootEl" class="_panel" :class="[$style.root, { [$style.naked]: naked, [$style.thin]: thin, [$style.scrollable]: scrollable }]">
|
2023-04-23 01:13:12 +02:00
|
|
|
<header v-if="showHeader" ref="headerEl" :class="$style.header">
|
2023-01-15 00:30:29 +01:00
|
|
|
<div :class="$style.title">
|
|
|
|
<span :class="$style.titleIcon"><slot name="icon"></slot></span>
|
|
|
|
<slot name="header"></slot>
|
|
|
|
</div>
|
|
|
|
<div :class="$style.headerSub">
|
2023-05-19 06:58:09 +02:00
|
|
|
<slot name="func" :buttonStyleClass="$style.headerButton"></slot>
|
2023-01-15 00:30:29 +01:00
|
|
|
<button v-if="foldable" :class="$style.headerButton" class="_button" @click="() => showBody = !showBody">
|
2024-06-21 17:53:54 +02:00
|
|
|
<template v-if="showBody"><i class="ti ti-chevron-up"></i></template>
|
2023-09-30 21:53:52 +02:00
|
|
|
<template v-else><i class="ph-caret-down ph-bold ph-lg"></i></template>
|
2020-08-13 16:02:43 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
</header>
|
2022-12-30 05:37:14 +01:00
|
|
|
<Transition
|
2023-05-19 06:58:09 +02:00
|
|
|
:enterActiveClass="defaultStore.state.animation ? $style.transition_toggle_enterActive : ''"
|
|
|
|
:leaveActiveClass="defaultStore.state.animation ? $style.transition_toggle_leaveActive : ''"
|
|
|
|
:enterFromClass="defaultStore.state.animation ? $style.transition_toggle_enterFrom : ''"
|
|
|
|
:leaveToClass="defaultStore.state.animation ? $style.transition_toggle_leaveTo : ''"
|
2020-02-08 06:31:51 +01:00
|
|
|
@enter="enter"
|
2023-05-19 06:58:09 +02:00
|
|
|
@afterEnter="afterEnter"
|
2020-02-08 06:31:51 +01:00
|
|
|
@leave="leave"
|
2023-05-19 06:58:09 +02:00
|
|
|
@afterLeave="afterLeave"
|
2020-02-08 06:31:51 +01:00
|
|
|
>
|
2023-04-23 01:13:12 +02:00
|
|
|
<div v-show="showBody" ref="contentEl" :class="[$style.content, { [$style.omitted]: omitted }]">
|
2020-02-08 06:31:51 +01:00
|
|
|
<slot></slot>
|
2023-01-15 00:30:29 +01:00
|
|
|
<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>
|
2021-04-16 02:41:56 +02:00
|
|
|
</button>
|
2020-02-08 06:31:51 +01:00
|
|
|
</div>
|
2022-12-30 05:37:14 +01:00
|
|
|
</Transition>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-04-23 01:13:12 +02:00
|
|
|
<script lang="ts" setup>
|
2023-05-31 18:00:55 +02:00
|
|
|
import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-23 01:13:12 +02:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
showHeader?: boolean;
|
|
|
|
thin?: boolean;
|
|
|
|
naked?: boolean;
|
|
|
|
foldable?: boolean;
|
|
|
|
scrollable?: boolean;
|
|
|
|
expanded?: boolean;
|
|
|
|
maxHeight?: number | null;
|
|
|
|
}>(), {
|
|
|
|
expanded: true,
|
|
|
|
showHeader: true,
|
|
|
|
maxHeight: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
const rootEl = shallowRef<HTMLElement>();
|
|
|
|
const contentEl = shallowRef<HTMLElement>();
|
|
|
|
const headerEl = shallowRef<HTMLElement>();
|
|
|
|
const showBody = ref(props.expanded);
|
|
|
|
const ignoreOmit = ref(false);
|
|
|
|
const omitted = ref(false);
|
|
|
|
|
|
|
|
function enter(el) {
|
|
|
|
const elementHeight = el.getBoundingClientRect().height;
|
|
|
|
el.style.height = 0;
|
|
|
|
el.offsetHeight; // reflow
|
|
|
|
el.style.height = Math.min(elementHeight, props.maxHeight ?? Infinity) + 'px';
|
|
|
|
}
|
|
|
|
|
|
|
|
function afterEnter(el) {
|
|
|
|
el.style.height = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function leave(el) {
|
|
|
|
const elementHeight = el.getBoundingClientRect().height;
|
|
|
|
el.style.height = elementHeight + 'px';
|
|
|
|
el.offsetHeight; // reflow
|
|
|
|
el.style.height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function afterLeave(el) {
|
|
|
|
el.style.height = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const calcOmit = () => {
|
|
|
|
if (omitted.value || ignoreOmit.value || props.maxHeight == null) return;
|
2023-05-31 18:00:55 +02:00
|
|
|
if (!contentEl.value) return;
|
2023-04-23 01:13:12 +02:00
|
|
|
const height = contentEl.value.offsetHeight;
|
|
|
|
omitted.value = height > props.maxHeight;
|
|
|
|
};
|
|
|
|
|
2023-05-31 18:00:55 +02:00
|
|
|
const omitObserver = new ResizeObserver((entries, observer) => {
|
|
|
|
calcOmit();
|
|
|
|
});
|
|
|
|
|
2023-04-23 01:13:12 +02:00
|
|
|
onMounted(() => {
|
|
|
|
watch(showBody, v => {
|
2023-05-31 18:00:55 +02:00
|
|
|
if (!rootEl.value) return;
|
|
|
|
const headerHeight = props.showHeader ? headerEl.value?.offsetHeight ?? 0 : 0;
|
2023-04-23 01:13:12 +02:00
|
|
|
rootEl.value.style.minHeight = `${headerHeight}px`;
|
|
|
|
if (v) {
|
|
|
|
rootEl.value.style.flexBasis = 'auto';
|
|
|
|
} else {
|
|
|
|
rootEl.value.style.flexBasis = `${headerHeight}px`;
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
2021-04-16 02:41:56 +02:00
|
|
|
|
2023-05-31 18:00:55 +02:00
|
|
|
if (rootEl.value) rootEl.value.style.setProperty('--maxHeight', props.maxHeight + 'px');
|
2021-04-16 02:41:56 +02:00
|
|
|
|
2023-04-23 01:13:12 +02:00
|
|
|
calcOmit();
|
2021-04-16 02:41:56 +02:00
|
|
|
|
2023-05-31 18:00:55 +02:00
|
|
|
if (contentEl.value) omitObserver.observe(contentEl.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
omitObserver.disconnect();
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
<style lang="scss" module>
|
|
|
|
.transition_toggle_enterActive,
|
|
|
|
.transition_toggle_leaveActive {
|
2022-12-30 07:40:29 +01:00
|
|
|
overflow-y: clip;
|
2020-02-08 06:31:51 +01:00
|
|
|
transition: opacity 0.5s, height 0.5s !important;
|
|
|
|
}
|
2023-01-15 00:30:29 +01:00
|
|
|
.transition_toggle_enterFrom,
|
|
|
|
.transition_toggle_leaveTo {
|
2020-02-08 06:31:51 +01:00
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.root {
|
2020-01-29 20:37:25 +01:00
|
|
|
position: relative;
|
2022-07-13 14:41:06 +02:00
|
|
|
overflow: clip;
|
2022-07-05 15:35:57 +02:00
|
|
|
contain: content;
|
2023-10-09 04:38:31 +02:00
|
|
|
background: color-mix(in srgb, var(--panel) 65%, transparent);
|
2020-01-29 20:37:25 +01:00
|
|
|
&.naked {
|
|
|
|
background: transparent !important;
|
|
|
|
box-shadow: none !important;
|
|
|
|
}
|
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
&.scrollable {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
|
2021-04-16 02:41:56 +02:00
|
|
|
> .content {
|
2020-07-11 03:13:11 +02:00
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
&.thin {
|
|
|
|
> .header {
|
|
|
|
> .title {
|
|
|
|
padding: 8px 10px;
|
|
|
|
font-size: 0.9em;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
2023-01-15 00:30:29 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.header {
|
|
|
|
position: sticky;
|
|
|
|
top: var(--stickyTop, 0px);
|
|
|
|
left: 0;
|
|
|
|
color: var(--panelHeaderFg);
|
2023-04-21 02:29:32 +02:00
|
|
|
border-bottom: solid 0.5px var(--panelHeaderDivider);
|
2023-01-15 00:30:29 +01:00
|
|
|
z-index: 2;
|
|
|
|
line-height: 1.4em;
|
2023-10-09 04:38:31 +02:00
|
|
|
background: color-mix(in srgb, var(--panelHeaderBg) 35%, transparent);
|
2023-01-15 00:30:29 +01:00
|
|
|
}
|
2020-08-13 16:02:43 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.title {
|
|
|
|
margin: 0;
|
|
|
|
padding: 12px 16px;
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2021-07-19 04:36:35 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.titleIcon {
|
|
|
|
margin-right: 6px;
|
|
|
|
}
|
2021-04-16 02:41:56 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.headerSub {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
height: 100%;
|
|
|
|
}
|
2020-08-09 08:51:02 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.headerButton {
|
|
|
|
width: 42px;
|
|
|
|
height: 100%;
|
|
|
|
}
|
2021-04-16 02:41:56 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
.content {
|
|
|
|
--stickyTop: 0px;
|
2020-08-09 08:51:02 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
&.omitted {
|
|
|
|
position: relative;
|
|
|
|
max-height: var(--maxHeight);
|
|
|
|
overflow: hidden;
|
2020-08-09 08:51:02 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
> .fade {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 64px;
|
|
|
|
background: linear-gradient(0deg, var(--panel), var(--X15));
|
2020-07-11 03:13:11 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
> .fadeLabel {
|
|
|
|
display: inline-block;
|
|
|
|
background: var(--panel);
|
|
|
|
padding: 6px 10px;
|
|
|
|
font-size: 0.8em;
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-ellipse);
|
2023-01-15 00:30:29 +01:00
|
|
|
box-shadow: 0 2px 6px rgb(0 0 0 / 20%);
|
2022-12-26 00:40:13 +01:00
|
|
|
}
|
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
&:hover {
|
|
|
|
> .fadeLabel {
|
|
|
|
background: var(--panelHighlight);
|
|
|
|
}
|
|
|
|
}
|
2020-07-11 03:13:11 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
2020-07-12 04:34:45 +02:00
|
|
|
|
2023-01-15 00:30:29 +01:00
|
|
|
@container (max-width: 380px) {
|
|
|
|
.title {
|
|
|
|
padding: 8px 10px;
|
|
|
|
font-size: 0.9em;
|
2020-07-12 04:34:45 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
</style>
|