@daryasidorovich/modsen-datepicker 1.0.0
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/.babelrc.json +7 -0
- package/.github/workflows/chromatic.yml +25 -0
- package/.github/workflows/ci.yml +56 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +16 -0
- package/.prettierrc +6 -0
- package/.storybook/main.js +93 -0
- package/.storybook/preview-head.html +6 -0
- package/.storybook/preview.js +26 -0
- package/.storybook/preview.tsx +18 -0
- package/README.md +302 -0
- package/commitlint.config.js +23 -0
- package/dist/components/BaseCalendar/index.d.ts +2 -0
- package/dist/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.d.ts +8 -0
- package/dist/components/CalendarGrid/CalendarGridWithTasks/index.d.ts +2 -0
- package/dist/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.d.ts +1 -0
- package/dist/components/CalendarGrid/CalendarGridWithoutTasks/index.d.ts +4 -0
- package/dist/components/CalendarGrid/index.d.ts +2 -0
- package/dist/components/CalendarGrid/types.d.ts +21 -0
- package/dist/components/Clear/index.d.ts +5 -0
- package/dist/components/DatePicker/index.d.ts +5 -0
- package/dist/components/Day/index.d.ts +16 -0
- package/dist/components/Input/index.d.ts +10 -0
- package/dist/components/Modal/CrudModal/index.d.ts +2 -0
- package/dist/components/Modal/index.d.ts +12 -0
- package/dist/components/Modal/types.d.ts +12 -0
- package/dist/components/Month/index.d.ts +7 -0
- package/dist/components/RangePicker/index.d.ts +6 -0
- package/dist/components/TasksManager/AddModal/index.d.ts +6 -0
- package/dist/components/TasksManager/DeleteModal/index.d.ts +6 -0
- package/dist/components/TasksManager/EditModal/index.d.ts +7 -0
- package/dist/components/TasksManager/index.d.ts +9 -0
- package/dist/components/Week/index.d.ts +17 -0
- package/dist/components/WeekDay/index.d.ts +7 -0
- package/dist/constants/dateMask.d.ts +21 -0
- package/dist/constants/firstDayOfWeek.d.ts +5 -0
- package/dist/constants/holidays.d.ts +1 -0
- package/dist/constants/modes.d.ts +5 -0
- package/dist/constants/monthsNames.d.ts +1 -0
- package/dist/constants/weekdaysNames.d.ts +1 -0
- package/dist/hooks/useCalendar.d.ts +7 -0
- package/dist/hooks/useLockBodyScroll.d.ts +2 -0
- package/dist/hooks/useModal.d.ts +13 -0
- package/dist/hooks/useTooltip.d.ts +9 -0
- package/dist/hooks/useValidate.d.ts +11 -0
- package/dist/index.cjs +17250 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +17233 -0
- package/dist/index.js.map +1 -0
- package/dist/services/calendarService.d.ts +19 -0
- package/dist/services/decorators/withHolidays.d.ts +2 -0
- package/dist/services/decorators/withHolidays.test.d.ts +1 -0
- package/dist/services/decorators/withMinMax.d.ts +2 -0
- package/dist/services/decorators/withMinMax.test.d.ts +1 -0
- package/dist/services/holidayService.d.ts +5 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/store/localStorage.d.ts +3 -0
- package/dist/store/tasksStore.d.ts +8 -0
- package/dist/store/tasksStore.test.d.ts +1 -0
- package/dist/store/types.d.ts +18 -0
- package/dist/utils/calendar.d.ts +7 -0
- package/dist/utils/calendar.test.d.ts +1 -0
- package/dist/utils/controlDate.d.ts +1 -0
- package/dist/utils/dateChecks.d.ts +10 -0
- package/dist/utils/dateChecks.test.d.ts +1 -0
- package/dist/utils/formatDate.d.ts +3 -0
- package/dist/utils/formatDate.test.d.ts +1 -0
- package/dist/utils/schema.d.ts +6 -0
- package/dist/utils/schema.test.d.ts +1 -0
- package/dist/utils/weekdayOrder.d.ts +1 -0
- package/dist/utils/weekdayOrder.test.d.ts +1 -0
- package/docs/base-calendar.png +0 -0
- package/docs/dark-theme.png +0 -0
- package/docs/datepicker.png +0 -0
- package/docs/rangepicker-with-error.png +0 -0
- package/docs/rangepicker.png +0 -0
- package/eslint.config.ts +80 -0
- package/jest.config.json +21 -0
- package/package.json +106 -0
- package/rollup.config.js +65 -0
- package/src/assets/actions/Delete.svg +4 -0
- package/src/assets/actions/Edit.svg +3 -0
- package/src/assets/arrows/Next.svg +4 -0
- package/src/assets/arrows/Prev.svg +4 -0
- package/src/assets/input/Calendar.svg +3 -0
- package/src/assets/input/Clear.svg +3 -0
- package/src/components/BaseCalendar/BaseCalendar.stories.tsx +77 -0
- package/src/components/BaseCalendar/index.tsx +63 -0
- package/src/components/BaseCalendar/styles.module.scss +15 -0
- package/src/components/CalendarGrid/CalendarGrid.stories.tsx +136 -0
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/index.tsx +27 -0
- package/src/components/CalendarGrid/CalendarGridWithTasks/Tooltip/styles.module.scss +9 -0
- package/src/components/CalendarGrid/CalendarGridWithTasks/index.tsx +51 -0
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/CalendarGridWithoutTasks.test.tsx +223 -0
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/index.tsx +36 -0
- package/src/components/CalendarGrid/CalendarGridWithoutTasks/styles.module.scss +11 -0
- package/src/components/CalendarGrid/index.tsx +19 -0
- package/src/components/CalendarGrid/types.ts +26 -0
- package/src/components/Clear/Clear.stories.tsx +16 -0
- package/src/components/Clear/index.tsx +12 -0
- package/src/components/Clear/styles.module.scss +34 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +127 -0
- package/src/components/DatePicker/index.tsx +72 -0
- package/src/components/DatePicker/styles.module.scss +10 -0
- package/src/components/Day/Day.stories.tsx +75 -0
- package/src/components/Day/index.tsx +95 -0
- package/src/components/Day/styles.module.scss +97 -0
- package/src/components/Input/Input.stories.tsx +37 -0
- package/src/components/Input/index.tsx +64 -0
- package/src/components/Input/styles.module.scss +79 -0
- package/src/components/Modal/CrudModal/index.tsx +43 -0
- package/src/components/Modal/CrudModal/styles.module.scss +44 -0
- package/src/components/Modal/index.tsx +66 -0
- package/src/components/Modal/styles.module.scss +40 -0
- package/src/components/Modal/types.ts +13 -0
- package/src/components/Month/Month.stories.tsx +19 -0
- package/src/components/Month/index.tsx +31 -0
- package/src/components/Month/styles.module.scss +30 -0
- package/src/components/RangePicker/RangePicker.stories.tsx +134 -0
- package/src/components/RangePicker/index.tsx +144 -0
- package/src/components/RangePicker/styles.module.scss +19 -0
- package/src/components/TasksManager/AddModal/index.tsx +62 -0
- package/src/components/TasksManager/DeleteModal/index.tsx +22 -0
- package/src/components/TasksManager/EditModal/index.tsx +96 -0
- package/src/components/TasksManager/index.tsx +112 -0
- package/src/components/TasksManager/styles.module.scss +62 -0
- package/src/components/Week/Week.stories.tsx +49 -0
- package/src/components/Week/index.tsx +68 -0
- package/src/components/Week/styles.module.scss +7 -0
- package/src/components/WeekDay/WeekDay.stories.tsx +38 -0
- package/src/components/WeekDay/index.tsx +35 -0
- package/src/components/WeekDay/styles.module.scss +19 -0
- package/src/constants/dateMask.ts +23 -0
- package/src/constants/firstDayOfWeek.ts +7 -0
- package/src/constants/holidays.ts +32 -0
- package/src/constants/modes.ts +6 -0
- package/src/constants/monthsNames.ts +14 -0
- package/src/constants/weekdaysNames.ts +1 -0
- package/src/hooks/useCalendar.ts +62 -0
- package/src/hooks/useLockBodyScroll.ts +19 -0
- package/src/hooks/useModal.ts +45 -0
- package/src/hooks/useTooltip.ts +41 -0
- package/src/hooks/useValidate.ts +80 -0
- package/src/index.ts +15 -0
- package/src/services/calendarService.ts +62 -0
- package/src/services/decorators/withHolidays.test.ts +64 -0
- package/src/services/decorators/withHolidays.ts +12 -0
- package/src/services/decorators/withMinMax.test.ts +77 -0
- package/src/services/decorators/withMinMax.ts +19 -0
- package/src/services/holidayService.ts +56 -0
- package/src/setupTests.ts +1 -0
- package/src/store/localStorage.ts +33 -0
- package/src/store/tasksStore.test.tsx +208 -0
- package/src/store/tasksStore.tsx +146 -0
- package/src/store/types.ts +22 -0
- package/src/styles/_border.scss +9 -0
- package/src/styles/_colors.scss +53 -0
- package/src/styles/_gap.scss +4 -0
- package/src/styles/_globals.scss +61 -0
- package/src/styles/_grid.scss +9 -0
- package/src/styles/_mixins.scss +6 -0
- package/src/styles/_reset.scss +98 -0
- package/src/styles/_theme-mixins.scss +51 -0
- package/src/styles/_typography.scss +10 -0
- package/src/styles/_variables.scss +8 -0
- package/src/styles/main.scss +3 -0
- package/src/types/types.d.ts +15 -0
- package/src/utils/calendar.test.ts +154 -0
- package/src/utils/calendar.ts +82 -0
- package/src/utils/controlDate.ts +3 -0
- package/src/utils/dateChecks.test.ts +216 -0
- package/src/utils/dateChecks.ts +75 -0
- package/src/utils/formatDate.test.ts +57 -0
- package/src/utils/formatDate.ts +27 -0
- package/src/utils/schema.test.ts +40 -0
- package/src/utils/schema.ts +8 -0
- package/src/utils/weekdayOrder.test.ts +11 -0
- package/src/utils/weekdayOrder.ts +7 -0
- package/tsconfig.json +31 -0
- package/vitest.config.ts +38 -0
- package/vitest.shims.d.ts +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.header {
|
|
2
|
+
margin-bottom: $gap-24;
|
|
3
|
+
margin-top: $gap-8;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.title {
|
|
7
|
+
font-size: $font-size-18;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.footer {
|
|
11
|
+
display: flex;
|
|
12
|
+
width: 100%;
|
|
13
|
+
gap: $gap-10;
|
|
14
|
+
justify-content: end;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.children {
|
|
18
|
+
display: flex;
|
|
19
|
+
gap: $gap-8;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
min-width: 300px;
|
|
22
|
+
width: fit-content;
|
|
23
|
+
margin-bottom: $gap-24;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.modalButtons {
|
|
27
|
+
@include themify-modules($themes) {
|
|
28
|
+
background-color: themed('light-blue');
|
|
29
|
+
border-color: themed('border');
|
|
30
|
+
color: themed('text');
|
|
31
|
+
}
|
|
32
|
+
@include border;
|
|
33
|
+
|
|
34
|
+
padding: $gap-5 $gap-10;
|
|
35
|
+
border-radius: $radius-8;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.confirm {
|
|
39
|
+
@include themify-modules($themes) {
|
|
40
|
+
background-color: themed('middle-blue');
|
|
41
|
+
border-color: themed('border');
|
|
42
|
+
color: themed('white-color');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import React, { ReactNode, useRef } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
4
|
+
|
|
5
|
+
import useLockBodyScroll from '@/hooks/useLockBodyScroll';
|
|
6
|
+
|
|
7
|
+
import styles from './styles.module.scss';
|
|
8
|
+
|
|
9
|
+
export interface ModalProps {
|
|
10
|
+
isOpen: boolean;
|
|
11
|
+
onClose: () => void;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
showCloseButton?: boolean;
|
|
14
|
+
showOverlay?: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
classNameOverlay?: string;
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Modal = ({
|
|
21
|
+
isOpen,
|
|
22
|
+
onClose,
|
|
23
|
+
children,
|
|
24
|
+
showOverlay = true,
|
|
25
|
+
showCloseButton = true,
|
|
26
|
+
className = '',
|
|
27
|
+
classNameOverlay = '',
|
|
28
|
+
style = {},
|
|
29
|
+
}: ModalProps) => {
|
|
30
|
+
const modalRoot = document.body;
|
|
31
|
+
const targetElement = modalRoot || document.body;
|
|
32
|
+
const modalRef = useRef(null);
|
|
33
|
+
useLockBodyScroll(isOpen);
|
|
34
|
+
|
|
35
|
+
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
36
|
+
if (e.target === e.currentTarget) {
|
|
37
|
+
onClose();
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (!isOpen) return null;
|
|
42
|
+
|
|
43
|
+
const modalContent = (
|
|
44
|
+
<div
|
|
45
|
+
className={classNames(styles.overlay, classNameOverlay, {
|
|
46
|
+
[styles.overlayColor]: showOverlay,
|
|
47
|
+
})}
|
|
48
|
+
onClick={handleClick}
|
|
49
|
+
>
|
|
50
|
+
<div
|
|
51
|
+
ref={modalRef}
|
|
52
|
+
className={classNames(styles.modal, className)}
|
|
53
|
+
style={style}
|
|
54
|
+
>
|
|
55
|
+
{showCloseButton && (
|
|
56
|
+
<button className={styles.closeButton} onClick={onClose}>
|
|
57
|
+
<span>×</span>
|
|
58
|
+
</button>
|
|
59
|
+
)}
|
|
60
|
+
{children}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return createPortal(modalContent, targetElement);
|
|
66
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.overlay {
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
display: flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
justify-content: center;
|
|
7
|
+
z-index: $z-index-10;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.overlayColor {
|
|
11
|
+
@include themify-modules($themes) {
|
|
12
|
+
background-color: themed('overlay');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.modal {
|
|
17
|
+
position: relative;
|
|
18
|
+
@include themify-modules($themes) {
|
|
19
|
+
background-color: themed('background');
|
|
20
|
+
border-color: themed('border');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@include border;
|
|
24
|
+
border-radius: $radius-8;
|
|
25
|
+
padding: $gap-24;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.closeButton {
|
|
29
|
+
border: none;
|
|
30
|
+
background-color: transparent;
|
|
31
|
+
position: absolute;
|
|
32
|
+
right: $gap-8;
|
|
33
|
+
top: 0;
|
|
34
|
+
font-size: 24px;
|
|
35
|
+
line-height: normal;
|
|
36
|
+
|
|
37
|
+
@include themify-modules($themes) {
|
|
38
|
+
color: themed('text');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface CrudModalProps {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
onConfirm: () => void;
|
|
7
|
+
title: string;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
cancelText?: string;
|
|
10
|
+
confirmText?: string;
|
|
11
|
+
isLoading?: boolean;
|
|
12
|
+
showCloseButton?: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Month } from '.';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Month> = {
|
|
5
|
+
component: Month,
|
|
6
|
+
parameters: {
|
|
7
|
+
layout: 'centered',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default meta;
|
|
12
|
+
|
|
13
|
+
type Story = StoryObj<typeof Month>;
|
|
14
|
+
|
|
15
|
+
export const Default: Story = {
|
|
16
|
+
args: {
|
|
17
|
+
date: new Date(),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Next from '@assets/arrows/Next.svg?react';
|
|
2
|
+
import Prev from '@assets/arrows/Prev.svg?react';
|
|
3
|
+
|
|
4
|
+
import { MONTHS_NAMES } from '@/constants/monthsNames';
|
|
5
|
+
|
|
6
|
+
import styles from './styles.module.scss';
|
|
7
|
+
|
|
8
|
+
interface MonthProps {
|
|
9
|
+
date: Date;
|
|
10
|
+
onPrev: () => void;
|
|
11
|
+
onNext: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Month = ({ date, onPrev, onNext }: MonthProps) => {
|
|
15
|
+
const year = date.getFullYear();
|
|
16
|
+
const month = MONTHS_NAMES[date.getMonth()];
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className={styles.month}>
|
|
20
|
+
<button className={styles.arrow} onClick={onPrev} type="button">
|
|
21
|
+
<Prev />
|
|
22
|
+
</button>
|
|
23
|
+
<p>
|
|
24
|
+
{month} {year}
|
|
25
|
+
</p>
|
|
26
|
+
<button className={styles.arrow} onClick={onNext} type="button">
|
|
27
|
+
<Next />
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.month {
|
|
2
|
+
@include themify-modules($themes) {
|
|
3
|
+
color: themed('text');
|
|
4
|
+
background-color: themed('background');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
align-items: center;
|
|
10
|
+
width: 100%;
|
|
11
|
+
padding-block: 5px;
|
|
12
|
+
gap: 2px;
|
|
13
|
+
font-weight: $font-weight-bold;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.arrow {
|
|
17
|
+
@include themify-modules($themes) {
|
|
18
|
+
color: themed('text');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
width: max-content;
|
|
22
|
+
border: none;
|
|
23
|
+
background-color: transparent;
|
|
24
|
+
|
|
25
|
+
&:hover {
|
|
26
|
+
@include themify-modules($themes) {
|
|
27
|
+
color: themed('middle-blue');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { RangePicker } from './index';
|
|
3
|
+
import { setControlDate } from '../../utils/controlDate';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof RangePicker> = {
|
|
6
|
+
component: RangePicker,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: 'centered',
|
|
9
|
+
},
|
|
10
|
+
argTypes: {
|
|
11
|
+
monthDate: { control: 'date' },
|
|
12
|
+
minDate: { control: 'date' },
|
|
13
|
+
maxDate: { control: 'date' },
|
|
14
|
+
rangeStart: { control: 'date' },
|
|
15
|
+
rangeEnd: { control: 'date' },
|
|
16
|
+
firstDayOfWeek: {
|
|
17
|
+
control: 'select',
|
|
18
|
+
options: [0, 1],
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default meta;
|
|
24
|
+
type Story = StoryObj<typeof RangePicker>;
|
|
25
|
+
|
|
26
|
+
export const Default: Story = {
|
|
27
|
+
args: {
|
|
28
|
+
monthDate: new Date(2026, 7, 1),
|
|
29
|
+
firstDayOfWeek: 1,
|
|
30
|
+
rangeStart: new Date(2026, 7, 10),
|
|
31
|
+
rangeEnd: new Date(2026, 7, 15),
|
|
32
|
+
},
|
|
33
|
+
render: (args) => (
|
|
34
|
+
<RangePicker
|
|
35
|
+
{...args}
|
|
36
|
+
monthDate={new Date(args.monthDate)}
|
|
37
|
+
minDate={setControlDate(args.minDate)}
|
|
38
|
+
maxDate={setControlDate(args.maxDate)}
|
|
39
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
40
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
41
|
+
/>
|
|
42
|
+
),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const WithTasks: Story = {
|
|
46
|
+
args: {
|
|
47
|
+
monthDate: new Date(2026, 7, 25),
|
|
48
|
+
firstDayOfWeek: 1,
|
|
49
|
+
enableTasks: true,
|
|
50
|
+
},
|
|
51
|
+
render: (args) => (
|
|
52
|
+
<RangePicker
|
|
53
|
+
{...args}
|
|
54
|
+
monthDate={new Date(args.monthDate)}
|
|
55
|
+
minDate={setControlDate(args.minDate)}
|
|
56
|
+
maxDate={setControlDate(args.maxDate)}
|
|
57
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
58
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
59
|
+
/>
|
|
60
|
+
),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const HideWeekends: Story = {
|
|
64
|
+
args: {
|
|
65
|
+
monthDate: new Date(2026, 8, 7),
|
|
66
|
+
firstDayOfWeek: 1,
|
|
67
|
+
hideWeekends: true,
|
|
68
|
+
},
|
|
69
|
+
render: (args) => (
|
|
70
|
+
<RangePicker
|
|
71
|
+
{...args}
|
|
72
|
+
monthDate={new Date(args.monthDate)}
|
|
73
|
+
minDate={setControlDate(args.minDate)}
|
|
74
|
+
maxDate={setControlDate(args.maxDate)}
|
|
75
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
76
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
77
|
+
/>
|
|
78
|
+
),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const ShowHolidays: Story = {
|
|
82
|
+
args: {
|
|
83
|
+
monthDate: new Date(2025, 0, 3),
|
|
84
|
+
firstDayOfWeek: 1,
|
|
85
|
+
showHolidays: true,
|
|
86
|
+
},
|
|
87
|
+
render: (args) => (
|
|
88
|
+
<RangePicker
|
|
89
|
+
{...args}
|
|
90
|
+
monthDate={new Date(args.monthDate)}
|
|
91
|
+
minDate={setControlDate(args.minDate)}
|
|
92
|
+
maxDate={setControlDate(args.maxDate)}
|
|
93
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
94
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
95
|
+
/>
|
|
96
|
+
),
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const WeekMode: Story = {
|
|
100
|
+
args: {
|
|
101
|
+
monthDate: new Date(2025, 0, 31),
|
|
102
|
+
firstDayOfWeek: 1,
|
|
103
|
+
showHolidays: true,
|
|
104
|
+
mode: 'week',
|
|
105
|
+
},
|
|
106
|
+
render: (args) => (
|
|
107
|
+
<RangePicker
|
|
108
|
+
{...args}
|
|
109
|
+
monthDate={new Date(args.monthDate)}
|
|
110
|
+
minDate={setControlDate(args.minDate)}
|
|
111
|
+
maxDate={setControlDate(args.maxDate)}
|
|
112
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
113
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
114
|
+
/>
|
|
115
|
+
),
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const WithMinMaxDates: Story = {
|
|
119
|
+
args: {
|
|
120
|
+
monthDate: new Date(2026, 7, 1),
|
|
121
|
+
firstDayOfWeek: 1,
|
|
122
|
+
minDate: new Date(2026, 7, 10),
|
|
123
|
+
maxDate: new Date(2026, 7, 20),
|
|
124
|
+
},
|
|
125
|
+
render: (args) => (
|
|
126
|
+
<RangePicker
|
|
127
|
+
{...args}
|
|
128
|
+
minDate={setControlDate(args.minDate)}
|
|
129
|
+
maxDate={setControlDate(args.maxDate)}
|
|
130
|
+
rangeStart={setControlDate(args.rangeStart)}
|
|
131
|
+
rangeEnd={setControlDate(args.rangeEnd)}
|
|
132
|
+
/>
|
|
133
|
+
),
|
|
134
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ChangeEvent, KeyboardEvent, Ref } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useValidate } from '@/hooks/useValidate';
|
|
4
|
+
|
|
5
|
+
import { BaseCalendar } from '../BaseCalendar';
|
|
6
|
+
import { BaseCalendarProps, CalendarProps } from '../CalendarGrid/types';
|
|
7
|
+
import { Clear } from '../Clear';
|
|
8
|
+
import { Input } from '../Input';
|
|
9
|
+
import styles from './styles.module.scss';
|
|
10
|
+
|
|
11
|
+
export interface RangePickerProps
|
|
12
|
+
extends BaseCalendarProps, Pick<CalendarProps, 'rangeStart' | 'rangeEnd'> {
|
|
13
|
+
onChangeStart?: (date?: Date) => void;
|
|
14
|
+
onChangeEnd?: (date?: Date) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const RangePicker = ({
|
|
18
|
+
rangeStart,
|
|
19
|
+
rangeEnd,
|
|
20
|
+
monthDate = new Date(),
|
|
21
|
+
onChangeStart,
|
|
22
|
+
onChangeEnd,
|
|
23
|
+
...props
|
|
24
|
+
}: RangePickerProps) => {
|
|
25
|
+
const {
|
|
26
|
+
currentDate: startDate,
|
|
27
|
+
value: startValue,
|
|
28
|
+
error: startError,
|
|
29
|
+
ref: startRef,
|
|
30
|
+
handleDateSelect: handleStartDateSelect,
|
|
31
|
+
handleDateValidation: handleStartDateValidation,
|
|
32
|
+
handleClearInput: handleStartClearInput,
|
|
33
|
+
} = useValidate(rangeStart);
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
currentDate: endDate,
|
|
37
|
+
value: endValue,
|
|
38
|
+
error: endError,
|
|
39
|
+
ref: endRef,
|
|
40
|
+
handleDateSelect: handleEndDateSelect,
|
|
41
|
+
handleDateValidation: handleEndDateValidation,
|
|
42
|
+
handleClearInput: handleEndClearInput,
|
|
43
|
+
} = useValidate(rangeEnd);
|
|
44
|
+
|
|
45
|
+
const handleDateSelectAndExternalUpdate = (
|
|
46
|
+
e: React.MouseEvent<HTMLButtonElement>,
|
|
47
|
+
date: Date
|
|
48
|
+
) => {
|
|
49
|
+
if (!startDate) {
|
|
50
|
+
handleStartDateSelect(date);
|
|
51
|
+
onChangeStart?.(date);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!endDate || e.ctrlKey) {
|
|
56
|
+
if (startDate && date < startDate) {
|
|
57
|
+
handleStartDateSelect(date);
|
|
58
|
+
handleEndDateSelect(startDate);
|
|
59
|
+
onChangeStart?.(date);
|
|
60
|
+
onChangeEnd?.(startDate);
|
|
61
|
+
} else {
|
|
62
|
+
handleEndDateSelect(date);
|
|
63
|
+
onChangeEnd?.(date);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
handleStartDateSelect(date);
|
|
69
|
+
handleEndDateSelect();
|
|
70
|
+
onChangeStart?.(date);
|
|
71
|
+
onChangeEnd?.();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleStartChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
75
|
+
const parsed = handleStartDateValidation(e.target.value);
|
|
76
|
+
if (!parsed) return;
|
|
77
|
+
onChangeStart?.(parsed);
|
|
78
|
+
if (endValue) handleEndDateValidation(endValue, parsed);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleStartKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
82
|
+
if (e.key !== 'Enter') return;
|
|
83
|
+
const parsed = handleStartDateValidation(e.currentTarget.value);
|
|
84
|
+
if (!parsed) return;
|
|
85
|
+
onChangeStart?.(parsed);
|
|
86
|
+
if (endValue) handleEndDateValidation(endValue, parsed);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleEndChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
90
|
+
const parsed = handleEndDateValidation(e.target.value, startDate);
|
|
91
|
+
if (parsed) onChangeEnd?.(parsed);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const handleEndKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
95
|
+
if (e.key !== 'Enter') return;
|
|
96
|
+
const parsed = handleEndDateValidation(e.currentTarget.value, startDate);
|
|
97
|
+
if (parsed) onChangeEnd?.(parsed);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const handleClearRange = () => {
|
|
101
|
+
handleStartClearInput();
|
|
102
|
+
handleEndClearInput();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div className={styles.rangePicker}>
|
|
107
|
+
<div className={styles.inputs}>
|
|
108
|
+
<Input
|
|
109
|
+
isDateInput
|
|
110
|
+
label="From"
|
|
111
|
+
value={startValue}
|
|
112
|
+
ref={startRef as Ref<HTMLInputElement>}
|
|
113
|
+
placeholder="dd/mm/yyyy"
|
|
114
|
+
onBlur={handleStartChange}
|
|
115
|
+
onReset={handleStartClearInput}
|
|
116
|
+
onKeyDown={handleStartKeyDown}
|
|
117
|
+
error={startError}
|
|
118
|
+
/>
|
|
119
|
+
<Input
|
|
120
|
+
isDateInput
|
|
121
|
+
label="To"
|
|
122
|
+
value={endValue}
|
|
123
|
+
ref={endRef as Ref<HTMLInputElement>}
|
|
124
|
+
placeholder="dd/mm/yyyy"
|
|
125
|
+
onBlur={handleEndChange}
|
|
126
|
+
onReset={handleEndClearInput}
|
|
127
|
+
onKeyDown={handleEndKeyDown}
|
|
128
|
+
error={endError}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div className={styles.calendar}>
|
|
133
|
+
<BaseCalendar
|
|
134
|
+
monthDate={monthDate}
|
|
135
|
+
rangeStart={startDate}
|
|
136
|
+
rangeEnd={endDate}
|
|
137
|
+
onDateClick={handleDateSelectAndExternalUpdate}
|
|
138
|
+
{...props}
|
|
139
|
+
/>
|
|
140
|
+
<Clear onClick={handleClearRange} />
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.rangePicker {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
padding: $gap-8;
|
|
5
|
+
|
|
6
|
+
@include themify-modules($themes) {
|
|
7
|
+
background-color: themed('background');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.calendar {
|
|
12
|
+
margin-top: 15px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.inputs {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: $gap-8;
|
|
19
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
2
|
+
import { useForm } from 'react-hook-form';
|
|
3
|
+
|
|
4
|
+
import { Input } from '@/components/Input';
|
|
5
|
+
import { ModalProps } from '@/components/Modal';
|
|
6
|
+
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
7
|
+
import { useTasks } from '@/store/tasksStore';
|
|
8
|
+
import { formatDate } from '@/utils/formatDate';
|
|
9
|
+
import { FormData } from '@/utils/schema';
|
|
10
|
+
import { formSchema } from '@/utils/schema';
|
|
11
|
+
|
|
12
|
+
interface AddModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
13
|
+
date: Date;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const AddModal = ({ isOpen, onClose, date }: AddModalProps) => {
|
|
17
|
+
const { addTask } = useTasks();
|
|
18
|
+
const {
|
|
19
|
+
register,
|
|
20
|
+
handleSubmit,
|
|
21
|
+
reset,
|
|
22
|
+
formState: { errors },
|
|
23
|
+
} = useForm<FormData>({
|
|
24
|
+
resolver: zodResolver(formSchema),
|
|
25
|
+
defaultValues: {
|
|
26
|
+
title: '',
|
|
27
|
+
date: formatDate(date),
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const onSubmit = (data: FormData) => {
|
|
32
|
+
addTask(date, data.title);
|
|
33
|
+
reset();
|
|
34
|
+
onClose();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const handleClose = () => {
|
|
38
|
+
reset({
|
|
39
|
+
title: '',
|
|
40
|
+
});
|
|
41
|
+
onClose();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<CrudModal
|
|
46
|
+
isOpen={isOpen}
|
|
47
|
+
onClose={handleClose}
|
|
48
|
+
onConfirm={handleSubmit(onSubmit)}
|
|
49
|
+
showCloseButton={true}
|
|
50
|
+
confirmText="Add"
|
|
51
|
+
cancelText="Cancel"
|
|
52
|
+
title="Add task"
|
|
53
|
+
>
|
|
54
|
+
<Input
|
|
55
|
+
{...register('title')}
|
|
56
|
+
label="Title"
|
|
57
|
+
placeholder="Training name"
|
|
58
|
+
error={errors.title?.message}
|
|
59
|
+
/>
|
|
60
|
+
</CrudModal>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModalProps } from '@/components/Modal';
|
|
2
|
+
import { CrudModal } from '@/components/Modal/CrudModal';
|
|
3
|
+
import { useTasks } from '@/store/tasksStore';
|
|
4
|
+
|
|
5
|
+
interface DeleteModalProps extends Pick<ModalProps, 'isOpen' | 'onClose'> {
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export const DeleteModal = ({ id, isOpen, onClose }: DeleteModalProps) => {
|
|
9
|
+
const { deleteTask } = useTasks();
|
|
10
|
+
const handleDelete = () => {
|
|
11
|
+
deleteTask(id);
|
|
12
|
+
onClose();
|
|
13
|
+
};
|
|
14
|
+
return (
|
|
15
|
+
<CrudModal
|
|
16
|
+
isOpen={isOpen}
|
|
17
|
+
onClose={onClose}
|
|
18
|
+
onConfirm={handleDelete}
|
|
19
|
+
title="Are you sure you want to delete this task?"
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
};
|