1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-28 13:39:11 +09:00
misskey/src/client/app/desktop/views/pages/deck/deck.column.vue

224 lines
4.7 KiB
Vue
Raw Normal View History

2018-06-05 21:36:21 +09:00
<template>
<div class="dnpfarvgbnfmyzbdquhhzyxcmstpdqzs" :class="{ naked, narrow, isActive, isStacked }">
<header :class="{ indicate }" @click="toggleActive">
2018-06-05 22:54:03 +09:00
<slot name="header"></slot>
<button ref="menu" @click.stop="showMenu">%fa:caret-down%</button>
2018-06-05 21:36:21 +09:00
</header>
<div ref="body" v-show="isActive">
2018-06-05 22:54:03 +09:00
<slot></slot>
2018-06-05 21:36:21 +09:00
</div>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
2018-06-06 05:18:08 +09:00
import Menu from '../../../../common/views/components/menu.vue';
2018-06-05 21:36:21 +09:00
export default Vue.extend({
2018-06-06 05:18:08 +09:00
props: {
2018-06-07 06:13:57 +09:00
name: {
type: String,
required: false
},
menu: {
type: Array,
required: false,
default: null
},
naked: {
type: Boolean,
required: false,
default: false
},
narrow: {
type: Boolean,
required: false,
default: false
2018-06-06 05:18:08 +09:00
}
},
inject: {
column: { from: 'column' },
_isActive: { from: 'isActive' },
isStacked: { from: 'isStacked' },
getColumnVm: { from: 'getColumnVm' }
},
2018-06-06 01:54:24 +09:00
data() {
return {
indicate: false,
isActive: this._isActive
2018-06-06 01:54:24 +09:00
};
2018-06-05 21:36:21 +09:00
},
2018-06-06 01:54:24 +09:00
2018-06-05 22:54:03 +09:00
provide() {
return {
2018-06-06 01:54:24 +09:00
column: this,
isScrollTop: this.isScrollTop,
indicate: v => this.indicate = v
2018-06-05 22:54:03 +09:00
};
},
2018-06-06 01:54:24 +09:00
2018-06-05 21:36:21 +09:00
mounted() {
2018-06-07 01:52:03 +09:00
this.$refs.body.addEventListener('scroll', this.onScroll, { passive: true });
2018-06-06 01:54:24 +09:00
},
beforeDestroy() {
this.$refs.body.removeEventListener('scroll', this.onScroll);
},
methods: {
toggleActive() {
if (!this.isStacked) return;
const vms = this.$store.state.settings.deck.layout.find(ids => ids.indexOf(this.column.id) != -1).map(id => this.getColumnVm(id));
if (this.isActive && vms.filter(vm => vm.$el.classList.contains('isActive')).length == 1) return;
this.isActive = !this.isActive;
},
2018-06-06 01:54:24 +09:00
isScrollTop() {
return this.$refs.body.scrollTop == 0;
},
onScroll() {
if (this.isScrollTop()) {
this.$emit('top');
}
2018-06-05 22:54:03 +09:00
2018-06-06 01:54:24 +09:00
if (this.$store.state.settings.fetchOnScroll !== false) {
const current = this.$refs.body.scrollTop + this.$refs.body.clientHeight;
if (current > this.$refs.body.scrollHeight - 1) this.$emit('bottom');
}
2018-06-06 05:18:08 +09:00
},
showMenu() {
const items = [{
2018-06-07 06:13:57 +09:00
content: '%fa:pencil-alt% %i18n:common.deck.rename%',
onClick: () => {
(this as any).apis.input({
title: '%i18n:common.deck.rename%',
default: this.name,
allowEmpty: false
}).then(name => {
this.$store.dispatch('settings/renameDeckColumn', { id: this.column.id, name });
2018-06-07 06:13:57 +09:00
});
}
}, null, {
2018-06-07 01:17:29 +09:00
content: '%fa:arrow-left% %i18n:common.deck.swap-left%',
onClick: () => {
this.$store.dispatch('settings/swapLeftDeckColumn', this.column.id);
}
}, {
2018-06-07 01:17:29 +09:00
content: '%fa:arrow-right% %i18n:common.deck.swap-right%',
onClick: () => {
this.$store.dispatch('settings/swapRightDeckColumn', this.column.id);
}
}, null, {
content: '%fa:window-restore R% %i18n:common.deck.stack-left%',
onClick: () => {
this.$store.dispatch('settings/stackLeftDeckColumn', this.column.id);
}
}, {
content: '%fa:window-restore R% %i18n:common.deck.pop-right%',
onClick: () => {
this.$store.dispatch('settings/popRightDeckColumn', this.column.id);
}
2018-06-07 06:13:57 +09:00
}, null, {
2018-06-07 01:17:29 +09:00
content: '%fa:trash-alt R% %i18n:common.deck.remove%',
onClick: () => {
this.$store.dispatch('settings/removeDeckColumn', this.column.id);
}
}];
if (this.menu) {
items.unshift(null);
this.menu.reverse().forEach(i => items.unshift(i));
}
2018-06-06 05:18:08 +09:00
this.os.new(Menu, {
source: this.$refs.menu,
compact: false,
items
2018-06-06 05:18:08 +09:00
});
2018-06-06 01:54:24 +09:00
}
2018-06-05 21:36:21 +09:00
}
});
</script>
<style lang="stylus" scoped>
@import '~const.styl'
root(isDark)
2018-06-06 05:18:08 +09:00
$header-height = 42px
2018-06-07 08:41:58 +09:00
width 330px
min-width 330px
2018-06-05 21:36:21 +09:00
height 100%
background isDark ? #282C37 : #fff
border-radius 6px
box-shadow 0 2px 16px rgba(#000, 0.1)
overflow hidden
&:not(.isActive)
flex-basis $header-height
min-height $header-height
&:not(.isStacked).narrow
2018-06-07 08:41:58 +09:00
width 285px
min-width 285px
&.naked
background rgba(#000, isDark ? 0.25 : 0.1)
> header
background transparent
box-shadow none
if !isDark
> button
color #bbb
2018-06-05 21:36:21 +09:00
> header
z-index 1
2018-06-06 05:18:08 +09:00
line-height $header-height
2018-06-05 21:36:21 +09:00
padding 0 16px
2018-06-07 05:14:37 +09:00
font-size 14px
2018-06-05 21:36:21 +09:00
color isDark ? #e3e5e8 : #888
background isDark ? #313543 : #fff
box-shadow 0 1px rgba(#000, 0.15)
&, *
user-select none
2018-06-06 01:54:24 +09:00
&.indicate
box-shadow 0 3px 0 0 $theme-color
2018-06-06 05:18:08 +09:00
> span
[data-fa]
margin-right 8px
> button
position absolute
top 0
right 0
width $header-height
line-height $header-height
color isDark ? #9baec8 : #ccc
&:hover
color isDark ? #b2c1d5 : #aaa
&:active
color isDark ? #b2c1d5 : #999
2018-06-05 21:36:21 +09:00
> div
2018-06-06 05:29:31 +09:00
height "calc(100% - %s)" % $header-height
2018-06-05 21:36:21 +09:00
overflow auto
2018-06-05 21:44:02 +09:00
overflow-x hidden
2018-06-05 21:36:21 +09:00
.dnpfarvgbnfmyzbdquhhzyxcmstpdqzs[data-darkmode]
root(true)
.dnpfarvgbnfmyzbdquhhzyxcmstpdqzs:not([data-darkmode])
root(false)
</style>