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

Add days in shoulder months #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
34 changes: 28 additions & 6 deletions src/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,45 @@ export class Calendar extends LPCore {
const days = document.createElement('div');
days.className = style.containerDays;

const elementsPerRow = this.options.showWeekNumbers ? 8 : 7;
let week = document.createElement('div');
week.className = style.monthItemWeekRow;

const skipDays = this.calcSkipDays(startDate);

if (this.options.showWeekNumbers && skipDays) {
days.appendChild(this.renderWeekNumber(startDate));
week.appendChild(this.renderWeekNumber(startDate));
}

const skipDate = startDate.clone();
skipDate.setDate(-skipDays + 1);
for (let idx = 0; idx < skipDays; idx += 1) {
const dummy = document.createElement('div');
days.appendChild(dummy);
week.appendChild(this.renderDay(skipDate, date));
skipDate.setDate(skipDate.getDate() + 1);
}

// tslint:disable-next-line: prefer-for-of
for (let idx = 1; idx <= totalDays; idx += 1) {
startDate.setDate(idx);

if (this.options.showWeekNumbers && startDate.getDay() === this.options.firstDay) {
days.appendChild(this.renderWeekNumber(startDate));
week.appendChild(this.renderWeekNumber(startDate));
}

week.appendChild(this.renderDay(startDate, date));
if (week.childNodes.length == elementsPerRow) {
days.appendChild(week);
week = document.createElement('div');
week.className = style.monthItemWeekRow;
}
}

days.appendChild(this.renderDay(startDate));
const remainingDays = elementsPerRow - week.childNodes.length;
for (let idx = 0; idx < remainingDays; idx += 1) {
startDate.setDate(startDate.getDate() + 1);
week.appendChild(this.renderDay(startDate, date));
}
days.appendChild(week);

month.appendChild(monthHeader);
month.appendChild(weekdaysRow);
Expand All @@ -305,7 +323,7 @@ export class Calendar extends LPCore {
return month;
}

protected renderDay(date: DateTime) {
protected renderDay(date: DateTime, month: DateTime) {
date.setHours();

const day = document.createElement('div');
Expand All @@ -317,6 +335,10 @@ export class Calendar extends LPCore {
day.classList.add(style.isToday);
}

if (date.getMonth() != month.getMonth()) {
day.classList.add(style.isDifferentMonth);
}

if (this.datePicked.length) {
if (this.datePicked[0].toDateString() === date.toDateString()) {
day.classList.add(style.isStartDate);
Expand Down
13 changes: 11 additions & 2 deletions src/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--litepicker-button-prev-month-color: #9e9e9e;
--litepicker-button-next-month-color: #9e9e9e;
--litepicker-button-prev-month-color-hover: #2196f3;
--litepicker-button-next-month-color-hover: #2196f3;
--litepicker-button-next-month-color-hover: #2196f3;
--litepicker-month-width: calc(var(--litepicker-day-width) * 7); // 7 days
--litepicker-month-weekday-color: #9e9e9e;
--litepicker-month-week-number-color: #9e9e9e;
Expand All @@ -28,6 +28,8 @@
--litepicker-button-apply-color-bg: #2196f3;
--litepicker-button-reset-color: #909090;
--litepicker-button-reset-color-hover: #2196f3;
--litepicker-different-month-day-color: #333;
--litepicker-different-month-day-color-bg: #ddd;
--litepicker-highlighted-day-color: #333;
--litepicker-highlighted-day-color-bg: #ffeb3b;
}
Expand Down Expand Up @@ -174,7 +176,8 @@
}
}

&-weekdays-row {
&-weekdays-row,
&-week-row {
display: flex;
justify-self: center;
justify-content: flex-start;
Expand All @@ -189,6 +192,7 @@
}
}


&:first-child {
.button-previous-month {
visibility: visible;
Expand Down Expand Up @@ -304,6 +308,11 @@
color: var(--litepicker-highlighted-day-color);
background-color: var(--litepicker-highlighted-day-color-bg);
}

&.is-different-month {
color: var(--litepicker-different-month-day-color);
background-color: var(--litepicker-different-month-day-color-bg);
}
}

.week-number {
Expand Down
2 changes: 2 additions & 0 deletions src/scss/main.scss.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const monthItemWeekdaysRow: string;
export const noPreviousMonth: string;
export const noNextMonth: string;
export const containerDays: string;
export const monthItemWeekRow: string;
export const dayItem: string;
export const isToday: string;
export const isLocked: string;
Expand All @@ -25,6 +26,7 @@ export const isStartDate: string;
export const isFlipped: string;
export const isEndDate: string;
export const isHighlighted: string;
export const isDifferentMonth: string;
export const weekNumber: string;
export const containerFooter: string;
export const previewDateRange: string;
Expand Down