2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2021-11-19 11:36:12 +01:00
|
|
|
<div ref="el" class="fdidabkb" :class="{ slim: narrow, thin: thin_ }" :style="{ background: bg }" @click="onClick">
|
2020-10-17 13:12:00 +02:00
|
|
|
<template v-if="info">
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-if="!hideTitle" class="titleContainer" @click="showTabsPopup">
|
2021-10-23 21:03:07 +02:00
|
|
|
<MkAvatar v-if="info.avatar" class="avatar" :user="info.avatar" :disable-preview="true" :show-indicator="true"/>
|
|
|
|
<i v-else-if="info.icon" class="icon" :class="info.icon"></i>
|
2021-08-05 15:43:14 +02:00
|
|
|
|
2020-12-29 03:33:21 +01:00
|
|
|
<div class="title">
|
2021-12-25 08:53:15 +01:00
|
|
|
<MkUserName v-if="info.userName" :user="info.userName" :nowrap="true" class="title"/>
|
2021-08-05 15:43:14 +02:00
|
|
|
<div v-else-if="info.title" class="title">{{ info.title }}</div>
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-if="!narrow && info.subtitle" class="subtitle">
|
2021-08-05 15:43:14 +02:00
|
|
|
{{ info.subtitle }}
|
|
|
|
</div>
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-if="narrow && hasTabs" class="subtitle activeTab">
|
2021-09-17 15:39:15 +02:00
|
|
|
{{ info.tabs.find(tab => tab.active)?.title }}
|
|
|
|
<i class="chevron fas fa-chevron-down"></i>
|
|
|
|
</div>
|
2020-12-29 03:33:21 +01:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-if="!narrow || hideTitle" class="tabs">
|
|
|
|
<button v-for="tab in info.tabs" v-tooltip="tab.title" class="tab _button" :class="{ active: tab.active }" @click="tab.onClick">
|
2021-09-17 15:39:15 +02:00
|
|
|
<i v-if="tab.icon" class="icon" :class="tab.icon"></i>
|
|
|
|
<span v-if="!tab.iconOnly" class="title">{{ tab.title }}</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
2021-09-22 14:58:08 +02:00
|
|
|
<div class="buttons right">
|
|
|
|
<template v-if="info && info.actions && !narrow">
|
2021-10-09 05:33:08 +02:00
|
|
|
<template v-for="action in info.actions">
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton v-if="action.asFullButton" class="fullButton" primary @click.stop="action.handler"><i :class="action.icon" style="margin-right: 6px;"></i>{{ action.text }}</MkButton>
|
|
|
|
<button v-else v-tooltip="action.text" class="_button button" :class="{ highlighted: action.highlighted }" @click.stop="action.handler" @touchstart="preventDrag"><i :class="action.icon"></i></button>
|
2021-10-09 05:33:08 +02:00
|
|
|
</template>
|
2021-09-22 14:58:08 +02:00
|
|
|
</template>
|
2021-11-19 11:36:12 +01:00
|
|
|
<button v-if="shouldShowMenu" v-tooltip="$ts.menu" class="_button button" @click.stop="showMenu" @touchstart="preventDrag"><i class="fas fa-ellipsis-h"></i></button>
|
2021-09-22 14:58:08 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-10-14 11:51:15 +02:00
|
|
|
import { computed, defineComponent, onMounted, onUnmounted, PropType, ref, inject } from 'vue';
|
2021-10-09 05:33:08 +02:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
2021-11-11 18:02:25 +01:00
|
|
|
import { popupMenu } from '@/os';
|
|
|
|
import { url } from '@/config';
|
|
|
|
import { scrollToTop } from '@/scripts/scroll';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { globalEvents } from '@/events';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
|
|
|
export default defineComponent({
|
2021-10-09 05:33:08 +02:00
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
props: {
|
|
|
|
info: {
|
2021-10-10 12:54:15 +02:00
|
|
|
type: Object as PropType<{
|
|
|
|
actions?: {}[];
|
|
|
|
tabs?: {}[];
|
|
|
|
}>,
|
2020-10-17 13:12:00 +02:00
|
|
|
required: true
|
|
|
|
},
|
2021-08-05 15:43:14 +02:00
|
|
|
menu: {
|
|
|
|
required: false
|
|
|
|
},
|
2021-10-08 15:03:06 +02:00
|
|
|
thin: {
|
2021-08-05 15:43:14 +02:00
|
|
|
required: false,
|
2021-10-08 15:03:06 +02:00
|
|
|
default: false
|
2021-02-14 14:26:07 +01:00
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
setup(props) {
|
|
|
|
const el = ref<HTMLElement>(null);
|
|
|
|
const bg = ref(null);
|
|
|
|
const narrow = ref(false);
|
|
|
|
const height = ref(0);
|
|
|
|
const hasTabs = computed(() => {
|
|
|
|
return props.info.tabs && props.info.tabs.length > 0;
|
|
|
|
});
|
|
|
|
const shouldShowMenu = computed(() => {
|
|
|
|
if (props.info == null) return false;
|
|
|
|
if (props.info.actions != null && narrow.value) return true;
|
|
|
|
if (props.info.menu != null) return true;
|
|
|
|
if (props.info.share != null) return true;
|
|
|
|
if (props.menu != null) return true;
|
2021-04-10 06:38:24 +02:00
|
|
|
return false;
|
2021-10-10 12:54:15 +02:00
|
|
|
});
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
const share = () => {
|
2021-04-10 16:52:45 +02:00
|
|
|
navigator.share({
|
2021-10-10 12:54:15 +02:00
|
|
|
url: url + props.info.path,
|
|
|
|
...props.info.share,
|
2021-04-10 16:52:45 +02:00
|
|
|
});
|
2021-10-10 12:54:15 +02:00
|
|
|
};
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
const showMenu = (ev: MouseEvent) => {
|
|
|
|
let menu = props.info.menu ? props.info.menu() : [];
|
|
|
|
if (narrow.value && props.info.actions) {
|
|
|
|
menu = [...props.info.actions.map(x => ({
|
2021-04-11 05:31:24 +02:00
|
|
|
text: x.text,
|
|
|
|
icon: x.icon,
|
|
|
|
action: x.handler
|
|
|
|
})), menu.length > 0 ? null : undefined, ...menu];
|
|
|
|
}
|
2021-10-10 12:54:15 +02:00
|
|
|
if (props.info.share) {
|
2021-04-10 05:40:50 +02:00
|
|
|
if (menu.length > 0) menu.push(null);
|
|
|
|
menu.push({
|
2022-01-28 03:39:49 +01:00
|
|
|
text: i18n.ts.share,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-share-alt',
|
2021-10-10 12:54:15 +02:00
|
|
|
action: share
|
2021-04-10 05:40:50 +02:00
|
|
|
});
|
|
|
|
}
|
2021-10-10 12:54:15 +02:00
|
|
|
if (props.menu) {
|
2021-08-05 15:43:14 +02:00
|
|
|
if (menu.length > 0) menu.push(null);
|
2021-10-10 12:54:15 +02:00
|
|
|
menu = menu.concat(props.menu);
|
2021-08-05 15:43:14 +02:00
|
|
|
}
|
2022-01-28 03:53:12 +01:00
|
|
|
popupMenu(menu, ev.currentTarget ?? ev.target);
|
2021-10-10 12:54:15 +02:00
|
|
|
};
|
2021-08-16 11:11:15 +02:00
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
const showTabsPopup = (ev: MouseEvent) => {
|
|
|
|
if (!hasTabs.value) return;
|
|
|
|
if (!narrow.value) return;
|
2021-09-17 15:39:15 +02:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
2021-10-10 12:54:15 +02:00
|
|
|
const menu = props.info.tabs.map(tab => ({
|
2021-09-17 15:39:15 +02:00
|
|
|
text: tab.title,
|
|
|
|
icon: tab.icon,
|
|
|
|
action: tab.onClick,
|
|
|
|
}));
|
2022-01-28 03:53:12 +01:00
|
|
|
popupMenu(menu, ev.currentTarget ?? ev.target);
|
2021-10-10 12:54:15 +02:00
|
|
|
};
|
2021-09-17 15:39:15 +02:00
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
const preventDrag = (ev: TouchEvent) => {
|
2021-08-16 11:11:15 +02:00
|
|
|
ev.stopPropagation();
|
2021-10-10 12:54:15 +02:00
|
|
|
};
|
2021-10-09 05:33:08 +02:00
|
|
|
|
2021-10-10 12:54:15 +02:00
|
|
|
const onClick = () => {
|
|
|
|
scrollToTop(el.value, { behavior: 'smooth' });
|
|
|
|
};
|
|
|
|
|
2021-10-10 17:36:47 +02:00
|
|
|
const calcBg = () => {
|
2021-10-10 12:54:15 +02:00
|
|
|
const rawBg = props.info?.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();
|
2021-10-10 17:36:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
calcBg();
|
|
|
|
globalEvents.on('themeChanged', calcBg);
|
|
|
|
onUnmounted(() => {
|
|
|
|
globalEvents.off('themeChanged', calcBg);
|
|
|
|
});
|
2021-10-10 12:54:15 +02:00
|
|
|
|
|
|
|
if (el.value.parentElement) {
|
|
|
|
narrow.value = el.value.parentElement.offsetWidth < 500;
|
2021-10-10 19:47:23 +02:00
|
|
|
const ro = new ResizeObserver((entries, observer) => {
|
|
|
|
if (el.value) {
|
|
|
|
narrow.value = el.value.parentElement.offsetWidth < 500;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ro.observe(el.value.parentElement);
|
|
|
|
onUnmounted(() => {
|
|
|
|
ro.disconnect();
|
|
|
|
});
|
2021-10-10 12:54:15 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
el,
|
|
|
|
bg,
|
|
|
|
narrow,
|
|
|
|
height,
|
|
|
|
hasTabs,
|
|
|
|
shouldShowMenu,
|
|
|
|
share,
|
|
|
|
showMenu,
|
|
|
|
showTabsPopup,
|
|
|
|
preventDrag,
|
|
|
|
onClick,
|
2021-10-14 15:40:43 +02:00
|
|
|
hideTitle: inject('shouldOmitHeaderTitle', false),
|
2021-10-14 11:51:15 +02:00
|
|
|
thin_: props.thin || inject('shouldHeaderThin', false)
|
2021-10-10 12:54:15 +02:00
|
|
|
};
|
|
|
|
},
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-11-28 04:15:22 +01:00
|
|
|
<style lang="scss" scoped>
|
2020-10-17 13:12:00 +02:00
|
|
|
.fdidabkb {
|
2021-10-08 15:03:06 +02:00
|
|
|
--height: 60px;
|
2021-08-05 15:43:14 +02:00
|
|
|
display: flex;
|
2021-10-09 05:33:08 +02:00
|
|
|
position: sticky;
|
|
|
|
top: var(--stickyTop, 0);
|
|
|
|
z-index: 1000;
|
2021-10-08 17:46:52 +02:00
|
|
|
width: 100%;
|
2021-10-09 05:33:08 +02:00
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
2021-10-10 19:47:23 +02:00
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2021-08-05 15:43:14 +02:00
|
|
|
|
2021-10-08 15:03:06 +02:00
|
|
|
&.thin {
|
|
|
|
--height: 50px;
|
2021-10-19 13:35:29 +02:00
|
|
|
|
|
|
|
> .buttons {
|
|
|
|
> .button {
|
|
|
|
font-size: 0.9em;
|
|
|
|
}
|
|
|
|
}
|
2021-10-08 15:03:06 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:39:15 +02:00
|
|
|
&.slim {
|
2021-02-14 14:26:07 +01:00
|
|
|
text-align: center;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-04-10 05:40:50 +02:00
|
|
|
> .titleContainer {
|
2021-10-16 06:02:21 +02:00
|
|
|
flex: 1;
|
2021-04-10 05:40:50 +02:00
|
|
|
margin: 0 auto;
|
2021-10-16 06:02:21 +02:00
|
|
|
margin-left: var(--height);
|
|
|
|
|
|
|
|
> *:first-child {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> *:last-child {
|
|
|
|
margin-right: auto;
|
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-10 06:38:24 +02:00
|
|
|
> .buttons {
|
2021-08-05 15:43:14 +02:00
|
|
|
--margin: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: var(--height);
|
|
|
|
margin: 0 var(--margin);
|
2021-04-10 06:38:24 +02:00
|
|
|
|
2021-08-05 15:43:14 +02:00
|
|
|
&.right {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:empty {
|
2021-04-10 06:38:24 +02:00
|
|
|
width: var(--height);
|
|
|
|
}
|
2021-08-05 15:43:14 +02:00
|
|
|
|
|
|
|
> .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);
|
|
|
|
}
|
|
|
|
}
|
2021-10-09 05:33:08 +02:00
|
|
|
|
|
|
|
> .fullButton {
|
|
|
|
& + .fullButton {
|
|
|
|
margin-left: 12px;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
> .titleContainer {
|
2021-08-05 15:43:14 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-12-25 08:53:15 +01:00
|
|
|
max-width: 400px;
|
2020-10-17 13:12:00 +02:00
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
2021-08-05 15:43:14 +02:00
|
|
|
text-align: left;
|
2021-09-17 15:39:15 +02:00
|
|
|
font-weight: bold;
|
2021-09-25 18:53:56 +02:00
|
|
|
flex-shrink: 0;
|
2021-10-08 15:03:06 +02:00
|
|
|
margin-left: 24px;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-08-05 15:43:14 +02:00
|
|
|
> .avatar {
|
|
|
|
$size: 32px;
|
2020-10-17 13:12:00 +02:00
|
|
|
display: inline-block;
|
2021-08-05 15:43:14 +02:00
|
|
|
width: $size;
|
|
|
|
height: $size;
|
2020-10-17 13:12:00 +02:00
|
|
|
vertical-align: bottom;
|
2021-08-05 15:43:14 +02:00
|
|
|
margin: 0 8px;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-08-05 15:43:14 +02:00
|
|
|
> .icon {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2021-08-05 15:43:14 +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;
|
2021-09-17 15:39:15 +02:00
|
|
|
|
|
|
|
&.activeTab {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .chevron {
|
|
|
|
display: inline-block;
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tabs {
|
|
|
|
margin-left: 16px;
|
|
|
|
font-size: 0.8em;
|
2021-09-25 18:53:56 +02:00
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
2021-09-17 15:39:15 +02:00
|
|
|
|
|
|
|
> .tab {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
padding: 0 10px;
|
|
|
|
height: 100%;
|
|
|
|
font-weight: normal;
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
opacity: 1;
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: 0 auto;
|
|
|
|
width: 100%;
|
|
|
|
height: 3px;
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .icon + .title {
|
|
|
|
margin-left: 8px;
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|