2020-01-29 12:37:25 -07:00
|
|
|
<script lang="ts">
|
2021-05-29 19:05:25 -06:00
|
|
|
import { defineComponent, h, PropType, TransitionGroup } from 'vue';
|
2022-08-30 09:24:33 -06:00
|
|
|
import MkAd from '@/components/global/MkAd.vue';
|
2022-01-10 08:05:18 -07:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { defaultStore } from '@/store';
|
2020-01-29 12:37:25 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
export default defineComponent({
|
2020-01-29 12:37:25 -07:00
|
|
|
props: {
|
|
|
|
items: {
|
2021-05-29 19:05:25 -06:00
|
|
|
type: Array as PropType<{ id: string; createdAt: string; _shouldInsertAd_: boolean; }[]>,
|
2020-01-29 12:37:25 -07:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
direction: {
|
|
|
|
type: String,
|
2020-02-20 17:11:35 -07:00
|
|
|
required: false,
|
2022-08-30 09:24:33 -06:00
|
|
|
default: 'down',
|
2020-02-05 22:23:01 -07:00
|
|
|
},
|
|
|
|
reversed: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 09:24:33 -06:00
|
|
|
default: false,
|
2021-04-16 09:12:50 -06:00
|
|
|
},
|
|
|
|
noGap: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 09:24:33 -06:00
|
|
|
default: false,
|
2021-04-16 09:12:50 -06:00
|
|
|
},
|
2021-05-04 06:15:57 -06:00
|
|
|
ad: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-08-30 09:24:33 -06:00
|
|
|
default: false,
|
2021-05-04 06:15:57 -06:00
|
|
|
},
|
2020-01-29 12:37:25 -07:00
|
|
|
},
|
|
|
|
|
2022-01-10 08:05:18 -07:00
|
|
|
setup(props, { slots, expose }) {
|
|
|
|
function getDateText(time: string) {
|
2020-01-29 12:37:25 -07:00
|
|
|
const date = new Date(time).getDate();
|
|
|
|
const month = new Date(time).getMonth() + 1;
|
2022-01-10 08:05:18 -07:00
|
|
|
return i18n.t('monthAndDay', {
|
2020-01-29 12:37:25 -07:00
|
|
|
month: month.toString(),
|
2022-08-30 09:24:33 -06:00
|
|
|
day: date.toString(),
|
2020-01-29 12:37:25 -07:00
|
|
|
});
|
2020-12-11 21:06:26 -07:00
|
|
|
}
|
2020-01-29 12:37:25 -07:00
|
|
|
|
2022-01-10 08:05:18 -07:00
|
|
|
if (props.items.length === 0) return;
|
|
|
|
|
|
|
|
const renderChildren = () => props.items.map((item, i) => {
|
|
|
|
if (!slots || !slots.default) return;
|
2021-04-15 05:26:02 -06:00
|
|
|
|
2022-01-10 08:05:18 -07:00
|
|
|
const el = slots.default({
|
2022-08-30 09:24:33 -06:00
|
|
|
item: item,
|
2020-12-11 21:06:26 -07:00
|
|
|
})[0];
|
2020-12-30 01:31:59 -07:00
|
|
|
if (el.key == null && item.id) el.key = item.id;
|
2020-12-11 21:06:26 -07:00
|
|
|
|
|
|
|
if (
|
2022-03-01 05:36:20 -07:00
|
|
|
i !== props.items.length - 1 &&
|
|
|
|
new Date(item.createdAt).getDate() !== new Date(props.items[i + 1].createdAt).getDate()
|
2020-12-11 21:06:26 -07:00
|
|
|
) {
|
|
|
|
const separator = h('div', {
|
|
|
|
class: 'separator',
|
|
|
|
key: item.id + ':separator',
|
|
|
|
}, h('p', {
|
2022-08-30 09:24:33 -06:00
|
|
|
class: 'date',
|
2020-12-11 21:06:26 -07:00
|
|
|
}, [
|
|
|
|
h('span', [
|
2021-04-20 08:22:59 -06:00
|
|
|
h('i', {
|
2022-11-06 19:30:26 -07:00
|
|
|
class: 'ph-caret-up-bold icon',
|
2020-12-11 21:06:26 -07:00
|
|
|
}),
|
2022-08-30 09:24:33 -06:00
|
|
|
getDateText(item.createdAt),
|
2020-12-11 21:06:26 -07:00
|
|
|
]),
|
|
|
|
h('span', [
|
2022-01-10 08:05:18 -07:00
|
|
|
getDateText(props.items[i + 1].createdAt),
|
2021-04-20 08:22:59 -06:00
|
|
|
h('i', {
|
2022-11-06 19:30:26 -07:00
|
|
|
class: 'ph-caret-down-bold icon',
|
2022-08-30 09:24:33 -06:00
|
|
|
}),
|
|
|
|
]),
|
2020-12-11 21:06:26 -07:00
|
|
|
]));
|
|
|
|
|
|
|
|
return [el, separator];
|
|
|
|
} else {
|
2022-01-10 08:05:18 -07:00
|
|
|
if (props.ad && item._shouldInsertAd_) {
|
2021-05-04 06:15:57 -06:00
|
|
|
return [h(MkAd, {
|
2021-05-05 00:16:47 -06:00
|
|
|
class: 'a', // advertiseの意(ブロッカー対策)
|
2021-05-04 06:15:57 -06:00
|
|
|
key: item.id + ':ad',
|
2021-05-05 04:05:19 -06:00
|
|
|
prefer: ['horizontal', 'horizontal-big'],
|
2021-05-04 06:15:57 -06:00
|
|
|
}), el];
|
|
|
|
} else {
|
|
|
|
return el;
|
|
|
|
}
|
2020-12-11 21:06:26 -07:00
|
|
|
}
|
2021-08-10 03:19:59 -06:00
|
|
|
});
|
|
|
|
|
2022-01-10 08:05:18 -07:00
|
|
|
return () => h(
|
|
|
|
defaultStore.state.animation ? TransitionGroup : 'div',
|
|
|
|
defaultStore.state.animation ? {
|
2022-08-30 09:24:33 -06:00
|
|
|
class: 'sqadhkmv' + (props.noGap ? ' noGap' : ''),
|
|
|
|
name: 'list',
|
|
|
|
tag: 'div',
|
|
|
|
'data-direction': props.direction,
|
|
|
|
'data-reversed': props.reversed ? 'true' : 'false',
|
|
|
|
} : {
|
|
|
|
class: 'sqadhkmv' + (props.noGap ? ' noGap' : ''),
|
|
|
|
},
|
2022-01-10 08:05:18 -07:00
|
|
|
{ default: renderChildren });
|
2022-08-30 09:24:33 -06:00
|
|
|
},
|
2020-01-29 12:37:25 -07:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2020-02-20 17:11:35 -07:00
|
|
|
<style lang="scss">
|
|
|
|
.sqadhkmv {
|
2021-05-04 08:12:36 -06:00
|
|
|
> *:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-07-04 06:07:45 -06:00
|
|
|
> *:not(:last-child) {
|
|
|
|
margin-bottom: var(--margin);
|
|
|
|
}
|
|
|
|
|
2020-02-20 17:11:35 -07:00
|
|
|
> .list-move {
|
|
|
|
transition: transform 0.7s cubic-bezier(0.23, 1, 0.32, 1);
|
|
|
|
}
|
|
|
|
|
2020-03-20 03:55:15 -06: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 17:11:35 -07:00
|
|
|
&[data-direction="up"] {
|
2020-10-17 05:12:00 -06:00
|
|
|
> .list-enter-from {
|
2020-02-20 17:11:35 -07:00
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&[data-direction="down"] {
|
2020-10-17 05:12:00 -06:00
|
|
|
> .list-enter-from {
|
2020-02-20 17:11:35 -07:00
|
|
|
opacity: 0;
|
|
|
|
transform: translateY(-64px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 12:37:25 -07: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 21:40:50 -06:00
|
|
|
|
2021-04-16 09:12:50 -06:00
|
|
|
&.noGap {
|
|
|
|
> * {
|
|
|
|
margin: 0 !important;
|
|
|
|
border: none;
|
|
|
|
border-radius: 0;
|
|
|
|
box-shadow: none;
|
2021-04-09 21:40:50 -06:00
|
|
|
|
2021-04-16 09:12:50 -06:00
|
|
|
&:not(:last-child) {
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
|
|
|
}
|
2021-04-09 21:40:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 12:37:25 -07:00
|
|
|
</style>
|