2022-06-20 10:38:49 +02:00
|
|
|
<template>
|
|
|
|
<div v-if="show" ref="el" class="fdidabkb" :class="{ slim: narrow, thin: thin_ }" :style="{ background: bg }" @click="onClick">
|
2022-08-16 09:28:33 +02:00
|
|
|
<div v-if="narrow" class="buttons left" @click="openAccountMenu">
|
|
|
|
<MkAvatar v-if="props.displayMyAvatar && $i" class="avatar" :user="$i" :disable-preview="true"/>
|
2022-08-13 10:41:17 +02:00
|
|
|
</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
<template v-if="metadata">
|
|
|
|
<div v-if="!hideTitle" class="titleContainer" @click="showTabsPopup">
|
|
|
|
<MkAvatar v-if="metadata.avatar" class="avatar" :user="metadata.avatar" :disable-preview="true" :show-indicator="true"/>
|
2022-09-08 01:18:04 +02:00
|
|
|
<i v-else-if="metadata.icon && !narrow" class="icon" :class="metadata.icon"></i>
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
<div class="title">
|
|
|
|
<MkUserName v-if="metadata.userName" :user="metadata.userName" :nowrap="true" class="title"/>
|
2022-09-10 00:04:31 +02:00
|
|
|
<div v-else-if="metadata.title && !(tabs != null && tabs.length > 0 && narrow)" class="title">{{ metadata.title }}</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
<div v-if="!narrow && metadata.subtitle" class="subtitle">
|
|
|
|
{{ metadata.subtitle }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-08 00:33:21 +02:00
|
|
|
<div class="tabs">
|
2022-07-16 06:49:23 +02:00
|
|
|
<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)">
|
2022-09-08 01:18:04 +02:00
|
|
|
<i v-if="tab.icon" class="icon" :class="tab.icon"></i>
|
2022-09-08 00:37:04 +02:00
|
|
|
<span v-if="!tab.iconOnly && !narrow" class="title">{{ tab.title }}</span>
|
2022-06-20 10:38:49 +02:00
|
|
|
</button>
|
2022-06-22 09:29:21 +02:00
|
|
|
<div ref="tabHighlightEl" class="highlight"></div>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<div class="buttons right">
|
|
|
|
<template v-for="action in actions">
|
2022-07-16 06:49:23 +02:00
|
|
|
<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>
|
2022-06-20 10:38:49 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-07-01 11:55:45 +02:00
|
|
|
import { computed, onMounted, onUnmounted, ref, inject, watch, shallowReactive, nextTick, reactive } from 'vue';
|
2022-06-20 10:38:49 +02:00
|
|
|
import tinycolor from 'tinycolor2';
|
|
|
|
import { popupMenu } from '@/os';
|
|
|
|
import { scrollToTop } from '@/scripts/scroll';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { globalEvents } from '@/events';
|
2022-06-22 09:29:21 +02:00
|
|
|
import { injectPageMetadata } from '@/scripts/page-metadata';
|
2022-08-16 09:22:37 +02:00
|
|
|
import { $i, openAccountMenu as openAccountMenu_ } from '@/account';
|
2022-06-22 09:29:21 +02:00
|
|
|
|
|
|
|
type Tab = {
|
|
|
|
key?: string | null;
|
|
|
|
title: string;
|
|
|
|
icon?: string;
|
|
|
|
iconOnly?: boolean;
|
|
|
|
onClick?: (ev: MouseEvent) => void;
|
|
|
|
};
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2022-06-22 09:29:21 +02:00
|
|
|
tabs?: Tab[];
|
|
|
|
tab?: string;
|
2022-06-20 10:38:49 +02:00
|
|
|
actions?: {
|
|
|
|
text: string;
|
|
|
|
icon: string;
|
|
|
|
handler: (ev: MouseEvent) => void;
|
|
|
|
}[];
|
|
|
|
thin?: boolean;
|
2022-08-13 10:41:17 +02:00
|
|
|
displayMyAvatar?: boolean;
|
2022-06-20 10:38:49 +02:00
|
|
|
}>();
|
|
|
|
|
2022-06-22 09:29:21 +02:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'update:tab', key: string);
|
|
|
|
}>();
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const metadata = injectPageMetadata();
|
|
|
|
|
|
|
|
const hideTitle = inject('shouldOmitHeaderTitle', false);
|
|
|
|
const thin_ = props.thin || inject('shouldHeaderThin', false);
|
|
|
|
|
|
|
|
const el = $ref<HTMLElement | null>(null);
|
2022-06-22 09:29:21 +02:00
|
|
|
const tabRefs = {};
|
|
|
|
const tabHighlightEl = $ref<HTMLElement | null>(null);
|
2022-06-20 10:38:49 +02:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
2022-08-16 09:22:37 +02:00
|
|
|
const openAccountMenu = (ev: MouseEvent) => {
|
|
|
|
openAccountMenu_({
|
|
|
|
withExtraOperation: true,
|
|
|
|
}, ev);
|
|
|
|
};
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
const showTabsPopup = (ev: MouseEvent) => {
|
|
|
|
if (!hasTabs) return;
|
|
|
|
if (!narrow) return;
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
const menu = props.tabs.map(tab => ({
|
|
|
|
text: tab.title,
|
|
|
|
icon: tab.icon,
|
2022-06-22 09:29:21 +02:00
|
|
|
active: tab.key != null && tab.key === props.tab,
|
|
|
|
action: (ev) => {
|
|
|
|
onTabClick(tab, ev);
|
|
|
|
},
|
2022-06-20 10:38:49 +02:00
|
|
|
}));
|
|
|
|
popupMenu(menu, ev.currentTarget ?? ev.target);
|
|
|
|
};
|
|
|
|
|
|
|
|
const preventDrag = (ev: TouchEvent) => {
|
|
|
|
ev.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
const onClick = () => {
|
|
|
|
scrollToTop(el, { behavior: 'smooth' });
|
|
|
|
};
|
|
|
|
|
2022-06-22 09:29:21 +02:00
|
|
|
function onTabMousedown(tab: Tab, ev: MouseEvent): void {
|
|
|
|
// ユーザビリティの観点からmousedown時にはonClickは呼ばない
|
|
|
|
if (tab.key) {
|
|
|
|
emit('update:tab', tab.key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onTabClick(tab: Tab, ev: MouseEvent): void {
|
2022-06-22 13:47:53 +02:00
|
|
|
if (tab.onClick) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
tab.onClick(ev);
|
|
|
|
}
|
2022-06-22 09:29:21 +02:00
|
|
|
if (tab.key) {
|
|
|
|
emit('update:tab', tab.key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
calcBg();
|
|
|
|
globalEvents.on('themeChanged', calcBg);
|
|
|
|
|
2022-07-01 11:55:45 +02:00
|
|
|
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
|
|
|
|
const parentRect = tabEl.parentElement.getBoundingClientRect();
|
|
|
|
const rect = tabEl.getBoundingClientRect();
|
|
|
|
tabHighlightEl.style.width = rect.width + 'px';
|
|
|
|
tabHighlightEl.style.left = (rect.left - parentRect.left) + 'px';
|
|
|
|
}
|
|
|
|
});
|
2022-06-22 09:29:21 +02:00
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
if (el && el.parentElement) {
|
|
|
|
narrow = el.parentElement.offsetWidth < 500;
|
|
|
|
ro = new ResizeObserver((entries, observer) => {
|
2022-06-22 13:47:53 +02:00
|
|
|
if (el.parentElement && document.body.contains(el)) {
|
2022-06-20 10:38:49 +02:00
|
|
|
narrow = el.parentElement.offsetWidth < 500;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ro.observe(el.parentElement);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
globalEvents.off('themeChanged', calcBg);
|
|
|
|
if (ro) ro.disconnect();
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.fdidabkb {
|
2022-07-03 09:46:00 +02:00
|
|
|
--height: 55px;
|
2022-06-20 10:38:49 +02:00
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2022-07-05 15:35:57 +02:00
|
|
|
contain: strict;
|
|
|
|
height: var(--height);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
&.thin {
|
2022-06-28 11:09:42 +02:00
|
|
|
--height: 45px;
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
> .buttons {
|
|
|
|
> .button {
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.slim {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .titleContainer {
|
|
|
|
flex: 1;
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
|
|
> *:first-child {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> *:last-child {
|
|
|
|
margin-right: auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .buttons {
|
|
|
|
--margin: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2022-08-13 10:41:17 +02:00
|
|
|
min-width: var(--height);
|
2022-06-20 10:38:49 +02:00
|
|
|
height: var(--height);
|
|
|
|
margin: 0 var(--margin);
|
|
|
|
|
2022-08-13 10:41:17 +02:00
|
|
|
&.left {
|
|
|
|
margin-right: auto;
|
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
$size: 32px;
|
|
|
|
display: inline-block;
|
|
|
|
width: $size;
|
|
|
|
height: $size;
|
|
|
|
vertical-align: bottom;
|
|
|
|
margin: 0 8px;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
&.right {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
width: var(--height);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .button {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
height: calc(var(--height) - (var(--margin) * 2));
|
|
|
|
width: calc(var(--height) - (var(--margin) * 2));
|
|
|
|
box-sizing: border-box;
|
|
|
|
position: relative;
|
|
|
|
border-radius: 5px;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: rgba(0, 0, 0, 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.highlighted {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .fullButton {
|
|
|
|
& + .fullButton {
|
|
|
|
margin-left: 12px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .titleContainer {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
max-width: 400px;
|
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
|
|
|
text-align: left;
|
|
|
|
font-weight: bold;
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin-left: 24px;
|
2022-10-26 08:19:45 +02:00
|
|
|
margin-right: 1rem;
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
$size: 32px;
|
|
|
|
display: inline-block;
|
|
|
|
width: $size;
|
|
|
|
height: $size;
|
|
|
|
vertical-align: bottom;
|
|
|
|
margin: 0 8px;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin-right: 8px;
|
2022-06-22 13:47:53 +02:00
|
|
|
width: 16px;
|
|
|
|
text-align: center;
|
2022-11-07 04:29:42 +01:00
|
|
|
transform: translate(0em);
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
> .title {
|
|
|
|
min-width: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
line-height: 1.1;
|
|
|
|
|
|
|
|
> .subtitle {
|
|
|
|
opacity: 0.6;
|
|
|
|
font-size: 0.8em;
|
|
|
|
font-weight: normal;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
|
|
&.activeTab {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .chevron {
|
|
|
|
display: inline-block;
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tabs {
|
2022-06-22 09:29:21 +02:00
|
|
|
position: relative;
|
2022-09-08 19:42:01 +02:00
|
|
|
width: 100%;
|
|
|
|
font-size: 1em;
|
2022-06-20 10:38:49 +02:00
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
> .tab {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
padding: 0 10px;
|
|
|
|
height: 100%;
|
|
|
|
font-weight: normal;
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .icon + .title {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
}
|
2022-06-22 09:29:21 +02:00
|
|
|
|
|
|
|
> .highlight {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
height: 3px;
|
|
|
|
background: var(--accent);
|
|
|
|
border-radius: 999px;
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2022-06-20 10:38:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|