misskey/src/client/components/menu.vue

192 lines
4.0 KiB
Vue
Raw Normal View History

<template>
2020-02-08 15:52:40 +01:00
<x-popup :source="source" :no-center="noCenter" :fixed="fixed" :width="width" ref="popup" @closed="() => { $emit('closed'); destroyDom(); }" v-hotkey.global="keymap">
2020-03-20 16:21:33 +01:00
<div class="rrevdjwt" :class="{ left: align === 'left' }" ref="items">
<template v-for="(item, i) in items.filter(item => item !== undefined)">
2020-02-06 06:23:01 +01:00
<div v-if="item === null" class="divider" :key="i"></div>
<span v-else-if="item.type === 'label'" class="label item" :key="i">
<span>{{ item.text }}</span>
</span>
2020-02-06 06:23:01 +01:00
<router-link v-else-if="item.type === 'link'" :to="item.to" @click.native="close()" :tabindex="i" class="_button item" :key="i">
<fa v-if="item.icon" :icon="item.icon" fixed-width/>
<mk-avatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
<span>{{ item.text }}</span>
<i v-if="item.indicate"><fa :icon="faCircle"/></i>
</router-link>
2020-02-06 06:23:01 +01:00
<a v-else-if="item.type === 'a'" :href="item.href" :target="item.target" :download="item.download" @click="close()" :tabindex="i" class="_button item" :key="i">
<fa v-if="item.icon" :icon="item.icon" fixed-width/>
<span>{{ item.text }}</span>
<i v-if="item.indicate"><fa :icon="faCircle"/></i>
</a>
2020-02-06 06:23:01 +01:00
<button v-else-if="item.type === 'user'" @click="clicked(item.action)" :tabindex="i" class="_button item" :key="i">
<mk-avatar :user="item.user" class="avatar"/><mk-user-name :user="item.user"/>
<i v-if="item.indicate"><fa :icon="faCircle"/></i>
</button>
2020-02-06 06:23:01 +01:00
<button v-else @click="clicked(item.action)" :tabindex="i" class="_button item" :key="i">
<fa v-if="item.icon" :icon="item.icon" fixed-width/>
<mk-avatar v-if="item.avatar" :user="item.avatar" class="avatar"/>
<span>{{ item.text }}</span>
<i v-if="item.indicate"><fa :icon="faCircle"/></i>
</button>
</template>
2020-03-20 16:21:33 +01:00
</div>
</x-popup>
</template>
<script lang="ts">
import Vue from 'vue';
import { faCircle } from '@fortawesome/free-solid-svg-icons';
import XPopup from './popup.vue';
2020-02-08 15:52:40 +01:00
import { focusPrev, focusNext } from '../scripts/focus';
export default Vue.extend({
components: {
XPopup
},
props: {
source: {
required: true
},
items: {
type: Array,
required: true
},
align: {
type: String,
required: false
},
noCenter: {
type: Boolean,
required: false
},
fixed: {
type: Boolean,
required: false
},
width: {
type: Number,
required: false
},
direction: {
type: String,
required: false
},
2020-02-08 15:52:40 +01:00
viaKeyboard: {
type: Boolean,
required: false
},
},
data() {
return {
faCircle
};
},
2020-02-08 15:52:40 +01:00
computed: {
keymap(): any {
return {
'up|k|shift+tab': this.focusUp,
'down|j|tab': this.focusDown,
};
},
},
mounted() {
if (this.viaKeyboard) {
this.$nextTick(() => {
2020-03-20 16:21:33 +01:00
focusNext(this.$refs.items.children[0], true);
2020-02-08 15:52:40 +01:00
});
}
},
methods: {
clicked(fn) {
fn();
this.close();
},
close() {
this.$refs.popup.close();
2020-02-08 15:52:40 +01:00
},
focusUp() {
focusPrev(document.activeElement);
},
focusDown() {
focusNext(document.activeElement);
}
}
});
</script>
<style lang="scss" scoped>
.rrevdjwt {
padding: 8px 0;
&.left {
> .item {
text-align: left;
}
}
> .item {
display: block;
2020-02-13 14:48:56 +01:00
position: relative;
padding: 8px 16px;
width: 100%;
box-sizing: border-box;
white-space: nowrap;
font-size: 0.9em;
2020-02-14 18:26:45 +01:00
line-height: 20px;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
&:hover {
color: #fff;
background: var(--accent);
text-decoration: none;
}
&:active {
color: #fff;
background: var(--accentDarken);
}
2020-02-08 15:52:40 +01:00
&:not(:active):focus {
box-shadow: 0 0 0 2px var(--focus) inset;
}
&.label {
pointer-events: none;
font-size: 0.7em;
padding-bottom: 4px;
> span {
opacity: 0.7;
}
}
> [data-icon] {
margin-right: 4px;
width: 20px;
}
> .avatar {
margin-right: 4px;
width: 20px;
height: 20px;
}
> i {
position: absolute;
top: 5px;
left: 13px;
2020-02-16 23:14:03 +01:00
color: var(--indicator);
font-size: 12px;
animation: blink 1s infinite;
}
}
> .divider {
margin: 8px 0;
height: 1px;
background: var(--divider);
}
}
</style>