Merge pull request 'Center header tabs, only hide labels if more than 3' (#10178) from Freeplay/calckey:header into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10178
This commit is contained in:
Kainoa Kanter 2023-05-22 23:48:01 +00:00
commit 2c36590ec7
3 changed files with 199 additions and 187 deletions

View File

@ -518,7 +518,7 @@ onUnmounted(() => {
cursor: unset; cursor: unset;
padding-bottom: 0; padding-bottom: 0;
} }
&:first-of-type { &:first-child {
padding-top: 28px; padding-top: 28px;
} }
} }

View File

@ -3,31 +3,32 @@
v-if="show" v-if="show"
ref="el" ref="el"
class="fdidabkb" class="fdidabkb"
:class="{ slim: narrow, thin: thin_ }" :class="{ thin: thin_, tabs: tabs?.length > 0 }"
:style="{ background: bg }" :style="{ background: bg }"
@click="onClick" @click="onClick"
> >
<button <div class="left">
v-if="props.displayBackButton" <div class="buttons">
class="_button button icon backButton" <button
@click.stop="goBack()" v-if="props.displayBackButton"
@touchstart="preventDrag" class="_button button icon backButton"
v-tooltip.noDelay="i18n.ts.goBack" @click.stop="goBack()"
> @touchstart="preventDrag"
<i class="ph-caret-left ph-bold ph-lg"></i> v-tooltip.noDelay="i18n.ts.goBack"
</button> >
<div v-if="narrow" class="buttons left" @click="openAccountMenu"> <i class="ph-caret-left ph-bold ph-lg"></i>
<MkAvatar </button>
v-if="props.displayMyAvatar && $i" <MkAvatar
class="avatar" v-if="narrow && props.displayMyAvatar && $i"
:user="$i" class="avatar button"
:disable-preview="true" :user="$i"
disableLink :disable-preview="true"
/> disableLink
</div> @click.stop="openAccountMenu"
<template v-if="metadata"> />
</div>
<div <div
v-if="!hideTitle" v-if="!hideTitle && metadata"
class="titleContainer" class="titleContainer"
@click="showTabsPopup" @click="showTabsPopup"
> >
@ -66,7 +67,9 @@
</div> </div>
</div> </div>
</div> </div>
<nav ref="tabsEl" v-if="hasTabs" class="tabs"> </div>
<template v-if="metadata">
<nav 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)"
@ -90,11 +93,13 @@
v-if="narrow" v-if="narrow"
:user="metadata.avatar" :user="metadata.avatar"
:full="false" :full="false"
class="fullButton"
></MkFollowButton> ></MkFollowButton>
<MkFollowButton <MkFollowButton
v-else v-else
:user="metadata.avatar" :user="metadata.avatar"
:full="true" :full="true"
class="fullButton"
></MkFollowButton> ></MkFollowButton>
</template> </template>
<template v-for="action in actions"> <template v-for="action in actions">
@ -124,7 +129,6 @@ import {
nextTick, nextTick,
reactive, reactive,
} from "vue"; } from "vue";
import tinycolor from "tinycolor2";
import MkFollowButton from "@/components/MkFollowButton.vue"; import MkFollowButton from "@/components/MkFollowButton.vue";
import { popupMenu } from "@/os"; import { popupMenu } from "@/os";
import { scrollToTop } from "@/scripts/scroll"; import { scrollToTop } from "@/scripts/scroll";
@ -236,25 +240,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],
() => { () => {
@ -264,17 +252,15 @@ 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 rect = tabEl.getBoundingClientRect();
const left =
rect.left - parentRect.left + tabsEl?.scrollLeft;
tabHighlightEl.style.width = tabSizeX + "px"; tabHighlightEl.style.width = tabSizeX + "px";
tabHighlightEl.style.transform = `translateX(${left}px)`; tabHighlightEl.style.transform = `translateX(${tabEl.offsetLeft}px)`;
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
tabsEl?.scrollTo({ tabsEl?.scrollTo({
left: left - 60, left: tabEl.offsetLeft - 60,
behavior: "smooth", behavior: "smooth",
}); });
}); });
@ -299,7 +285,6 @@ onMounted(() => {
}); });
onUnmounted(() => { onUnmounted(() => {
globalEvents.off("themeChanged", calcBg);
if (ro) ro.disconnect(); if (ro) ro.disconnect();
}); });
</script> </script>
@ -308,99 +293,97 @@ onUnmounted(() => {
.fdidabkb { .fdidabkb {
--height: 55px; --height: 55px;
display: flex; display: flex;
justify-content: space-between;
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);
padding-inline: 24px;
box-sizing: border-box;
overflow: hidden;
@media (max-width: 500px) {
padding-inline: 12p
}
@media (max-width: 700px) {
> .left {
min-width: unset !important;
max-width: 40%;
}
> .left, > .right {
flex: unset !important;
}
&:not(.tabs) {
> .left {
width: 0 !important;
flex-grow: 1 !important;
max-width: unset !important;
}
}
&.tabs {
> .left {
flex-shrink: 0 !important;
}
.buttons ~ .titleContainer > .title {
display: none;
}
}
}
&::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;
} }
} }
} }
&.slim { > .left {
> .titleContainer { display: flex;
flex: 1; > .buttons {
margin: 0 auto; &:not(:empty) {
margin-left: calc(0px - var(--margin));
> *:first-child {
margin-left: auto;
} }
> .avatar {
> *:last-child { width: 32px;
margin-right: auto; height: 32px;
} margin-left: var(--margin);
}
> .tabs {
padding-inline: 12px;
mask: linear-gradient(
to right,
transparent,
black 10px 80%,
transparent
);
-webkit-mask: linear-gradient(
to right,
transparent,
black 10px 80%,
transparent
);
margin-left: -10px;
padding-left: 22px;
scrollbar-width: none;
&::before {
content: unset;
}
&::-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;
height: var(--height); height: var(--height);
margin: 0 var(--margin);
&.left {
margin-right: auto;
> .avatar {
$size: 32px;
display: inline-block;
width: $size;
height: $size;
vertical-align: bottom;
margin: 0 8px;
pointer-events: none;
}
}
&.right { &.right {
margin-left: auto; justify-content: flex-end;
:deep(.follow-button) { // margin-right: calc(0px - var(--margin));
margin-right: 6px; // margin-left: var(--margin);
> .button:last-child {
margin-right: calc(0px - var(--margin));
} }
} }
&:empty {
display: none;
}
> .button/*, @at-root .backButton*/ { > .button/*, @at-root .backButton*/ {
/* I don't know how to get this to work */ /* I don't know how to get this to work */
display: flex; display: flex;
@ -428,85 +411,117 @@ onUnmounted(() => {
} }
} }
> .backButton { > .left {
display: flex; > .backButton {
align-items: center; display: flex;
justify-content: center; align-items: center;
margin-left: 1rem; justify-content: center;
}
> .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;
margin-right: 1rem;
> .avatar {
$size: 32px;
display: inline-block;
width: $size;
height: $size;
vertical-align: bottom;
margin: 0 8px;
pointer-events: none;
} }
> .titleContainer {
> .icon { display: flex;
margin-right: 8px; align-items: center;
width: 16px; max-width: 400px;
text-align: center; overflow: auto;
transform: translate(0em);
}
> .title {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
line-height: 1.1; text-align: left;
font-weight: bold;
> .subtitle { flex-shrink: 0;
opacity: 0.6; margin-right: 1rem;
font-size: 0.8em;
font-weight: normal; > .avatar {
white-space: nowrap; $size: 32px;
display: inline-block;
width: $size;
height: $size;
vertical-align: bottom;
margin: 0 8px;
pointer-events: none;
}
> .icon {
margin-right: 8px;
width: 16px;
text-align: center;
}
> .title {
min-width: 0;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap;
&.activeTab { line-height: 1.1;
text-align: center;
> .subtitle {
> .chevron { opacity: 0.6;
display: inline-block; font-size: 0.8em;
margin-left: 6px; font-weight: normal;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&.activeTab {
text-align: center;
> .chevron {
display: inline-block;
margin-left: 6px;
}
} }
} }
} }
} }
} }
> .left, > .right {
flex-basis: 100%;
flex-shrink: 9999;
overflow: hidden;
}
> .left {
min-width: 20%;
margin-left: -10px;
padding-left: 10px;
}
> .right {
// margin-left: auto;
min-width: max-content;
margin-right: -10px;
padding-right: 10px;
}
> .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: content;
display: flex;
padding-inline: 20px;
margin-inline: -20px;
mask: linear-gradient(
to right,
transparent,
black 20px calc(100% - 20px),
transparent
);
-webkit-mask: linear-gradient(
to right,
transparent,
black 20px calc(100% - 20px),
transparent
);
scrollbar-width: none;
&::before { &.collapse {
content: ""; --width: 38px;
display: inline-block; > .tab {
height: 40%; width: 38px;
border-left: 1px solid var(--divider); min-width: 38px !important;
margin-right: 1em; &:not(.active) > .title {
margin-left: 10px; opacity: 0;
vertical-align: -1px; }
}
} }
> .tab { > .tab {
@ -515,12 +530,12 @@ onUnmounted(() => {
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, min-width .2s;
--width: max-content;
&:hover { &:hover {
opacity: 1; opacity: 1;
@ -531,9 +546,7 @@ onUnmounted(() => {
color: var(--accent); color: var(--accent);
font-weight: 600; font-weight: 600;
width: var(--width); width: var(--width);
} min-width: var(--width) !important;
&:not(.active) > .title {
opacity: 0;
} }
> .icon + .title { > .icon + .title {
@ -543,7 +556,6 @@ onUnmounted(() => {
transition: opacity 0.2s; transition: opacity 0.2s;
} }
} }
> .highlight { > .highlight {
position: absolute; position: absolute;
bottom: 0; bottom: 0;

View File

@ -103,7 +103,7 @@ body::-webkit-scrollbar-thumb {
} }
html._themeChanging_ { html._themeChanging_ {
&, * { &, *, ::before, ::after {
transition: background 1s ease, border 1s ease !important; transition: background 1s ease, border 1s ease !important;
} }
} }