Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Show previous/next month's days in current month's view? #291

Open
marchershey opened this issue Feb 6, 2022 · 2 comments
Open

Show previous/next month's days in current month's view? #291

marchershey opened this issue Feb 6, 2022 · 2 comments

Comments

@marchershey
Copy link

Is there a way I can show the previous and next months days in the current month view?

Example:
asdf

@antontrafimovich
Copy link

+1

@marchershey marchershey changed the title Show previous / next month's days in current month? Show previous/next month's days in current month's view? Apr 3, 2022
@akondo06
Copy link

akondo06 commented Nov 29, 2022

Had to do this recently and here's what I ended up with:

const picker = new Litepicker({
  ...
}};
...
picker.on('render:month', (month, date) => {
  const days = month.querySelector('.container__days');
  const pre = days.querySelectorAll(':not([class])') || [];
  const daysInMonth = days.children.length - pre.length;

  const calendars = picker.calendars;
  const isFirst = calendars[0].isSame(date, 'day');
  const isLast = calendars[calendars.length - 1].isSame(date, 'day');

  if(isFirst) {
    const before = date.clone();
    pre.forEach((element) => {
      days.removeChild(element);
      before.subtract(1, 'day');
      const day = picker.renderDay(before);
      day.classList.add('is-pre');
      days.prepend(day);
    });
  }

  if(isLast) {
    const after = date.clone().add(daysInMonth, 'days');
    const maxDays = days.children.length > 35 ? 42 : 35;
    while(days.children.length < maxDays) {
      const day = picker.renderDay(after);
      day.classList.add('is-post');
      days.appendChild(day);
      after.add(1, 'day');
    }
  }
});

And some css to distinguish those days:

&.is-pre, &.is-post {
  font-weight: 300;
  color: var(--litepicker-is-locked-color);

  &:hover {
    color: var(--litepicker-is-locked-color);
  }
}

This was a pretty easy drop-in for me, it also works with the range plugin!
Hopefully it helps anybody ending up here :)

Cheers!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants