Merge pull request 'Add labels to mobile top nav' (#9579) from Freeplay/calckey:mobile-navbar into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9579
This commit is contained in:
Kainoa Kanter 2023-02-09 19:17:07 +00:00
commit 52e6bf7f4c
1 changed files with 30 additions and 13 deletions

View File

@ -1,8 +1,5 @@
<template> <template>
<div v-if="show" ref="el" class="fdidabkb" :class="{ slim: narrow, thin: thin_ }" :style="{ background: bg }" @click="onClick"> <div v-if="show" ref="el" class="fdidabkb" :class="{ slim: narrow, thin: thin_ }" :style="{ background: bg }" @click="onClick">
<div v-if="narrow" class="buttons left" @click="openAccountMenu">
<MkAvatar v-if="props.displayMyAvatar && $i" class="avatar" :user="$i" :disable-preview="true"/>
</div>
<template v-if="metadata"> <template v-if="metadata">
<div v-if="!hideTitle" class="titleContainer" @click="showTabsPopup"> <div v-if="!hideTitle" class="titleContainer" @click="showTabsPopup">
<MkAvatar v-if="metadata.avatar" class="avatar" :user="metadata.avatar" :disable-preview="true" :show-indicator="true"/> <MkAvatar v-if="metadata.avatar" class="avatar" :user="metadata.avatar" :disable-preview="true" :show-indicator="true"/>
@ -16,10 +13,10 @@
</div> </div>
</div> </div>
</div> </div>
<div class="tabs"> <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)"> <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> <i v-if="tab.icon" class="icon" :class="tab.icon"></i>
<span v-if="!tab.iconOnly && !narrow" class="title">{{ tab.title }}</span> <span v-if="deviceKind !== 'desktop' || isTouchUsing || (!tab.iconOnly && !narrow)" class="title">{{ tab.title }}</span>
</button> </button>
<div ref="tabHighlightEl" class="highlight"></div> <div ref="tabHighlightEl" class="highlight"></div>
</div> </div>
@ -39,6 +36,8 @@ import { popupMenu } from '@/os';
import { scrollToTop } from '@/scripts/scroll'; import { scrollToTop } from '@/scripts/scroll';
import { i18n } from '@/i18n'; import { i18n } from '@/i18n';
import { globalEvents } from '@/events'; import { globalEvents } from '@/events';
import { deviceKind } from '@/scripts/device-kind';
import { isTouchUsing } from '@/scripts/touch';
import { injectPageMetadata } from '@/scripts/page-metadata'; import { injectPageMetadata } from '@/scripts/page-metadata';
import { $i, openAccountMenu as openAccountMenu_ } from '@/account'; import { $i, openAccountMenu as openAccountMenu_ } from '@/account';
@ -74,6 +73,7 @@ const thin_ = props.thin || inject('shouldHeaderThin', false);
const el = $ref<HTMLElement | null>(null); const el = $ref<HTMLElement | null>(null);
const tabRefs = {}; const tabRefs = {};
const tabHighlightEl = $ref<HTMLElement | null>(null); const tabHighlightEl = $ref<HTMLElement | null>(null);
const tabsEl = $ref<HTMLElement | null>(null);
const bg = ref(null); const bg = ref(null);
let narrow = $ref(false); let narrow = $ref(false);
const height = ref(0); const height = ref(0);
@ -150,10 +150,12 @@ onMounted(() => {
if (tabEl && tabHighlightEl) { if (tabEl && tabHighlightEl) {
// offsetWidth offsetLeft getBoundingClientRect 使 // offsetWidth offsetLeft getBoundingClientRect 使
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4 // https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
const parentRect = tabEl.parentElement.getBoundingClientRect(); const parentRect = tabsEl.getBoundingClientRect();
const rect = tabEl.getBoundingClientRect(); const rect = tabEl.getBoundingClientRect();
const left = (rect.left - parentRect.left + tabsEl?.scrollLeft);
tabHighlightEl.style.width = rect.width + 'px'; tabHighlightEl.style.width = rect.width + 'px';
tabHighlightEl.style.left = (rect.left - parentRect.left) + 'px'; tabHighlightEl.style.left = left + 'px';
tabsEl.scrollTo({left: left - 80, behavior: "smooth"});
} }
}); });
}, { }, {
@ -199,8 +201,6 @@ onUnmounted(() => {
} }
&.slim { &.slim {
text-align: center;
> .titleContainer { > .titleContainer {
flex: 1; flex: 1;
margin: 0 auto; margin: 0 auto;
@ -213,13 +213,26 @@ onUnmounted(() => {
margin-right: auto; margin-right: auto;
} }
} }
> .tabs {
padding-inline: 12px;
mask: linear-gradient(to right, black 80%, transparent);
-webkit-mask: linear-gradient(to right, black 80%, transparent);
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
&::after { // Force right padding
content: "";
display: inline-block;
min-width: 20%;
}
}
} }
> .buttons { > .buttons {
--margin: 8px; --margin: 8px;
display: flex; display: flex;
align-items: center; align-items: center;
min-width: var(--height);
height: var(--height); height: var(--height);
margin: 0 var(--margin); margin: 0 var(--margin);
@ -242,7 +255,7 @@ onUnmounted(() => {
} }
&:empty { &:empty {
width: var(--height); display: none;
} }
> .button { > .button {
@ -331,16 +344,18 @@ onUnmounted(() => {
position: relative; position: relative;
width: 100%; width: 100%;
font-size: 1em; font-size: 1em;
overflow: auto; overflow-x: auto;
white-space: nowrap; white-space: nowrap;
> .tab { > .tab {
display: inline-block; display: inline-flex;
align-items: center;
position: relative; position: relative;
padding: 0 10px; padding: 0 10px;
height: 100%; height: 100%;
font-weight: normal; font-weight: normal;
opacity: 0.7; opacity: 0.7;
transition: color .2s, opacity .2s;
&:hover { &:hover {
opacity: 1; opacity: 1;
@ -348,6 +363,8 @@ onUnmounted(() => {
&.active { &.active {
opacity: 1; opacity: 1;
color: var(--accent);
font-weight: 600;
} }
> .icon + .title { > .icon + .title {