@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
5
5
6
6
<template>
7
7
<div ref="rootEl" :class="$style.root">
8
- <header :class="$style.header" class="_button" :style="{ background: bg }" @click="showBody = !showBody">
8
+ <header :class="$style.header" class="_button" @click="showBody = !showBody">
9
9
<div :class="$style.title"><div><slot name="header"></slot></div></div>
10
10
<div :class="$style.divider"></div>
11
11
<button class="_button" :class="$style.button">
@@ -32,21 +32,23 @@ SPDX-License-Identifier: AGPL-3.0-only
32
32
33
33
<script lang="ts" setup>
34
34
import { onMounted, ref, shallowRef, watch } from 'vue';
35
- import tinycolor from 'tinycolor2';
36
35
import { miLocalStorage } from '@/local-storage.js';
37
36
import { defaultStore } from '@/store.js';
37
+ import { getBgColor } from '@/scripts/tms/get-bg-color.js';
38
38
39
39
const miLocalStoragePrefix = 'ui:folder:' as const;
40
40
41
41
const props = withDefaults(defineProps<{
42
42
expanded?: boolean;
43
- persistKey?: string;
43
+ persistKey?: string | null ;
44
44
}>(), {
45
45
expanded: true,
46
+ persistKey: null,
46
47
});
47
48
48
- const rootEl = shallowRef<HTMLDivElement>();
49
- const bg = ref<string>();
49
+ const rootEl = shallowRef<HTMLElement>();
50
+ const parentBg = ref<string | null>(null);
51
+ // eslint-disable-next-line vue/no-setup-props-reactivity-loss
50
52
const showBody = ref((props.persistKey && miLocalStorage.getItem(`${miLocalStoragePrefix}${props.persistKey}`)) ? (miLocalStorage.getItem(`${miLocalStoragePrefix}${props.persistKey}`) === 't') : props.expanded);
51
53
52
54
watch(showBody, () => {
@@ -55,55 +57,42 @@ watch(showBody, () => {
55
57
}
56
58
});
57
59
58
- function enter(element : Element) {
59
- const el = element as HTMLElement;
60
+ function enter(el : Element) {
61
+ if (!( el instanceof HTMLElement)) return ;
60
62
const elementHeight = el.getBoundingClientRect().height;
61
63
el.style.height = '0';
62
64
el.offsetHeight; // reflow
63
- el.style.height = elementHeight + 'px' ;
65
+ el.style.height = `${ elementHeight}px` ;
64
66
}
65
67
66
- function afterEnter(element : Element) {
67
- const el = element as HTMLElement;
68
- el.style.height = 'unset ';
68
+ function afterEnter(el : Element) {
69
+ if (!( el instanceof HTMLElement)) return ;
70
+ el.style.height = '';
69
71
}
70
72
71
- function leave(element : Element) {
72
- const el = element as HTMLElement;
73
+ function leave(el : Element) {
74
+ if (!( el instanceof HTMLElement)) return ;
73
75
const elementHeight = el.getBoundingClientRect().height;
74
- el.style.height = elementHeight + 'px' ;
76
+ el.style.height = `${ elementHeight}px` ;
75
77
el.offsetHeight; // reflow
76
78
el.style.height = '0';
77
79
}
78
80
79
- function afterLeave(element : Element) {
80
- const el = element as HTMLElement;
81
- el.style.height = 'unset ';
81
+ function afterLeave(el : Element) {
82
+ if (!( el instanceof HTMLElement)) return ;
83
+ el.style.height = '';
82
84
}
83
85
84
86
onMounted(() => {
85
- function getParentBg(el?: HTMLElement | null): string {
86
- if (el == null || el.tagName === 'BODY') return 'var(--bg)';
87
- const background = el.style.background || el.style.backgroundColor;
88
- if (background) {
89
- return background;
90
- } else {
91
- return getParentBg(el.parentElement);
92
- }
93
- }
94
-
95
- const rawBg = getParentBg(rootEl.value);
96
- const _bg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
97
- _bg.setAlpha(0.85);
98
- bg.value = _bg.toRgbString();
87
+ parentBg.value = getBgColor(rootEl.value?.parentElement);
99
88
});
100
89
</script>
101
90
102
91
<style lang="scss" module>
103
92
.folderToggleEnterActive, .folderToggleLeaveActive {
104
93
overflow-y: hidden; // fallback (overflow-y: clip)
105
94
overflow-y: clip;
106
- transition: opacity 0.5s , height 0.5s !important;
95
+ transition: opacity 0.3s , height 0.3s !important;
107
96
}
108
97
109
98
.folderToggleEnterFrom, .folderToggleLeaveTo {
@@ -120,8 +109,9 @@ onMounted(() => {
120
109
z-index: 10;
121
110
position: sticky;
122
111
top: var(--stickyTop, 0px);
123
- -webkit-backdrop-filter: var(--blur, blur(8px));
124
- backdrop-filter: var(--blur, blur(20px));
112
+ -webkit-backdrop-filter: var(--blur, blur(15px));
113
+ backdrop-filter: var(--blur, blur(15px));
114
+ background-color: color(from v-bind("parentBg ?? 'var(--bg)'") srgb r g b / 0.85);
125
115
}
126
116
127
117
.title {
0 commit comments