@egov3/system-design 1.3.124 → 1.3.126
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/dist/cjs/baseComponents/Modal/Modal.module.css.js +1 -1
- package/dist/cjs/components/Calendar/Body/CalendarBody.module.css.js +2 -2
- package/dist/cjs/components/Calendar/Body/index.js +17 -13
- package/dist/cjs/components/Calendar/Body/index.js.map +1 -1
- package/dist/cjs/components/Calendar/Calendar.module.css.js +22 -0
- package/dist/cjs/components/Calendar/Calendar.module.css.js.map +1 -0
- package/dist/cjs/components/Calendar/Header/CalendarHeader.module.css.js +2 -2
- package/dist/cjs/components/Calendar/Header/index.js +16 -11
- package/dist/cjs/components/Calendar/Header/index.js.map +1 -1
- package/dist/cjs/components/Calendar/index.js +68 -34
- package/dist/cjs/components/Calendar/index.js.map +1 -1
- package/dist/cjs/constants/i18n/Calendar.js +42 -0
- package/dist/cjs/constants/i18n/Calendar.js.map +1 -0
- package/dist/cjs/constants/i18n/index.js +2 -0
- package/dist/cjs/constants/i18n/index.js.map +1 -1
- package/dist/cjs/customHooks/useCalendar.js +47 -32
- package/dist/cjs/customHooks/useCalendar.js.map +1 -1
- package/dist/cjs/utils/calendar.js +64 -0
- package/dist/cjs/utils/calendar.js.map +1 -0
- package/dist/cjs/utils/date/getMonthNameProper.js +27 -2
- package/dist/cjs/utils/date/getMonthNameProper.js.map +1 -1
- package/dist/esm/baseComponents/Modal/Modal.module.css.js +1 -1
- package/dist/esm/components/Calendar/Body/CalendarBody.module.css.js +2 -2
- package/dist/esm/components/Calendar/Body/index.js +16 -12
- package/dist/esm/components/Calendar/Body/index.js.map +1 -1
- package/dist/esm/components/Calendar/Calendar.module.css.js +18 -0
- package/dist/esm/components/Calendar/Calendar.module.css.js.map +1 -0
- package/dist/esm/components/Calendar/Header/CalendarHeader.module.css.js +2 -2
- package/dist/esm/components/Calendar/Header/index.js +15 -10
- package/dist/esm/components/Calendar/Header/index.js.map +1 -1
- package/dist/esm/components/Calendar/index.js +68 -34
- package/dist/esm/components/Calendar/index.js.map +1 -1
- package/dist/esm/constants/i18n/Calendar.js +40 -0
- package/dist/esm/constants/i18n/Calendar.js.map +1 -0
- package/dist/esm/constants/i18n/index.js +2 -0
- package/dist/esm/constants/i18n/index.js.map +1 -1
- package/dist/esm/customHooks/useCalendar.js +46 -31
- package/dist/esm/customHooks/useCalendar.js.map +1 -1
- package/dist/esm/utils/calendar.js +54 -0
- package/dist/esm/utils/calendar.js.map +1 -0
- package/dist/esm/utils/date/getMonthNameProper.js +27 -2
- package/dist/esm/utils/date/getMonthNameProper.js.map +1 -1
- package/dist/types/components/Calendar/Body/index.d.ts +3 -1
- package/dist/types/components/Calendar/index.d.ts +19 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/interfaces/Calendar.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1,74 +1,88 @@
|
|
|
1
|
-
import { useState, useRef,
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
2
|
import { PERIOD_KEYS } from '../constants/calendar/index.js';
|
|
3
|
+
import { clampCalendarVisibleDate, isCalendarMonthAfterDate, getCalendarDateWithoutTime, isSameCalendarDate } from '../utils/calendar.js';
|
|
3
4
|
import { getDaysInMonth } from '../utils/date/getDaysInMonth.js';
|
|
4
5
|
|
|
5
6
|
const TODAY = new Date();
|
|
6
7
|
const YEARS_BACK = 100;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
left.getDate() === right.getDate();
|
|
10
|
-
const buildCalendarDays = (month, year, selectedDate, selectedPeriodInterval, rangeStart, rangeEnd) => {
|
|
8
|
+
const getDateTimestamp = (date) => date ? getCalendarDateWithoutTime(date).getTime() : null;
|
|
9
|
+
const buildCalendarDays = ({ month, year, selectedDate, selectedPeriodInterval, rangeStart, rangeEnd, maxDate, }) => {
|
|
11
10
|
const firstDayIndex = (new Date(year, month, 1).getDay() + 6) % 7;
|
|
12
11
|
const daysInMonth = getDaysInMonth(month, year);
|
|
13
12
|
const trailingDays = (7 - ((firstDayIndex + daysInMonth) % 7)) % 7;
|
|
14
13
|
const cellCount = firstDayIndex + daysInMonth + trailingDays;
|
|
15
14
|
const startDate = new Date(year, month, 1 - firstDayIndex);
|
|
15
|
+
const rangeStartTime = getDateTimestamp(rangeStart);
|
|
16
|
+
const rangeEndTime = getDateTimestamp(rangeEnd);
|
|
17
|
+
const maxDateTime = getDateTimestamp(maxDate);
|
|
18
|
+
const isDateInRange = (dateTime) => rangeStartTime !== null &&
|
|
19
|
+
rangeEndTime !== null &&
|
|
20
|
+
dateTime >= rangeStartTime &&
|
|
21
|
+
dateTime <= rangeEndTime;
|
|
22
|
+
const isDateDisabled = (dateTime) => {
|
|
23
|
+
if (maxDateTime !== null && dateTime > maxDateTime) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (selectedPeriodInterval === PERIOD_KEYS.from) {
|
|
27
|
+
return rangeEndTime !== null && dateTime > rangeEndTime;
|
|
28
|
+
}
|
|
29
|
+
return rangeStartTime !== null && dateTime < rangeStartTime;
|
|
30
|
+
};
|
|
16
31
|
return Array.from({ length: cellCount }, (_, index) => {
|
|
17
32
|
const date = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + index);
|
|
33
|
+
const dateTime = getCalendarDateWithoutTime(date).getTime();
|
|
18
34
|
return {
|
|
19
35
|
date,
|
|
20
36
|
day: date.getDate(),
|
|
21
37
|
isCurrentMonth: date.getMonth() === month,
|
|
22
|
-
isToday:
|
|
23
|
-
isSelected: selectedDate ?
|
|
24
|
-
isInRange:
|
|
25
|
-
|
|
26
|
-
date.getTime() >= rangeStart.getTime() &&
|
|
27
|
-
date.getTime() <= rangeEnd.getTime()),
|
|
28
|
-
isDisabled: Boolean((selectedPeriodInterval === PERIOD_KEYS.from &&
|
|
29
|
-
rangeEnd &&
|
|
30
|
-
date.getTime() > rangeEnd.getTime()) ||
|
|
31
|
-
(selectedPeriodInterval === PERIOD_KEYS.to &&
|
|
32
|
-
rangeStart &&
|
|
33
|
-
date.getTime() < rangeStart.getTime())),
|
|
38
|
+
isToday: isSameCalendarDate(date, TODAY),
|
|
39
|
+
isSelected: selectedDate ? isSameCalendarDate(date, selectedDate) : false,
|
|
40
|
+
isInRange: isDateInRange(dateTime),
|
|
41
|
+
isDisabled: isDateDisabled(dateTime),
|
|
34
42
|
};
|
|
35
43
|
});
|
|
36
44
|
};
|
|
37
|
-
const useCalendar = ({ month, year, selectedDate, selectedPeriodInterval, rangeStart, rangeEnd, onMonthChange, }) => {
|
|
38
|
-
const [visibleDate, setVisibleDate] = useState(() => new Date(year, month, 1));
|
|
45
|
+
const useCalendar = ({ month, year, selectedDate, selectedPeriodInterval, rangeStart, rangeEnd, maxDate, onMonthChange, }) => {
|
|
46
|
+
const [visibleDate, setVisibleDate] = useState(() => clampCalendarVisibleDate(new Date(year, month, 1), maxDate));
|
|
39
47
|
const [isYearPickerOpen, setIsYearPickerOpen] = useState(false);
|
|
40
48
|
const yearListRef = useRef(null);
|
|
41
49
|
const visibleMonth = visibleDate.getMonth();
|
|
42
50
|
const visibleYear = visibleDate.getFullYear();
|
|
43
|
-
const days =
|
|
44
|
-
visibleMonth,
|
|
45
|
-
visibleYear,
|
|
46
|
-
rangeEnd,
|
|
47
|
-
rangeStart,
|
|
51
|
+
const days = buildCalendarDays({
|
|
52
|
+
month: visibleMonth,
|
|
53
|
+
year: visibleYear,
|
|
48
54
|
selectedDate,
|
|
49
55
|
selectedPeriodInterval,
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
rangeStart,
|
|
57
|
+
rangeEnd,
|
|
58
|
+
maxDate,
|
|
59
|
+
});
|
|
60
|
+
const maxYear = maxDate?.getFullYear() ?? TODAY.getFullYear();
|
|
52
61
|
const minYear = maxYear - YEARS_BACK;
|
|
53
62
|
const years = Array.from({ length: maxYear - minYear + 1 }, (_, index) => maxYear - index);
|
|
63
|
+
const isNextMonthDisabled = Boolean(maxDate && isCalendarMonthAfterDate(visibleMonth + 1, visibleYear, maxDate));
|
|
54
64
|
const changeMonth = (offset) => {
|
|
55
65
|
setVisibleDate((current) => {
|
|
56
66
|
const next = new Date(current.getFullYear(), current.getMonth() + offset, 1);
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
const clampedNext = clampCalendarVisibleDate(next, maxDate);
|
|
68
|
+
if (clampedNext.getTime() === current.getTime()) {
|
|
69
|
+
return current;
|
|
70
|
+
}
|
|
71
|
+
onMonthChange?.(clampedNext);
|
|
72
|
+
return clampedNext;
|
|
59
73
|
});
|
|
60
74
|
};
|
|
61
75
|
const pickYear = (pickedYear) => {
|
|
62
76
|
setVisibleDate((current) => {
|
|
63
|
-
const next = new Date(pickedYear, current.getMonth(), 1);
|
|
77
|
+
const next = clampCalendarVisibleDate(new Date(pickedYear, current.getMonth(), 1), maxDate);
|
|
64
78
|
onMonthChange?.(next);
|
|
65
79
|
return next;
|
|
66
80
|
});
|
|
67
81
|
setIsYearPickerOpen(false);
|
|
68
82
|
};
|
|
69
83
|
useEffect(() => {
|
|
70
|
-
setVisibleDate(new Date(year, month, 1));
|
|
71
|
-
}, [month, year]);
|
|
84
|
+
setVisibleDate(clampCalendarVisibleDate(new Date(year, month, 1), maxDate));
|
|
85
|
+
}, [month, maxDate, year]);
|
|
72
86
|
useEffect(() => {
|
|
73
87
|
if (!isYearPickerOpen || !yearListRef.current) {
|
|
74
88
|
return;
|
|
@@ -82,6 +96,7 @@ const useCalendar = ({ month, year, selectedDate, selectedPeriodInterval, rangeS
|
|
|
82
96
|
visibleMonth,
|
|
83
97
|
visibleYear,
|
|
84
98
|
isYearPickerOpen,
|
|
99
|
+
isNextMonthDisabled,
|
|
85
100
|
setIsYearPickerOpen,
|
|
86
101
|
yearListRef,
|
|
87
102
|
changeMonth,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCalendar.js","sources":["../../../src/customHooks/useCalendar.tsx"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCalendar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;QACX,WAAW;QACX,QAAQ;KACT;AACH;;;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { convertType } from './date/convertType.js';
|
|
2
|
+
|
|
3
|
+
const formatCalendarDate = (date) => {
|
|
4
|
+
if (!date) {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
|
7
|
+
return `${convertType.day.toString(date.getDate())}.${convertType.month.toString(date.getMonth())}.${date.getFullYear()}`;
|
|
8
|
+
};
|
|
9
|
+
const normalizeCalendarDate = (value) => {
|
|
10
|
+
if (!value) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const normalizedDate = value instanceof Date ? value : new Date(value);
|
|
14
|
+
return Number.isNaN(normalizedDate.getTime()) ? null : normalizedDate;
|
|
15
|
+
};
|
|
16
|
+
const getCalendarDateWithoutTime = (date) => new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
17
|
+
const isSameCalendarDate = (left, right) => left.getFullYear() === right.getFullYear() &&
|
|
18
|
+
left.getMonth() === right.getMonth() &&
|
|
19
|
+
left.getDate() === right.getDate();
|
|
20
|
+
const isCalendarDateAfter = (date, maxDate) => {
|
|
21
|
+
if (!date || !maxDate) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return (getCalendarDateWithoutTime(date).getTime() >
|
|
25
|
+
getCalendarDateWithoutTime(maxDate).getTime());
|
|
26
|
+
};
|
|
27
|
+
const getPeriodDateKey = (periodKey) => `${periodKey}Date`;
|
|
28
|
+
const updateSelectedPeriod = (currentPeriod, selectedPeriodInterval, nextDate) => {
|
|
29
|
+
const periodDateKey = getPeriodDateKey(selectedPeriodInterval);
|
|
30
|
+
const currentDate = currentPeriod[periodDateKey];
|
|
31
|
+
const isSameDate = currentDate
|
|
32
|
+
? isSameCalendarDate(currentDate, nextDate)
|
|
33
|
+
: false;
|
|
34
|
+
const nextPeriod = {
|
|
35
|
+
...currentPeriod,
|
|
36
|
+
[periodDateKey]: isSameDate ? null : nextDate,
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
...nextPeriod,
|
|
40
|
+
periodSelected: Boolean(nextPeriod.fromDate && nextPeriod.toDate),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const isCalendarMonthAfterDate = (month, year, date) => year > date.getFullYear() ||
|
|
44
|
+
(year === date.getFullYear() && month > date.getMonth());
|
|
45
|
+
const clampCalendarVisibleDate = (date, maxDate) => {
|
|
46
|
+
if (!maxDate ||
|
|
47
|
+
!isCalendarMonthAfterDate(date.getMonth(), date.getFullYear(), maxDate)) {
|
|
48
|
+
return date;
|
|
49
|
+
}
|
|
50
|
+
return new Date(maxDate.getFullYear(), maxDate.getMonth(), 1);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { clampCalendarVisibleDate, formatCalendarDate, getCalendarDateWithoutTime, getPeriodDateKey, isCalendarDateAfter, isCalendarMonthAfterDate, isSameCalendarDate, normalizeCalendarDate, updateSelectedPeriod };
|
|
54
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","sources":["../../../src/utils/calendar.tsx"],"sourcesContent":[null],"names":[],"mappings":";;AAGO,MAAM,kBAAkB,GAAG,CAAC,IAAkB,KAAI;IACvD,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,OAAO,EAAE;AACV,IAAA;AACD,IAAA,OAAO,CAAA,EAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA,CAAA,EAAI,IAAI,CAAC,WAAW,EAAE,EAAE;AAC3H;AAEO,MAAM,qBAAqB,GAAG,CACnC,KAAqC,KACnC;IACF,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,IAAI;AACZ,IAAA;AACD,IAAA,MAAM,cAAc,GAAG,KAAK,YAAY,IAAI,G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IAAI,GAAG,QAAQ;KAC9C;IAED,OAAO;AACL,QAAA,GAAG,UAAU;QACb,cAAc,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,MAAM,CAAC;KAClE;AACH;AAEO,MAAM,wBAAwB,GAAG,CACtC,KAAa,EACb,IAAY,EACZ,IAAU,KAEV,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;AACzB,KAAC,IAAI,KAAK,IAAI,CAAC,WAAW,EAAE,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE;MAE5C,wBAAwB,GAAG,CAAC,IAAU,EAAE,OAAqB,KAAI;AAC5E,IAAA,IACE,CAAC,OAAO;AACR,QAAA,CAAC,wBAAwB,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,EACvE;AACA,QAAA,OAAO,IAAI;AACZ,IAAA;AACD,IAAA,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC/D;;;;"}
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { currentYear } from './index.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const localeByLang = {
|
|
4
|
+
ru: "ru-RU",
|
|
5
|
+
kk: "kk-KZ",
|
|
6
|
+
en: "en-US",
|
|
7
|
+
};
|
|
8
|
+
const monthNamesByLang = {
|
|
9
|
+
kk: [
|
|
10
|
+
"Қаңтар",
|
|
11
|
+
"Ақпан",
|
|
12
|
+
"Наурыз",
|
|
13
|
+
"Сәуір",
|
|
14
|
+
"Мамыр",
|
|
15
|
+
"Маусым",
|
|
16
|
+
"Шілде",
|
|
17
|
+
"Тамыз",
|
|
18
|
+
"Қыркүйек",
|
|
19
|
+
"Қазан",
|
|
20
|
+
"Қараша",
|
|
21
|
+
"Желтоқсан",
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
const getMonthNameProper = (month, lang) => {
|
|
25
|
+
const translatedMonthName = monthNamesByLang[lang]?.[month];
|
|
26
|
+
if (translatedMonthName) {
|
|
27
|
+
return translatedMonthName;
|
|
28
|
+
}
|
|
29
|
+
const monthName = new Date(currentYear, month).toLocaleString(localeByLang[lang], {
|
|
5
30
|
month: "long",
|
|
6
31
|
});
|
|
7
32
|
return monthName.charAt(0).toUpperCase() + monthName.slice(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMonthNameProper.js","sources":["../../../../src/utils/date/getMonthNameProper.tsx"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"getMonthNameProper.js","sources":["../../../../src/utils/date/getMonthNameProper.tsx"],"sourcesContent":[null],"names":[],"mappings":";;AAGA,MAAM,YAAY,GAAuC;AACvD,IAAA,EAAE,EAAE,OAAO;AACX,IAAA,EAAE,EAAE,OAAO;AACX,IAAA,EAAE,EAAE,OAAO;CACZ;AAED,MAAM,gBAAgB,GAAkD;AACtE,IAAA,EAAE,EAAE;QACF,QAAQ;QACR,OAAO;QACP,QAAQ;QACR,OAAO;QACP,OAAO;QACP,QAAQ;QACR,OAAO;QACP,OAAO;QACP,UAAU;QACV,OAAO;QACP,QAAQ;QACR,WAAW;AACZ,KAAA;CACF;MAEY,kBAAkB,GAAG,CAChC,KAAa,EACb,IAAwB,KACd;IACV,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;AAE3D,IAAA,IAAI,mBAAmB,EAAE;AACvB,QAAA,OAAO,mBAAmB;AAC3B,IAAA;AAED,IAAA,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,cAAc,CAC3D,YAAY,CAAC,IAAI,CAAC,EAClB;AACE,QAAA,KAAK,EAAE,MAAM;AACd,KAAA,CACF;AACD,IAAA,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/D;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { TPeriodKeys } from '../../../interfaces/Calendar.js';
|
|
2
|
+
import { ILangProps } from '../../../interfaces/common/index.js';
|
|
2
3
|
|
|
3
|
-
interface ICalendarBodyProps {
|
|
4
|
+
interface ICalendarBodyProps extends ILangProps {
|
|
4
5
|
month?: number;
|
|
5
6
|
year?: number;
|
|
6
7
|
selectedDate?: Date | null;
|
|
7
8
|
rangeStart?: Date | null;
|
|
8
9
|
rangeEnd?: Date | null;
|
|
10
|
+
maxDate?: Date | null;
|
|
9
11
|
selectedPeriodInterval?: TPeriodKeys;
|
|
10
12
|
onDayClick?: (date: Date) => void;
|
|
11
13
|
onMonthChange?: (date: Date) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { TCalendarMode, ISelectedPeriod, TPeriodKeys } from '../../interfaces/Calendar.js';
|
|
3
|
+
import { ILangProps } from '../../interfaces/common/index.js';
|
|
4
|
+
|
|
5
|
+
interface ICalendarProps extends ILangProps {
|
|
6
|
+
mode?: TCalendarMode;
|
|
7
|
+
isOpen?: boolean;
|
|
8
|
+
setIsOpen?: Dispatch<SetStateAction<boolean>>;
|
|
9
|
+
title?: string;
|
|
10
|
+
maxDate?: Date | null;
|
|
11
|
+
selectedDate?: Date | null;
|
|
12
|
+
selectedPeriod?: ISelectedPeriod;
|
|
13
|
+
defaultPeriodInterval?: TPeriodKeys;
|
|
14
|
+
onDateChange?: (date: Date | null) => void;
|
|
15
|
+
onPeriodChange?: (period: ISelectedPeriod) => void;
|
|
16
|
+
onSave?: (value: Date | null | ISelectedPeriod) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type { ICalendarProps };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ICalendarBodyProps } from './components/Calendar/Body/index.js';
|
|
2
|
+
import { ICalendarProps } from './components/Calendar/index.js';
|
|
2
3
|
import { INotificationWrapperProps } from './components/Notification/Wrapper/index.js';
|
|
3
4
|
import { INotificationComponentProps } from './components/Notification/Item/index.js';
|
|
4
5
|
import { IServiceCardComponentProps } from './components/ServiceCardComponent/index.js';
|
|
@@ -100,8 +101,8 @@ declare const SystemDesign: {
|
|
|
100
101
|
ServiceCardComponent: ({ handleOrderService, badge, isNew, title, }: IServiceCardComponentProps) => react_jsx_runtime.JSX.Element;
|
|
101
102
|
NotificationItem: ({ type, text, onClick, }: INotificationComponentProps) => react_jsx_runtime.JSX.Element;
|
|
102
103
|
NotificationWrapper: ({ items, removeNotificationData, }: INotificationWrapperProps) => react_jsx_runtime.JSX.Element | null;
|
|
103
|
-
Calendar: () => react_jsx_runtime.JSX.Element;
|
|
104
|
-
CalendarBody: ({ month, year, selectedDate, rangeStart, rangeEnd, selectedPeriodInterval, onDayClick, onMonthChange, }: ICalendarBodyProps) => react_jsx_runtime.JSX.Element;
|
|
104
|
+
Calendar: ({ mode, isOpen, setIsOpen, lang, title, maxDate, selectedDate, selectedPeriod, defaultPeriodInterval, onDateChange, onPeriodChange, onSave, }: ICalendarProps) => react_jsx_runtime.JSX.Element;
|
|
105
|
+
CalendarBody: ({ lang, month, year, selectedDate, rangeStart, rangeEnd, maxDate, selectedPeriodInterval, onDayClick, onMonthChange, }: ICalendarBodyProps) => react_jsx_runtime.JSX.Element;
|
|
105
106
|
};
|
|
106
107
|
};
|
|
107
108
|
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
interface ISelectedPeriod {
|
|
2
|
+
fromDate?: Date | null;
|
|
3
|
+
toDate?: Date | null;
|
|
4
|
+
periodSelected: boolean;
|
|
5
|
+
}
|
|
6
|
+
type TCalendarMode = "default" | "period";
|
|
1
7
|
interface IPeriodKeys {
|
|
2
8
|
from: "from";
|
|
3
9
|
to: "to";
|
|
4
10
|
}
|
|
5
11
|
type TPeriodKeys = keyof IPeriodKeys;
|
|
6
12
|
|
|
7
|
-
export type { IPeriodKeys, TPeriodKeys };
|
|
13
|
+
export type { IPeriodKeys, ISelectedPeriod, TCalendarMode, TPeriodKeys };
|