apply mobile nav styling to desktop, maybe also fix misalignment ? (#9623)

Co-authored-by: Freeplay <Freeplay@duck.com>
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9623
Co-authored-by: Free <freeplay@duck.com>
Co-committed-by: Free <freeplay@duck.com>
This commit is contained in:
Free 2023-02-12 23:41:54 +00:00 committed by Kainoa Kanter
parent 4c0d30c368
commit 256fd485fd

View file

@ -19,7 +19,7 @@
<div ref="tabsEl" v-if="hasTabs" class="tabs">
<button v-for="tab in tabs" :ref="(el) => tabRefs[tab.key] = el" v-tooltip.noDelay="tab.title" class="tab _button" :class="{ active: tab.key != null && tab.key === props.tab }" @mousedown="(ev) => onTabMousedown(tab, ev)" @click="(ev) => onTabClick(tab, ev)">
<i v-if="tab.icon" class="icon" :class="tab.icon"></i>
<span v-if="deviceKind !== 'desktop' || isTouchUsing || (!tab.iconOnly && !narrow)" class="title">{{ tab.title }}</span>
<span class="title">{{ tab.title }}</span>
</button>
<div ref="tabHighlightEl" class="highlight"></div>
</div>
@ -38,8 +38,6 @@ import tinycolor from 'tinycolor2';
import { popupMenu } from '@/os';
import { scrollToTop } from '@/scripts/scroll';
import { globalEvents } from '@/events';
import { deviceKind } from '@/scripts/device-kind';
import { isTouchUsing } from '@/scripts/touch';
import { injectPageMetadata } from '@/scripts/page-metadata';
import { $i, openAccountMenu as openAccountMenu_ } from '@/account';
@ -145,25 +143,21 @@ let ro: ResizeObserver | null;
onMounted(() => {
calcBg();
globalEvents.on('themeChanged', calcBg);
watch(() => [props.tab, props.tabs], () => {
nextTick(() => {
const tabEl = tabRefs[props.tab];
if (tabEl && tabHighlightEl) {
// offsetWidth offsetLeft getBoundingClientRect 使
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
function transition() {
window.requestAnimationFrame(() => {
const parentRect = tabsEl.getBoundingClientRect();
const rect = tabEl.getBoundingClientRect();
const left = (rect.left - parentRect.left + tabsEl?.scrollLeft);
tabHighlightEl.style.width = rect.width + 'px';
tabHighlightEl.style.left = left + 'px';
tabsEl?.scrollTo({left: left - 80, behavior: "smooth"});
})
tabEl.removeEventListener("transitionend", transition);
}
tabEl.addEventListener("transitionend", transition);
setTimeout(() => {
const parentRect = tabsEl.getBoundingClientRect();
const rect = tabEl.getBoundingClientRect();
const left = (rect.left - parentRect.left + tabsEl?.scrollLeft);
tabHighlightEl.style.width = rect.width + 'px';
tabHighlightEl.style.left = left + 'px';
tabsEl?.scrollTo({left: left - 60, behavior: "smooth"});
}, 200);
}
});
}, {
@ -234,14 +228,6 @@ onUnmounted(() => {
display: inline-block;
min-width: 20%;
}
> .tab {
&:not(.active) > .title {
font-size: 0;
opacity: 0;
margin-inline: 0;
transition: font-size .2s, opacity .1s;
}
}
}
}
@ -389,6 +375,12 @@ onUnmounted(() => {
> .title {
transition: font-size .2s, opacity .2s .15s;
}
&:not(.active) > .title {
font-size: 0;
opacity: 0;
margin-inline: 0;
transition: font-size .2s, opacity .1s;
}
}
> .highlight {