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
|
|
|
|
-->
|
|
|
|
|
2023-01-09 01:41:25 +01:00
|
|
|
<template>
|
2024-01-30 11:53:53 +01:00
|
|
|
<div ref="rootEl" :class="$style.root">
|
2023-05-19 06:58:09 +02:00
|
|
|
<header :class="$style.header" class="_button" :style="{ background: bg }" @click="showBody = !showBody">
|
|
|
|
<div :class="$style.title"><div><slot name="header"></slot></div></div>
|
|
|
|
<div :class="$style.divider"></div>
|
|
|
|
<button class="_button" :class="$style.button">
|
2024-06-21 17:53:54 +02:00
|
|
|
<template v-if="showBody"><i class="ti ti-chevron-up"></i></template>
|
2024-06-21 17:58:33 +02:00
|
|
|
<template v-else><i class="ti ti-chevron-down"></i></template>
|
2023-01-09 01:41:25 +01:00
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
<Transition
|
2024-01-31 12:35:07 +01:00
|
|
|
:enterActiveClass="defaultStore.state.animation ? $style.folderToggleEnterActive : ''"
|
|
|
|
:leaveActiveClass="defaultStore.state.animation ? $style.folderToggleLeaveActive : ''"
|
|
|
|
:enterFromClass="defaultStore.state.animation ? $style.folderToggleEnterFrom : ''"
|
|
|
|
:leaveToClass="defaultStore.state.animation ? $style.folderToggleLeaveTo : ''"
|
2023-01-09 01:41:25 +01:00
|
|
|
@enter="enter"
|
2023-05-19 06:58:09 +02:00
|
|
|
@afterEnter="afterEnter"
|
2023-01-09 01:41:25 +01:00
|
|
|
@leave="leave"
|
2023-05-19 06:58:09 +02:00
|
|
|
@afterLeave="afterLeave"
|
2023-01-09 01:41:25 +01:00
|
|
|
>
|
|
|
|
<div v-show="showBody">
|
|
|
|
<slot></slot>
|
|
|
|
</div>
|
|
|
|
</Transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, ref, shallowRef, watch } from 'vue';
|
2023-01-09 01:41:25 +01:00
|
|
|
import tinycolor from 'tinycolor2';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { miLocalStorage } from '@/local-storage.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2023-01-09 01:41:25 +01:00
|
|
|
|
|
|
|
const miLocalStoragePrefix = 'ui:folder:' as const;
|
|
|
|
|
2023-05-14 05:23:39 +02:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
expanded?: boolean;
|
|
|
|
persistKey?: string;
|
|
|
|
}>(), {
|
|
|
|
expanded: true,
|
|
|
|
});
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
const rootEl = shallowRef<HTMLDivElement>();
|
|
|
|
const bg = ref<string>();
|
2023-05-14 05:23:39 +02:00
|
|
|
const showBody = ref((props.persistKey && miLocalStorage.getItem(`${miLocalStoragePrefix}${props.persistKey}`)) ? (miLocalStorage.getItem(`${miLocalStoragePrefix}${props.persistKey}`) === 't') : props.expanded);
|
|
|
|
|
|
|
|
watch(showBody, () => {
|
|
|
|
if (props.persistKey) {
|
|
|
|
miLocalStorage.setItem(`${miLocalStoragePrefix}${props.persistKey}`, showBody.value ? 't' : 'f');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
function enter(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
2023-05-14 05:23:39 +02:00
|
|
|
const elementHeight = el.getBoundingClientRect().height;
|
2024-01-30 11:53:53 +01:00
|
|
|
el.style.height = '0';
|
2023-05-14 05:23:39 +02:00
|
|
|
el.offsetHeight; // reflow
|
|
|
|
el.style.height = elementHeight + 'px';
|
|
|
|
}
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
function afterEnter(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
|
|
|
el.style.height = 'unset';
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
function leave(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
2023-05-14 05:23:39 +02:00
|
|
|
const elementHeight = el.getBoundingClientRect().height;
|
|
|
|
el.style.height = elementHeight + 'px';
|
|
|
|
el.offsetHeight; // reflow
|
2024-01-30 11:53:53 +01:00
|
|
|
el.style.height = '0';
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
function afterLeave(element: Element) {
|
|
|
|
const el = element as HTMLElement;
|
|
|
|
el.style.height = 'unset';
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(() => {
|
2024-01-30 11:53:53 +01:00
|
|
|
function getParentBg(el?: HTMLElement | null): string {
|
2023-05-14 05:23:39 +02:00
|
|
|
if (el == null || el.tagName === 'BODY') return 'var(--bg)';
|
2024-01-30 11:53:53 +01:00
|
|
|
const background = el.style.background || el.style.backgroundColor;
|
|
|
|
if (background) {
|
|
|
|
return background;
|
2023-05-14 05:23:39 +02:00
|
|
|
} else {
|
|
|
|
return getParentBg(el.parentElement);
|
2023-01-09 01:41:25 +01:00
|
|
|
}
|
2023-05-14 05:23:39 +02:00
|
|
|
}
|
2023-10-29 08:09:20 +01:00
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
const rawBg = getParentBg(rootEl.value);
|
2023-05-14 05:23:39 +02:00
|
|
|
const _bg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
|
|
|
|
_bg.setAlpha(0.85);
|
|
|
|
bg.value = _bg.toRgbString();
|
2023-01-09 01:41:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
<style lang="scss" module>
|
2024-01-31 12:35:07 +01:00
|
|
|
.folderToggleEnterActive, .folderToggleLeaveActive {
|
2023-01-09 01:41:25 +01:00
|
|
|
overflow-y: clip;
|
|
|
|
transition: opacity 0.5s, height 0.5s !important;
|
|
|
|
}
|
2024-01-30 11:53:53 +01:00
|
|
|
|
2024-01-31 12:35:07 +01:00
|
|
|
.folderToggleEnterFrom, .folderToggleLeaveTo {
|
2023-01-09 01:41:25 +01:00
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
.root {
|
2023-01-09 01:41:25 +01:00
|
|
|
position: relative;
|
2023-05-19 06:58:09 +02:00
|
|
|
}
|
2023-01-09 01:41:25 +01:00
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
.header {
|
|
|
|
display: flex;
|
|
|
|
position: relative;
|
|
|
|
z-index: 10;
|
|
|
|
position: sticky;
|
|
|
|
top: var(--stickyTop, 0px);
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(8px));
|
|
|
|
backdrop-filter: var(--blur, blur(20px));
|
|
|
|
}
|
2023-01-09 01:41:25 +01:00
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
.title {
|
|
|
|
display: grid;
|
|
|
|
place-content: center;
|
|
|
|
margin: 0;
|
|
|
|
padding: 12px 16px 12px 0;
|
|
|
|
}
|
2023-01-09 01:41:25 +01:00
|
|
|
|
2023-05-19 06:58:09 +02:00
|
|
|
.divider {
|
|
|
|
flex: 1;
|
|
|
|
margin: auto;
|
|
|
|
height: 1px;
|
|
|
|
background: var(--divider);
|
|
|
|
}
|
|
|
|
|
|
|
|
.button {
|
|
|
|
padding: 12px 0 12px 16px;
|
2023-01-09 01:41:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@container (max-width: 500px) {
|
2023-05-19 06:58:09 +02:00
|
|
|
.title {
|
|
|
|
padding: 8px 10px 8px 0;
|
2023-01-09 01:41:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|