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