@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
package/src/utils/schema.test.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
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
|
-
});
|
|
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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
+
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 +1,11 @@
|
|
|
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
|
-
});
|
|
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
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const getOrderedDays = (firstDayOfWeek: 0 | 1): Array<number> => {
|
|
2
|
-
if (firstDayOfWeek === 0) {
|
|
3
|
-
return [0, 1, 2, 3, 4, 5, 6];
|
|
4
|
-
} else {
|
|
5
|
-
return [1, 2, 3, 4, 5, 6, 0];
|
|
6
|
-
}
|
|
7
|
-
};
|
|
1
|
+
export const getOrderedDays = (firstDayOfWeek: 0 | 1): Array<number> => {
|
|
2
|
+
if (firstDayOfWeek === 0) {
|
|
3
|
+
return [0, 1, 2, 3, 4, 5, 6];
|
|
4
|
+
} else {
|
|
5
|
+
return [1, 2, 3, 4, 5, 6, 0];
|
|
6
|
+
}
|
|
7
|
+
};
|
package/vitest.config.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
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
|
-
});
|
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/// <reference types="@vitest/browser-playwright" />
|
|
1
|
+
/// <reference types="@vitest/browser-playwright" />
|