Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
uvarov-frontend committed Sep 30, 2023
1 parent 782d211 commit 8736e67
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IVanillaCalendar } from '../../types';

const getColumn = (self: IVanillaCalendar, columnClass: string, personalClass: string, id: number, dataAttr: string) => {
const getColumnID = (self: IVanillaCalendar, columnClass: string, personalClass: string, id: number, dataAttr: string) => {
const columnEls = (self.HTMLElement as HTMLElement).querySelectorAll(`.${self.CSSClasses.column}`) as NodeListOf<HTMLElement>;
const firstColumnID = Number((columnEls[0].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr));
const lastColumnID = Number((columnEls[columnEls.length - 1].querySelector(`.${personalClass}`) as HTMLElement).getAttribute(dataAttr));
Expand All @@ -17,4 +17,4 @@ const getColumn = (self: IVanillaCalendar, columnClass: string, personalClass: s
return id;
};

export default getColumn;
export default getColumnID;
6 changes: 3 additions & 3 deletions package/src/scripts/methods/clickCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import createYears from './createYears';
import generateDate from '../helpers/generateDate';
import mainMethod from './mainMethod';
import handlerMultipleRanged from './handlerMultipleRanged';
import getColumn from '../helpers/getColumn';
import getColumnID from '../helpers/getColumnID';

const clickCalendar = (self: IVanillaCalendar) => {
(self.HTMLElement as HTMLElement).addEventListener('click', (e) => {
Expand Down Expand Up @@ -161,7 +161,7 @@ const clickCalendar = (self: IVanillaCalendar) => {
} else if (yearItemEl) {
if (self.selectedMonth === undefined || !self.dateMin || !self.dateMax) return;
self.selectedYear = self.type === 'multiple'
? getColumn(self, self.CSSClasses.columnYear, self.CSSClasses.year, Number(yearItemEl.dataset.calendarYear), 'data-calendar-selected-year')
? getColumnID(self, self.CSSClasses.columnYear, self.CSSClasses.year, Number(yearItemEl.dataset.calendarYear), 'data-calendar-selected-year')
: Number(yearItemEl.dataset.calendarYear);
self.currentType = self.type;
if (self.selectedMonth < self.dateMin.getMonth() && self.selectedYear === self.dateMin.getFullYear()) {
Expand All @@ -187,7 +187,7 @@ const clickCalendar = (self: IVanillaCalendar) => {
mainMethod(self);
} else if (monthItemEl) {
self.selectedMonth = self.type === 'multiple'
? getColumn(self, self.CSSClasses.columnMonth, self.CSSClasses.month, Number(monthItemEl.dataset.calendarMonth), 'data-calendar-selected-month')
? getColumnID(self, self.CSSClasses.columnMonth, self.CSSClasses.month, Number(monthItemEl.dataset.calendarMonth), 'data-calendar-selected-month')
: Number(monthItemEl.dataset.calendarMonth);
if (self.type === 'multiple') {
const column = monthItemEl.closest(`.${self.CSSClasses.columnMonth}`) as HTMLElement;
Expand Down
8 changes: 4 additions & 4 deletions package/src/scripts/methods/createDOM.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IVanillaCalendar, TypesCalendar } from '../../types';
import { IVanillaCalendar } from '../../types';
import { DOMParser, MultipleParser } from '../helpers/parserComponent';

const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HTMLElement) => {
const createDOM = (self: IVanillaCalendar, target?: HTMLElement) => {
const calendarElement = (self.HTMLElement as HTMLElement);
calendarElement.classList.add(self.CSSClasses.calendar);

Expand Down Expand Up @@ -31,7 +31,7 @@ const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HT
calendarElement.innerHTML = MultipleParser(self, DOMParser(self, self.DOMTemplates.multiple));
break;
case 'month':
if (initType === 'multiple') {
if (self.type === 'multiple') {
switcherTypeMultiple(self.CSSClasses.columnMonth, self.DOMTemplates.month);
break;
}
Expand All @@ -41,7 +41,7 @@ const createDOM = (self: IVanillaCalendar, initType?: TypesCalendar, target?: HT
calendarElement.innerHTML = DOMParser(self, self.DOMTemplates.month);
break;
case 'year':
if (initType === 'multiple') {
if (self.type === 'multiple') {
switcherTypeMultiple(self.CSSClasses.columnYear, self.DOMTemplates.year);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion package/src/scripts/methods/createMonths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import showYear from './showYear';
const createMonths = (self: IVanillaCalendar, target?: HTMLElement) => {
const selectedMonth = target?.dataset.calendarSelectedMonth ? Number(target?.dataset.calendarSelectedMonth) : self.selectedMonth;
self.currentType = 'month';
createDOM(self, self.type, target);
createDOM(self, target);
showMonth(self);
showYear(self);

Expand Down
2 changes: 1 addition & 1 deletion package/src/scripts/methods/createYears.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const createYears = (self: IVanillaCalendar, target?: HTMLElement) => {
if (self.viewYear === undefined || !self.dateMin || !self.dateMax) return;
const selectedYear = target?.dataset.calendarSelectedYear ? Number(target?.dataset.calendarSelectedYear) : self.selectedYear;
self.currentType = 'year';
createDOM(self, self.type, target);
createDOM(self, target);
showMonth(self);
showYear(self);
controlArrows(self);
Expand Down

0 comments on commit 8736e67

Please sign in to comment.