2020-01-29 11:37:25 -08:00
|
|
|
<script lang="ts">
|
2020-12-11 20:06:26 -08:00
|
|
|
import { defineComponent, h, TransitionGroup } from 'vue';
|
2021-05-04 05:15:57 -07:00
|
|
|
import MkAd from '@client/components/global/ad.vue';
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2020-10-17 04:12:00 -07:00
|
|
|
export default defineComponent({
|
2020-01-29 11:37:25 -08:00
|
|
|
props: {
|
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
direction: {
|
|
|
|
type: String,
|
2020-02-20 16:11:35 -08:00
|
|
|
required: false,
|
|
|
|
default: 'down'
|
2020-02-05 21:23:01 -08:00
|
|
|
},
|
|
|
|
reversed: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2021-04-16 08:12:50 -07:00
|
|
|
},
|
|
|
|
noGap: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2021-05-04 05:15:57 -07:00
|
|
|
ad: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
},
|
|
|
|
|
2020-12-11 20:06:26 -08:00
|
|
|
methods: {
|
|
|
|
focus() {
|
|
|
|
this.$slots.default[0].elm.focus();
|
2021-04-15 04:26:02 -07:00
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2021-04-15 04:26:02 -07:00
|
|
|
getDateText(time: string) {
|
2020-01-29 11:37:25 -08:00
|
|
|
const date = new Date(time).getDate();
|
|
|
|
const month = new Date(time).getMonth() + 1;
|
|
|
|
return this.$t('monthAndDay', {
|
|
|
|
month: month.toString(),
|
|
|
|
day: date.toString()
|
|
|
|
});
|
2020-12-11 20:06:26 -08:00
|
|
|
}
|
2021-04-15 04:26:02 -07:00
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2021-04-15 04:26:02 -07:00
|
|
|
render() {
|
|
|
|
if (this.items.length === 0) return;
|
|
|
|
|
2020-12-18 17:55:52 -08:00
|
|
|
return h(this.$store.state.animation ? TransitionGroup : 'div', this.$store.state.animation ? {
|
2021-04-16 08:12:50 -07:00
|
|
|
class: 'sqadhkmv' + (this.noGap ? ' noGap _block' : ''),
|
2020-12-11 20:06:26 -08:00
|
|
|
name: 'list',
|
|
|
|
tag: 'div',
|
|
|
|
'data-direction': this.direction,
|
|
|
|
'data-reversed': this.reversed ? 'true' : 'false',
|
2020-12-18 17:55:52 -08:00
|
|
|
} : {
|
2021-04-16 08:12:50 -07:00
|
|
|
class: 'sqadhkmv' + (this.noGap ? ' noGap _block' : ''),
|
2020-12-11 20:06:26 -08:00
|
|
|
}, this.items.map((item, i) => {
|
|
|
|
const el = this.$slots.default({
|
|
|
|
item: item
|
|
|
|
})[0];
|
2020-12-30 00:31:59 -08:00
|
|
|
if (el.key == null && item.id) el.key = item.id;
|
2020-12-11 20:06:26 -08:00
|
|
|
|
|
|
|
if (
|
2020-02-18 02:05:11 -08:00
|
|
|
i != this.items.length - 1 &&
|
2021-05-04 05:15:57 -07:00
|
|
|
new Date(item.createdAt).getDate() != new Date(this.items[i + 1].createdAt).getDate()
|
2020-12-11 20:06:26 -08:00
|
|
|
) {
|
|
|
|
const separator = h('div', {
|
|
|
|
class: 'separator',
|
|
|
|
key: item.id + ':separator',
|
|
|
|
}, h('p', {
|
|
|
|
class: 'date'
|
|
|
|
}, [
|
|
|
|
h('span', [
|
2021-04-20 07:22:59 -07:00
|
|
|
h('i', {
|
|
|
|
class: 'fas fa-angle-up icon',
|
2020-12-11 20:06:26 -08:00
|
|
|
}),
|
2021-04-15 04:26:02 -07:00
|
|
|
this.getDateText(item.createdAt)
|
2020-12-11 20:06:26 -08:00
|
|
|
]),
|
|
|
|
h('span', [
|
2021-04-15 04:26:02 -07:00
|
|
|
this.getDateText(this.items[i + 1].createdAt),
|
2021-04-20 07:22:59 -07:00
|
|
|
h('i', {
|
|
|
|
class: 'fas fa-angle-down icon',
|
2020-12-11 20:06:26 -08:00
|
|
|
})
|
|
|
|
])
|
|
|
|
]));
|
|
|
|
|
|
|
|
return [el, separator];
|
|
|
|
} else {
|
2021-05-04 05:15:57 -07:00
|
|
|
if (this.ad && item._shouldInsertAd_) {
|
|
|
|
return [h(MkAd, {
|
2021-05-04 23:16:47 -07:00
|
|
|
class: 'a', // advertiseの意(ブロッカー対策)
|
2021-05-04 05:15:57 -07:00
|
|
|
key: item.id + ':ad',
|
2021-05-05 03:05:19 -07:00
|
|
|
prefer: ['horizontal', 'horizontal-big'],
|
2021-05-04 05:15:57 -07:00
|
|
|
}), el];
|
|
|
|
} else {
|
|
|
|
return el;
|
|
|
|
}
|
2020-12-11 20:06:26 -08:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-02-20 16:11:35 -08:00
|
|
|
<style lang="scss">
|
|
|
|
.sqadhkmv {
|
2021-05-04 07:12:36 -07:00
|
|
|
> *:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-07-04 05:07:45 -07:00
|
|
|
> *:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
|
|
|
|
2020-02-20 16:11:35 -08:00
|
|
|
> .list-move {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
2020-03-20 02:55:15 -07:00
|
|
|
> .list-enter-active {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
2020-02-20 16:11:35 -08:00
|
|
|
&[data-direction="up"] {
|
2020-10-17 04:12:00 -07:00
|
|
|
> .list-enter-from {
|
2020-02-20 16:11:35 -08:00
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&[data-direction="down"] {
|
2020-10-17 04:12:00 -07:00
|
|
|
> .list-enter-from {
|
2020-02-20 16:11:35 -08:00
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 11:37:25 -08:00
|
|
|
> .separator {
|
|
|
|
text-align: center;
|
|
|
|
|
|
|
|
> .date {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
line-height: 32px;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
|
|
|
color: var(--dateLabelFg);
|
|
|
|
|
|
|
|
> span {
|
|
|
|
&:first-child {
|
|
|
|
margin-right: 8px;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
margin-left: 8px;
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 20:40:50 -07:00
|
|
|
|
2021-04-16 08:12:50 -07:00
|
|
|
&.noGap {
|
|
|
|
> * {
|
|
|
|
margin: 0 !important;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
2021-04-09 20:40:50 -07:00
|
|
|
|
2021-04-16 08:12:50 -07:00
|
|
|
&:not(:last-child) {
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
|
|
|
}
|
2021-04-09 20:40:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 11:37:25 -08:00
|
|
|
</style>
|