Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change weekend days, fixes #283 #286

Closed
Closed
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
4 changes: 4 additions & 0 deletions demo/pages/input/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import '@src/styles/vanilla-calendar.css';

const configInput: IOptions = {
input: true,
date: {
weekends: [5, 6]
},
actions: {
changeToInput(e, self) {
if (!self.selectedDates || !self.HTMLInputElement) return;
Expand All @@ -20,6 +23,7 @@ const configInput: IOptions = {
},
},
settings: {
iso8601: false,
visibility: {
positionToInput: 'center',
},
Expand Down
2 changes: 1 addition & 1 deletion package/src/scripts/methods/createDays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const setDayModifier = (
}

// if weekend
if (self.settings.visibility.weekend && (dayWeekID === 0 || dayWeekID === 6)) {
if (self.settings.visibility.weekend && (self.date.weekends || [0, 6]).includes(dayWeekID)) {
dayBtnEl.classList.add(self.CSSClasses.dayBtnWeekend);
}

Expand Down
16 changes: 11 additions & 5 deletions package/src/scripts/methods/createWeek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ const createWeekDays = (self: VanillaCalendar, weekEl: HTMLElement, weekday: str
const weekDayName = weekday[i];
const weekDayEl = templateWeekDayEl.cloneNode(true) as HTMLElement;
weekDayEl.className = `${self.CSSClasses.weekDay}`;
weekDayEl.className = `${self.CSSClasses.weekDay}${self.settings.visibility.weekend && self.settings.iso8601
? (i === 5 || i === 6
? ` ${self.CSSClasses.weekDayWeekend}` : '')
: self.settings.visibility.weekend && !self.settings.iso8601
? (i === 0 || i === 6 ? ` ${self.CSSClasses.weekDayWeekend}` : '')
if (self.date.weekends) {
weekDayEl.className = `${self.CSSClasses.weekDay}${self.settings.visibility.weekend
? (self.date.weekends?.includes(i) ? ` ${self.CSSClasses.weekDayWeekend}` : '')
: ''}`;
} else {
weekDayEl.className = `${self.CSSClasses.weekDay}${self.settings.visibility.weekend && self.settings.iso8601
? (i === 5 || i === 6
? ` ${self.CSSClasses.weekDayWeekend}` : '')
: self.settings.visibility.weekend && !self.settings.iso8601
? (i === 0 || i === 6 ? ` ${self.CSSClasses.weekDayWeekend}` : '')
: ''}`;
}
weekDayEl.innerText = `${weekDayName}`;
weekEl.appendChild(weekDayEl);
}
Expand Down
1 change: 1 addition & 0 deletions package/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IDates {
min: FormatDateString;
max: FormatDateString;
today: Date;
weekends?: number[];
}

export interface IRange {
Expand Down
Loading