Hide inactive tab labels on mobile (#9609)
Co-authored-by: Freeplay <Freeplay@duck.com> Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9609 Co-authored-by: Free <freeplay@duck.com> Co-committed-by: Free <freeplay@duck.com>
This commit is contained in:
parent
5c88cef03b
commit
474a02bfe0
@ -1,5 +1,5 @@
|
||||
<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>
|
||||
@ -29,30 +29,30 @@
|
||||
<button v-tooltip.noDelay="action.text" class="_button button" :class="{ highlighted: action.highlighted }" @click.stop="action.handler" @touchstart="preventDrag"><i :class="action.icon"></i></button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, ref, inject, watch, shallowReactive, nextTick, reactive } from 'vue';
|
||||
import tinycolor from 'tinycolor2';
|
||||
import { popupMenu } from '@/os';
|
||||
import { scrollToTop } from '@/scripts/scroll';
|
||||
import { i18n } from '@/i18n';
|
||||
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';
|
||||
import { computed, onMounted, onUnmounted, ref, inject, watch, shallowReactive, nextTick, reactive } from 'vue';
|
||||
import tinycolor from 'tinycolor2';
|
||||
import { popupMenu } from '@/os';
|
||||
import { scrollToTop } from '@/scripts/scroll';
|
||||
import { i18n } from '@/i18n';
|
||||
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';
|
||||
|
||||
type Tab = {
|
||||
type Tab = {
|
||||
key?: string | null;
|
||||
title: string;
|
||||
icon?: string;
|
||||
iconOnly?: boolean;
|
||||
onClick?: (ev: MouseEvent) => void;
|
||||
};
|
||||
};
|
||||
|
||||
const props = defineProps<{
|
||||
const props = defineProps<{
|
||||
tabs?: Tab[];
|
||||
tab?: string;
|
||||
actions?: {
|
||||
@ -62,37 +62,37 @@ const props = defineProps<{
|
||||
}[];
|
||||
thin?: boolean;
|
||||
displayMyAvatar?: boolean;
|
||||
}>();
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
const emit = defineEmits<{
|
||||
(ev: 'update:tab', key: string);
|
||||
}>();
|
||||
}>();
|
||||
|
||||
const metadata = injectPageMetadata();
|
||||
const metadata = injectPageMetadata();
|
||||
|
||||
const hideTitle = inject('shouldOmitHeaderTitle', false);
|
||||
const thin_ = props.thin || inject('shouldHeaderThin', false);
|
||||
const hideTitle = inject('shouldOmitHeaderTitle', false);
|
||||
const thin_ = props.thin || inject('shouldHeaderThin', false);
|
||||
|
||||
const el = $ref<HTMLElement | null>(null);
|
||||
const tabRefs = {};
|
||||
const tabHighlightEl = $ref<HTMLElement | null>(null);
|
||||
const tabsEl = $ref<HTMLElement | null>(null);
|
||||
const bg = ref(null);
|
||||
let narrow = $ref(false);
|
||||
const height = ref(0);
|
||||
const hasTabs = $computed(() => props.tabs && props.tabs.length > 0);
|
||||
const hasActions = $computed(() => props.actions && props.actions.length > 0);
|
||||
const show = $computed(() => {
|
||||
const el = $ref<HTMLElement | null>(null);
|
||||
const tabRefs = {};
|
||||
const tabHighlightEl = $ref<HTMLElement | null>(null);
|
||||
const tabsEl = $ref<HTMLElement | null>(null);
|
||||
const bg = ref(null);
|
||||
let narrow = $ref(false);
|
||||
const height = ref(0);
|
||||
const hasTabs = $computed(() => props.tabs && props.tabs.length > 0);
|
||||
const hasActions = $computed(() => props.actions && props.actions.length > 0);
|
||||
const show = $computed(() => {
|
||||
return !hideTitle || hasTabs || hasActions;
|
||||
});
|
||||
});
|
||||
|
||||
const openAccountMenu = (ev: MouseEvent) => {
|
||||
const openAccountMenu = (ev: MouseEvent) => {
|
||||
openAccountMenu_({
|
||||
withExtraOperation: true,
|
||||
}, ev);
|
||||
};
|
||||
};
|
||||
|
||||
const showTabsPopup = (ev: MouseEvent) => {
|
||||
const showTabsPopup = (ev: MouseEvent) => {
|
||||
if (!hasTabs) return;
|
||||
if (!narrow) return;
|
||||
ev.preventDefault();
|
||||
@ -106,24 +106,24 @@ const showTabsPopup = (ev: MouseEvent) => {
|
||||
},
|
||||
}));
|
||||
popupMenu(menu, ev.currentTarget ?? ev.target);
|
||||
};
|
||||
};
|
||||
|
||||
const preventDrag = (ev: TouchEvent) => {
|
||||
const preventDrag = (ev: TouchEvent) => {
|
||||
ev.stopPropagation();
|
||||
};
|
||||
};
|
||||
|
||||
const onClick = () => {
|
||||
const onClick = () => {
|
||||
scrollToTop(el, { behavior: 'smooth' });
|
||||
};
|
||||
};
|
||||
|
||||
function onTabMousedown(tab: Tab, ev: MouseEvent): void {
|
||||
function onTabMousedown(tab: Tab, ev: MouseEvent): void {
|
||||
// ユーザビリティの観点からmousedown時にはonClickは呼ばない
|
||||
if (tab.key) {
|
||||
emit('update:tab', tab.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onTabClick(tab: Tab, ev: MouseEvent): void {
|
||||
function onTabClick(tab: Tab, ev: MouseEvent): void {
|
||||
if (tab.onClick) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
@ -132,18 +132,18 @@ function onTabClick(tab: Tab, ev: MouseEvent): void {
|
||||
if (tab.key) {
|
||||
emit('update:tab', tab.key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const calcBg = () => {
|
||||
const calcBg = () => {
|
||||
const rawBg = metadata?.bg || 'var(--bg)';
|
||||
const tinyBg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
|
||||
tinyBg.setAlpha(0.85);
|
||||
bg.value = tinyBg.toRgbString();
|
||||
};
|
||||
};
|
||||
|
||||
let ro: ResizeObserver | null;
|
||||
let ro: ResizeObserver | null;
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(() => {
|
||||
calcBg();
|
||||
globalEvents.on('themeChanged', calcBg);
|
||||
|
||||
@ -153,12 +153,14 @@ onMounted(() => {
|
||||
if (tabEl && tabHighlightEl) {
|
||||
// offsetWidth や offsetLeft は少数を丸めてしまうため getBoundingClientRect を使う必要がある
|
||||
// https://developer.mozilla.org/ja/docs/Web/API/HTMLElement/offsetWidth#%E5%80%A4
|
||||
tabEl.addEventListener("transitionend", () => {
|
||||
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"});
|
||||
tabsEl?.scrollTo({left: left - 80, behavior: "smooth"});
|
||||
})
|
||||
}
|
||||
});
|
||||
}, {
|
||||
@ -174,16 +176,16 @@ onMounted(() => {
|
||||
});
|
||||
ro.observe(el.parentElement);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
onUnmounted(() => {
|
||||
globalEvents.off('themeChanged', calcBg);
|
||||
if (ro) ro.disconnect();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.fdidabkb {
|
||||
.fdidabkb {
|
||||
--height: 55px;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
@ -229,6 +231,14 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,6 +383,9 @@ onUnmounted(() => {
|
||||
> .icon + .title {
|
||||
margin-left: 8px;
|
||||
}
|
||||
> .title {
|
||||
transition: font-size .2s, opacity .2s .15s;
|
||||
}
|
||||
}
|
||||
|
||||
> .highlight {
|
||||
@ -381,9 +394,10 @@ onUnmounted(() => {
|
||||
height: 3px;
|
||||
background: var(--accent);
|
||||
border-radius: 999px;
|
||||
transition: all 0.2s ease;
|
||||
transition: width .2s, left .2s;
|
||||
transition-timing-function: cubic-bezier(0,0,0,1.2);
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user