center header

This commit is contained in:
Freeplay 2023-05-04 08:16:51 -04:00
parent 9727a03f05
commit 015eed31f8

View file

@ -7,24 +7,24 @@
:style="{ background: bg }" :style="{ background: bg }"
@click="onClick" @click="onClick"
> >
<i <div class="left">
@click="goBack()" <i
v-if="props.displayBackButton" @click="goBack()"
v-tooltip.noDelay="i18n.ts.goBack" v-if="props.displayBackButton"
class="icon backButton ph-caret-left ph-bold ph-lg" v-tooltip.noDelay="i18n.ts.goBack"
></i> class="icon backButton ph-caret-left ph-bold ph-lg"
<div v-if="narrow" class="buttons left" @click="openAccountMenu"> ></i>
<MkAvatar <div v-if="narrow" class="buttons left" @click="openAccountMenu">
v-if="props.displayMyAvatar && $i" <MkAvatar
class="avatar" v-if="props.displayMyAvatar && $i"
:user="$i" class="avatar"
:disable-preview="true" :user="$i"
disableLink :disable-preview="true"
/> disableLink
</div> />
<template v-if="metadata"> </div>
<div <div
v-if="!hideTitle" v-if="!hideTitle && metadata"
class="titleContainer" class="titleContainer"
@click="showTabsPopup" @click="showTabsPopup"
> >
@ -63,7 +63,9 @@
</div> </div>
</div> </div>
</div> </div>
<div ref="tabsEl" v-if="hasTabs" class="tabs"> </div>
<template v-if="metadata">
<div ref="tabsEl" v-if="hasTabs" class="tabs" :class="{collapse: hasTabs && tabs.length > 3}">
<button <button
v-for="tab in tabs" v-for="tab in tabs"
:ref="(el) => (tabRefs[tab.key] = el)" :ref="(el) => (tabRefs[tab.key] = el)"
@ -215,25 +217,9 @@ function goBack(): void {
window.history.back(); window.history.back();
} }
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);
watch( watch(
() => [props.tab, props.tabs], () => [props.tab, props.tabs],
() => { () => {
@ -243,7 +229,9 @@ onMounted(() => {
// 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 tabSizeX = tabEl.scrollWidth + 20; // + the tab's padding const tabSizeX = tabEl.scrollWidth + 20; // + the tab's padding
tabEl.style = `--width: ${tabSizeX}px`; if (props.tabs.length > 3) {
tabEl.style = `--width: ${tabSizeX}px`;
}
setTimeout(() => { setTimeout(() => {
const parentRect = tabsEl.getBoundingClientRect(); const parentRect = tabsEl.getBoundingClientRect();
const rect = tabEl.getBoundingClientRect(); const rect = tabEl.getBoundingClientRect();
@ -278,7 +266,6 @@ onMounted(() => {
}); });
onUnmounted(() => { onUnmounted(() => {
globalEvents.off("themeChanged", calcBg);
if (ro) ro.disconnect(); if (ro) ro.disconnect();
}); });
</script> </script>
@ -288,15 +275,32 @@ onUnmounted(() => {
--height: 55px; --height: 55px;
display: flex; display: flex;
width: 100%; width: 100%;
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
border-bottom: solid 0.5px var(--divider);
height: var(--height); height: var(--height);
max-width: 850px;
margin: auto;
&::before {
content: "";
position: absolute;
inset: 0;
border-bottom: solid 0.5px var(--divider);
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
z-index: -1;
}
&::after {
content: "";
position: absolute;
inset: 0;
background: var(--bg);
opacity: .85;
z-index: -2;
}
&.thin { &.thin {
--height: 45px; --height: 45px;
> .buttons { .buttons {
> .button { > .button {
font-size: 0.9em; font-size: 0.9em;
} }
@ -304,7 +308,7 @@ onUnmounted(() => {
} }
&.slim { &.slim {
> .titleContainer { > .left > .titleContainer {
flex: 1; flex: 1;
margin: 0 auto; margin: 0 auto;
@ -348,14 +352,9 @@ onUnmounted(() => {
} }
} }
> .buttons { > .left {
--margin: 8px;
display: flex; display: flex;
align-items: center; > .buttons {
height: var(--height);
margin: 0 var(--margin);
&.left {
margin-right: auto; margin-right: auto;
> .avatar { > .avatar {
@ -368,13 +367,17 @@ onUnmounted(() => {
pointer-events: none; pointer-events: none;
} }
} }
}
> .buttons {
--margin: 8px;
display: flex;
align-items: center;
height: var(--height);
margin: 0 var(--margin);
&.right { &.right {
margin-left: auto; justify-content: flex-end;
}
&:empty {
display: none;
} }
> .button { > .button {
@ -410,7 +413,7 @@ onUnmounted(() => {
margin-left: 1rem; margin-left: 1rem;
} }
> .titleContainer { > .left > .titleContainer {
display: flex; display: flex;
align-items: center; align-items: center;
max-width: 400px; max-width: 400px;
@ -466,34 +469,49 @@ onUnmounted(() => {
} }
} }
> .buttons, > .left {
width: 20%;
}
> .tabs { > .tabs {
position: relative; position: relative;
width: 100%;
font-size: 1em; font-size: 1em;
overflow-x: auto; overflow-x: auto;
white-space: nowrap; white-space: nowrap;
contain: strict; contain: strict;
display: flex;
&::before { flex-grow: 1;
content: ""; justify-content: center;
display: inline-block; &.collapse {
height: 40%; --width: 38px;
border-left: 1px solid var(--divider); > .tab {
margin-right: 1em; width: 38px;
margin-left: 10px; min-width: unset !important;
vertical-align: -1px; &:not(.active) > .title {
opacity: 0;
}
}
} }
// &::before {
// content: "";
// display: inline-block;
// height: 40%;
// border-left: 1px solid var(--divider);
// margin-right: 1em;
// margin-left: 10px;
// vertical-align: -1px;
// }
> .tab { > .tab {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
position: relative; position: relative;
border-inline: 10px solid transparent; border-inline: 10px solid transparent;
height: 100%; height: 100%;
min-width: max-content;
font-weight: normal; font-weight: normal;
opacity: 0.7; opacity: 0.7;
width: 38px;
--width: 38px;
overflow: hidden; overflow: hidden;
transition: color 0.2s, opacity 0.2s, width 0.2s; transition: color 0.2s, opacity 0.2s, width 0.2s;
@ -507,9 +525,6 @@ onUnmounted(() => {
font-weight: 600; font-weight: 600;
width: var(--width); width: var(--width);
} }
&:not(.active) > .title {
opacity: 0;
}
> .icon + .title { > .icon + .title {
margin-left: 8px; margin-left: 8px;
@ -518,7 +533,6 @@ onUnmounted(() => {
transition: opacity 0.2s; transition: opacity 0.2s;
} }
} }
> .highlight { > .highlight {
position: absolute; position: absolute;
bottom: 0; bottom: 0;