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';
|
2020-01-29 11:37:25 -08:00
|
|
|
import { faAngleUp, faAngleDown } from '@fortawesome/free-solid-svg-icons';
|
2020-12-11 20:06:26 -08:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
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
|
2020-01-29 11:37:25 -08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-12-11 20:06:26 -08:00
|
|
|
methods: {
|
|
|
|
focus() {
|
|
|
|
this.$slots.default[0].elm.focus();
|
|
|
|
}
|
2020-01-29 11:37:25 -08:00
|
|
|
},
|
|
|
|
|
2020-12-11 20:06:26 -08:00
|
|
|
render() {
|
|
|
|
const 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
|
|
|
}
|
2020-01-29 11:37:25 -08:00
|
|
|
|
2020-12-18 17:55:52 -08:00
|
|
|
return h(this.$store.state.animation ? TransitionGroup : 'div', this.$store.state.animation ? {
|
2020-12-11 20:06:26 -08:00
|
|
|
class: 'sqadhkmv _list_',
|
|
|
|
name: 'list',
|
|
|
|
tag: 'div',
|
|
|
|
'data-direction': this.direction,
|
|
|
|
'data-reversed': this.reversed ? 'true' : 'false',
|
2020-12-18 17:55:52 -08:00
|
|
|
} : {
|
|
|
|
class: 'sqadhkmv _list_',
|
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 &&
|
|
|
|
new Date(item.createdAt).getDate() != new Date(this.items[i + 1].createdAt).getDate() &&
|
|
|
|
!item._prId_ &&
|
|
|
|
!this.items[i + 1]._prId_ &&
|
|
|
|
!item._featuredId_ &&
|
2020-12-11 20:06:26 -08:00
|
|
|
!this.items[i + 1]._featuredId_
|
|
|
|
) {
|
|
|
|
const separator = h('div', {
|
|
|
|
class: 'separator',
|
|
|
|
key: item.id + ':separator',
|
|
|
|
}, h('p', {
|
|
|
|
class: 'date'
|
|
|
|
}, [
|
|
|
|
h('span', [
|
|
|
|
h(FontAwesomeIcon, {
|
|
|
|
class: 'icon',
|
|
|
|
icon: faAngleUp,
|
|
|
|
}),
|
|
|
|
getDateText(item.createdAt)
|
|
|
|
]),
|
|
|
|
h('span', [
|
|
|
|
getDateText(this.items[i + 1].createdAt),
|
|
|
|
h(FontAwesomeIcon, {
|
|
|
|
class: 'icon',
|
|
|
|
icon: faAngleDown,
|
|
|
|
})
|
|
|
|
])
|
|
|
|
]));
|
|
|
|
|
|
|
|
return [el, separator];
|
|
|
|
} else {
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
2020-01-29 11:37:25 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-02-20 16:11:35 -08:00
|
|
|
<style lang="scss">
|
|
|
|
.sqadhkmv {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2020-12-11 20:06:26 -08:00
|
|
|
<style lang="scss">
|
2020-01-29 11:37:25 -08:00
|
|
|
.sqadhkmv {
|
|
|
|
> .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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|