@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,146 +1,146 @@
1
- import {
2
- createContext,
3
- ReactNode,
4
- useCallback,
5
- useContext,
6
- useEffect,
7
- useState,
8
- } from 'react';
9
-
10
- import { isSameDay } from '@/utils/dateChecks';
11
-
12
- import { loadTasksFromStorage, saveTasksToStorage } from './localStorage';
13
- import { Task, TasksContextValue } from './types';
14
-
15
- const TasksContext = createContext<TasksContextValue | null>(null);
16
-
17
- interface TasksProviderProps {
18
- children: ReactNode;
19
- }
20
-
21
- export const TasksProvider = ({ children }: TasksProviderProps) => {
22
- const [tasks, setTasks] = useState<Task[]>([]);
23
- const [loading, setLoading] = useState(false);
24
- const [error, setError] = useState<string>('');
25
-
26
- const loadTasks = useCallback(() => {
27
- setLoading(true);
28
- setError('');
29
- try {
30
- const loadedTasks = loadTasksFromStorage();
31
- setTasks(loadedTasks);
32
- } catch (err) {
33
- setError(err instanceof Error ? err.message : 'Failed to load tasks');
34
- } finally {
35
- setLoading(false);
36
- }
37
- }, []);
38
-
39
- useEffect(() => {
40
- loadTasks();
41
- }, [loadTasks]);
42
-
43
- const getTasksByDate = (date: Date) => {
44
- return tasks.filter((task) => isSameDay(task.date, date));
45
- };
46
-
47
- const hasTasks = (date: Date) => {
48
- return tasks.some((task) => isSameDay(task.date, date));
49
- };
50
-
51
- const addTask = (date: Date, title: string) => {
52
- const newTask = {
53
- id: Date.now().toString(),
54
- date,
55
- title,
56
- completed: false,
57
- };
58
-
59
- setTasks((prev) => {
60
- const updated = [...prev, newTask];
61
- saveTasksToStorage(updated);
62
- return updated;
63
- });
64
-
65
- return newTask;
66
- };
67
-
68
- const editTask = (id: string, updates: Partial<Omit<Task, 'id'>>) => {
69
- let result: Task | undefined;
70
-
71
- setTasks((prevTasks) => {
72
- const updatedTasks = prevTasks.map((task) => {
73
- if (task.id === id) {
74
- result = { ...task, ...updates };
75
- return result;
76
- }
77
- return task;
78
- });
79
-
80
- saveTasksToStorage(updatedTasks);
81
- return updatedTasks;
82
- });
83
-
84
- return result;
85
- };
86
-
87
- const deleteTask = (id: string) => {
88
- let deleted = false;
89
-
90
- setTasks((prev) => {
91
- const updated = prev.filter((task) => {
92
- if (task.id === id) {
93
- deleted = true;
94
- return false;
95
- }
96
- return true;
97
- });
98
- saveTasksToStorage(updated);
99
- return updated;
100
- });
101
-
102
- return deleted;
103
- };
104
-
105
- const toggleTask = (id: string) => {
106
- let toggledTask;
107
-
108
- setTasks((prev) => {
109
- const updated = prev.map((task) => {
110
- if (task.id === id) {
111
- toggledTask = { ...task, completed: !task.completed };
112
- return toggledTask;
113
- }
114
- return task;
115
- });
116
- saveTasksToStorage(updated);
117
- return updated;
118
- });
119
-
120
- return toggledTask;
121
- };
122
-
123
- const value = {
124
- tasks,
125
- loading,
126
- error,
127
- getTasksByDate,
128
- hasTasks,
129
- addTask,
130
- editTask,
131
- deleteTask,
132
- toggleTask,
133
- loadTasks,
134
- };
135
- return (
136
- <TasksContext.Provider value={value}>{children}</TasksContext.Provider>
137
- );
138
- };
139
-
140
- export const useTasks = () => {
141
- const context = useContext(TasksContext);
142
- if (!context) {
143
- throw new Error('Error while loading context');
144
- }
145
- return context;
146
- };
1
+ import {
2
+ createContext,
3
+ ReactNode,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useState,
8
+ } from 'react';
9
+
10
+ import { isSameDay } from '@/utils/dateChecks';
11
+
12
+ import { loadTasksFromStorage, saveTasksToStorage } from './localStorage';
13
+ import { Task, TasksContextValue } from './types';
14
+
15
+ const TasksContext = createContext<TasksContextValue | null>(null);
16
+
17
+ interface TasksProviderProps {
18
+ children: ReactNode;
19
+ }
20
+
21
+ export const TasksProvider = ({ children }: TasksProviderProps) => {
22
+ const [tasks, setTasks] = useState<Task[]>([]);
23
+ const [loading, setLoading] = useState(false);
24
+ const [error, setError] = useState<string>('');
25
+
26
+ const loadTasks = useCallback(() => {
27
+ setLoading(true);
28
+ setError('');
29
+ try {
30
+ const loadedTasks = loadTasksFromStorage();
31
+ setTasks(loadedTasks);
32
+ } catch (err) {
33
+ setError(err instanceof Error ? err.message : 'Failed to load tasks');
34
+ } finally {
35
+ setLoading(false);
36
+ }
37
+ }, []);
38
+
39
+ useEffect(() => {
40
+ loadTasks();
41
+ }, [loadTasks]);
42
+
43
+ const getTasksByDate = (date: Date) => {
44
+ return tasks.filter((task) => isSameDay(task.date, date));
45
+ };
46
+
47
+ const hasTasks = (date: Date) => {
48
+ return tasks.some((task) => isSameDay(task.date, date));
49
+ };
50
+
51
+ const addTask = (date: Date, title: string) => {
52
+ const newTask = {
53
+ id: Date.now().toString(),
54
+ date,
55
+ title,
56
+ completed: false,
57
+ };
58
+
59
+ setTasks((prev) => {
60
+ const updated = [...prev, newTask];
61
+ saveTasksToStorage(updated);
62
+ return updated;
63
+ });
64
+
65
+ return newTask;
66
+ };
67
+
68
+ const editTask = (id: string, updates: Partial<Omit<Task, 'id'>>) => {
69
+ let result: Task | undefined;
70
+
71
+ setTasks((prevTasks) => {
72
+ const updatedTasks = prevTasks.map((task) => {
73
+ if (task.id === id) {
74
+ result = { ...task, ...updates };
75
+ return result;
76
+ }
77
+ return task;
78
+ });
79
+
80
+ saveTasksToStorage(updatedTasks);
81
+ return updatedTasks;
82
+ });
83
+
84
+ return result;
85
+ };
86
+
87
+ const deleteTask = (id: string) => {
88
+ let deleted = false;
89
+
90
+ setTasks((prev) => {
91
+ const updated = prev.filter((task) => {
92
+ if (task.id === id) {
93
+ deleted = true;
94
+ return false;
95
+ }
96
+ return true;
97
+ });
98
+ saveTasksToStorage(updated);
99
+ return updated;
100
+ });
101
+
102
+ return deleted;
103
+ };
104
+
105
+ const toggleTask = (id: string) => {
106
+ let toggledTask;
107
+
108
+ setTasks((prev) => {
109
+ const updated = prev.map((task) => {
110
+ if (task.id === id) {
111
+ toggledTask = { ...task, completed: !task.completed };
112
+ return toggledTask;
113
+ }
114
+ return task;
115
+ });
116
+ saveTasksToStorage(updated);
117
+ return updated;
118
+ });
119
+
120
+ return toggledTask;
121
+ };
122
+
123
+ const value = {
124
+ tasks,
125
+ loading,
126
+ error,
127
+ getTasksByDate,
128
+ hasTasks,
129
+ addTask,
130
+ editTask,
131
+ deleteTask,
132
+ toggleTask,
133
+ loadTasks,
134
+ };
135
+ return (
136
+ <TasksContext.Provider value={value}>{children}</TasksContext.Provider>
137
+ );
138
+ };
139
+
140
+ export const useTasks = () => {
141
+ const context = useContext(TasksContext);
142
+ if (!context) {
143
+ throw new Error('Error while loading context');
144
+ }
145
+ return context;
146
+ };
@@ -1,22 +1,22 @@
1
- export interface Task {
2
- id: string;
3
- date: Date;
4
- title: string;
5
- completed: boolean;
6
- }
7
-
8
- export interface TasksContextValue {
9
- tasks: Task[];
10
- loading: boolean;
11
- error: string;
12
- getTasksByDate: (date: Date) => Task[];
13
- hasTasks: (date: Date) => boolean;
14
- addTask: (date: Date, title: string) => Task;
15
- editTask: (
16
- id: string,
17
- updates: Partial<Omit<Task, 'id'>>
18
- ) => Task | undefined;
19
- deleteTask: (id: string) => boolean;
20
- toggleTask: (id: string) => Task | undefined;
21
- loadTasks: () => void;
22
- }
1
+ export interface Task {
2
+ id: string;
3
+ date: Date;
4
+ title: string;
5
+ completed: boolean;
6
+ }
7
+
8
+ export interface TasksContextValue {
9
+ tasks: Task[];
10
+ loading: boolean;
11
+ error: string;
12
+ getTasksByDate: (date: Date) => Task[];
13
+ hasTasks: (date: Date) => boolean;
14
+ addTask: (date: Date, title: string) => Task;
15
+ editTask: (
16
+ id: string,
17
+ updates: Partial<Omit<Task, 'id'>>
18
+ ) => Task | undefined;
19
+ deleteTask: (id: string) => boolean;
20
+ toggleTask: (id: string) => Task | undefined;
21
+ loadTasks: () => void;
22
+ }
@@ -0,0 +1,54 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite';
2
+
3
+ import { fn } from 'storybook/test';
4
+
5
+ import { Button } from './Button';
6
+
7
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
8
+ const meta = {
9
+ title: 'Example/Button',
10
+ component: Button,
11
+ parameters: {
12
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
13
+ layout: 'centered',
14
+ },
15
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
16
+ tags: ['autodocs'],
17
+ // More on argTypes: https://storybook.js.org/docs/api/arg-types
18
+ argTypes: {
19
+ backgroundColor: { control: 'color' },
20
+ },
21
+ // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#story-args
22
+ args: { onClick: fn() },
23
+ } satisfies Meta<typeof Button>;
24
+
25
+ export default meta;
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
29
+ export const Primary: Story = {
30
+ args: {
31
+ primary: true,
32
+ label: 'Button',
33
+ },
34
+ };
35
+
36
+ export const Secondary: Story = {
37
+ args: {
38
+ label: 'Button',
39
+ },
40
+ };
41
+
42
+ export const Large: Story = {
43
+ args: {
44
+ size: 'large',
45
+ label: 'Button',
46
+ },
47
+ };
48
+
49
+ export const Small: Story = {
50
+ args: {
51
+ size: 'small',
52
+ label: 'Button',
53
+ },
54
+ };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+
3
+ import './button.css';
4
+
5
+ export interface ButtonProps {
6
+ /** Is this the principal call to action on the page? */
7
+ primary?: boolean;
8
+ /** What background color to use */
9
+ backgroundColor?: string;
10
+ /** How large should the button be? */
11
+ size?: 'small' | 'medium' | 'large';
12
+ /** Button contents */
13
+ label: string;
14
+ /** Optional click handler */
15
+ onClick?: () => void;
16
+ }
17
+
18
+ /** Primary UI component for user interaction */
19
+ export const Button = ({
20
+ primary = false,
21
+ size = 'medium',
22
+ backgroundColor,
23
+ label,
24
+ ...props
25
+ }: ButtonProps) => {
26
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
27
+ return (
28
+ <button
29
+ type="button"
30
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
31
+ style={{ backgroundColor }}
32
+ {...props}
33
+ >
34
+ {label}
35
+ </button>
36
+ );
37
+ };