@daryasidorovich/modsen-datepicker 1.0.1 → 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.
Files changed (149) hide show
  1. package/README.md +302 -302
  2. package/package.json +111 -106
  3. package/.babelrc.json +0 -7
  4. package/.github/workflows/chromatic.yml +0 -25
  5. package/.github/workflows/ci.yml +0 -56
  6. package/.husky/commit-msg +0 -1
  7. package/.husky/pre-commit +0 -1
  8. package/.prettierignore +0 -16
  9. package/.prettierrc +0 -6
  10. package/.storybook/main.js +0 -93
  11. package/.storybook/main.ts +0 -16
  12. package/.storybook/preview-head.html +0 -6
  13. package/.storybook/preview.js +0 -26
  14. package/.storybook/preview.tsx +0 -18
  15. package/commitlint.config.js +0 -23
  16. package/eslint.config.ts +0 -80
  17. package/jest.config.json +0 -21
  18. package/rollup.config.js +0 -65
  19. package/src/assets/actions/Delete.svg +0 -4
  20. package/src/assets/actions/Edit.svg +0 -3
  21. package/src/assets/arrows/Next.svg +0 -4
  22. package/src/assets/arrows/Prev.svg +0 -4
  23. package/src/assets/input/Calendar.svg +0 -3
  24. package/src/assets/input/Clear.svg +0 -3
  25. package/src/components/BaseCalendar/BaseCalendar.stories.tsx +0 -77
  26. package/src/components/BaseCalendar/index.tsx +0 -63
  27. package/src/components/BaseCalendar/styles.module.scss +0 -15
  28. package/src/components/Button/Button.stories.tsx +0 -16
  29. package/src/components/Button/Button.tsx +0 -14
  30. package/src/components/Button/index.ts +0 -1
  31. package/src/components/Button/styles.module.scss +0 -3
  32. package/src/components/CalendarGrid/CalendarGrid.stories.tsx +0 -136
  33. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +0 -27
  34. package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +0 -9
  35. package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +0 -51
  36. package/src/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.tsx +0 -223
  37. package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +0 -36
  38. package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +0 -11
  39. package/src/components/CalendarGrid/index.tsx +0 -19
  40. package/src/components/CalendarGrid/types.ts +0 -26
  41. package/src/components/Clear/Clear.stories.tsx +0 -16
  42. package/src/components/Clear/index.tsx +0 -12
  43. package/src/components/Clear/styles.module.scss +0 -34
  44. package/src/components/DatePicker/DatePicker.stories.tsx +0 -127
  45. package/src/components/DatePicker/index.tsx +0 -72
  46. package/src/components/DatePicker/styles.module.scss +0 -10
  47. package/src/components/Day/Day.stories.tsx +0 -75
  48. package/src/components/Day/index.tsx +0 -95
  49. package/src/components/Day/styles.module.scss +0 -97
  50. package/src/components/Input/Input.stories.tsx +0 -37
  51. package/src/components/Input/index.tsx +0 -64
  52. package/src/components/Input/styles.module.scss +0 -79
  53. package/src/components/Modal/CrudModal/index.tsx +0 -43
  54. package/src/components/Modal/CrudModal/styles.module.scss +0 -44
  55. package/src/components/Modal/index.tsx +0 -66
  56. package/src/components/Modal/styles.module.scss +0 -40
  57. package/src/components/Modal/types.ts +0 -13
  58. package/src/components/Month/Month.stories.tsx +0 -19
  59. package/src/components/Month/index.tsx +0 -31
  60. package/src/components/Month/styles.module.scss +0 -30
  61. package/src/components/RangePicker/RangePicker.stories.tsx +0 -134
  62. package/src/components/RangePicker/index.tsx +0 -144
  63. package/src/components/RangePicker/styles.module.scss +0 -19
  64. package/src/components/TasksManager/AddModal/index.tsx +0 -62
  65. package/src/components/TasksManager/DeleteModal/index.tsx +0 -22
  66. package/src/components/TasksManager/EditModal/index.tsx +0 -96
  67. package/src/components/TasksManager/index.tsx +0 -112
  68. package/src/components/TasksManager/styles.module.scss +0 -62
  69. package/src/components/Week/Week.stories.tsx +0 -49
  70. package/src/components/Week/index.tsx +0 -68
  71. package/src/components/Week/styles.module.scss +0 -7
  72. package/src/components/WeekDay/WeekDay.stories.tsx +0 -38
  73. package/src/components/WeekDay/index.tsx +0 -35
  74. package/src/components/WeekDay/styles.module.scss +0 -19
  75. package/src/constants/dateMask.ts +0 -23
  76. package/src/constants/firstDayOfWeek.ts +0 -7
  77. package/src/constants/holidays.ts +0 -32
  78. package/src/constants/modes.ts +0 -6
  79. package/src/constants/monthsNames.ts +0 -14
  80. package/src/constants/weekdaysNames.ts +0 -1
  81. package/src/hooks/useCalendar.ts +0 -62
  82. package/src/hooks/useLockBodyScroll.ts +0 -19
  83. package/src/hooks/useModal.ts +0 -45
  84. package/src/hooks/useTooltip.ts +0 -41
  85. package/src/hooks/useValidate.ts +0 -80
  86. package/src/index.ts +0 -15
  87. package/src/services/calendarService.ts +0 -62
  88. package/src/services/decorators/withHolidays.test.ts +0 -64
  89. package/src/services/decorators/withHolidays.ts +0 -12
  90. package/src/services/decorators/withMinMax.test.ts +0 -77
  91. package/src/services/decorators/withMinMax.ts +0 -19
  92. package/src/services/holidayService.ts +0 -56
  93. package/src/setupTests.ts +0 -1
  94. package/src/store/localStorage.ts +0 -33
  95. package/src/store/tasksStore.test.tsx +0 -208
  96. package/src/store/tasksStore.tsx +0 -146
  97. package/src/store/types.ts +0 -22
  98. package/src/stories/Button.stories.ts +0 -54
  99. package/src/stories/Button.tsx +0 -37
  100. package/src/stories/Configure.mdx +0 -388
  101. package/src/stories/Header.stories.ts +0 -34
  102. package/src/stories/Header.tsx +0 -56
  103. package/src/stories/Page.stories.ts +0 -33
  104. package/src/stories/Page.tsx +0 -73
  105. package/src/stories/assets/accessibility.png +0 -0
  106. package/src/stories/assets/accessibility.svg +0 -1
  107. package/src/stories/assets/addon-library.png +0 -0
  108. package/src/stories/assets/assets.png +0 -0
  109. package/src/stories/assets/avif-test-image.avif +0 -0
  110. package/src/stories/assets/context.png +0 -0
  111. package/src/stories/assets/discord.svg +0 -1
  112. package/src/stories/assets/docs.png +0 -0
  113. package/src/stories/assets/figma-plugin.png +0 -0
  114. package/src/stories/assets/github.svg +0 -1
  115. package/src/stories/assets/share.png +0 -0
  116. package/src/stories/assets/styling.png +0 -0
  117. package/src/stories/assets/testing.png +0 -0
  118. package/src/stories/assets/theming.png +0 -0
  119. package/src/stories/assets/tutorials.svg +0 -1
  120. package/src/stories/assets/youtube.svg +0 -1
  121. package/src/stories/button.css +0 -30
  122. package/src/stories/header.css +0 -32
  123. package/src/stories/page.css +0 -68
  124. package/src/styles/_border.scss +0 -9
  125. package/src/styles/_colors.scss +0 -53
  126. package/src/styles/_gap.scss +0 -4
  127. package/src/styles/_globals.scss +0 -61
  128. package/src/styles/_grid.scss +0 -9
  129. package/src/styles/_mixins.scss +0 -6
  130. package/src/styles/_reset.scss +0 -98
  131. package/src/styles/_theme-mixins.scss +0 -51
  132. package/src/styles/_typography.scss +0 -10
  133. package/src/styles/_variables.scss +0 -8
  134. package/src/styles/main.scss +0 -3
  135. package/src/types/types.d.ts +0 -15
  136. package/src/utils/calendar.test.ts +0 -154
  137. package/src/utils/calendar.ts +0 -82
  138. package/src/utils/controlDate.ts +0 -3
  139. package/src/utils/dateChecks.test.ts +0 -216
  140. package/src/utils/dateChecks.ts +0 -75
  141. package/src/utils/formatDate.test.ts +0 -57
  142. package/src/utils/formatDate.ts +0 -27
  143. package/src/utils/schema.test.ts +0 -40
  144. package/src/utils/schema.ts +0 -8
  145. package/src/utils/weekdayOrder.test.ts +0 -11
  146. package/src/utils/weekdayOrder.ts +0 -7
  147. package/tsconfig.json +0 -31
  148. package/vitest.config.ts +0 -38
  149. package/vitest.shims.d.ts +0 -1
@@ -1,77 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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
- };
package/src/setupTests.ts DELETED
@@ -1 +0,0 @@
1
- import '@testing-library/jest-dom';
@@ -1,33 +0,0 @@
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,208 +0,0 @@
1
- import { render, screen, waitFor } from '@testing-library/react';
2
- import { userEvent } from '@testing-library/user-event';
3
- import { TasksProvider, useTasks } from '@/store/tasksStore';
4
- import { loadTasksFromStorage, saveTasksToStorage } from './localStorage';
5
-
6
- jest.mock('@/store/localStorage', () => ({
7
- loadTasksFromStorage: jest.fn(),
8
- saveTasksToStorage: jest.fn(),
9
- }));
10
-
11
- const TestComponent = () => {
12
- const {
13
- tasks,
14
- error,
15
- getTasksByDate,
16
- hasTasks,
17
- addTask,
18
- editTask,
19
- deleteTask,
20
- toggleTask,
21
- } = useTasks();
22
-
23
- return (
24
- <div>
25
- {error && <div data-testid="error">{error}</div>}
26
-
27
- <div data-testid="tasks-count">Count: {tasks.length}</div>
28
- <ul data-testid="tasks-list">
29
- {Array.isArray(tasks) &&
30
- tasks.map((task) => (
31
- <li key={task.id}>
32
- <p data-testid={`task-title-${task.id}`}>{task.title}</p>
33
- <span data-testid={`task-completed-${task.id}`}>
34
- {task.completed ? 'yes' : 'no'}
35
- </span>
36
- <button
37
- data-testid={`toggle-${task.id}`}
38
- onClick={() => toggleTask(task.id)}
39
- >
40
- Toggle
41
- </button>
42
- <button
43
- data-testid={`delete-${task.id}`}
44
- onClick={() => deleteTask(task.id)}
45
- >
46
- Delete
47
- </button>
48
- <button
49
- data-testid={`edit-${task.id}`}
50
- onClick={() => editTask(task.id, { title: 'Edited task' })}
51
- ></button>
52
- </li>
53
- ))}
54
- </ul>
55
-
56
- <div data-testid="has-tasks-today">
57
- Has tasks today:
58
- {Array.isArray(tasks) && hasTasks(new Date()) ? 'yes' : 'no'}
59
- </div>
60
- <div data-testid="tasks-by-date">
61
- Tasks today: {Array.isArray(tasks) && getTasksByDate(new Date()).length}
62
- </div>
63
-
64
- <button
65
- data-testid="add-task-btn"
66
- onClick={() => addTask(new Date(), 'New task')}
67
- >
68
- Add Task
69
- </button>
70
- </div>
71
- );
72
- };
73
-
74
- describe('TasksContext:', () => {
75
- beforeEach(() => {
76
- jest.resetAllMocks();
77
- });
78
-
79
- const mockTasks = [
80
- { id: '1', date: new Date(), title: 'Task 1', completed: false },
81
- { id: '2', date: new Date(), title: 'Task 2', completed: true },
82
- ];
83
-
84
- test('loads tasks from localStorage on mount:', () => {
85
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
86
-
87
- render(
88
- <TasksProvider>
89
- <TestComponent />
90
- </TasksProvider>
91
- );
92
-
93
- expect(screen.getByTestId('tasks-count')).toHaveTextContent('Count: 2');
94
-
95
- expect(screen.getByTestId('task-title-1')).toHaveTextContent('Task 1');
96
- expect(screen.getByTestId('task-title-2')).toHaveTextContent('Task 2');
97
- });
98
-
99
- test('adds task correctly:', async () => {
100
- (loadTasksFromStorage as jest.Mock).mockReturnValue([]);
101
-
102
- render(
103
- <TasksProvider>
104
- <TestComponent />
105
- </TasksProvider>
106
- );
107
-
108
- expect(screen.getByTestId('tasks-count')).toHaveTextContent('Count: 0');
109
-
110
- await userEvent.click(screen.getByTestId('add-task-btn'));
111
-
112
- expect(screen.getByTestId('tasks-count')).toHaveTextContent('Count: 1');
113
- expect(screen.getByText('New task')).toBeInTheDocument();
114
-
115
- expect(saveTasksToStorage).toHaveBeenCalled();
116
- expect(saveTasksToStorage).toHaveBeenCalledWith([
117
- expect.objectContaining({ title: 'New task' }),
118
- ]);
119
- });
120
-
121
- test('edits task correctly:', async () => {
122
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
123
-
124
- render(
125
- <TasksProvider>
126
- <TestComponent />
127
- </TasksProvider>
128
- );
129
-
130
- await userEvent.click(screen.getByTestId('edit-1'));
131
-
132
- expect(screen.getByTestId('task-title-1')).toHaveTextContent('Edited task');
133
- });
134
-
135
- test('deletes task correctly', async () => {
136
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
137
-
138
- render(
139
- <TasksProvider>
140
- <TestComponent />
141
- </TasksProvider>
142
- );
143
-
144
- expect(screen.getByTestId('task-title-1')).toBeInTheDocument();
145
-
146
- await userEvent.click(screen.getByTestId('delete-1'));
147
-
148
- expect(screen.queryByTestId('task-title-1')).not.toBeInTheDocument();
149
- expect(screen.getByTestId('tasks-count')).toHaveTextContent('Count: 1');
150
- });
151
-
152
- test('toggles task completion status', async () => {
153
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
154
-
155
- render(
156
- <TasksProvider>
157
- <TestComponent />
158
- </TasksProvider>
159
- );
160
-
161
- expect(screen.getByTestId('task-completed-1')).toHaveTextContent('no');
162
-
163
- await userEvent.click(screen.getByTestId('toggle-1'));
164
-
165
- expect(screen.getByTestId('task-completed-1')).toHaveTextContent('yes');
166
- });
167
-
168
- test('checks if tasks exist for a date', () => {
169
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
170
-
171
- render(
172
- <TasksProvider>
173
- <TestComponent />
174
- </TasksProvider>
175
- );
176
-
177
- expect(screen.getByTestId('has-tasks-today')).toHaveTextContent('yes');
178
- });
179
-
180
- test('gets tasks by date', () => {
181
- (loadTasksFromStorage as jest.Mock).mockReturnValue(mockTasks);
182
-
183
- render(
184
- <TasksProvider>
185
- <TestComponent />
186
- </TasksProvider>
187
- );
188
-
189
- expect(screen.getByTestId('tasks-by-date')).toHaveTextContent(
190
- 'Tasks today: 2'
191
- );
192
- });
193
-
194
- test('handles loading error', () => {
195
- const errorMessage = 'Failed to load tasks';
196
- (loadTasksFromStorage as jest.Mock).mockImplementation(() => {
197
- throw new Error(errorMessage);
198
- });
199
-
200
- render(
201
- <TasksProvider>
202
- <TestComponent />
203
- </TasksProvider>
204
- );
205
-
206
- expect(screen.getByTestId('error')).toHaveTextContent(errorMessage);
207
- });
208
- });
@@ -1,146 +0,0 @@
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 +0,0 @@
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,54 +0,0 @@
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
- };
@@ -1,37 +0,0 @@
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
- };