@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.
Files changed (128) hide show
  1. package/.prettierrc +6 -6
  2. package/.storybook/main.js +93 -93
  3. package/.storybook/main.ts +16 -0
  4. package/.storybook/preview.js +26 -26
  5. package/.storybook/preview.tsx +18 -18
  6. package/README.md +5 -5
  7. package/commitlint.config.js +23 -23
  8. package/package.json +1 -1
  9. package/rollup.config.js +65 -65
  10. package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -77
  11. package/src/components/BaseCalendar/index.tsx +63 -63
  12. package/src/components/BaseCalendar/styles.module.scss +15 -15
  13. package/src/components/Button/Button.stories.tsx +16 -0
  14. package/src/components/Button/Button.tsx +14 -0
  15. package/src/components/Button/index.ts +1 -0
  16. package/src/components/Button/styles.module.scss +3 -0
  17. package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -136
  18. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -27
  19. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -9
  20. package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -51
  21. package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -36
  22. package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -11
  23. package/src/components/CalendarGrid/index.tsx +19 -19
  24. package/src/components/CalendarGrid/types.ts +26 -26
  25. package/src/components/Clear/Clear.stories.tsx +16 -16
  26. package/src/components/Clear/index.tsx +12 -12
  27. package/src/components/Clear/styles.module.scss +34 -34
  28. package/src/components/DatePicker/DatePicker.stories.tsx +127 -127
  29. package/src/components/DatePicker/index.tsx +72 -72
  30. package/src/components/DatePicker/styles.module.scss +10 -10
  31. package/src/components/Day/Day.stories.tsx +75 -75
  32. package/src/components/Day/index.tsx +95 -95
  33. package/src/components/Day/styles.module.scss +97 -97
  34. package/src/components/Input/Input.stories.tsx +37 -37
  35. package/src/components/Input/index.tsx +64 -64
  36. package/src/components/Input/styles.module.scss +79 -79
  37. package/src/components/Modal/CrudModal/index.tsx +43 -43
  38. package/src/components/Modal/CrudModal/styles.module.scss +44 -44
  39. package/src/components/Modal/index.tsx +66 -66
  40. package/src/components/Modal/styles.module.scss +40 -40
  41. package/src/components/Modal/types.ts +13 -13
  42. package/src/components/Month/Month.stories.tsx +19 -19
  43. package/src/components/Month/index.tsx +31 -31
  44. package/src/components/Month/styles.module.scss +30 -30
  45. package/src/components/RangePicker/RangePicker.stories.tsx +134 -134
  46. package/src/components/RangePicker/index.tsx +144 -144
  47. package/src/components/RangePicker/styles.module.scss +19 -19
  48. package/src/components/TasksManager/AddModal/index.tsx +62 -62
  49. package/src/components/TasksManager/DeleteModal/index.tsx +22 -22
  50. package/src/components/TasksManager/EditModal/index.tsx +96 -96
  51. package/src/components/TasksManager/index.tsx +112 -112
  52. package/src/components/TasksManager/styles.module.scss +62 -62
  53. package/src/components/Week/Week.stories.tsx +49 -49
  54. package/src/components/Week/index.tsx +68 -68
  55. package/src/components/Week/styles.module.scss +7 -7
  56. package/src/components/WeekDay/WeekDay.stories.tsx +38 -38
  57. package/src/components/WeekDay/index.tsx +35 -35
  58. package/src/components/WeekDay/styles.module.scss +19 -19
  59. package/src/constants/dateMask.ts +23 -23
  60. package/src/constants/firstDayOfWeek.ts +7 -7
  61. package/src/constants/holidays.ts +32 -32
  62. package/src/constants/modes.ts +6 -6
  63. package/src/constants/monthsNames.ts +14 -14
  64. package/src/constants/weekdaysNames.ts +1 -1
  65. package/src/hooks/useCalendar.ts +62 -62
  66. package/src/hooks/useLockBodyScroll.ts +19 -19
  67. package/src/hooks/useModal.ts +45 -45
  68. package/src/hooks/useTooltip.ts +41 -41
  69. package/src/hooks/useValidate.ts +80 -80
  70. package/src/index.ts +15 -15
  71. package/src/services/calendarService.ts +62 -62
  72. package/src/services/decorators/withHolidays.ts +12 -12
  73. package/src/services/decorators/withMinMax.test.ts +77 -77
  74. package/src/services/decorators/withMinMax.ts +19 -19
  75. package/src/services/holidayService.ts +56 -56
  76. package/src/store/localStorage.ts +33 -33
  77. package/src/store/tasksStore.tsx +146 -146
  78. package/src/store/types.ts +22 -22
  79. package/src/stories/Button.stories.ts +54 -0
  80. package/src/stories/Button.tsx +37 -0
  81. package/src/stories/Configure.mdx +388 -0
  82. package/src/stories/Header.stories.ts +34 -0
  83. package/src/stories/Header.tsx +56 -0
  84. package/src/stories/Page.stories.ts +33 -0
  85. package/src/stories/Page.tsx +73 -0
  86. package/src/stories/assets/accessibility.png +0 -0
  87. package/src/stories/assets/accessibility.svg +1 -0
  88. package/src/stories/assets/addon-library.png +0 -0
  89. package/src/stories/assets/assets.png +0 -0
  90. package/src/stories/assets/avif-test-image.avif +0 -0
  91. package/src/stories/assets/context.png +0 -0
  92. package/src/stories/assets/discord.svg +1 -0
  93. package/src/stories/assets/docs.png +0 -0
  94. package/src/stories/assets/figma-plugin.png +0 -0
  95. package/src/stories/assets/github.svg +1 -0
  96. package/src/stories/assets/share.png +0 -0
  97. package/src/stories/assets/styling.png +0 -0
  98. package/src/stories/assets/testing.png +0 -0
  99. package/src/stories/assets/theming.png +0 -0
  100. package/src/stories/assets/tutorials.svg +1 -0
  101. package/src/stories/assets/youtube.svg +1 -0
  102. package/src/stories/button.css +30 -0
  103. package/src/stories/header.css +32 -0
  104. package/src/stories/page.css +68 -0
  105. package/src/styles/_border.scss +9 -9
  106. package/src/styles/_colors.scss +53 -53
  107. package/src/styles/_gap.scss +4 -4
  108. package/src/styles/_globals.scss +61 -61
  109. package/src/styles/_grid.scss +9 -9
  110. package/src/styles/_mixins.scss +6 -6
  111. package/src/styles/_reset.scss +98 -98
  112. package/src/styles/_theme-mixins.scss +51 -51
  113. package/src/styles/_typography.scss +10 -10
  114. package/src/styles/_variables.scss +8 -8
  115. package/src/styles/main.scss +3 -3
  116. package/src/types/types.d.ts +15 -15
  117. package/src/utils/calendar.test.ts +154 -154
  118. package/src/utils/calendar.ts +82 -82
  119. package/src/utils/controlDate.ts +3 -3
  120. package/src/utils/dateChecks.test.ts +216 -216
  121. package/src/utils/dateChecks.ts +75 -75
  122. package/src/utils/formatDate.ts +27 -27
  123. package/src/utils/schema.test.ts +40 -40
  124. package/src/utils/schema.ts +8 -8
  125. package/src/utils/weekdayOrder.test.ts +11 -11
  126. package/src/utils/weekdayOrder.ts +7 -7
  127. package/vitest.config.ts +38 -38
  128. package/vitest.shims.d.ts +1 -1
@@ -1,9 +1,9 @@
1
- .tooltip {
2
- @include themify-modules($themes) {
3
- background-color: themed('border');
4
- }
5
-
6
- border-radius: $radius-8;
7
- padding: 2px $gap-8;
8
- position: absolute;
9
- }
1
+ .tooltip {
2
+ @include themify-modules($themes) {
3
+ background-color: themed('border');
4
+ }
5
+
6
+ border-radius: $radius-8;
7
+ padding: 2px $gap-8;
8
+ position: absolute;
9
+ }
@@ -1,51 +1,51 @@
1
- import { useState } from 'react';
2
-
3
- import { TasksManager } from '@/components/TasksManager';
4
- import { useModal } from '@/hooks/useModal';
5
- import { useTooltip } from '@/hooks/useTooltip';
6
- import { useTasks } from '@/store/tasksStore';
7
-
8
- import { CalendarGridWithoutTasks } from '../CalendarGridWithoutTasks';
9
- import { CalendarProps } from '../types';
10
- import { Tooltip } from './Tooltip';
11
-
12
- export const CalendarGridWithTasks = (props: CalendarProps) => {
13
- const { getTasksByDate, hasTasks } = useTasks();
14
- const [selectedDate, setSelectedDate] = useState<Date>();
15
- const tasksManagerModal = useModal();
16
- const { tooltip, handleDayMouseEnter, handleDayMouseLeave } = useTooltip();
17
-
18
- const handleDateDoubleClick = (date: Date) => {
19
- setSelectedDate(date);
20
- tasksManagerModal.open();
21
- };
22
-
23
- const currentTasks = selectedDate ? getTasksByDate(selectedDate) : [];
24
-
25
- return (
26
- <>
27
- <CalendarGridWithoutTasks
28
- {...props}
29
- hasTasks={hasTasks}
30
- onDateDoubleClick={handleDateDoubleClick}
31
- onMouseEnter={handleDayMouseEnter}
32
- onMouseLeave={handleDayMouseLeave}
33
- >
34
- {selectedDate && (
35
- <TasksManager
36
- tasks={currentTasks}
37
- isOpen={tasksManagerModal.isOpen}
38
- onClose={tasksManagerModal.close}
39
- selectedDate={selectedDate}
40
- />
41
- )}
42
- </CalendarGridWithoutTasks>
43
- <Tooltip
44
- isVisible={tooltip.isVisible}
45
- text="Double-click to open the task manager"
46
- x={tooltip.x}
47
- y={tooltip.y}
48
- />
49
- </>
50
- );
51
- };
1
+ import { useState } from 'react';
2
+
3
+ import { TasksManager } from '@/components/TasksManager';
4
+ import { useModal } from '@/hooks/useModal';
5
+ import { useTooltip } from '@/hooks/useTooltip';
6
+ import { useTasks } from '@/store/tasksStore';
7
+
8
+ import { CalendarGridWithoutTasks } from '../CalendarGridWithoutTasks';
9
+ import { CalendarProps } from '../types';
10
+ import { Tooltip } from './Tooltip';
11
+
12
+ export const CalendarGridWithTasks = (props: CalendarProps) => {
13
+ const { getTasksByDate, hasTasks } = useTasks();
14
+ const [selectedDate, setSelectedDate] = useState<Date>();
15
+ const tasksManagerModal = useModal();
16
+ const { tooltip, handleDayMouseEnter, handleDayMouseLeave } = useTooltip();
17
+
18
+ const handleDateDoubleClick = (date: Date) => {
19
+ setSelectedDate(date);
20
+ tasksManagerModal.open();
21
+ };
22
+
23
+ const currentTasks = selectedDate ? getTasksByDate(selectedDate) : [];
24
+
25
+ return (
26
+ <>
27
+ <CalendarGridWithoutTasks
28
+ {...props}
29
+ hasTasks={hasTasks}
30
+ onDateDoubleClick={handleDateDoubleClick}
31
+ onMouseEnter={handleDayMouseEnter}
32
+ onMouseLeave={handleDayMouseLeave}
33
+ >
34
+ {selectedDate && (
35
+ <TasksManager
36
+ tasks={currentTasks}
37
+ isOpen={tasksManagerModal.isOpen}
38
+ onClose={tasksManagerModal.close}
39
+ selectedDate={selectedDate}
40
+ />
41
+ )}
42
+ </CalendarGridWithoutTasks>
43
+ <Tooltip
44
+ isVisible={tooltip.isVisible}
45
+ text="Double-click to open the task manager"
46
+ x={tooltip.x}
47
+ y={tooltip.y}
48
+ />
49
+ </>
50
+ );
51
+ };
@@ -1,36 +1,36 @@
1
- import { Week } from '@/components/Week';
2
- import { useCalendar } from '@/hooks/useCalendar';
3
-
4
- import { CalendarProps } from '../types';
5
- import styles from './styles.module.scss';
6
-
7
- export const CalendarGridWithoutTasks = ({
8
- children,
9
- ...props
10
- }: CalendarProps & { children?: React.ReactNode }) => {
11
- const { calendar, loading, error } = useCalendar(props);
12
-
13
- const weeks = calendar.getWeeks();
14
-
15
- return (
16
- <div className={styles.calendar}>
17
- {weeks.map((weekDays) => (
18
- <Week
19
- key={weekDays[0].toISOString()}
20
- weekDays={weekDays}
21
- selectedDate={calendar.selectedDate}
22
- getIsDisabled={calendar.getIsDisabled}
23
- getIsCurrentMonth={calendar.getIsCurrentMonth}
24
- getIsHoliday={calendar.getIsHoliday}
25
- rangeStart={calendar.rangeStart}
26
- rangeEnd={calendar.rangeEnd}
27
- {...props}
28
- />
29
- ))}
30
-
31
- {error && <p className={styles.errorMessage}>{error}</p>}
32
- {loading && <div>Loading...</div>}
33
- {children}
34
- </div>
35
- );
36
- };
1
+ import { Week } from '@/components/Week';
2
+ import { useCalendar } from '@/hooks/useCalendar';
3
+
4
+ import { CalendarProps } from '../types';
5
+ import styles from './styles.module.scss';
6
+
7
+ export const CalendarGridWithoutTasks = ({
8
+ children,
9
+ ...props
10
+ }: CalendarProps & { children?: React.ReactNode }) => {
11
+ const { calendar, loading, error } = useCalendar(props);
12
+
13
+ const weeks = calendar.getWeeks();
14
+
15
+ return (
16
+ <div className={styles.calendar}>
17
+ {weeks.map((weekDays) => (
18
+ <Week
19
+ key={weekDays[0].toISOString()}
20
+ weekDays={weekDays}
21
+ selectedDate={calendar.selectedDate}
22
+ getIsDisabled={calendar.getIsDisabled}
23
+ getIsCurrentMonth={calendar.getIsCurrentMonth}
24
+ getIsHoliday={calendar.getIsHoliday}
25
+ rangeStart={calendar.rangeStart}
26
+ rangeEnd={calendar.rangeEnd}
27
+ {...props}
28
+ />
29
+ ))}
30
+
31
+ {error && <p className={styles.errorMessage}>{error}</p>}
32
+ {loading && <div>Loading...</div>}
33
+ {children}
34
+ </div>
35
+ );
36
+ };
@@ -1,11 +1,11 @@
1
- .calendar {
2
- display: flex;
3
- flex-direction: column;
4
- gap: $gap-8;
5
- }
6
-
7
- .errorMessage {
8
- @include themify-modules($themes) {
9
- color: themed('accent');
10
- }
11
- }
1
+ .calendar {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: $gap-8;
5
+ }
6
+
7
+ .errorMessage {
8
+ @include themify-modules($themes) {
9
+ color: themed('accent');
10
+ }
11
+ }
@@ -1,19 +1,19 @@
1
- import { TasksProvider } from '@/store/tasksStore';
2
-
3
- import { CalendarGridWithoutTasks } from './CalendarGridWithoutTasks';
4
- import { CalendarGridWithTasks } from './CalendarGridWithTasks';
5
- import { CalendarProps } from './types';
6
-
7
- export const CalendarGrid = (props: CalendarProps) => {
8
- const { enableTasks } = props;
9
-
10
- if (enableTasks) {
11
- return (
12
- <TasksProvider>
13
- <CalendarGridWithTasks {...props} />
14
- </TasksProvider>
15
- );
16
- }
17
-
18
- return <CalendarGridWithoutTasks {...props} />;
19
- };
1
+ import { TasksProvider } from '@/store/tasksStore';
2
+
3
+ import { CalendarGridWithoutTasks } from './CalendarGridWithoutTasks';
4
+ import { CalendarGridWithTasks } from './CalendarGridWithTasks';
5
+ import { CalendarProps } from './types';
6
+
7
+ export const CalendarGrid = (props: CalendarProps) => {
8
+ const { enableTasks } = props;
9
+
10
+ if (enableTasks) {
11
+ return (
12
+ <TasksProvider>
13
+ <CalendarGridWithTasks {...props} />
14
+ </TasksProvider>
15
+ );
16
+ }
17
+
18
+ return <CalendarGridWithoutTasks {...props} />;
19
+ };
@@ -1,26 +1,26 @@
1
- import { FIRST_DAY_OF_WEEK_TYPES } from '@/constants/firstDayOfWeek';
2
- import { MODES_TYPES } from '@/constants/modes';
3
-
4
- export interface CalendarProps {
5
- minDate?: Date;
6
- maxDate?: Date;
7
- monthDate: Date;
8
- firstDayOfWeek?: FIRST_DAY_OF_WEEK_TYPES;
9
- selectedDate?: Date;
10
- mode?: MODES_TYPES;
11
- rangeStart?: Date;
12
- rangeEnd?: Date;
13
- hideWeekends?: boolean;
14
- showHolidays?: boolean;
15
- enableTasks?: boolean;
16
- hasTasks?: (date: Date) => boolean;
17
- onDateClick?: (e: React.MouseEvent<HTMLButtonElement>, date: Date) => void;
18
- onDateDoubleClick?: (date: Date) => void;
19
- onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement>) => void;
20
- onMouseLeave?: () => void;
21
- }
22
-
23
- export type BaseCalendarProps = Omit<
24
- CalendarProps,
25
- 'hasTasks' | 'onDoubleDateClick' | 'onMouseEnter' | 'onMouseLeave'
26
- >;
1
+ import { FIRST_DAY_OF_WEEK_TYPES } from '@/constants/firstDayOfWeek';
2
+ import { MODES_TYPES } from '@/constants/modes';
3
+
4
+ export interface CalendarProps {
5
+ minDate?: Date;
6
+ maxDate?: Date;
7
+ monthDate: Date;
8
+ firstDayOfWeek?: FIRST_DAY_OF_WEEK_TYPES;
9
+ selectedDate?: Date;
10
+ mode?: MODES_TYPES;
11
+ rangeStart?: Date;
12
+ rangeEnd?: Date;
13
+ hideWeekends?: boolean;
14
+ showHolidays?: boolean;
15
+ enableTasks?: boolean;
16
+ hasTasks?: (date: Date) => boolean;
17
+ onDateClick?: (e: React.MouseEvent<HTMLButtonElement>, date: Date) => void;
18
+ onDateDoubleClick?: (date: Date) => void;
19
+ onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement>) => void;
20
+ onMouseLeave?: () => void;
21
+ }
22
+
23
+ export type BaseCalendarProps = Omit<
24
+ CalendarProps,
25
+ 'hasTasks' | 'onDoubleDateClick' | 'onMouseEnter' | 'onMouseLeave'
26
+ >;
@@ -1,16 +1,16 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { Clear } from '.';
3
-
4
- const meta: Meta<typeof Clear> = {
5
- component: Clear,
6
- };
7
-
8
- export default meta;
9
-
10
- type Story = StoryObj<typeof Clear>;
11
-
12
- export const Default: Story = {
13
- args: {
14
- onClick: () => console.log('Click'),
15
- },
16
- };
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Clear } from '.';
3
+
4
+ const meta: Meta<typeof Clear> = {
5
+ component: Clear,
6
+ };
7
+
8
+ export default meta;
9
+
10
+ type Story = StoryObj<typeof Clear>;
11
+
12
+ export const Default: Story = {
13
+ args: {
14
+ onClick: () => console.log('Click'),
15
+ },
16
+ };
@@ -1,12 +1,12 @@
1
- import styles from './styles.module.scss';
2
-
3
- interface ClearProps {
4
- onClick: () => void;
5
- }
6
- export const Clear = ({ onClick }: ClearProps) => {
7
- return (
8
- <button className={styles.clear} type="button" onClick={onClick}>
9
- Clear
10
- </button>
11
- );
12
- };
1
+ import styles from './styles.module.scss';
2
+
3
+ interface ClearProps {
4
+ onClick: () => void;
5
+ }
6
+ export const Clear = ({ onClick }: ClearProps) => {
7
+ return (
8
+ <button className={styles.clear} type="button" onClick={onClick}>
9
+ Clear
10
+ </button>
11
+ );
12
+ };
@@ -1,34 +1,34 @@
1
- .clear {
2
- @include border;
3
-
4
- @include themify-modules($themes) {
5
- border-color: themed('border');
6
- background-color: themed('background');
7
- color: themed('text');
8
- }
9
-
10
- display: flex;
11
- justify-content: center;
12
- align-items: center;
13
- padding: $gap-10;
14
- width: 100%;
15
- font-weight: $font-weight-semibold;
16
- border-bottom-right-radius: $radius-8;
17
- border-bottom-left-radius: $radius-8;
18
-
19
- &:hover {
20
- @include themify-modules($themes) {
21
- background-color: themed('button-hover');
22
- color: themed('white-color');
23
- }
24
- }
25
-
26
- &:active {
27
- transform: scale(0.98);
28
-
29
- @include themify-modules($themes) {
30
- background-color: themed('selected');
31
- color: themed('white-color');
32
- }
33
- }
34
- }
1
+ .clear {
2
+ @include border;
3
+
4
+ @include themify-modules($themes) {
5
+ border-color: themed('border');
6
+ background-color: themed('background');
7
+ color: themed('text');
8
+ }
9
+
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ padding: $gap-10;
14
+ width: 100%;
15
+ font-weight: $font-weight-semibold;
16
+ border-bottom-right-radius: $radius-8;
17
+ border-bottom-left-radius: $radius-8;
18
+
19
+ &:hover {
20
+ @include themify-modules($themes) {
21
+ background-color: themed('button-hover');
22
+ color: themed('white-color');
23
+ }
24
+ }
25
+
26
+ &:active {
27
+ transform: scale(0.98);
28
+
29
+ @include themify-modules($themes) {
30
+ background-color: themed('selected');
31
+ color: themed('white-color');
32
+ }
33
+ }
34
+ }