@daryasidorovich/modsen-datepicker 1.0.0 → 1.0.2
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/README.md +302 -302
- package/package.json +111 -106
- package/.babelrc.json +0 -7
- package/.github/workflows/chromatic.yml +0 -25
- package/.github/workflows/ci.yml +0 -56
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.prettierignore +0 -16
- package/.prettierrc +0 -6
- package/.storybook/main.js +0 -93
- package/.storybook/preview-head.html +0 -6
- package/.storybook/preview.js +0 -26
- package/.storybook/preview.tsx +0 -18
- package/commitlint.config.js +0 -23
- package/eslint.config.ts +0 -80
- package/jest.config.json +0 -21
- package/rollup.config.js +0 -65
- package/src/assets/actions/Delete.svg +0 -4
- package/src/assets/actions/Edit.svg +0 -3
- package/src/assets/arrows/Next.svg +0 -4
- package/src/assets/arrows/Prev.svg +0 -4
- package/src/assets/input/Calendar.svg +0 -3
- package/src/assets/input/Clear.svg +0 -3
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +0 -77
- package/src/components/BaseCalendar/index.tsx +0 -63
- package/src/components/BaseCalendar/styles.module.scss +0 -15
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +0 -136
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +0 -27
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +0 -9
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +0 -51
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.tsx +0 -223
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +0 -36
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +0 -11
- package/src/components/CalendarGrid/index.tsx +0 -19
- package/src/components/CalendarGrid/types.ts +0 -26
- package/src/components/Clear/Clear.stories.tsx +0 -16
- package/src/components/Clear/index.tsx +0 -12
- package/src/components/Clear/styles.module.scss +0 -34
- package/src/components/DatePicker/DatePicker.stories.tsx +0 -127
- package/src/components/DatePicker/index.tsx +0 -72
- package/src/components/DatePicker/styles.module.scss +0 -10
- package/src/components/Day/Day.stories.tsx +0 -75
- package/src/components/Day/index.tsx +0 -95
- package/src/components/Day/styles.module.scss +0 -97
- package/src/components/Input/Input.stories.tsx +0 -37
- package/src/components/Input/index.tsx +0 -64
- package/src/components/Input/styles.module.scss +0 -79
- package/src/components/Modal/CrudModal/index.tsx +0 -43
- package/src/components/Modal/CrudModal/styles.module.scss +0 -44
- package/src/components/Modal/index.tsx +0 -66
- package/src/components/Modal/styles.module.scss +0 -40
- package/src/components/Modal/types.ts +0 -13
- package/src/components/Month/Month.stories.tsx +0 -19
- package/src/components/Month/index.tsx +0 -31
- package/src/components/Month/styles.module.scss +0 -30
- package/src/components/RangePicker/RangePicker.stories.tsx +0 -134
- package/src/components/RangePicker/index.tsx +0 -144
- package/src/components/RangePicker/styles.module.scss +0 -19
- package/src/components/TasksManager/AddModal/index.tsx +0 -62
- package/src/components/TasksManager/DeleteModal/index.tsx +0 -22
- package/src/components/TasksManager/EditModal/index.tsx +0 -96
- package/src/components/TasksManager/index.tsx +0 -112
- package/src/components/TasksManager/styles.module.scss +0 -62
- package/src/components/Week/Week.stories.tsx +0 -49
- package/src/components/Week/index.tsx +0 -68
- package/src/components/Week/styles.module.scss +0 -7
- package/src/components/WeekDay/WeekDay.stories.tsx +0 -38
- package/src/components/WeekDay/index.tsx +0 -35
- package/src/components/WeekDay/styles.module.scss +0 -19
- package/src/constants/dateMask.ts +0 -23
- package/src/constants/firstDayOfWeek.ts +0 -7
- package/src/constants/holidays.ts +0 -32
- package/src/constants/modes.ts +0 -6
- package/src/constants/monthsNames.ts +0 -14
- package/src/constants/weekdaysNames.ts +0 -1
- package/src/hooks/useCalendar.ts +0 -62
- package/src/hooks/useLockBodyScroll.ts +0 -19
- package/src/hooks/useModal.ts +0 -45
- package/src/hooks/useTooltip.ts +0 -41
- package/src/hooks/useValidate.ts +0 -80
- package/src/index.ts +0 -15
- package/src/services/calendarService.ts +0 -62
- package/src/services/decorators/withHolidays.test.ts +0 -64
- package/src/services/decorators/withHolidays.ts +0 -12
- package/src/services/decorators/withMinMax.test.ts +0 -77
- package/src/services/decorators/withMinMax.ts +0 -19
- package/src/services/holidayService.ts +0 -56
- package/src/setupTests.ts +0 -1
- package/src/store/localStorage.ts +0 -33
- package/src/store/tasksStore.test.tsx +0 -208
- package/src/store/tasksStore.tsx +0 -146
- package/src/store/types.ts +0 -22
- package/src/styles/_border.scss +0 -9
- package/src/styles/_colors.scss +0 -53
- package/src/styles/_gap.scss +0 -4
- package/src/styles/_globals.scss +0 -61
- package/src/styles/_grid.scss +0 -9
- package/src/styles/_mixins.scss +0 -6
- package/src/styles/_reset.scss +0 -98
- package/src/styles/_theme-mixins.scss +0 -51
- package/src/styles/_typography.scss +0 -10
- package/src/styles/_variables.scss +0 -8
- package/src/styles/main.scss +0 -3
- package/src/types/types.d.ts +0 -15
- package/src/utils/calendar.test.ts +0 -154
- package/src/utils/calendar.ts +0 -82
- package/src/utils/controlDate.ts +0 -3
- package/src/utils/dateChecks.test.ts +0 -216
- package/src/utils/dateChecks.ts +0 -75
- package/src/utils/formatDate.test.ts +0 -57
- package/src/utils/formatDate.ts +0 -27
- package/src/utils/schema.test.ts +0 -40
- package/src/utils/schema.ts +0 -8
- package/src/utils/weekdayOrder.test.ts +0 -11
- package/src/utils/weekdayOrder.ts +0 -7
- package/tsconfig.json +0 -31
- package/vitest.config.ts +0 -38
- package/vitest.shims.d.ts +0 -1
package/src/utils/dateChecks.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { formatDateForInput } from './formatDate';
|
|
2
|
-
|
|
3
|
-
export const isSameDay = (date1: Date, date2: Date) => {
|
|
4
|
-
return (
|
|
5
|
-
date1.getFullYear() === date2.getFullYear() &&
|
|
6
|
-
date1.getMonth() === date2.getMonth() &&
|
|
7
|
-
date1.getDate() === date2.getDate()
|
|
8
|
-
);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const isCurrentMonth = (date: Date, monthDate: Date) => {
|
|
12
|
-
return (
|
|
13
|
-
date.getMonth() === monthDate.getMonth() &&
|
|
14
|
-
date.getFullYear() === monthDate.getFullYear()
|
|
15
|
-
);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const isWeekend = (date: Date) => {
|
|
19
|
-
return date.getDay() === 0 || date.getDay() === 6;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const isToday = (date: Date) => {
|
|
23
|
-
return isSameDay(date, new Date());
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const isSelected = (date: Date, selectedDate?: Date) => {
|
|
27
|
-
if (!selectedDate) return false;
|
|
28
|
-
return isSameDay(date, selectedDate);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const isDisabled = (
|
|
32
|
-
date: Date,
|
|
33
|
-
minDate?: Date | null,
|
|
34
|
-
maxDate?: Date | null
|
|
35
|
-
): boolean => {
|
|
36
|
-
if (minDate && date < minDate) return true;
|
|
37
|
-
if (maxDate && date > maxDate) return true;
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const isInRange = (date: Date, start?: Date, end?: Date) => {
|
|
42
|
-
if (!start || !end) return false;
|
|
43
|
-
|
|
44
|
-
const dateStart = new Date(
|
|
45
|
-
start.getFullYear(),
|
|
46
|
-
start.getMonth(),
|
|
47
|
-
start.getDate()
|
|
48
|
-
);
|
|
49
|
-
const dateEnd = new Date(end.getFullYear(), end.getMonth(), end.getDate());
|
|
50
|
-
const dateToCheck = new Date(
|
|
51
|
-
date.getFullYear(),
|
|
52
|
-
date.getMonth(),
|
|
53
|
-
date.getDate()
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
return dateToCheck > dateStart && dateToCheck < dateEnd;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const isRangeStart = (date: Date, start?: Date) => {
|
|
60
|
-
if (!start) return false;
|
|
61
|
-
return isSameDay(date, start);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const isRangeEnd = (date: Date, end?: Date) => {
|
|
65
|
-
if (!end) return false;
|
|
66
|
-
return isSameDay(date, end);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const getRangeError = (date: Date, startDate: Date): string => {
|
|
70
|
-
if (startDate && date < startDate) {
|
|
71
|
-
return `Date must be after ${formatDateForInput(startDate)}`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return '';
|
|
75
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { formatDate, formatDateForInput, parseDate } from './formatDate';
|
|
2
|
-
|
|
3
|
-
describe('formatting dates:', () => {
|
|
4
|
-
test('formatDate:', () => {
|
|
5
|
-
const date1 = new Date(2026, 0, 3);
|
|
6
|
-
const date2 = new Date(2024, 5, 15);
|
|
7
|
-
const date3 = new Date(2000, 11, 31);
|
|
8
|
-
const date4 = new Date(1999, 8, 9);
|
|
9
|
-
const date5 = new Date(2025, 2, 1);
|
|
10
|
-
|
|
11
|
-
expect(formatDate(date1)).toBe('2026-01-03');
|
|
12
|
-
expect(formatDate(date2)).toBe('2024-06-15');
|
|
13
|
-
expect(formatDate(date3)).toBe('2000-12-31');
|
|
14
|
-
expect(formatDate(date4)).toBe('1999-09-09');
|
|
15
|
-
expect(formatDate(date5)).toBe('2025-03-01');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('formatDateForInput:', () => {
|
|
19
|
-
const date1 = new Date(2026, 0, 3);
|
|
20
|
-
const date2 = new Date(2024, 5, 15);
|
|
21
|
-
const date3 = new Date(2000, 11, 31);
|
|
22
|
-
const date4 = new Date(1999, 8, 9);
|
|
23
|
-
const date5 = new Date(2025, 2, 1);
|
|
24
|
-
|
|
25
|
-
expect(formatDateForInput(date1)).toBe('03/01/2026');
|
|
26
|
-
expect(formatDateForInput(date2)).toBe('15/06/2024');
|
|
27
|
-
expect(formatDateForInput(date3)).toBe('31/12/2000');
|
|
28
|
-
expect(formatDateForInput(date4)).toBe('09/09/1999');
|
|
29
|
-
expect(formatDateForInput(date5)).toBe('01/03/2025');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('parseDate:', () => {
|
|
33
|
-
test('returns parsed date', () => {
|
|
34
|
-
const date1 = '03/03/2026';
|
|
35
|
-
const date2 = '15/06/2024';
|
|
36
|
-
const date3 = '31/12/2000';
|
|
37
|
-
const date4 = '09/09/1999';
|
|
38
|
-
const date5 = '01/03/2025';
|
|
39
|
-
|
|
40
|
-
expect(parseDate(date1)).toEqual(new Date(2026, 2, 3));
|
|
41
|
-
expect(parseDate(date2)).toEqual(new Date(2024, 5, 15));
|
|
42
|
-
expect(parseDate(date3)).toEqual(new Date(2000, 11, 31));
|
|
43
|
-
expect(parseDate(date4)).toEqual(new Date(1999, 8, 9));
|
|
44
|
-
expect(parseDate(date5)).toEqual(new Date(2025, 2, 1));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('returns null id date is invalid', () => {
|
|
48
|
-
const date1 = '31/02/2026';
|
|
49
|
-
const date2 = '00/06/2024';
|
|
50
|
-
const date3 = '31/14/2000';
|
|
51
|
-
|
|
52
|
-
expect(parseDate(date1)).toBeNull();
|
|
53
|
-
expect(parseDate(date2)).toBeNull();
|
|
54
|
-
expect(parseDate(date3)).toBeNull();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
});
|
package/src/utils/formatDate.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const formatDate = (date: Date): string => {
|
|
2
|
-
const year = date.getFullYear();
|
|
3
|
-
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
4
|
-
const day = String(date.getDate()).padStart(2, '0');
|
|
5
|
-
return `${year}-${month}-${day}`;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const formatDateForInput = (date: Date): string => {
|
|
9
|
-
const year = date.getFullYear();
|
|
10
|
-
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
11
|
-
const day = String(date.getDate()).padStart(2, '0');
|
|
12
|
-
return `${day}/${month}/${year}`;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const parseDate = (value: string): Date | null => {
|
|
16
|
-
if (!value.trim()) return null;
|
|
17
|
-
|
|
18
|
-
const [day, month, year] = value.split('/').map(Number);
|
|
19
|
-
const parsed = new Date(year, month - 1, day);
|
|
20
|
-
|
|
21
|
-
const isValid =
|
|
22
|
-
parsed.getFullYear() === year &&
|
|
23
|
-
parsed.getMonth() === month - 1 &&
|
|
24
|
-
parsed.getDate() === day;
|
|
25
|
-
|
|
26
|
-
return isValid ? parsed : null;
|
|
27
|
-
};
|
package/src/utils/schema.test.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
import { formSchema } from './schema';
|
|
4
|
-
|
|
5
|
-
describe('formSchema:', () => {
|
|
6
|
-
it('successfully validates correct data', () => {
|
|
7
|
-
const validData = { title: 'Run 100 km', date: '2026-03-11' };
|
|
8
|
-
const result = formSchema.safeParse(validData);
|
|
9
|
-
|
|
10
|
-
expect(result.success).toBe(true);
|
|
11
|
-
if (result.success) {
|
|
12
|
-
expect(result.data).toEqual(validData);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns an error if title is shorter than 3 characters', () => {
|
|
17
|
-
const result = formSchema.safeParse({ title: 'Ru', date: '2026-03-11' });
|
|
18
|
-
|
|
19
|
-
expect(result.success).toBe(false);
|
|
20
|
-
if (!result.success) {
|
|
21
|
-
const errors = z.treeifyError(result.error).properties;
|
|
22
|
-
expect(errors?.title?.errors).toContain(
|
|
23
|
-
'Title must be at least 3 characters'
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns an error if date format is incorrect', () => {
|
|
29
|
-
const result = formSchema.safeParse({
|
|
30
|
-
title: 'Run 100 km',
|
|
31
|
-
date: '2026.01.13',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(result.success).toBe(false);
|
|
35
|
-
if (!result.success) {
|
|
36
|
-
const errors = z.treeifyError(result.error).properties;
|
|
37
|
-
expect(errors?.date?.errors).toContain('Incorrect date format');
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
package/src/utils/schema.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
export const formSchema = z.object({
|
|
4
|
-
title: z.string().min(3, 'Title must be at least 3 characters'),
|
|
5
|
-
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Incorrect date format'),
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export type FormData = z.infer<typeof formSchema>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getOrderedDays } from './weekdayOrder';
|
|
2
|
-
|
|
3
|
-
describe('getOrderedDays:', () => {
|
|
4
|
-
test('returns indexes for Sunday', () => {
|
|
5
|
-
expect(getOrderedDays(0)).toEqual([0, 1, 2, 3, 4, 5, 6]);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
test('returns indexes for Monday', () => {
|
|
9
|
-
expect(getOrderedDays(1)).toEqual([1, 2, 3, 4, 5, 6, 0]);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"lib": ["DOM", "ES2022"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"noEmit": false,
|
|
15
|
-
"importHelpers": true,
|
|
16
|
-
"jsx": "react-jsx",
|
|
17
|
-
"declaration": true,
|
|
18
|
-
"rootDir": "src",
|
|
19
|
-
"module": "ESNext",
|
|
20
|
-
"types": ["jest", "@testing-library/jest-dom", "node"],
|
|
21
|
-
"paths": {
|
|
22
|
-
"@/*": ["./src/*"],
|
|
23
|
-
"@components/*": ["./src/components/*"],
|
|
24
|
-
"@utils/*": ["./src/utils/*"],
|
|
25
|
-
"@styles/*": ["./src/styles/*"],
|
|
26
|
-
"@assets/*": ["./src/assets/*"]
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"include": ["src"],
|
|
30
|
-
"exclude": ["lib", "node_modules", "**/*.stories.tsx"]
|
|
31
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
-
|
|
4
|
-
import { defineConfig } from 'vitest/config';
|
|
5
|
-
|
|
6
|
-
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
|
|
7
|
-
|
|
8
|
-
import { playwright } from '@vitest/browser-playwright';
|
|
9
|
-
|
|
10
|
-
const dirname =
|
|
11
|
-
typeof __dirname !== 'undefined'
|
|
12
|
-
? __dirname
|
|
13
|
-
: path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
|
|
15
|
-
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
|
|
16
|
-
export default defineConfig({
|
|
17
|
-
test: {
|
|
18
|
-
projects: [
|
|
19
|
-
{
|
|
20
|
-
extends: true,
|
|
21
|
-
plugins: [
|
|
22
|
-
// The plugin will run tests for the stories defined in your Storybook config
|
|
23
|
-
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
|
|
24
|
-
storybookTest({ configDir: path.join(dirname, '.storybook') }),
|
|
25
|
-
],
|
|
26
|
-
test: {
|
|
27
|
-
name: 'storybook',
|
|
28
|
-
browser: {
|
|
29
|
-
enabled: true,
|
|
30
|
-
headless: true,
|
|
31
|
-
provider: playwright({}),
|
|
32
|
-
instances: [{ browser: 'chromium' }],
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
});
|
package/vitest.shims.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="@vitest/browser-playwright" />
|