From c520b69e53bae52b848ae4209132cbba36feba5a Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Thu, 8 Aug 2024 01:36:36 -0400 Subject: [PATCH] feat: change weekend days, fixes #283 --- demo/pages/input/main.ts | 4 ++++ package/src/scripts/methods/createDays.ts | 2 +- package/src/scripts/methods/createWeek.ts | 16 +++++++++++----- package/types.ts | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/demo/pages/input/main.ts b/demo/pages/input/main.ts index 9c1891c0..2c58afd0 100644 --- a/demo/pages/input/main.ts +++ b/demo/pages/input/main.ts @@ -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; @@ -20,6 +23,7 @@ const configInput: IOptions = { }, }, settings: { + iso8601: false, visibility: { positionToInput: 'center', }, diff --git a/package/src/scripts/methods/createDays.ts b/package/src/scripts/methods/createDays.ts index eb0eb40e..5d60be05 100644 --- a/package/src/scripts/methods/createDays.ts +++ b/package/src/scripts/methods/createDays.ts @@ -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); } diff --git a/package/src/scripts/methods/createWeek.ts b/package/src/scripts/methods/createWeek.ts index 5c6262ce..fe37c81a 100644 --- a/package/src/scripts/methods/createWeek.ts +++ b/package/src/scripts/methods/createWeek.ts @@ -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); } diff --git a/package/types.ts b/package/types.ts index 71d45965..64a0c853 100644 --- a/package/types.ts +++ b/package/types.ts @@ -22,6 +22,7 @@ export interface IDates { min: FormatDateString; max: FormatDateString; today: Date; + weekends?: number[]; } export interface IRange {