2020-01-29 19:37:25 +00:00
|
|
|
<script lang="ts">
|
2023-01-13 09:25:40 +00:00
|
|
|
import { defineComponent, h, PropType, TransitionGroup, useCssModule } from 'vue';
|
2022-08-30 15:24:33 +00:00
|
|
|
import MkAd from '@/components/global/MkAd.vue';
|
2022-01-10 15:05:18 +00:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { defaultStore } from '@/store';
|
2023-01-13 09:25:40 +00:00
|
|
|
import { MisskeyEntity } from '@/types/date-separated-list';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-01-29 19:37:25 +00:00
|
|
|
props: {
|
|
|
|
items: {
|
2023-01-13 09:25:40 +00:00
|
|
|
type: Array as PropType<MisskeyEntity[]>,
|
2020-01-29 19:37:25 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
direction: {
|
|
|
|
type: String,
|
2020-02-21 00:11:35 +00:00
|
|
|
required: false,
|
2022-08-30 15:24:33 +00:00
|
|
|
default: 'down',
|
2020-02-06 05:23:01 +00:00
|
|
|
},
|
|
|
|
reversed: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 15:24:33 +00:00
|
|
|
default: false,
|
2021-04-16 15:12:50 +00:00
|
|
|
},
|
|
|
|
noGap: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 15:24:33 +00:00
|
|
|
default: false,
|
2021-04-16 15:12:50 +00:00
|
|
|
},
|
2021-05-04 12:15:57 +00:00
|
|
|
ad: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 15:24:33 +00:00
|
|
|
default: false,
|
2021-05-04 12:15:57 +00:00
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
|
2022-01-10 15:05:18 +00:00
|
|
|
setup(props, { slots, expose }) {
|
2023-01-13 09:25:40 +00:00
|
|
|
const $style = useCssModule();
|
2022-01-10 15:05:18 +00:00
|
|
|
function getDateText(time: string) {
|
2020-01-29 19:37:25 +00:00
|
|
|
const date = new Date(time).getDate();
|
|
|
|
const month = new Date(time).getMonth() + 1;
|
2022-01-10 15:05:18 +00:00
|
|
|
return i18n.t('monthAndDay', {
|
2020-01-29 19:37:25 +00:00
|
|
|
month: month.toString(),
|
2022-08-30 15:24:33 +00:00
|
|
|
day: date.toString(),
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
2020-12-12 04:06:26 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-10 15:05:18 +00:00
|
|
|
if (props.items.length === 0) return;
|
|
|
|
|
|
|
|
const renderChildren = () => props.items.map((item, i) => {
|
|
|
|
if (!slots || !slots.default) return;
|
2021-04-15 11:26:02 +00:00
|
|
|
|
2022-01-10 15:05:18 +00:00
|
|
|
const el = slots.default({
|
2022-08-30 15:24:33 +00:00
|
|
|
item: item,
|
2020-12-12 04:06:26 +00:00
|
|
|
})[0];
|
2020-12-30 08:31:59 +00:00
|
|
|
if (el.key == null && item.id) el.key = item.id;
|
2020-12-12 04:06:26 +00:00
|
|
|
|
|
|
|
if (
|
2022-03-01 12:36:20 +00:00
|
|
|
i !== props.items.length - 1 &&
|
|
|
|
new Date(item.createdAt).getDate() !== new Date(props.items[i + 1].createdAt).getDate()
|
2020-12-12 04:06:26 +00:00
|
|
|
) {
|
|
|
|
const separator = h('div', {
|
2023-01-13 09:25:40 +00:00
|
|
|
class: $style['separator'],
|
2020-12-12 04:06:26 +00:00
|
|
|
key: item.id + ':separator',
|
|
|
|
}, h('p', {
|
2023-01-13 09:25:40 +00:00
|
|
|
class: $style['date'],
|
2020-12-12 04:06:26 +00:00
|
|
|
}, [
|
2023-01-13 09:25:40 +00:00
|
|
|
h('span', {
|
|
|
|
class: $style['date-1'],
|
|
|
|
}, [
|
2021-04-20 14:22:59 +00:00
|
|
|
h('i', {
|
2023-01-13 09:25:40 +00:00
|
|
|
class: `ti ti-chevron-up ${$style['date-1-icon']}`,
|
2020-12-12 04:06:26 +00:00
|
|
|
}),
|
2022-08-30 15:24:33 +00:00
|
|
|
getDateText(item.createdAt),
|
2020-12-12 04:06:26 +00:00
|
|
|
]),
|
2023-01-13 09:25:40 +00:00
|
|
|
h('span', {
|
|
|
|
class: $style['date-2'],
|
|
|
|
}, [
|
2022-01-10 15:05:18 +00:00
|
|
|
getDateText(props.items[i + 1].createdAt),
|
2021-04-20 14:22:59 +00:00
|
|
|
h('i', {
|
2023-01-13 09:25:40 +00:00
|
|
|
class: `ti ti-chevron-down ${$style['date-2-icon']}`,
|
2022-08-30 15:24:33 +00:00
|
|
|
}),
|
|
|
|
]),
|
2020-12-12 04:06:26 +00:00
|
|
|
]));
|
|
|
|
|
|
|
|
return [el, separator];
|
|
|
|
} else {
|
2022-01-10 15:05:18 +00:00
|
|
|
if (props.ad && item._shouldInsertAd_) {
|
2021-05-04 12:15:57 +00:00
|
|
|
return [h(MkAd, {
|
|
|
|
key: item.id + ':ad',
|
2021-05-05 10:05:19 +00:00
|
|
|
prefer: ['horizontal', 'horizontal-big'],
|
2021-05-04 12:15:57 +00:00
|
|
|
}), el];
|
|
|
|
} else {
|
|
|
|
return el;
|
|
|
|
}
|
2020-12-12 04:06:26 +00:00
|
|
|
}
|
2021-08-10 09:19:59 +00:00
|
|
|
});
|
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
function onBeforeLeave(el: HTMLElement) {
|
|
|
|
el.style.top = `${el.offsetTop}px`;
|
|
|
|
el.style.left = `${el.offsetLeft}px`;
|
|
|
|
}
|
|
|
|
function onLeaveCanceled(el: HTMLElement) {
|
|
|
|
el.style.top = '';
|
|
|
|
el.style.left = '';
|
|
|
|
}
|
|
|
|
|
2022-01-10 15:05:18 +00:00
|
|
|
return () => h(
|
|
|
|
defaultStore.state.animation ? TransitionGroup : 'div',
|
2023-01-13 09:25:40 +00:00
|
|
|
{
|
2023-02-05 05:35:00 +00:00
|
|
|
class: {
|
|
|
|
[$style['date-separated-list']]: true,
|
|
|
|
[$style['date-separated-list-nogap']]: props.noGap,
|
|
|
|
[$style['reversed']]: props.reversed,
|
|
|
|
[$style['direction-down']]: props.direction === 'down',
|
|
|
|
[$style['direction-up']]: props.direction === 'up',
|
|
|
|
},
|
|
|
|
...(defaultStore.state.animation ? {
|
|
|
|
name: 'list',
|
|
|
|
tag: 'div',
|
|
|
|
onBeforeLeave,
|
|
|
|
onLeaveCanceled,
|
|
|
|
} : {}),
|
2022-08-30 15:24:33 +00:00
|
|
|
},
|
2022-01-10 15:05:18 +00:00
|
|
|
{ default: renderChildren });
|
2022-08-30 15:24:33 +00:00
|
|
|
},
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.date-separated-list {
|
2022-12-25 23:40:13 +00:00
|
|
|
container-type: inline-size;
|
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
&:global {
|
|
|
|
> .list-move {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.deny-move-transition > .list-move {
|
|
|
|
transition: none !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .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);
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:12:36 +00:00
|
|
|
> *:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:07:45 +00:00
|
|
|
> *:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
2020-02-21 00:11:35 +00:00
|
|
|
}
|
2023-01-13 09:25:40 +00:00
|
|
|
}
|
2020-02-21 00:11:35 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.date-separated-list-nogap {
|
|
|
|
> * {
|
|
|
|
margin: 0 !important;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
2020-03-20 09:55:15 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
&:not(:last-child) {
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2020-02-21 00:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-13 09:25:40 +00:00
|
|
|
}
|
2020-02-21 00:11:35 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.direction-up {
|
|
|
|
&:global {
|
|
|
|
> .list-enter-from,
|
|
|
|
> .list-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.direction-down {
|
|
|
|
&:global {
|
|
|
|
> .list-enter-from,
|
|
|
|
> .list-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-64px);
|
|
|
|
}
|
2020-02-21 00:11:35 +00:00
|
|
|
}
|
2023-01-13 09:25:40 +00:00
|
|
|
}
|
2020-02-21 00:11:35 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.reversed {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column-reverse;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.separator {
|
|
|
|
text-align: center;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.date {
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 16px;
|
|
|
|
line-height: 32px;
|
|
|
|
text-align: center;
|
|
|
|
font-size: 12px;
|
|
|
|
color: var(--dateLabelFg);
|
|
|
|
}
|
2021-04-10 03:40:50 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.date-1 {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
2021-04-10 03:40:50 +00:00
|
|
|
|
2023-01-13 09:25:40 +00:00
|
|
|
.date-1-icon {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.date-2 {
|
|
|
|
margin-left: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.date-2-icon {
|
|
|
|
margin-left: 8px;
|
2021-04-10 03:40:50 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
</style>
|
2023-01-13 09:25:40 +00:00
|
|
|
|