@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +6 -6
- package/.storybook/main.js +93 -93
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.js +26 -26
- package/.storybook/preview.tsx +18 -18
- package/README.md +5 -5
- package/commitlint.config.js +23 -23
- package/package.json +1 -1
- package/rollup.config.js +65 -65
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -77
- package/src/components/BaseCalendar/index.tsx +63 -63
- package/src/components/BaseCalendar/styles.module.scss +15 -15
- package/src/components/Button/Button.stories.tsx +16 -0
- package/src/components/Button/Button.tsx +14 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Button/styles.module.scss +3 -0
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -11
- package/src/components/CalendarGrid/index.tsx +19 -19
- package/src/components/CalendarGrid/types.ts +26 -26
- package/src/components/Clear/Clear.stories.tsx +16 -16
- package/src/components/Clear/index.tsx +12 -12
- package/src/components/Clear/styles.module.scss +34 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +127 -127
- package/src/components/DatePicker/index.tsx +72 -72
- package/src/components/DatePicker/styles.module.scss +10 -10
- package/src/components/Day/Day.stories.tsx +75 -75
- package/src/components/Day/index.tsx +95 -95
- package/src/components/Day/styles.module.scss +97 -97
- package/src/components/Input/Input.stories.tsx +37 -37
- package/src/components/Input/index.tsx +64 -64
- package/src/components/Input/styles.module.scss +79 -79
- package/src/components/Modal/CrudModal/index.tsx +43 -43
- package/src/components/Modal/CrudModal/styles.module.scss +44 -44
- package/src/components/Modal/index.tsx +66 -66
- package/src/components/Modal/styles.module.scss +40 -40
- package/src/components/Modal/types.ts +13 -13
- package/src/components/Month/Month.stories.tsx +19 -19
- package/src/components/Month/index.tsx +31 -31
- package/src/components/Month/styles.module.scss +30 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +134 -134
- package/src/components/RangePicker/index.tsx +144 -144
- package/src/components/RangePicker/styles.module.scss +19 -19
- package/src/components/TasksManager/AddModal/index.tsx +62 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +22 -22
- package/src/components/TasksManager/EditModal/index.tsx +96 -96
- package/src/components/TasksManager/index.tsx +112 -112
- package/src/components/TasksManager/styles.module.scss +62 -62
- package/src/components/Week/Week.stories.tsx +49 -49
- package/src/components/Week/index.tsx +68 -68
- package/src/components/Week/styles.module.scss +7 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +38 -38
- package/src/components/WeekDay/index.tsx +35 -35
- package/src/components/WeekDay/styles.module.scss +19 -19
- package/src/constants/dateMask.ts +23 -23
- package/src/constants/firstDayOfWeek.ts +7 -7
- package/src/constants/holidays.ts +32 -32
- package/src/constants/modes.ts +6 -6
- package/src/constants/monthsNames.ts +14 -14
- package/src/constants/weekdaysNames.ts +1 -1
- package/src/hooks/useCalendar.ts +62 -62
- package/src/hooks/useLockBodyScroll.ts +19 -19
- package/src/hooks/useModal.ts +45 -45
- package/src/hooks/useTooltip.ts +41 -41
- package/src/hooks/useValidate.ts +80 -80
- package/src/index.ts +15 -15
- package/src/services/calendarService.ts +62 -62
- package/src/services/decorators/withHolidays.ts +12 -12
- package/src/services/decorators/withMinMax.test.ts +77 -77
- package/src/services/decorators/withMinMax.ts +19 -19
- package/src/services/holidayService.ts +56 -56
- package/src/store/localStorage.ts +33 -33
- package/src/store/tasksStore.tsx +146 -146
- package/src/store/types.ts +22 -22
- package/src/stories/Button.stories.ts +54 -0
- package/src/stories/Button.tsx +37 -0
- package/src/stories/Configure.mdx +388 -0
- package/src/stories/Header.stories.ts +34 -0
- package/src/stories/Header.tsx +56 -0
- package/src/stories/Page.stories.ts +33 -0
- package/src/stories/Page.tsx +73 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/page.css +68 -0
- package/src/styles/_border.scss +9 -9
- package/src/styles/_colors.scss +53 -53
- package/src/styles/_gap.scss +4 -4
- package/src/styles/_globals.scss +61 -61
- package/src/styles/_grid.scss +9 -9
- package/src/styles/_mixins.scss +6 -6
- package/src/styles/_reset.scss +98 -98
- package/src/styles/_theme-mixins.scss +51 -51
- package/src/styles/_typography.scss +10 -10
- package/src/styles/_variables.scss +8 -8
- package/src/styles/main.scss +3 -3
- package/src/types/types.d.ts +15 -15
- package/src/utils/calendar.test.ts +154 -154
- package/src/utils/calendar.ts +82 -82
- package/src/utils/controlDate.ts +3 -3
- package/src/utils/dateChecks.test.ts +216 -216
- package/src/utils/dateChecks.ts +75 -75
- package/src/utils/formatDate.ts +27 -27
- package/src/utils/schema.test.ts +40 -40
- package/src/utils/schema.ts +8 -8
- package/src/utils/weekdayOrder.test.ts +11 -11
- package/src/utils/weekdayOrder.ts +7 -7
- package/vitest.config.ts +38 -38
- package/vitest.shims.d.ts +1 -1
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { FIRST_DAY_OF_WEEK_TYPES } from '@/constants/firstDayOfWeek';
|
|
2
|
-
import { MODES, MODES_TYPES } from '@/constants/modes';
|
|
3
|
-
import { getMonthDays, getWeekDays, getWeeksFromDays } from '@/utils/calendar';
|
|
4
|
-
import { isCurrentMonth, isWeekend } from '@/utils/dateChecks';
|
|
5
|
-
|
|
6
|
-
export class CalendarService {
|
|
7
|
-
private hideWeekends: boolean = false;
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
public monthDate: Date = new Date(),
|
|
11
|
-
public firstDayOfWeek?: FIRST_DAY_OF_WEEK_TYPES,
|
|
12
|
-
public selectedDate?: Date,
|
|
13
|
-
public mode: MODES_TYPES = MODES.MONTH,
|
|
14
|
-
public rangeStart?: Date,
|
|
15
|
-
public rangeEnd?: Date
|
|
16
|
-
) {}
|
|
17
|
-
|
|
18
|
-
setHideWeekends(value: boolean) {
|
|
19
|
-
this.hideWeekends = value;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getDays(): Date[] {
|
|
24
|
-
let days: Date[];
|
|
25
|
-
|
|
26
|
-
if (this.mode === MODES.MONTH) {
|
|
27
|
-
days = getMonthDays(this.monthDate, this.firstDayOfWeek);
|
|
28
|
-
} else {
|
|
29
|
-
days = getWeekDays(this.monthDate, this.firstDayOfWeek);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return this.applyFilters(days);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private applyFilters(days: Date[]): Date[] {
|
|
36
|
-
let filteredDays = days;
|
|
37
|
-
|
|
38
|
-
if (this.hideWeekends) {
|
|
39
|
-
filteredDays = filteredDays.filter((day) => !isWeekend(day));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return filteredDays;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getWeeks(): Date[][] {
|
|
46
|
-
const days = this.getDays();
|
|
47
|
-
const weekLength = this.hideWeekends ? 5 : 7;
|
|
48
|
-
return getWeeksFromDays(days, weekLength);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getIsCurrentMonth = (date: Date) => {
|
|
52
|
-
return isCurrentMonth(date, this.monthDate);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
getIsDisabled = (_date: Date) => {
|
|
56
|
-
return false;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
getIsHoliday = (_date: Date) => {
|
|
60
|
-
return false;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
import { FIRST_DAY_OF_WEEK_TYPES } from '@/constants/firstDayOfWeek';
|
|
2
|
+
import { MODES, MODES_TYPES } from '@/constants/modes';
|
|
3
|
+
import { getMonthDays, getWeekDays, getWeeksFromDays } from '@/utils/calendar';
|
|
4
|
+
import { isCurrentMonth, isWeekend } from '@/utils/dateChecks';
|
|
5
|
+
|
|
6
|
+
export class CalendarService {
|
|
7
|
+
private hideWeekends: boolean = false;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
public monthDate: Date = new Date(),
|
|
11
|
+
public firstDayOfWeek?: FIRST_DAY_OF_WEEK_TYPES,
|
|
12
|
+
public selectedDate?: Date,
|
|
13
|
+
public mode: MODES_TYPES = MODES.MONTH,
|
|
14
|
+
public rangeStart?: Date,
|
|
15
|
+
public rangeEnd?: Date
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
setHideWeekends(value: boolean) {
|
|
19
|
+
this.hideWeekends = value;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getDays(): Date[] {
|
|
24
|
+
let days: Date[];
|
|
25
|
+
|
|
26
|
+
if (this.mode === MODES.MONTH) {
|
|
27
|
+
days = getMonthDays(this.monthDate, this.firstDayOfWeek);
|
|
28
|
+
} else {
|
|
29
|
+
days = getWeekDays(this.monthDate, this.firstDayOfWeek);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return this.applyFilters(days);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private applyFilters(days: Date[]): Date[] {
|
|
36
|
+
let filteredDays = days;
|
|
37
|
+
|
|
38
|
+
if (this.hideWeekends) {
|
|
39
|
+
filteredDays = filteredDays.filter((day) => !isWeekend(day));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return filteredDays;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getWeeks(): Date[][] {
|
|
46
|
+
const days = this.getDays();
|
|
47
|
+
const weekLength = this.hideWeekends ? 5 : 7;
|
|
48
|
+
return getWeeksFromDays(days, weekLength);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getIsCurrentMonth = (date: Date) => {
|
|
52
|
+
return isCurrentMonth(date, this.monthDate);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
getIsDisabled = (_date: Date) => {
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
getIsHoliday = (_date: Date) => {
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { isSameDay } from '@/utils/dateChecks';
|
|
2
|
-
|
|
3
|
-
import { CalendarService } from '../calendarService';
|
|
4
|
-
|
|
5
|
-
export const withHolidays = (calendar: CalendarService, holidays: Date[]) => {
|
|
6
|
-
if (!holidays.length) return calendar;
|
|
7
|
-
|
|
8
|
-
calendar.getIsHoliday = (date: Date) => {
|
|
9
|
-
return holidays.some((holiday) => isSameDay(holiday, date));
|
|
10
|
-
};
|
|
11
|
-
return calendar;
|
|
12
|
-
};
|
|
1
|
+
import { isSameDay } from '@/utils/dateChecks';
|
|
2
|
+
|
|
3
|
+
import { CalendarService } from '../calendarService';
|
|
4
|
+
|
|
5
|
+
export const withHolidays = (calendar: CalendarService, holidays: Date[]) => {
|
|
6
|
+
if (!holidays.length) return calendar;
|
|
7
|
+
|
|
8
|
+
calendar.getIsHoliday = (date: Date) => {
|
|
9
|
+
return holidays.some((holiday) => isSameDay(holiday, date));
|
|
10
|
+
};
|
|
11
|
+
return calendar;
|
|
12
|
+
};
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { isDisabled } from '@/utils/dateChecks';
|
|
2
|
-
|
|
3
|
-
import { CalendarService } from '../calendarService';
|
|
4
|
-
import { withMinMax } from './withMinMax';
|
|
5
|
-
|
|
6
|
-
jest.mock('@/utils/dateChecks', () => ({
|
|
7
|
-
isDisabled: jest.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
describe('withMinMax:', () => {
|
|
11
|
-
let calendar: CalendarService;
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
calendar = new CalendarService();
|
|
15
|
-
jest.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('returns the same calendar instance', () => {
|
|
19
|
-
const result = withMinMax(
|
|
20
|
-
calendar,
|
|
21
|
-
new Date(2026, 0, 1),
|
|
22
|
-
new Date(2026, 11, 31)
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
expect(result).toBe(calendar);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns true when the date is outside the min/max range', () => {
|
|
29
|
-
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
30
|
-
(isDisabled as jest.Mock).mockReturnValue(true);
|
|
31
|
-
|
|
32
|
-
withMinMax(calendar, new Date(2026, 0, 1), new Date(2026, 11, 31));
|
|
33
|
-
const result = calendar.getIsDisabled(new Date(2027, 0, 1));
|
|
34
|
-
|
|
35
|
-
expect(result).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('returns false when the date passes both checks', () => {
|
|
39
|
-
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
40
|
-
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
41
|
-
|
|
42
|
-
withMinMax(calendar, new Date(2026, 0, 1), new Date(2026, 11, 31));
|
|
43
|
-
const result = calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
44
|
-
|
|
45
|
-
expect(result).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('works with only minDate provided', () => {
|
|
49
|
-
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
50
|
-
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
51
|
-
|
|
52
|
-
const minDate = new Date(2026, 0, 1);
|
|
53
|
-
withMinMax(calendar, minDate);
|
|
54
|
-
calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
55
|
-
|
|
56
|
-
expect(isDisabled).toHaveBeenCalledWith(
|
|
57
|
-
new Date(2026, 5, 15),
|
|
58
|
-
minDate,
|
|
59
|
-
undefined
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('works with only maxDate provided', () => {
|
|
64
|
-
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
65
|
-
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
66
|
-
|
|
67
|
-
const maxDate = new Date(2026, 11, 31);
|
|
68
|
-
withMinMax(calendar, undefined, maxDate);
|
|
69
|
-
calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
70
|
-
|
|
71
|
-
expect(isDisabled).toHaveBeenCalledWith(
|
|
72
|
-
new Date(2026, 5, 15),
|
|
73
|
-
undefined,
|
|
74
|
-
maxDate
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
1
|
+
import { isDisabled } from '@/utils/dateChecks';
|
|
2
|
+
|
|
3
|
+
import { CalendarService } from '../calendarService';
|
|
4
|
+
import { withMinMax } from './withMinMax';
|
|
5
|
+
|
|
6
|
+
jest.mock('@/utils/dateChecks', () => ({
|
|
7
|
+
isDisabled: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('withMinMax:', () => {
|
|
11
|
+
let calendar: CalendarService;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
calendar = new CalendarService();
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('returns the same calendar instance', () => {
|
|
19
|
+
const result = withMinMax(
|
|
20
|
+
calendar,
|
|
21
|
+
new Date(2026, 0, 1),
|
|
22
|
+
new Date(2026, 11, 31)
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(calendar);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('returns true when the date is outside the min/max range', () => {
|
|
29
|
+
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
30
|
+
(isDisabled as jest.Mock).mockReturnValue(true);
|
|
31
|
+
|
|
32
|
+
withMinMax(calendar, new Date(2026, 0, 1), new Date(2026, 11, 31));
|
|
33
|
+
const result = calendar.getIsDisabled(new Date(2027, 0, 1));
|
|
34
|
+
|
|
35
|
+
expect(result).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns false when the date passes both checks', () => {
|
|
39
|
+
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
40
|
+
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
41
|
+
|
|
42
|
+
withMinMax(calendar, new Date(2026, 0, 1), new Date(2026, 11, 31));
|
|
43
|
+
const result = calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
44
|
+
|
|
45
|
+
expect(result).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('works with only minDate provided', () => {
|
|
49
|
+
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
50
|
+
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
51
|
+
|
|
52
|
+
const minDate = new Date(2026, 0, 1);
|
|
53
|
+
withMinMax(calendar, minDate);
|
|
54
|
+
calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
55
|
+
|
|
56
|
+
expect(isDisabled).toHaveBeenCalledWith(
|
|
57
|
+
new Date(2026, 5, 15),
|
|
58
|
+
minDate,
|
|
59
|
+
undefined
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('works with only maxDate provided', () => {
|
|
64
|
+
calendar.getIsDisabled = jest.fn().mockReturnValue(false);
|
|
65
|
+
(isDisabled as jest.Mock).mockReturnValue(false);
|
|
66
|
+
|
|
67
|
+
const maxDate = new Date(2026, 11, 31);
|
|
68
|
+
withMinMax(calendar, undefined, maxDate);
|
|
69
|
+
calendar.getIsDisabled(new Date(2026, 5, 15));
|
|
70
|
+
|
|
71
|
+
expect(isDisabled).toHaveBeenCalledWith(
|
|
72
|
+
new Date(2026, 5, 15),
|
|
73
|
+
undefined,
|
|
74
|
+
maxDate
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { isDisabled } from '@/utils/dateChecks';
|
|
2
|
-
|
|
3
|
-
import { CalendarService } from '../calendarService';
|
|
4
|
-
|
|
5
|
-
export function withMinMax(
|
|
6
|
-
calendar: CalendarService,
|
|
7
|
-
minDate?: Date,
|
|
8
|
-
maxDate?: Date
|
|
9
|
-
) {
|
|
10
|
-
const original = calendar.getIsDisabled;
|
|
11
|
-
|
|
12
|
-
calendar.getIsDisabled = (date: Date): boolean => {
|
|
13
|
-
if (original(date)) return true;
|
|
14
|
-
|
|
15
|
-
return isDisabled(date, minDate, maxDate);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return calendar;
|
|
19
|
-
}
|
|
1
|
+
import { isDisabled } from '@/utils/dateChecks';
|
|
2
|
+
|
|
3
|
+
import { CalendarService } from '../calendarService';
|
|
4
|
+
|
|
5
|
+
export function withMinMax(
|
|
6
|
+
calendar: CalendarService,
|
|
7
|
+
minDate?: Date,
|
|
8
|
+
maxDate?: Date
|
|
9
|
+
) {
|
|
10
|
+
const original = calendar.getIsDisabled;
|
|
11
|
+
|
|
12
|
+
calendar.getIsDisabled = (date: Date): boolean => {
|
|
13
|
+
if (original(date)) return true;
|
|
14
|
+
|
|
15
|
+
return isDisabled(date, minDate, maxDate);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return calendar;
|
|
19
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
const HOLIDAY_API_URL = process.env.STORYBOOK_HOLIDAY_API_URL;
|
|
2
|
-
const API_KEY = process.env.STORYBOOK_HOLIDAY_API_KEY;
|
|
3
|
-
|
|
4
|
-
export interface Holiday {
|
|
5
|
-
name: string;
|
|
6
|
-
date: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const getHolidays = async (
|
|
10
|
-
year: number = new Date().getFullYear(),
|
|
11
|
-
signal?: AbortSignal
|
|
12
|
-
): Promise<Date[]> => {
|
|
13
|
-
try {
|
|
14
|
-
let holidayDates;
|
|
15
|
-
const locale = new Intl.Locale(navigator.language);
|
|
16
|
-
const countryCode = locale.region;
|
|
17
|
-
|
|
18
|
-
if (!countryCode) {
|
|
19
|
-
throw new Error('Cannot get your country code');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!API_KEY) {
|
|
23
|
-
throw new Error('API key is not defined');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const url = `${HOLIDAY_API_URL}?key=${API_KEY}&country=${countryCode}&year=${year}`;
|
|
27
|
-
const response = await fetch(url, { signal });
|
|
28
|
-
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
throw new Error(`Error while loading holidays`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const data = await response.json();
|
|
34
|
-
|
|
35
|
-
if (data.holidays) {
|
|
36
|
-
holidayDates = data.holidays.map((holiday: Holiday) => {
|
|
37
|
-
const date = new Date(holiday.date);
|
|
38
|
-
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return holidayDates;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return [];
|
|
45
|
-
} catch (err) {
|
|
46
|
-
if (err instanceof Error && err.name === 'AbortError') {
|
|
47
|
-
throw new Error('Fetch aborted');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (err instanceof Error) {
|
|
51
|
-
throw err;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
throw new Error('Failed to fetch holidays');
|
|
55
|
-
}
|
|
56
|
-
};
|
|
1
|
+
const HOLIDAY_API_URL = process.env.STORYBOOK_HOLIDAY_API_URL;
|
|
2
|
+
const API_KEY = process.env.STORYBOOK_HOLIDAY_API_KEY;
|
|
3
|
+
|
|
4
|
+
export interface Holiday {
|
|
5
|
+
name: string;
|
|
6
|
+
date: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const getHolidays = async (
|
|
10
|
+
year: number = new Date().getFullYear(),
|
|
11
|
+
signal?: AbortSignal
|
|
12
|
+
): Promise<Date[]> => {
|
|
13
|
+
try {
|
|
14
|
+
let holidayDates;
|
|
15
|
+
const locale = new Intl.Locale(navigator.language);
|
|
16
|
+
const countryCode = locale.region;
|
|
17
|
+
|
|
18
|
+
if (!countryCode) {
|
|
19
|
+
throw new Error('Cannot get your country code');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!API_KEY) {
|
|
23
|
+
throw new Error('API key is not defined');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const url = `${HOLIDAY_API_URL}?key=${API_KEY}&country=${countryCode}&year=${year}`;
|
|
27
|
+
const response = await fetch(url, { signal });
|
|
28
|
+
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
throw new Error(`Error while loading holidays`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
|
|
35
|
+
if (data.holidays) {
|
|
36
|
+
holidayDates = data.holidays.map((holiday: Holiday) => {
|
|
37
|
+
const date = new Date(holiday.date);
|
|
38
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return holidayDates;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return [];
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
47
|
+
throw new Error('Fetch aborted');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (err instanceof Error) {
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error('Failed to fetch holidays');
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { Task } from './types';
|
|
2
|
-
|
|
3
|
-
const STORAGE_KEY = 'tasks';
|
|
4
|
-
|
|
5
|
-
export const loadTasksFromStorage = (): Task[] => {
|
|
6
|
-
try {
|
|
7
|
-
const stored = localStorage.getItem(STORAGE_KEY);
|
|
8
|
-
if (stored) {
|
|
9
|
-
const parsed = JSON.parse(stored);
|
|
10
|
-
return parsed.map((task: Task) => ({
|
|
11
|
-
...task,
|
|
12
|
-
date: new Date(task.date),
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
} catch (error) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
error instanceof Error
|
|
18
|
-
? error.message
|
|
19
|
-
: 'Failed to load tasks from storage'
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return [];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const saveTasksToStorage = (tasks: Task[]): void => {
|
|
26
|
-
try {
|
|
27
|
-
localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
|
|
28
|
-
} catch (error) {
|
|
29
|
-
throw new Error(
|
|
30
|
-
error instanceof Error ? error.message : 'Failed to save tasks to storage'
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
1
|
+
import { Task } from './types';
|
|
2
|
+
|
|
3
|
+
const STORAGE_KEY = 'tasks';
|
|
4
|
+
|
|
5
|
+
export const loadTasksFromStorage = (): Task[] => {
|
|
6
|
+
try {
|
|
7
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
8
|
+
if (stored) {
|
|
9
|
+
const parsed = JSON.parse(stored);
|
|
10
|
+
return parsed.map((task: Task) => ({
|
|
11
|
+
...task,
|
|
12
|
+
date: new Date(task.date),
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
error instanceof Error
|
|
18
|
+
? error.message
|
|
19
|
+
: 'Failed to load tasks from storage'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return [];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const saveTasksToStorage = (tasks: Task[]): void => {
|
|
26
|
+
try {
|
|
27
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(tasks));
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
error instanceof Error ? error.message : 'Failed to save tasks to storage'
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|