WIP Сделала CalendarHeader, подключила moment js
This commit is contained in:
@@ -1,10 +1,29 @@
|
||||
<template lang="pug">
|
||||
calendar-header
|
||||
calendar-header(
|
||||
:currentDay="currentDate"
|
||||
@previous-date="switchPreviousDate"
|
||||
@next-date="switchNextDate")
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as moment from "moment/moment";
|
||||
import CalendarHeader from "./components/CalendarHeader.vue";
|
||||
moment.locale("ru");
|
||||
export default {
|
||||
name: "TheCalendar",
|
||||
components: { CalendarHeader },
|
||||
data() {
|
||||
return {
|
||||
currentDate: moment(),
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
switchPreviousDate() {
|
||||
this.currentDate = this.currentDate.clone().subtract(1, "day");
|
||||
},
|
||||
switchNextDate() {
|
||||
this.currentDate = this.currentDate.clone().add(1, "day");
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,30 +1,58 @@
|
||||
<template lang="pug">
|
||||
.calendar-header-wrapper.flex.items-center.justify-between.ml-2.py-3.pl-5.pr-6
|
||||
.flex
|
||||
base-arrow-button.left-arrow.mr-4
|
||||
base-arrow-button.right-arrow.mr-6
|
||||
base-arrow-button.left-arrow.mr-4(@click="previousHandler")
|
||||
base-arrow-button.right-arrow.mr-6(@click="nextHandler")
|
||||
.text.flex.items-center
|
||||
span.font-medium.text-base 24 Мая 2022
|
||||
span.today.font-bold.text-xxs(v-if="isToday") Сегодня
|
||||
span.font-medium.text-base {{ dateString }}
|
||||
span.today.font-bold.text-xxs(v-if="isToday") Сегодня
|
||||
calendar-layout-switch(@selected="changeSelectedLayout")
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import * as moment from "moment/moment";
|
||||
import BaseArrowButton from "@/components/base/buttons/BaseArrowButton.vue";
|
||||
import CalendarLayoutSwitch from "./CalendarLayoutSwitch.vue";
|
||||
export default {
|
||||
name: "CalendarHeader",
|
||||
components: { BaseArrowButton, CalendarLayoutSwitch },
|
||||
props: {
|
||||
currentDay: Object,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isToday: true,
|
||||
selectedLayout: "",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
dateString() {
|
||||
let newStr = this.currentDay.format("D MMMM YYYY");
|
||||
return newStr
|
||||
.split(" ")
|
||||
.map((elem, index) => {
|
||||
if (index === 1) return elem[0].toUpperCase() + elem.slice(1);
|
||||
return elem;
|
||||
})
|
||||
.join(" ");
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
changeSelectedLayout(option) {
|
||||
this.selectedLayout = option;
|
||||
},
|
||||
previousHandler() {
|
||||
this.$emit("previous-date");
|
||||
},
|
||||
nextHandler() {
|
||||
this.$emit("next-date");
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
currentDay: function () {
|
||||
this.isToday =
|
||||
this.currentDay.format("DD.MM.YYYY") === moment().format("DD.MM.YYYY");
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user