Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CalendarPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,29 @@ CalendarPicker.prototype._insertCalendarIntoWrapper = function () {

handleSelectedElement(keyEvent);
}, false);

this.calendarGrid.addEventListener('animationend', () => {
this._resetCalendarAnimations();

if (this.goingToPrevious) {
this.calendarGrid.classList.add('swoosh-down-reverse');
this.goingToPrevious = false;
this._insertDaysIntoGrid();
}
if (this.goingToNext) {
this.calendarGrid.classList.add('swoosh-up-reverse');
this.goingToNext = false;
this._insertDaysIntoGrid();
}

}, false);
}

CalendarPicker.prototype._resetCalendarAnimations = function() {
this.calendarGrid.classList.remove('swoosh-up', 'swoosh-up-reverse', 'swoosh-down', 'swoosh-down-reverse');
}


/**
* @description Adds the "main" calendar-header.
*/
Expand Down Expand Up @@ -217,6 +238,8 @@ CalendarPicker.prototype._insertNavigationButtons = function () {
// Cannot use arrow-functions for IE support :(
var that = this;
this.navigationWrapper.addEventListener('click', function (clickEvent) {
that._resetCalendarAnimations();

if (clickEvent.target.closest('#' + that.previousMonthArrow.id)) {
if (that.month === 0) {
that.month = 11;
Expand Down Expand Up @@ -288,6 +311,7 @@ CalendarPicker.prototype._insertDaysIntoGrid = function () {
* given by the navigation. Also updates the UI with the new values.
*/
CalendarPicker.prototype._updateCalendar = function () {
this.previousDate = this.date;
this.date = new Date(this.year, this.month);

this._setDateText();
Expand All @@ -301,6 +325,14 @@ CalendarPicker.prototype._updateCalendar = function () {
window.requestAnimationFrame(function () {
that.calendarHeaderTitle.textContent = that.listOfAllMonthsAsText[that.month] + ' - ' + that.year;
that._insertDaysIntoGrid();

if (that.previousDate < that.date) {
that.calendarGrid.classList.add('swoosh-up');
that.goingToPrevious = true;
} else {
that.calendarGrid.classList.add('swoosh-down');
that.goingToNext = true;
}
})
}

Expand Down
49 changes: 49 additions & 0 deletions CalendarPicker.style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
@keyframes swoosh-up {
0% {
opacity: 1;
transform: translateY(0);
}

100% {
opacity: 0.1;
transform: translateY(0.8em);
}
}

@keyframes swoosh-down {
0% {
opacity: 1;
transform: translateY(0);
}

100% {
opacity: 0.1;
transform: translateY(-0.8em);
}
}

.swoosh-up {
animation: swoosh-up 100ms ;
}

.swoosh-up-reverse {
animation: swoosh-up 100ms reverse;
}

.swoosh-down {
animation: swoosh-down 100ms ;
}

.swoosh-down-reverse {
animation: swoosh-down 100ms reverse;
}

@media (prefers-reduced-motion) {
.swoosh-up,
.swoosh-up-reverse,
.swoosh-down,
.swoosh-down-reverse {
animation: none;
}
}

#calendar-wrapper {
width: 100%;
display: grid;
Expand Down