2020-10-17 06:12:00 -05:00
|
|
|
<template>
|
2022-01-29 23:11:52 -06:00
|
|
|
<div ref="itemsEl" v-hotkey="keymap"
|
2021-11-19 04:36:12 -06:00
|
|
|
class="rrevdjwt"
|
2021-12-16 11:14:40 -06:00
|
|
|
:class="{ center: align === 'center', asDrawer }"
|
2022-01-29 23:11:52 -06:00
|
|
|
:style="{ width: (width && !asDrawer) ? width + 'px' : '', maxHeight: maxHeight ? maxHeight + 'px' : '' }"
|
2020-10-17 06:12:00 -05:00
|
|
|
@contextmenu.self="e => e.preventDefault()"
|
|
|
|
>
|
2021-11-18 08:32:43 -06:00
|
|
|
<template v-for="(item, i) in items2">
|
2020-10-17 06:12:00 -05:00
|
|
|
<div v-if="item === null" class="divider"></div>
|
|
|
|
<span v-else-if="item.type === 'label'" class="label item">
|
|
|
|
<span>{{ item.text }}</span>
|
|
|
|
</span>
|
|
|
|
<span v-else-if="item.type === 'pending'" :tabindex="i" class="pending item">
|
|
|
|
<span><MkEllipsis/></span>
|
|
|
|
</span>
|
2021-11-19 04:36:12 -06:00
|
|
|
<MkA v-else-if="item.type === 'link'" :to="item.to" :tabindex="i" class="_button item" @click.passive="close()">
|
2021-04-20 09:22:59 -05:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
|
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 09:22:59 -05:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-24 11:21:41 -05:00
|
|
|
</MkA>
|
2021-11-19 04:36:12 -06:00
|
|
|
<a v-else-if="item.type === 'a'" :href="item.href" :target="item.target" :download="item.download" :tabindex="i" class="_button item" @click="close()">
|
2021-04-20 09:22:59 -05:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 06:12:00 -05:00
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 09:22:59 -05:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 06:12:00 -05:00
|
|
|
</a>
|
2022-01-21 05:17:31 -06:00
|
|
|
<button v-else-if="item.type === 'user'" :tabindex="i" class="_button item" :class="{ active: item.active }" :disabled="item.active" @click="clicked(item.action, $event)">
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkAvatar :user="item.user" class="avatar"/><MkUserName :user="item.user"/>
|
2021-04-20 09:22:59 -05:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 06:12:00 -05:00
|
|
|
</button>
|
2022-01-29 23:11:52 -06:00
|
|
|
<span v-else-if="item.type === 'switch'" :tabindex="i" class="item">
|
|
|
|
<FormSwitch v-model="item.ref" :disabled="item.disabled" class="form-switch">{{ item.text }}</FormSwitch>
|
|
|
|
</span>
|
2021-11-19 04:36:12 -06:00
|
|
|
<button v-else :tabindex="i" class="_button item" :class="{ danger: item.danger, active: item.active }" :disabled="item.active" @click="clicked(item.action, $event)">
|
2021-04-20 09:22:59 -05:00
|
|
|
<i v-if="item.icon" class="fa-fw" :class="item.icon"></i>
|
2020-10-17 06:12:00 -05:00
|
|
|
<MkAvatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
|
|
|
|
<span>{{ item.text }}</span>
|
2021-04-20 09:22:59 -05:00
|
|
|
<span v-if="item.indicate" class="indicator"><i class="fas fa-circle"></i></span>
|
2020-10-17 06:12:00 -05:00
|
|
|
</button>
|
|
|
|
</template>
|
2021-11-18 08:32:43 -06:00
|
|
|
<span v-if="items2.length === 0" class="none item">
|
2020-12-25 19:47:36 -06:00
|
|
|
<span>{{ $ts.none }}</span>
|
2020-10-17 06:12:00 -05:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-29 23:11:52 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { nextTick, onMounted, watch } from 'vue';
|
2021-11-11 11:02:25 -06:00
|
|
|
import { focusPrev, focusNext } from '@/scripts/focus';
|
2022-01-29 23:11:52 -06:00
|
|
|
import FormSwitch from '@/components/form/switch.vue';
|
|
|
|
import { MenuItem, InnerMenuItem, MenuPending, MenuAction } from '@/types/menu';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
items: MenuItem[];
|
|
|
|
viaKeyboard?: boolean;
|
|
|
|
asDrawer?: boolean;
|
|
|
|
align?: 'center' | string;
|
|
|
|
width?: number;
|
|
|
|
maxHeight?: number;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(e: 'close'): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let itemsEl = $ref<HTMLDivElement>();
|
|
|
|
|
|
|
|
let items2: InnerMenuItem[] = $ref([]);
|
|
|
|
|
|
|
|
let keymap = $computed(() => ({
|
|
|
|
'up|k|shift+tab': focusUp,
|
|
|
|
'down|j|tab': focusDown,
|
|
|
|
'esc': close,
|
|
|
|
}));
|
|
|
|
|
|
|
|
watch(() => props.items, () => {
|
|
|
|
const items: (MenuItem | MenuPending)[] = [...props.items].filter(item => item !== undefined);
|
|
|
|
|
|
|
|
for (let i = 0; i < items.length; i++) {
|
|
|
|
const item = items[i];
|
|
|
|
|
|
|
|
if (item && 'then' in item) { // if item is Promise
|
|
|
|
items[i] = { type: 'pending' };
|
|
|
|
item.then(actualItem => {
|
|
|
|
items2[i] = actualItem;
|
2020-10-17 06:12:00 -05:00
|
|
|
});
|
|
|
|
}
|
2022-01-29 23:11:52 -06:00
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2022-01-29 23:11:52 -06:00
|
|
|
items2 = items as InnerMenuItem[];
|
|
|
|
}, {
|
|
|
|
immediate: true,
|
|
|
|
});
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2022-01-29 23:11:52 -06:00
|
|
|
onMounted(() => {
|
|
|
|
if (props.viaKeyboard) {
|
|
|
|
nextTick(() => {
|
|
|
|
focusNext(itemsEl.children[0], true, false);
|
|
|
|
});
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
});
|
2022-01-29 23:11:52 -06:00
|
|
|
|
|
|
|
function clicked(fn: MenuAction, ev: MouseEvent) {
|
|
|
|
fn(ev);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
emit('close');
|
|
|
|
}
|
|
|
|
|
|
|
|
function focusUp() {
|
|
|
|
focusPrev(document.activeElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
function focusDown() {
|
|
|
|
focusNext(document.activeElement);
|
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.rrevdjwt {
|
|
|
|
padding: 8px 0;
|
2021-11-28 05:07:37 -06:00
|
|
|
box-sizing: border-box;
|
2021-10-03 01:39:39 -05:00
|
|
|
min-width: 200px;
|
2021-11-04 20:48:37 -05:00
|
|
|
overflow: auto;
|
2021-12-02 21:00:11 -06:00
|
|
|
overscroll-behavior: contain;
|
2020-10-17 06:12:00 -05:00
|
|
|
|
2021-10-03 01:39:39 -05:00
|
|
|
&.center {
|
2020-10-17 06:12:00 -05:00
|
|
|
> .item {
|
2021-10-03 01:39:39 -05:00
|
|
|
text-align: center;
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
display: block;
|
|
|
|
position: relative;
|
2021-10-15 09:35:28 -05:00
|
|
|
padding: 8px 18px;
|
2020-10-17 06:12:00 -05:00
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
white-space: nowrap;
|
|
|
|
font-size: 0.9em;
|
|
|
|
line-height: 20px;
|
2021-10-03 01:39:39 -05:00
|
|
|
text-align: left;
|
2021-03-02 07:57:16 -06:00
|
|
|
overflow: hidden;
|
2020-10-17 06:12:00 -05:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
2021-10-03 01:39:39 -05:00
|
|
|
&:before {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
margin: auto;
|
2021-10-15 09:33:27 -05:00
|
|
|
width: calc(100% - 16px);
|
2021-10-03 01:39:39 -05:00
|
|
|
height: 100%;
|
2021-10-15 09:33:27 -05:00
|
|
|
border-radius: 6px;
|
2021-10-03 01:39:39 -05:00
|
|
|
}
|
|
|
|
|
2021-10-08 23:12:41 -05:00
|
|
|
> * {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:12:00 -05:00
|
|
|
&.danger {
|
|
|
|
color: #ff2a2a;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: #fff;
|
2021-10-03 01:39:39 -05:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: #ff4242;
|
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
color: #fff;
|
2021-10-03 01:39:39 -05:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: #d42e2e;
|
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-08 23:12:41 -05:00
|
|
|
&.active {
|
|
|
|
color: var(--fgOnAccent);
|
|
|
|
opacity: 1;
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:not(:disabled):hover {
|
2021-10-03 01:39:39 -05:00
|
|
|
color: var(--accent);
|
2020-10-17 06:12:00 -05:00
|
|
|
text-decoration: none;
|
2021-10-03 01:39:39 -05:00
|
|
|
|
|
|
|
&:before {
|
|
|
|
background: var(--accentedBg);
|
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
|
2021-10-02 12:46:58 -05:00
|
|
|
&:not(:active):focus-visible {
|
2020-10-17 06:12:00 -05:00
|
|
|
box-shadow: 0 0 0 2px var(--focus) inset;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.label {
|
|
|
|
pointer-events: none;
|
|
|
|
font-size: 0.7em;
|
|
|
|
padding-bottom: 4px;
|
|
|
|
|
|
|
|
> span {
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.pending {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.none {
|
|
|
|
pointer-events: none;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
2021-04-20 09:22:59 -05:00
|
|
|
> i {
|
2021-10-15 09:35:28 -05:00
|
|
|
margin-right: 5px;
|
2020-10-17 06:12:00 -05:00
|
|
|
width: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .avatar {
|
2021-10-15 09:35:28 -05:00
|
|
|
margin-right: 5px;
|
2020-10-17 06:12:00 -05:00
|
|
|
width: 20px;
|
|
|
|
height: 20px;
|
|
|
|
}
|
|
|
|
|
2021-04-20 09:22:59 -05:00
|
|
|
> .indicator {
|
2020-10-17 06:12:00 -05:00
|
|
|
position: absolute;
|
|
|
|
top: 5px;
|
|
|
|
left: 13px;
|
|
|
|
color: var(--indicator);
|
|
|
|
font-size: 12px;
|
|
|
|
animation: blink 1s infinite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .divider {
|
|
|
|
margin: 8px 0;
|
2021-12-18 00:00:29 -06:00
|
|
|
border-top: solid 0.5px var(--divider);
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
2021-12-16 11:14:40 -06:00
|
|
|
|
|
|
|
&.asDrawer {
|
2021-12-24 08:25:23 -06:00
|
|
|
padding: 12px 0 calc(env(safe-area-inset-bottom, 0px) + 12px) 0;
|
2021-12-16 11:14:40 -06:00
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
> .item {
|
|
|
|
font-size: 1em;
|
|
|
|
padding: 12px 24px;
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
width: calc(100% - 24px);
|
|
|
|
border-radius: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> i {
|
|
|
|
margin-right: 14px;
|
|
|
|
width: 24px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .divider {
|
|
|
|
margin: 12px 0;
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 06:12:00 -05:00
|
|
|
}
|
|
|
|
</style>
|