2020-10-17 20:12:00 +09:00
|
|
|
<template>
|
2021-10-09 12:33:08 +09:00
|
|
|
<div class="fdidabkb" :class="{ slim: narrow, thin }" :style="{ background: bg }" @click="onClick">
|
2020-10-17 20:12:00 +09:00
|
|
|
<template v-if="info">
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="titleContainer" @click="showTabsPopup">
|
2021-08-05 22:43:14 +09:00
|
|
|
<i v-if="info.icon" class="icon" :class="info.icon"></i>
|
|
|
|
<MkAvatar v-else-if="info.avatar" class="avatar" :user="info.avatar" :disable-preview="true" :show-indicator="true"/>
|
|
|
|
|
2020-12-29 11:33:21 +09:00
|
|
|
<div class="title">
|
2021-08-05 22:43:14 +09:00
|
|
|
<MkUserName v-if="info.userName" :user="info.userName" :nowrap="false" class="title"/>
|
|
|
|
<div v-else-if="info.title" class="title">{{ info.title }}</div>
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="subtitle" v-if="!narrow && info.subtitle">
|
2021-08-05 22:43:14 +09:00
|
|
|
{{ info.subtitle }}
|
|
|
|
</div>
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="subtitle activeTab" v-if="narrow && hasTabs">
|
|
|
|
{{ info.tabs.find(tab => tab.active)?.title }}
|
|
|
|
<i class="chevron fas fa-chevron-down"></i>
|
|
|
|
</div>
|
2020-12-29 11:33:21 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
2021-09-17 22:39:15 +09:00
|
|
|
<div class="tabs" v-if="!narrow">
|
|
|
|
<button class="tab _button" v-for="tab in info.tabs" :class="{ active: tab.active }" @click="tab.onClick" v-tooltip="tab.title">
|
|
|
|
<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 20:12:00 +09:00
|
|
|
</template>
|
2021-09-22 21:58:08 +09:00
|
|
|
<div class="buttons right">
|
|
|
|
<template v-if="info && info.actions && !narrow">
|
2021-10-09 12:33:08 +09:00
|
|
|
<template v-for="action in info.actions">
|
|
|
|
<MkButton class="fullButton" v-if="action.asFullButton" @click.stop="action.handler" primary><i :class="action.icon" style="margin-right: 6px;"></i>{{ action.text }}</MkButton>
|
|
|
|
<button v-else class="_button button" :class="{ highlighted: action.highlighted }" @click.stop="action.handler" @touchstart="preventDrag" v-tooltip="action.text"><i :class="action.icon"></i></button>
|
|
|
|
</template>
|
2021-09-22 21:58:08 +09:00
|
|
|
</template>
|
|
|
|
<button v-if="shouldShowMenu" class="_button button" @click.stop="showMenu" @touchstart="preventDrag" v-tooltip="$ts.menu"><i class="fas fa-ellipsis-h"></i></button>
|
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent } from 'vue';
|
2021-10-09 12:33:08 +09:00
|
|
|
import * as tinycolor from 'tinycolor2';
|
2021-08-08 12:19:10 +09:00
|
|
|
import { popupMenu } from '@client/os';
|
2021-04-10 23:52:45 +09:00
|
|
|
import { url } from '@client/config';
|
2021-10-09 12:33:08 +09:00
|
|
|
import { scrollToTop } from '@client/scripts/scroll';
|
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
2020-10-17 20:12:00 +09:00
|
|
|
|
|
|
|
export default defineComponent({
|
2021-10-09 12:33:08 +09:00
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
props: {
|
|
|
|
info: {
|
|
|
|
required: true
|
|
|
|
},
|
2021-08-05 22:43:14 +09:00
|
|
|
menu: {
|
|
|
|
required: false
|
|
|
|
},
|
2021-10-08 22:03:06 +09:00
|
|
|
thin: {
|
2021-08-05 22:43:14 +09:00
|
|
|
required: false,
|
2021-10-08 22:03:06 +09:00
|
|
|
default: false
|
2021-02-14 22:26:07 +09:00
|
|
|
},
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-10-09 12:33:08 +09:00
|
|
|
bg: null,
|
2021-09-17 22:39:15 +09:00
|
|
|
narrow: false,
|
2020-10-17 20:12:00 +09:00
|
|
|
height: 0,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-04-10 13:38:24 +09:00
|
|
|
computed: {
|
2021-09-17 22:39:15 +09:00
|
|
|
hasTabs(): boolean {
|
|
|
|
return this.info.tabs && this.info.tabs.length > 0;
|
|
|
|
},
|
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
shouldShowMenu() {
|
2021-09-22 21:58:08 +09:00
|
|
|
if (this.info == null) return false;
|
2021-09-17 22:39:15 +09:00
|
|
|
if (this.info.actions != null && this.narrow) return true;
|
2021-04-10 13:38:24 +09:00
|
|
|
if (this.info.menu != null) return true;
|
|
|
|
if (this.info.share != null) return true;
|
2021-08-05 22:43:14 +09:00
|
|
|
if (this.menu != null) return true;
|
2021-04-10 13:38:24 +09:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
mounted() {
|
2021-10-09 12:33:08 +09:00
|
|
|
const rawBg = this.info?.bg || 'var(--bg)';
|
|
|
|
const bg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
|
|
|
|
bg.setAlpha(0.85);
|
|
|
|
this.bg = bg.toRgbString();
|
|
|
|
|
2021-10-09 00:46:52 +09:00
|
|
|
if (this.$el.parentElement == null) return;
|
|
|
|
this.narrow = this.$el.parentElement.offsetWidth < 500;
|
2020-10-17 20:12:00 +09:00
|
|
|
new ResizeObserver((entries, observer) => {
|
2021-10-09 00:46:52 +09:00
|
|
|
this.narrow = this.$el.parentElement.offsetWidth < 500;
|
|
|
|
}).observe(this.$el.parentElement);
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2021-04-10 12:40:50 +09:00
|
|
|
share() {
|
2021-04-10 23:52:45 +09:00
|
|
|
navigator.share({
|
|
|
|
url: url + this.info.path,
|
|
|
|
...this.info.share,
|
|
|
|
});
|
2021-04-10 12:40:50 +09:00
|
|
|
},
|
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
showMenu(ev) {
|
2021-04-11 12:31:24 +09:00
|
|
|
let menu = this.info.menu ? this.info.menu() : [];
|
2021-09-17 22:39:15 +09:00
|
|
|
if (this.narrow && this.info.actions) {
|
2021-04-11 12:31:24 +09:00
|
|
|
menu = [...this.info.actions.map(x => ({
|
|
|
|
text: x.text,
|
|
|
|
icon: x.icon,
|
|
|
|
action: x.handler
|
|
|
|
})), menu.length > 0 ? null : undefined, ...menu];
|
|
|
|
}
|
2021-04-10 12:40:50 +09:00
|
|
|
if (this.info.share) {
|
|
|
|
if (menu.length > 0) menu.push(null);
|
|
|
|
menu.push({
|
|
|
|
text: this.$ts.share,
|
2021-04-20 23:22:59 +09:00
|
|
|
icon: 'fas fa-share-alt',
|
2021-04-10 12:40:50 +09:00
|
|
|
action: this.share
|
|
|
|
});
|
|
|
|
}
|
2021-08-05 22:43:14 +09:00
|
|
|
if (this.menu) {
|
|
|
|
if (menu.length > 0) menu.push(null);
|
|
|
|
menu = menu.concat(this.menu);
|
|
|
|
}
|
2021-08-08 12:19:10 +09:00
|
|
|
popupMenu(menu, ev.currentTarget || ev.target);
|
2021-08-16 18:11:15 +09:00
|
|
|
},
|
|
|
|
|
2021-09-17 22:39:15 +09:00
|
|
|
showTabsPopup(ev) {
|
|
|
|
if (!this.hasTabs) return;
|
2021-09-26 01:53:56 +09:00
|
|
|
if (!this.narrow) return;
|
2021-09-17 22:39:15 +09:00
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
const menu = this.info.tabs.map(tab => ({
|
|
|
|
text: tab.title,
|
|
|
|
icon: tab.icon,
|
|
|
|
action: tab.onClick,
|
|
|
|
}));
|
|
|
|
popupMenu(menu, ev.currentTarget || ev.target);
|
|
|
|
},
|
|
|
|
|
2021-08-16 18:11:15 +09:00
|
|
|
preventDrag(ev) {
|
|
|
|
ev.stopPropagation();
|
2021-10-09 12:33:08 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick(ev) {
|
|
|
|
scrollToTop(this.$el, { behavior: 'smooth' });
|
2021-04-10 12:40:50 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-11-28 12:15:22 +09:00
|
|
|
<style lang="scss" scoped>
|
2020-10-17 20:12:00 +09:00
|
|
|
.fdidabkb {
|
2021-10-08 22:03:06 +09:00
|
|
|
--height: 60px;
|
2021-08-05 22:43:14 +09:00
|
|
|
display: flex;
|
2021-10-09 12:33:08 +09:00
|
|
|
position: sticky;
|
|
|
|
top: var(--stickyTop, 0);
|
|
|
|
z-index: 1000;
|
2021-10-09 00:46:52 +09:00
|
|
|
width: 100%;
|
2021-10-09 12:33:08 +09:00
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
2021-08-05 22:43:14 +09:00
|
|
|
|
2021-10-08 22:03:06 +09:00
|
|
|
&.thin {
|
|
|
|
--height: 50px;
|
|
|
|
}
|
|
|
|
|
2021-09-17 22:39:15 +09:00
|
|
|
&.slim {
|
2021-02-14 22:26:07 +09:00
|
|
|
text-align: center;
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-04-10 12:40:50 +09:00
|
|
|
> .titleContainer {
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
> .buttons {
|
|
|
|
&.right {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
|
2021-04-10 13:38:24 +09:00
|
|
|
> .buttons {
|
2021-08-05 22:43:14 +09:00
|
|
|
--margin: 8px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
height: var(--height);
|
|
|
|
margin: 0 var(--margin);
|
2021-04-10 13:38:24 +09:00
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
&.right {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:empty {
|
2021-04-10 13:38:24 +09:00
|
|
|
width: var(--height);
|
|
|
|
}
|
2021-08-05 22:43:14 +09: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 12:33:08 +09:00
|
|
|
|
|
|
|
> .fullButton {
|
|
|
|
& + .fullButton {
|
|
|
|
margin-left: 12px;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
> .titleContainer {
|
2021-08-05 22:43:14 +09:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-17 20:12:00 +09:00
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
2021-08-05 22:43:14 +09:00
|
|
|
text-align: left;
|
2021-09-17 22:39:15 +09:00
|
|
|
font-weight: bold;
|
2021-09-26 01:53:56 +09:00
|
|
|
flex-shrink: 0;
|
2021-10-08 22:03:06 +09:00
|
|
|
margin-left: 24px;
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
> .avatar {
|
|
|
|
$size: 32px;
|
2020-10-17 20:12:00 +09:00
|
|
|
display: inline-block;
|
2021-08-05 22:43:14 +09:00
|
|
|
width: $size;
|
|
|
|
height: $size;
|
2020-10-17 20:12:00 +09:00
|
|
|
vertical-align: bottom;
|
2021-08-05 22:43:14 +09:00
|
|
|
margin: 0 8px;
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-08-05 22:43:14 +09:00
|
|
|
> .icon {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2021-08-05 22:43:14 +09: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 22:39:15 +09:00
|
|
|
|
|
|
|
&.activeTab {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .chevron {
|
|
|
|
display: inline-block;
|
|
|
|
margin-left: 6px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .tabs {
|
|
|
|
margin-left: 16px;
|
|
|
|
font-size: 0.8em;
|
2021-09-26 01:53:56 +09:00
|
|
|
overflow: auto;
|
|
|
|
white-space: nowrap;
|
2021-09-17 22:39:15 +09: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 20:12:00 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|