Merge branch 'develop' into swn
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="fdidabkb" :class="{ slim: narrow, thin }" :style="{ background: bg }" @click="onClick">
|
||||
<div class="fdidabkb" :class="{ slim: narrow, thin }" :style="{ background: bg }" @click="onClick" ref="el">
|
||||
<template v-if="info">
|
||||
<div class="titleContainer" @click="showTabsPopup">
|
||||
<i v-if="info.icon" class="icon" :class="info.icon"></i>
|
||||
@@ -37,12 +37,14 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { computed, defineComponent, onMounted, onUnmounted, PropType, ref } from 'vue';
|
||||
import * as tinycolor from 'tinycolor2';
|
||||
import { popupMenu } from '@client/os';
|
||||
import { url } from '@client/config';
|
||||
import { scrollToTop } from '@client/scripts/scroll';
|
||||
import MkButton from '@client/components/ui/button.vue';
|
||||
import { i18n } from '@client/i18n';
|
||||
import { globalEvents } from '@client/events';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -51,6 +53,10 @@ export default defineComponent({
|
||||
|
||||
props: {
|
||||
info: {
|
||||
type: Object as PropType<{
|
||||
actions?: {}[];
|
||||
tabs?: {}[];
|
||||
}>,
|
||||
required: true
|
||||
},
|
||||
menu: {
|
||||
@@ -62,99 +68,122 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
bg: null,
|
||||
narrow: false,
|
||||
height: 0,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
hasTabs(): boolean {
|
||||
return this.info.tabs && this.info.tabs.length > 0;
|
||||
},
|
||||
|
||||
shouldShowMenu() {
|
||||
if (this.info == null) return false;
|
||||
if (this.info.actions != null && this.narrow) return true;
|
||||
if (this.info.menu != null) return true;
|
||||
if (this.info.share != null) return true;
|
||||
if (this.menu != null) return true;
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
mounted() {
|
||||
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();
|
||||
|
||||
if (this.$el.parentElement) {
|
||||
this.narrow = this.$el.parentElement.offsetWidth < 500;
|
||||
new ResizeObserver((entries, observer) => {
|
||||
this.narrow = this.$el.parentElement.offsetWidth < 500;
|
||||
}).observe(this.$el.parentElement);
|
||||
const currentStickyTop = getComputedStyle(this.$el).getPropertyValue('--stickyTop') || '0px';
|
||||
this.$el.style.setProperty('--stickyTop', currentStickyTop);
|
||||
this.$el.parentElement.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${this.$el.offsetHeight}px)`);
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
share() {
|
||||
const share = () => {
|
||||
navigator.share({
|
||||
url: url + this.info.path,
|
||||
...this.info.share,
|
||||
url: url + props.info.path,
|
||||
...props.info.share,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
showMenu(ev) {
|
||||
let menu = this.info.menu ? this.info.menu() : [];
|
||||
if (this.narrow && this.info.actions) {
|
||||
menu = [...this.info.actions.map(x => ({
|
||||
const showMenu = (ev: MouseEvent) => {
|
||||
let menu = props.info.menu ? props.info.menu() : [];
|
||||
if (narrow.value && props.info.actions) {
|
||||
menu = [...props.info.actions.map(x => ({
|
||||
text: x.text,
|
||||
icon: x.icon,
|
||||
action: x.handler
|
||||
})), menu.length > 0 ? null : undefined, ...menu];
|
||||
}
|
||||
if (this.info.share) {
|
||||
if (props.info.share) {
|
||||
if (menu.length > 0) menu.push(null);
|
||||
menu.push({
|
||||
text: this.$ts.share,
|
||||
text: i18n.locale.share,
|
||||
icon: 'fas fa-share-alt',
|
||||
action: this.share
|
||||
action: share
|
||||
});
|
||||
}
|
||||
if (this.menu) {
|
||||
if (props.menu) {
|
||||
if (menu.length > 0) menu.push(null);
|
||||
menu = menu.concat(this.menu);
|
||||
menu = menu.concat(props.menu);
|
||||
}
|
||||
popupMenu(menu, ev.currentTarget || ev.target);
|
||||
},
|
||||
};
|
||||
|
||||
showTabsPopup(ev) {
|
||||
if (!this.hasTabs) return;
|
||||
if (!this.narrow) return;
|
||||
const showTabsPopup = (ev: MouseEvent) => {
|
||||
if (!hasTabs.value) return;
|
||||
if (!narrow.value) return;
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const menu = this.info.tabs.map(tab => ({
|
||||
const menu = props.info.tabs.map(tab => ({
|
||||
text: tab.title,
|
||||
icon: tab.icon,
|
||||
action: tab.onClick,
|
||||
}));
|
||||
popupMenu(menu, ev.currentTarget || ev.target);
|
||||
},
|
||||
};
|
||||
|
||||
preventDrag(ev) {
|
||||
const preventDrag = (ev: TouchEvent) => {
|
||||
ev.stopPropagation();
|
||||
},
|
||||
};
|
||||
|
||||
onClick(ev) {
|
||||
scrollToTop(this.$el, { behavior: 'smooth' });
|
||||
}
|
||||
}
|
||||
const onClick = () => {
|
||||
scrollToTop(el.value, { behavior: 'smooth' });
|
||||
};
|
||||
|
||||
const calcBg = () => {
|
||||
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();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
calcBg();
|
||||
globalEvents.on('themeChanged', calcBg);
|
||||
onUnmounted(() => {
|
||||
globalEvents.off('themeChanged', calcBg);
|
||||
});
|
||||
|
||||
if (el.value.parentElement) {
|
||||
narrow.value = el.value.parentElement.offsetWidth < 500;
|
||||
const ro = new ResizeObserver((entries, observer) => {
|
||||
if (el.value) {
|
||||
narrow.value = el.value.parentElement.offsetWidth < 500;
|
||||
}
|
||||
});
|
||||
ro.observe(el.value.parentElement);
|
||||
onUnmounted(() => {
|
||||
ro.disconnect();
|
||||
});
|
||||
setTimeout(() => {
|
||||
const currentStickyTop = getComputedStyle(el.value.parentElement).getPropertyValue('--stickyTop') || '0px';
|
||||
el.value.style.setProperty('--stickyTop', currentStickyTop);
|
||||
el.value.parentElement.style.setProperty('--stickyTop', `calc(${currentStickyTop} + ${el.value.offsetHeight}px)`);
|
||||
}, 100); // レンダリング順序の関係で親のstickyTopの設定が少し遅れることがあるため
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
el,
|
||||
bg,
|
||||
narrow,
|
||||
height,
|
||||
hasTabs,
|
||||
shouldShowMenu,
|
||||
share,
|
||||
showMenu,
|
||||
showTabsPopup,
|
||||
preventDrag,
|
||||
onClick,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -168,6 +197,7 @@ export default defineComponent({
|
||||
width: 100%;
|
||||
-webkit-backdrop-filter: var(--blur, blur(15px));
|
||||
backdrop-filter: var(--blur, blur(15px));
|
||||
border-bottom: solid 0.5px var(--divider);
|
||||
|
||||
&.thin {
|
||||
--height: 50px;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
<component class="bghgjjyj _button"
|
||||
:is="link ? 'MkA' : 'button'"
|
||||
<button v-if="!link" class="bghgjjyj _button"
|
||||
:class="{ inline, primary, danger, rounded, full }"
|
||||
:type="type"
|
||||
@click="$emit('click', $event)"
|
||||
@@ -10,7 +9,17 @@
|
||||
<div class="content">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</component>
|
||||
</button>
|
||||
<MkA v-else class="bghgjjyj _button"
|
||||
:class="{ inline, primary, danger, rounded, full }"
|
||||
:to="to"
|
||||
@mousedown="onMousedown"
|
||||
>
|
||||
<div ref="ripples" class="ripples"></div>
|
||||
<div class="content">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</MkA>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
@@ -42,6 +51,10 @@ export default defineComponent({
|
||||
required: false,
|
||||
default: false
|
||||
},
|
||||
to: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
autofocus: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="ssazuxis" v-size="{ max: [500] }">
|
||||
<header @click="showBody = !showBody" class="_button">
|
||||
<header @click="showBody = !showBody" class="_button" :style="{ background: bg }">
|
||||
<div class="title"><slot name="header"></slot></div>
|
||||
<div class="divider"></div>
|
||||
<button class="_button">
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import * as tinycolor from 'tinycolor2';
|
||||
|
||||
const localStoragePrefix = 'ui:folder:';
|
||||
|
||||
@@ -41,6 +42,7 @@ export default defineComponent({
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
bg: null,
|
||||
showBody: (this.persistKey && localStorage.getItem(localStoragePrefix + this.persistKey)) ? localStorage.getItem(localStoragePrefix + this.persistKey) === 't' : this.expanded,
|
||||
};
|
||||
},
|
||||
@@ -51,6 +53,21 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
function getParentBg(el: Element | null): string {
|
||||
if (el == null || el.tagName === 'BODY') return 'var(--bg)';
|
||||
const bg = el.style.background || el.style.backgroundColor;
|
||||
if (bg) {
|
||||
return bg;
|
||||
} else {
|
||||
return getParentBg(el.parentElement);
|
||||
}
|
||||
}
|
||||
const rawBg = getParentBg(this.$el);
|
||||
const bg = tinycolor(rawBg.startsWith('var(') ? getComputedStyle(document.documentElement).getPropertyValue(rawBg.slice(4, -1)) : rawBg);
|
||||
bg.setAlpha(0.85);
|
||||
this.bg = bg.toRgbString();
|
||||
},
|
||||
methods: {
|
||||
toggleContent(show: boolean) {
|
||||
this.showBody = show;
|
||||
@@ -100,12 +117,8 @@ export default defineComponent({
|
||||
position: sticky;
|
||||
top: var(--stickyTop, 0px);
|
||||
padding: var(--x-padding);
|
||||
background: var(--x-header, var(--panel));
|
||||
/* TODO panelの半透明バージョンをプログラマティックに作りたい
|
||||
background: var(--X17);
|
||||
-webkit-backdrop-filter: var(--blur, blur(8px));
|
||||
backdrop-filter: var(--blur, blur(20px));
|
||||
*/
|
||||
|
||||
> .title {
|
||||
margin: 0;
|
||||
|
151
src/client/components/ui/super-menu.vue
Normal file
151
src/client/components/ui/super-menu.vue
Normal file
@@ -0,0 +1,151 @@
|
||||
<template>
|
||||
<div class="rrevdjwu" :class="{ grid }">
|
||||
<div class="group" v-for="group in def">
|
||||
<div class="title" v-if="group.title">{{ group.title }}</div>
|
||||
|
||||
<div class="items">
|
||||
<template v-for="(item, i) in group.items">
|
||||
<a v-if="item.type === 'a'" :href="item.href" :target="item.target" :tabindex="i" class="_button item" :class="{ danger: item.danger, active: item.active }">
|
||||
<i v-if="item.icon" class="icon fa-fw" :class="item.icon"></i>
|
||||
<span class="text">{{ item.text }}</span>
|
||||
</a>
|
||||
<button v-else-if="item.type === 'button'" @click="ev => item.action(ev)" :tabindex="i" class="_button item" :class="{ danger: item.danger, active: item.active }" :disabled="item.active">
|
||||
<i v-if="item.icon" class="icon fa-fw" :class="item.icon"></i>
|
||||
<span class="text">{{ item.text }}</span>
|
||||
</button>
|
||||
<MkA v-else :to="item.to" :tabindex="i" class="_button item" :class="{ danger: item.danger, active: item.active }">
|
||||
<i v-if="item.icon" class="icon fa-fw" :class="item.icon"></i>
|
||||
<span class="text">{{ item.text }}</span>
|
||||
</MkA>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, unref } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
props: {
|
||||
def: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
grid: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.rrevdjwu {
|
||||
> .group {
|
||||
& + .group {
|
||||
margin-top: 16px;
|
||||
padding-top: 16px;
|
||||
border-top: solid 0.5px var(--divider);
|
||||
}
|
||||
|
||||
margin-left: 16px;
|
||||
margin-right: 16px;
|
||||
|
||||
> .title {
|
||||
font-size: 0.9em;
|
||||
opacity: 0.7;
|
||||
margin: 0 0 8px 12px;
|
||||
}
|
||||
|
||||
> .items {
|
||||
> .item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: 10px 16px 10px 14px;
|
||||
border-radius: 999px;
|
||||
font-size: 0.9em;
|
||||
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
background: var(--panelHighlight);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: var(--accent);
|
||||
background: var(--accentedBg);
|
||||
}
|
||||
|
||||
&.danger {
|
||||
color: var(--error);
|
||||
}
|
||||
|
||||
> .icon {
|
||||
width: 32px;
|
||||
margin-right: 2px;
|
||||
flex-shrink: 0;
|
||||
text-align: center;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
> .text {
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
padding-right: 12px;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.grid {
|
||||
> .group {
|
||||
& + .group {
|
||||
padding-top: 0;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
margin-left: 0;
|
||||
margin-right: 0;
|
||||
|
||||
> .title {
|
||||
font-size: 1em;
|
||||
opacity: 0.7;
|
||||
margin: 0 0 8px 16px;
|
||||
}
|
||||
|
||||
> .items {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
||||
grid-gap: 8px;
|
||||
padding: 0 16px;
|
||||
|
||||
> .item {
|
||||
flex-direction: column;
|
||||
padding: 18px 16px 16px 16px;
|
||||
background: var(--panel);
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
|
||||
> .icon {
|
||||
display: block;
|
||||
margin-right: 0;
|
||||
margin-bottom: 12px;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
> .text {
|
||||
padding-right: 0;
|
||||
width: 100%;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user