diff --git a/assets/css/src/calendar-strip.css b/assets/css/src/calendar-strip.css index d58953c..a8bce69 100644 --- a/assets/css/src/calendar-strip.css +++ b/assets/css/src/calendar-strip.css @@ -15,12 +15,18 @@ width: 10rem; } -.calendar-strip__days { +.calendar-strip__days, +.calendar-strip__days .week > ul { display: flex; justify-content: space-evenly; width: 100%; } +.calendar-strip__days .week, +.calendar-strip__days .week > ul { + display: contents; +} + .calendar-strip__day { font-size: var(--font-size-s); transition: opacity 0.2s ease-in-out; @@ -97,4 +103,17 @@ .calendar-strip .next-month { display: none; } + + .calendar-strip__days .week, + .calendar-strip__days .week > ul { + display: inherit; + } + .calendar-strip__days .week:not(.current) { + display: none; + } + + .calendar-strip__days .week, + .calendar-strip__days .week > ul { + width: 100%; + } } diff --git a/assets/js/calendar.js b/assets/js/calendar.js index 1a0af4d..4a7cc6e 100644 --- a/assets/js/calendar.js +++ b/assets/js/calendar.js @@ -169,6 +169,8 @@ function createEmptyCalendar() { sessions: [], full: currentDay.format("DD-MM-YYYY"), initial: dayInitial, + index: parseInt(currentDay.format("DD")), + indexInWeek: currentDay.day() === 0 ? 7 : currentDay.day(), }; } } diff --git a/site/snippets/calendar-strip.php b/site/snippets/calendar-strip.php index 6e00f27..675522e 100644 --- a/site/snippets/calendar-strip.php +++ b/site/snippets/calendar-strip.php @@ -3,7 +3,18 @@ @mouseleave="open = false" x-data="{ calendar: createEmptyCalendar(), - monthNumb: dayjs().month() + 1, + currentMonthIndex: dayjs().month() + 1, + currentWeekIndex: (() => { + dayjs.extend(window.dayjs_plugin_weekOfYear); + + const today = dayjs(); + const firstDayOfMonth = today.startOf('month'); + const currentWeek = today.week(); + const firstWeekOfMonth = firstDayOfMonth.week(); + const currentWeekIndex = currentWeek - firstWeekOfMonth; + + return currentWeekIndex; + })(), token: 'mapadoToken() ?>', contractId: 'mapadoContractId() ?>', targetSessions: [], @@ -11,11 +22,29 @@ today: dayjs().format('DD-MM-YYYY'), get monthName() { - return dayjs().month(this.monthNumb - 1).format('MMMM'); + return dayjs().month(this.currentMonthIndex - 1).format('MMMM'); }, get currentMonth() { - return this.calendar[this.monthNumb] + return this.calendar[this.currentMonthIndex] + }, + + get currentWeeks() { + const weeks = [[]]; + let index = 0; + for (let key in this.currentMonth) { + const date = this.currentMonth[key] + weeks[index].push(date) + if (date.indexInWeek === 7) { + weeks.push([]) + index++ + } + } + return weeks + }, + + get currentWeek() { + this.currentWeeks[this.currentWeekIndex]; }, async updateDates() { @@ -29,7 +58,7 @@ .catch(error => console.log('No saved calendar.')) const daysNode = document.querySelector('.calendar-strip__days'); - daysNode.classList.toggle('progress'); + daysNode.classList.toggle('progress'); this.calendar = await getCurrentSeasonCalendar(); @@ -51,17 +80,17 @@ }, nextMonth() { - if (this.monthNumb == 12) { - this.monthNumb = 1 + if (this.currentMonthIndex == 12) { + this.currentMonthIndex = 1 } else { - this.monthNumb++ + this.currentMonthIndex++ } }, prevMonth() { - if (this.monthNumb == 1) { - this.monthNumb = 12 + if (this.currentMonthIndex == 1) { + this.currentMonthIndex = 12 } else { - this.monthNumb-- + this.currentMonthIndex-- } } }" @@ -70,28 +99,37 @@ x-init="updateDates()" >
- + - +
+