@salutejs/plasma-new-hope 0.322.0-canary.1933.14614537450.0 → 0.322.0-canary.1939.14616445713.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/cjs/components/Calendar/Calendar.types.js.map +1 -1
- package/cjs/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/cjs/components/Calendar/CalendarBase/CalendarBase.js.map +1 -1
- package/cjs/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/cjs/components/Calendar/CalendarDouble/CalendarDouble.js.map +1 -1
- package/cjs/components/Calendar/hoc/withRange.js.map +1 -1
- package/cjs/components/Calendar/store/reducer.js.map +1 -1
- package/cjs/components/Calendar/utils/calendarGridHelper.js.map +1 -1
- package/cjs/components/Calendar/utils/calendarRangeHelper.js.map +1 -1
- package/cjs/components/DatePicker/DatePicker.tokens.js +2 -1
- package/cjs/components/DatePicker/DatePicker.tokens.js.map +1 -1
- package/cjs/components/DatePicker/DatePickerBase.styles.js +1 -1
- package/cjs/components/DatePicker/DatePickerBase.styles.js.map +1 -1
- package/cjs/components/DatePicker/DatePickerBase.styles_1a5ddg3.css +2 -0
- package/cjs/components/DatePicker/RangeDate/RangeDate.css +4 -4
- package/cjs/components/DatePicker/RangeDate/RangeDate.js +160 -84
- package/cjs/components/DatePicker/RangeDate/RangeDate.js.map +1 -1
- package/cjs/components/DatePicker/RangeDate/RangeDate.styles.js.map +1 -1
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.css +2 -2
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.js.map +1 -1
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +1 -1
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js.map +1 -1
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles_1fhuiqs.css +2 -0
- package/cjs/components/DatePicker/SingleDate/SingleDate.css +2 -2
- package/cjs/components/DatePicker/SingleDate/SingleDate.js +66 -33
- package/cjs/components/DatePicker/SingleDate/SingleDate.js.map +1 -1
- package/cjs/components/DatePicker/SingleDate/SingleDate.styles.js.map +1 -1
- package/cjs/components/DatePicker/hooks/useDatePicker.js +133 -76
- package/cjs/components/DatePicker/hooks/useDatePicker.js.map +1 -1
- package/cjs/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/cjs/components/DatePicker/hooks/useKeyboardNavigation.js.map +1 -1
- package/cjs/components/DatePicker/utils/dateHelper.js +0 -109
- package/cjs/components/DatePicker/utils/dateHelper.js.map +1 -1
- package/cjs/components/DatePicker/utils/getFormattedDates.js +45 -0
- package/cjs/components/DatePicker/utils/getFormattedDates.js.map +1 -0
- package/cjs/components/DatePicker/utils/getMaskedDateOnInput.js +27 -0
- package/cjs/components/DatePicker/utils/getMaskedDateOnInput.js.map +1 -0
- package/cjs/components/DatePicker/utils/getOriginalDates.js +49 -0
- package/cjs/components/DatePicker/utils/getOriginalDates.js.map +1 -0
- package/cjs/components/DatePicker/utils/normalizeDates.js +33 -0
- package/cjs/components/DatePicker/utils/normalizeDates.js.map +1 -0
- package/cjs/index.css +4 -4
- package/emotion/cjs/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/emotion/cjs/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/emotion/cjs/components/DatePicker/DatePicker.tokens.js +2 -1
- package/emotion/cjs/components/DatePicker/DatePickerBase.styles.js +4 -4
- package/emotion/cjs/components/DatePicker/RangeDate/RangeDate.js +160 -84
- package/emotion/cjs/components/DatePicker/RangeDate/RangeDate.styles.js +4 -4
- package/emotion/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +3 -3
- package/emotion/cjs/components/DatePicker/SingleDate/SingleDate.js +66 -33
- package/emotion/cjs/components/DatePicker/SingleDate/SingleDate.styles.js +4 -4
- package/emotion/cjs/components/DatePicker/hooks/useDatePicker.js +132 -76
- package/emotion/cjs/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/emotion/cjs/components/DatePicker/utils/dateHelper.js +1 -104
- package/emotion/cjs/components/DatePicker/utils/getFormattedDates.js +43 -0
- package/emotion/cjs/components/DatePicker/utils/getMaskedDateOnInput.js +26 -0
- package/emotion/cjs/components/DatePicker/utils/getOriginalDates.js +47 -0
- package/emotion/cjs/components/DatePicker/utils/index.js +33 -0
- package/emotion/cjs/components/DatePicker/utils/normalizeDates.js +31 -0
- package/emotion/cjs/examples/plasma_b2c/components/DatePicker/DatePicker.config.js +7 -7
- package/emotion/cjs/examples/plasma_b2c/components/DatePicker/DatePicker.stories.tsx +20 -19
- package/emotion/cjs/examples/plasma_web/components/DatePicker/DatePicker.config.js +7 -7
- package/emotion/cjs/examples/plasma_web/components/DatePicker/DatePicker.stories.tsx +17 -12
- package/emotion/es/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/emotion/es/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/emotion/es/components/DatePicker/DatePicker.tokens.js +2 -1
- package/emotion/es/components/DatePicker/DatePickerBase.styles.js +4 -4
- package/emotion/es/components/DatePicker/RangeDate/RangeDate.js +161 -85
- package/emotion/es/components/DatePicker/RangeDate/RangeDate.styles.js +4 -4
- package/emotion/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +3 -3
- package/emotion/es/components/DatePicker/SingleDate/SingleDate.js +67 -34
- package/emotion/es/components/DatePicker/SingleDate/SingleDate.styles.js +4 -4
- package/emotion/es/components/DatePicker/hooks/useDatePicker.js +131 -75
- package/emotion/es/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/emotion/es/components/DatePicker/utils/dateHelper.js +0 -103
- package/emotion/es/components/DatePicker/utils/getFormattedDates.js +37 -0
- package/emotion/es/components/DatePicker/utils/getMaskedDateOnInput.js +20 -0
- package/emotion/es/components/DatePicker/utils/getOriginalDates.js +41 -0
- package/emotion/es/components/DatePicker/utils/index.js +4 -0
- package/emotion/es/components/DatePicker/utils/normalizeDates.js +25 -0
- package/emotion/es/examples/plasma_b2c/components/DatePicker/DatePicker.config.js +7 -7
- package/emotion/es/examples/plasma_b2c/components/DatePicker/DatePicker.stories.tsx +20 -19
- package/emotion/es/examples/plasma_web/components/DatePicker/DatePicker.config.js +7 -7
- package/emotion/es/examples/plasma_web/components/DatePicker/DatePicker.stories.tsx +17 -12
- package/es/components/Calendar/Calendar.types.js.map +1 -1
- package/es/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/es/components/Calendar/CalendarBase/CalendarBase.js.map +1 -1
- package/es/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/es/components/Calendar/CalendarDouble/CalendarDouble.js.map +1 -1
- package/es/components/Calendar/hoc/withRange.js.map +1 -1
- package/es/components/Calendar/store/reducer.js.map +1 -1
- package/es/components/Calendar/utils/calendarGridHelper.js.map +1 -1
- package/es/components/Calendar/utils/calendarRangeHelper.js.map +1 -1
- package/es/components/DatePicker/DatePicker.tokens.js +2 -1
- package/es/components/DatePicker/DatePicker.tokens.js.map +1 -1
- package/es/components/DatePicker/DatePickerBase.styles.js +1 -1
- package/es/components/DatePicker/DatePickerBase.styles.js.map +1 -1
- package/es/components/DatePicker/DatePickerBase.styles_1a5ddg3.css +2 -0
- package/es/components/DatePicker/RangeDate/RangeDate.css +4 -4
- package/es/components/DatePicker/RangeDate/RangeDate.js +162 -86
- package/es/components/DatePicker/RangeDate/RangeDate.js.map +1 -1
- package/es/components/DatePicker/RangeDate/RangeDate.styles.js.map +1 -1
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.css +2 -2
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.js.map +1 -1
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +1 -1
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js.map +1 -1
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles_1fhuiqs.css +2 -0
- package/es/components/DatePicker/SingleDate/SingleDate.css +2 -2
- package/es/components/DatePicker/SingleDate/SingleDate.js +68 -35
- package/es/components/DatePicker/SingleDate/SingleDate.js.map +1 -1
- package/es/components/DatePicker/SingleDate/SingleDate.styles.js.map +1 -1
- package/es/components/DatePicker/hooks/useDatePicker.js +132 -75
- package/es/components/DatePicker/hooks/useDatePicker.js.map +1 -1
- package/es/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/es/components/DatePicker/hooks/useKeyboardNavigation.js.map +1 -1
- package/es/components/DatePicker/utils/dateHelper.js +1 -105
- package/es/components/DatePicker/utils/dateHelper.js.map +1 -1
- package/es/components/DatePicker/utils/getFormattedDates.js +41 -0
- package/es/components/DatePicker/utils/getFormattedDates.js.map +1 -0
- package/es/components/DatePicker/utils/getMaskedDateOnInput.js +23 -0
- package/es/components/DatePicker/utils/getMaskedDateOnInput.js.map +1 -0
- package/es/components/DatePicker/utils/getOriginalDates.js +45 -0
- package/es/components/DatePicker/utils/getOriginalDates.js.map +1 -0
- package/es/components/DatePicker/utils/normalizeDates.js +29 -0
- package/es/components/DatePicker/utils/normalizeDates.js.map +1 -0
- package/es/index.css +4 -4
- package/package.json +4 -4
- package/styled-components/cjs/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/styled-components/cjs/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/styled-components/cjs/components/DatePicker/DatePicker.tokens.js +2 -1
- package/styled-components/cjs/components/DatePicker/DatePickerBase.styles.js +2 -2
- package/styled-components/cjs/components/DatePicker/RangeDate/RangeDate.js +160 -84
- package/styled-components/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +1 -1
- package/styled-components/cjs/components/DatePicker/SingleDate/SingleDate.js +66 -33
- package/styled-components/cjs/components/DatePicker/hooks/useDatePicker.js +132 -76
- package/styled-components/cjs/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/styled-components/cjs/components/DatePicker/utils/dateHelper.js +1 -104
- package/styled-components/cjs/components/DatePicker/utils/getFormattedDates.js +43 -0
- package/styled-components/cjs/components/DatePicker/utils/getMaskedDateOnInput.js +26 -0
- package/styled-components/cjs/components/DatePicker/utils/getOriginalDates.js +47 -0
- package/styled-components/cjs/components/DatePicker/utils/index.js +33 -0
- package/styled-components/cjs/components/DatePicker/utils/normalizeDates.js +31 -0
- package/styled-components/cjs/examples/plasma_b2c/components/DatePicker/DatePicker.config.js +1 -1
- package/styled-components/cjs/examples/plasma_b2c/components/DatePicker/DatePicker.stories.tsx +20 -19
- package/styled-components/cjs/examples/plasma_web/components/DatePicker/DatePicker.config.js +1 -1
- package/styled-components/cjs/examples/plasma_web/components/DatePicker/DatePicker.stories.tsx +17 -12
- package/styled-components/es/components/Calendar/CalendarBase/CalendarBase.js +3 -6
- package/styled-components/es/components/Calendar/CalendarDouble/CalendarDouble.js +3 -6
- package/styled-components/es/components/DatePicker/DatePicker.tokens.js +2 -1
- package/styled-components/es/components/DatePicker/DatePickerBase.styles.js +2 -2
- package/styled-components/es/components/DatePicker/RangeDate/RangeDate.js +161 -85
- package/styled-components/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.js +1 -1
- package/styled-components/es/components/DatePicker/SingleDate/SingleDate.js +67 -34
- package/styled-components/es/components/DatePicker/hooks/useDatePicker.js +131 -75
- package/styled-components/es/components/DatePicker/hooks/useKeyboardNavigation.js +7 -0
- package/styled-components/es/components/DatePicker/utils/dateHelper.js +0 -103
- package/styled-components/es/components/DatePicker/utils/getFormattedDates.js +37 -0
- package/styled-components/es/components/DatePicker/utils/getMaskedDateOnInput.js +20 -0
- package/styled-components/es/components/DatePicker/utils/getOriginalDates.js +41 -0
- package/styled-components/es/components/DatePicker/utils/index.js +4 -0
- package/styled-components/es/components/DatePicker/utils/normalizeDates.js +25 -0
- package/styled-components/es/examples/plasma_b2c/components/DatePicker/DatePicker.config.js +1 -1
- package/styled-components/es/examples/plasma_b2c/components/DatePicker/DatePicker.stories.tsx +20 -19
- package/styled-components/es/examples/plasma_web/components/DatePicker/DatePicker.config.js +1 -1
- package/styled-components/es/examples/plasma_web/components/DatePicker/DatePicker.stories.tsx +17 -12
- package/types/components/Calendar/Calendar.types.d.ts +4 -3
- package/types/components/Calendar/Calendar.types.d.ts.map +1 -1
- package/types/components/Calendar/CalendarBase/CalendarBase.d.ts.map +1 -1
- package/types/components/Calendar/CalendarDouble/CalendarDouble.d.ts.map +1 -1
- package/types/components/Calendar/hoc/withRange.d.ts.map +1 -1
- package/types/components/Calendar/store/reducer.d.ts +2 -1
- package/types/components/Calendar/store/reducer.d.ts.map +1 -1
- package/types/components/Calendar/utils/calendarGridHelper.d.ts +4 -4
- package/types/components/Calendar/utils/calendarGridHelper.d.ts.map +1 -1
- package/types/components/Calendar/utils/calendarRangeHelper.d.ts +4 -4
- package/types/components/Calendar/utils/calendarRangeHelper.d.ts.map +1 -1
- package/types/components/DatePicker/DatePicker.tokens.d.ts +1 -0
- package/types/components/DatePicker/DatePicker.tokens.d.ts.map +1 -1
- package/types/components/DatePicker/DatePickerBase.styles.d.ts.map +1 -1
- package/types/components/DatePicker/DatePickerBase.types.d.ts +16 -6
- package/types/components/DatePicker/DatePickerBase.types.d.ts.map +1 -1
- package/types/components/DatePicker/RangeDate/RangeDate.d.ts +3 -2
- package/types/components/DatePicker/RangeDate/RangeDate.d.ts.map +1 -1
- package/types/components/DatePicker/RangeDate/RangeDate.types.d.ts +2 -2
- package/types/components/DatePicker/RangeDate/RangeDate.types.d.ts.map +1 -1
- package/types/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.d.ts +1 -1
- package/types/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles.d.ts.map +1 -1
- package/types/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.types.d.ts +3 -3
- package/types/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.types.d.ts.map +1 -1
- package/types/components/DatePicker/SingleDate/SingleDate.d.ts +10 -6
- package/types/components/DatePicker/SingleDate/SingleDate.d.ts.map +1 -1
- package/types/components/DatePicker/SingleDate/SingleDate.types.d.ts +8 -6
- package/types/components/DatePicker/SingleDate/SingleDate.types.d.ts.map +1 -1
- package/types/components/DatePicker/hooks/useDatePicker.d.ts +5 -4
- package/types/components/DatePicker/hooks/useDatePicker.d.ts.map +1 -1
- package/types/components/DatePicker/hooks/useKeyboardNavigation.d.ts +4 -1
- package/types/components/DatePicker/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/types/components/DatePicker/utils/dateHelper.d.ts +0 -27
- package/types/components/DatePicker/utils/dateHelper.d.ts.map +1 -1
- package/types/components/DatePicker/utils/getFormattedDates.d.ts +21 -0
- package/types/components/DatePicker/utils/getFormattedDates.d.ts.map +1 -0
- package/types/components/DatePicker/utils/getMaskedDateOnInput.d.ts +2 -0
- package/types/components/DatePicker/utils/getMaskedDateOnInput.d.ts.map +1 -0
- package/types/components/DatePicker/utils/getOriginalDates.d.ts +10 -0
- package/types/components/DatePicker/utils/getOriginalDates.d.ts.map +1 -0
- package/types/components/DatePicker/utils/index.d.ts +5 -0
- package/types/components/DatePicker/utils/index.d.ts.map +1 -0
- package/types/components/DatePicker/utils/normalizeDates.d.ts +15 -0
- package/types/components/DatePicker/utils/normalizeDates.d.ts.map +1 -0
- package/cjs/components/DatePicker/DatePickerBase.styles_1jm7rc0.css +0 -2
- package/cjs/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles_r5ataz.css +0 -2
- package/es/components/DatePicker/DatePickerBase.styles_1jm7rc0.css +0 -2
- package/es/components/DatePicker/RangeDate/RangeDatePopover/RangeDatePopover.styles_r5ataz.css +0 -2
@@ -1,147 +1,203 @@
|
|
1
|
+
import { customDayjs } from "../../../utils/datejs";
|
2
|
+
import { QUARTER_NAMES } from "../../Calendar/utils";
|
1
3
|
import { classes } from "../DatePicker.tokens";
|
2
|
-
import {
|
4
|
+
import { getFormattedDates, getMaskedDateOnInput } from "../utils";
|
3
5
|
export var useDatePicker = function useDatePicker(_ref) {
|
4
6
|
var currentValue = _ref.currentValue,
|
5
|
-
setInputValue = _ref.setInputValue,
|
6
|
-
setCalendarValue = _ref.setCalendarValue,
|
7
|
-
dateFormatDelimiter = _ref.dateFormatDelimiter,
|
8
7
|
format = _ref.format,
|
9
8
|
_ref$lang = _ref.lang,
|
10
9
|
lang = _ref$lang === void 0 ? 'ru' : _ref$lang,
|
11
10
|
disabled = _ref.disabled,
|
12
11
|
readOnly = _ref.readOnly,
|
13
|
-
maskWithFormat = _ref.maskWithFormat,
|
14
12
|
valueError = _ref.valueError,
|
15
13
|
valueSuccess = _ref.valueSuccess,
|
16
14
|
name = _ref.name,
|
15
|
+
type = _ref.type,
|
16
|
+
min = _ref.min,
|
17
|
+
max = _ref.max,
|
18
|
+
includeEdgeDates = _ref.includeEdgeDates,
|
19
|
+
maskWithFormat = _ref.maskWithFormat,
|
20
|
+
setCorrectDates = _ref.setCorrectDates,
|
21
|
+
setInputValue = _ref.setInputValue,
|
22
|
+
setCalendarValue = _ref.setCalendarValue,
|
23
|
+
dateFormatDelimiter = _ref.dateFormatDelimiter,
|
17
24
|
onChangeValue = _ref.onChangeValue,
|
18
25
|
onCommitDate = _ref.onCommitDate,
|
19
26
|
onChange = _ref.onChange;
|
20
27
|
var datePickerErrorClass = valueError ? classes.datePickerError : undefined;
|
21
28
|
var datePickerSuccessClass = valueSuccess ? classes.datePickerSuccess : undefined;
|
29
|
+
var getQuarterInfo = function getQuarterInfo(originalDate) {
|
30
|
+
if (type !== 'Quarters') {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
var endQuarter = new Date(originalDate);
|
34
|
+
endQuarter.setMonth(originalDate.getMonth() + 3);
|
35
|
+
endQuarter.setDate(0);
|
36
|
+
customDayjs.locale(lang);
|
37
|
+
var quarterIndex = customDayjs(originalDate).quarter() - 1;
|
38
|
+
return {
|
39
|
+
name: QUARTER_NAMES[quarterIndex],
|
40
|
+
fullValue: [originalDate, endQuarter]
|
41
|
+
};
|
42
|
+
};
|
22
43
|
var handleChangeValue = function handleChangeValue(event) {
|
23
44
|
if (disabled || readOnly) {
|
24
45
|
return;
|
25
46
|
}
|
26
47
|
var value = event.target.value;
|
27
48
|
var newValue = maskWithFormat ? getMaskedDateOnInput(value, format, dateFormatDelimiter(), currentValue) : value;
|
28
|
-
|
29
|
-
setCalendarValue(formatCalendarValue(newValue));
|
30
|
-
setInputValue(formatInputValue({
|
49
|
+
var _getFormattedDates = getFormattedDates({
|
31
50
|
value: newValue,
|
51
|
+
lang: lang,
|
52
|
+
delimiter: dateFormatDelimiter(),
|
32
53
|
format: format,
|
33
|
-
|
34
|
-
|
35
|
-
|
54
|
+
includeEdgeDates: includeEdgeDates,
|
55
|
+
min: min,
|
56
|
+
max: max
|
57
|
+
}),
|
58
|
+
formattedDate = _getFormattedDates.formattedDate,
|
59
|
+
isoDate = _getFormattedDates.isoDate,
|
60
|
+
originalDate = _getFormattedDates.originalDate;
|
61
|
+
if (originalDate) {
|
62
|
+
setCorrectDates({
|
63
|
+
calendar: originalDate,
|
64
|
+
input: formattedDate
|
65
|
+
});
|
66
|
+
var dateInfo = getQuarterInfo(originalDate);
|
67
|
+
onCommitDate === null || onCommitDate === void 0 || onCommitDate(formattedDate, false, true, dateInfo, originalDate, isoDate);
|
68
|
+
setCalendarValue(originalDate);
|
69
|
+
setInputValue(formattedDate);
|
70
|
+
onChangeValue === null || onChangeValue === void 0 || onChangeValue(event, formattedDate, originalDate, isoDate);
|
36
71
|
onChange === null || onChange === void 0 || onChange({
|
37
72
|
target: {
|
38
|
-
value:
|
73
|
+
value: formattedDate,
|
74
|
+
originalDate: originalDate,
|
75
|
+
isoDate: isoDate,
|
39
76
|
name: name
|
40
77
|
}
|
41
78
|
});
|
42
79
|
return;
|
43
80
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
})
|
49
|
-
hasMonthFullName = _validateDateWithFull.hasMonthFullName,
|
50
|
-
isValidMonth = _validateDateWithFull.isValidMonth,
|
51
|
-
isLengthEqual = _validateDateWithFull.isLengthEqual;
|
52
|
-
if (!hasMonthFullName && (newValue === null || newValue === void 0 ? void 0 : newValue.length) === (format === null || format === void 0 ? void 0 : format.length) || isValidMonth && isLengthEqual) {
|
53
|
-
setCalendarValue(formatCalendarValue(newValue, format, lang));
|
81
|
+
if (formattedDate === '') {
|
82
|
+
setCorrectDates({
|
83
|
+
calendar: undefined,
|
84
|
+
input: ''
|
85
|
+
});
|
54
86
|
}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
lang: lang,
|
59
|
-
hasMonthFullName: hasMonthFullName,
|
60
|
-
isValidMonth: isValidMonth,
|
61
|
-
isLengthEqual: isLengthEqual
|
62
|
-
}));
|
63
|
-
onChangeValue === null || onChangeValue === void 0 || onChangeValue(event, newValue);
|
87
|
+
setCalendarValue(originalDate);
|
88
|
+
setInputValue(formattedDate);
|
89
|
+
onChangeValue === null || onChangeValue === void 0 || onChangeValue(event, formattedDate, originalDate, isoDate);
|
64
90
|
onChange === null || onChange === void 0 || onChange({
|
65
91
|
target: {
|
66
|
-
value:
|
92
|
+
value: formattedDate,
|
93
|
+
originalDate: originalDate,
|
94
|
+
isoDate: isoDate,
|
67
95
|
name: name
|
68
96
|
}
|
69
97
|
});
|
70
98
|
};
|
71
|
-
var
|
99
|
+
var handleSearch = function handleSearch(date) {
|
72
100
|
if (disabled || readOnly) {
|
73
101
|
return;
|
74
102
|
}
|
75
103
|
if (!date) {
|
76
104
|
setCalendarValue(undefined);
|
77
105
|
setInputValue('');
|
78
|
-
return onCommitDate === null || onCommitDate === void 0 ? void 0 : onCommitDate('', false, true);
|
106
|
+
return onCommitDate === null || onCommitDate === void 0 ? void 0 : onCommitDate('', false, true, undefined, undefined, '');
|
79
107
|
}
|
80
|
-
|
81
|
-
var _formattedInputValue = formatInputValue({
|
108
|
+
var _getFormattedDates2 = getFormattedDates({
|
82
109
|
value: date,
|
110
|
+
lang: lang,
|
111
|
+
delimiter: dateFormatDelimiter(),
|
83
112
|
format: format,
|
84
|
-
|
113
|
+
includeEdgeDates: includeEdgeDates,
|
114
|
+
min: min,
|
115
|
+
max: max
|
116
|
+
}),
|
117
|
+
formattedDate = _getFormattedDates2.formattedDate,
|
118
|
+
isoDate = _getFormattedDates2.isoDate,
|
119
|
+
originalDate = _getFormattedDates2.originalDate;
|
120
|
+
if (originalDate) {
|
121
|
+
var dateInfo = getQuarterInfo(originalDate);
|
122
|
+
onCommitDate === null || onCommitDate === void 0 || onCommitDate(formattedDate, false, true, dateInfo, originalDate, isoDate);
|
123
|
+
}
|
124
|
+
};
|
125
|
+
var handleCalendarPick = function handleCalendarPick(date, dateInfo) {
|
126
|
+
if (disabled || readOnly) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
if (!date) {
|
130
|
+
setInputValue('');
|
131
|
+
setCalendarValue(date);
|
132
|
+
setCorrectDates({
|
133
|
+
calendar: date || undefined,
|
134
|
+
input: ''
|
85
135
|
});
|
86
|
-
|
87
|
-
setInputValue(_formattedInputValue);
|
88
|
-
onCommitDate === null || onCommitDate === void 0 || onCommitDate(date, false, true, dateInfo);
|
89
|
-
onChangeValue === null || onChangeValue === void 0 || onChangeValue(null, _formattedInputValue);
|
136
|
+
onChangeValue === null || onChangeValue === void 0 || onChangeValue(null, '', date, '');
|
90
137
|
onChange === null || onChange === void 0 || onChange({
|
91
138
|
target: {
|
92
|
-
value:
|
139
|
+
value: '',
|
140
|
+
originalDate: date,
|
141
|
+
isoDate: '',
|
93
142
|
name: name
|
94
143
|
}
|
95
144
|
});
|
145
|
+
onCommitDate === null || onCommitDate === void 0 || onCommitDate('', false, true, dateInfo, date || undefined, '');
|
96
146
|
return;
|
97
147
|
}
|
98
|
-
|
99
|
-
var
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
lang: lang
|
148
|
+
customDayjs.locale(lang);
|
149
|
+
var formattedDate = customDayjs(date).format(format);
|
150
|
+
var isoDate = date.toISOString();
|
151
|
+
setCalendarValue(date);
|
152
|
+
setInputValue(formattedDate);
|
153
|
+
setCorrectDates({
|
154
|
+
calendar: date,
|
155
|
+
input: formattedDate
|
107
156
|
});
|
108
|
-
|
109
|
-
setInputValue(formattedInputValue);
|
110
|
-
onCommitDate === null || onCommitDate === void 0 || onCommitDate(newDate, isError, isSuccess);
|
111
|
-
onChangeValue === null || onChangeValue === void 0 || onChangeValue(null, formattedInputValue);
|
157
|
+
onChangeValue === null || onChangeValue === void 0 || onChangeValue(null, formattedDate, date, isoDate);
|
112
158
|
onChange === null || onChange === void 0 || onChange({
|
113
159
|
target: {
|
114
|
-
value:
|
160
|
+
value: formattedDate,
|
161
|
+
originalDate: date,
|
162
|
+
isoDate: isoDate,
|
115
163
|
name: name
|
116
164
|
}
|
117
165
|
});
|
166
|
+
onCommitDate === null || onCommitDate === void 0 || onCommitDate(formattedDate, false, true, dateInfo, date, isoDate);
|
118
167
|
};
|
119
|
-
var updateExternalDate = function updateExternalDate(externalDate
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
168
|
+
var updateExternalDate = function updateExternalDate(externalDate) {
|
169
|
+
var _getFormattedDates3 = getFormattedDates({
|
170
|
+
value: externalDate || null,
|
171
|
+
lang: lang,
|
172
|
+
delimiter: dateFormatDelimiter(),
|
173
|
+
format: format,
|
174
|
+
includeEdgeDates: includeEdgeDates,
|
175
|
+
min: min,
|
176
|
+
max: max
|
177
|
+
}),
|
178
|
+
formattedDate = _getFormattedDates3.formattedDate,
|
179
|
+
originalDate = _getFormattedDates3.originalDate;
|
180
|
+
setInputValue(formattedDate);
|
181
|
+
setCalendarValue(originalDate);
|
182
|
+
if (originalDate) {
|
183
|
+
setCorrectDates({
|
184
|
+
calendar: originalDate,
|
185
|
+
input: formattedDate
|
186
|
+
});
|
132
187
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
188
|
+
if (formattedDate === '') {
|
189
|
+
setCorrectDates({
|
190
|
+
calendar: undefined,
|
191
|
+
input: ''
|
192
|
+
});
|
138
193
|
}
|
139
194
|
};
|
140
195
|
return {
|
141
196
|
datePickerErrorClass: datePickerErrorClass,
|
142
197
|
datePickerSuccessClass: datePickerSuccessClass,
|
143
198
|
handleChangeValue: handleChangeValue,
|
144
|
-
|
199
|
+
handleSearch: handleSearch,
|
200
|
+
handleCalendarPick: handleCalendarPick,
|
145
201
|
updateExternalDate: updateExternalDate
|
146
202
|
};
|
147
203
|
};
|
@@ -5,8 +5,15 @@ export var keys = {
|
|
5
5
|
export var useKeyNavigation = function useKeyNavigation(_ref) {
|
6
6
|
var isCalendarOpen = _ref.isCalendarOpen,
|
7
7
|
closeOnEsc = _ref.closeOnEsc,
|
8
|
+
format = _ref.format,
|
9
|
+
maskWithFormat = _ref.maskWithFormat,
|
10
|
+
delimiter = _ref.delimiter,
|
8
11
|
onToggle = _ref.onToggle;
|
9
12
|
var onKeyDown = function onKeyDown(event) {
|
13
|
+
if (event.key === delimiter && maskWithFormat && format && !/M{3,4}/g.test(format)) {
|
14
|
+
event.preventDefault();
|
15
|
+
return;
|
16
|
+
}
|
10
17
|
switch (event.code) {
|
11
18
|
case keys.Space:
|
12
19
|
{
|
@@ -1,58 +1,3 @@
|
|
1
|
-
import { customDayjs } from "../../../utils/datejs";
|
2
|
-
export var formatInputValue = function formatInputValue(_ref) {
|
3
|
-
var value = _ref.value,
|
4
|
-
format = _ref.format,
|
5
|
-
lang = _ref.lang,
|
6
|
-
hasMonthFullName = _ref.hasMonthFullName,
|
7
|
-
isValidMonth = _ref.isValidMonth,
|
8
|
-
isLengthEqual = _ref.isLengthEqual;
|
9
|
-
if (!value || !lang) {
|
10
|
-
return '';
|
11
|
-
}
|
12
|
-
if (hasMonthFullName && (!isValidMonth || !isLengthEqual)) {
|
13
|
-
return String(value);
|
14
|
-
}
|
15
|
-
if (format && customDayjs(value, format, true).isValid()) {
|
16
|
-
return customDayjs(value, format).locale(lang).format(format);
|
17
|
-
}
|
18
|
-
if (format && String(value).length >= 10 && String(new Date(value)) !== 'Invalid Date') {
|
19
|
-
return customDayjs(value).locale(lang).format(format);
|
20
|
-
}
|
21
|
-
return String(value);
|
22
|
-
};
|
23
|
-
export var formatCalendarValue = function formatCalendarValue(value, format, lang) {
|
24
|
-
if (!value || !lang) {
|
25
|
-
return undefined;
|
26
|
-
}
|
27
|
-
if (format && customDayjs(value, format, true).isValid()) {
|
28
|
-
return customDayjs(value, format, true).locale(lang).toDate();
|
29
|
-
}
|
30
|
-
if (String(new Date(value)) !== 'Invalid Date') {
|
31
|
-
return customDayjs(value).locale(lang).toDate();
|
32
|
-
}
|
33
|
-
return undefined;
|
34
|
-
};
|
35
|
-
export var getDateFromFormat = function getDateFromFormat(value, format, lang) {
|
36
|
-
if (format && customDayjs(value, format, true).isValid() && lang) {
|
37
|
-
return {
|
38
|
-
value: customDayjs(value, format, true).locale(lang).toDate(),
|
39
|
-
isError: false,
|
40
|
-
isSuccess: true
|
41
|
-
};
|
42
|
-
}
|
43
|
-
if (!format && String(new Date(value)) !== 'Invalid Date' && lang) {
|
44
|
-
return {
|
45
|
-
value: customDayjs(value).locale(lang).toDate(),
|
46
|
-
isError: false,
|
47
|
-
isSuccess: true
|
48
|
-
};
|
49
|
-
}
|
50
|
-
return {
|
51
|
-
value: value,
|
52
|
-
isError: true,
|
53
|
-
isSuccess: false
|
54
|
-
};
|
55
|
-
};
|
56
1
|
export var getDateFormatDelimiter = function getDateFormatDelimiter(format) {
|
57
2
|
var _format$match;
|
58
3
|
if (!format) {
|
@@ -60,52 +5,4 @@ export var getDateFormatDelimiter = function getDateFormatDelimiter(format) {
|
|
60
5
|
}
|
61
6
|
var delimiter = (_format$match = format.match(/[^a-zA-Z0-9]/)) === null || _format$match === void 0 ? void 0 : _format$match[0];
|
62
7
|
return delimiter !== null && delimiter !== void 0 ? delimiter : '';
|
63
|
-
};
|
64
|
-
export var getMaskedDateOnInput = function getMaskedDateOnInput(value, format, delimiter, prevValue) {
|
65
|
-
if (!value) {
|
66
|
-
return '';
|
67
|
-
}
|
68
|
-
if (!format || !delimiter || /M{3,4}/g.test(format)) {
|
69
|
-
return value;
|
70
|
-
}
|
71
|
-
if (value.length >= format.length) {
|
72
|
-
return value.slice(0, format.length);
|
73
|
-
}
|
74
|
-
if (prevValue && value.length < prevValue.length && (prevValue === null || prevValue === void 0 ? void 0 : prevValue[value.length]) === delimiter) {
|
75
|
-
return value.slice(0, -1);
|
76
|
-
}
|
77
|
-
if ((format === null || format === void 0 ? void 0 : format[value.length]) === delimiter) {
|
78
|
-
return value + delimiter;
|
79
|
-
}
|
80
|
-
return value;
|
81
|
-
};
|
82
|
-
export var validateDateWithFullMonth = function validateDateWithFullMonth(_ref2) {
|
83
|
-
var currentValue = _ref2.currentValue,
|
84
|
-
format = _ref2.format,
|
85
|
-
lang = _ref2.lang;
|
86
|
-
/**
|
87
|
-
* NOTE: если в формате даты есть месяц в полном названии или сокращенном,
|
88
|
-
* нужно дополнительно проводить валидацию на полноту введенной даты.
|
89
|
-
* Иначе dayjs циклически будет пытаться отформатировать некорректную дату.
|
90
|
-
*/
|
91
|
-
var hasMonthFullName = /M{3,4}/g.test(format);
|
92
|
-
if (!hasMonthFullName) {
|
93
|
-
return {
|
94
|
-
hasMonthFullName: hasMonthFullName,
|
95
|
-
isValidMonth: false,
|
96
|
-
isLengthEqual: false
|
97
|
-
};
|
98
|
-
}
|
99
|
-
customDayjs.locale(lang);
|
100
|
-
var firstIndexOfMonth = format.indexOf('M');
|
101
|
-
var lastIndexOfMonth = currentValue.indexOf(getDateFormatDelimiter(format), firstIndexOfMonth);
|
102
|
-
var fullMonthName = !lastIndexOfMonth ? currentValue.slice(firstIndexOfMonth) : currentValue.slice(firstIndexOfMonth, lastIndexOfMonth);
|
103
|
-
var monthFormatting = format.replace(/[^M]/g, '');
|
104
|
-
var isValidMonth = customDayjs("01 ".concat(fullMonthName, " 1970"), "DD ".concat(monthFormatting, " YYYY"), true).isValid();
|
105
|
-
var isLengthEqual = format.length - monthFormatting.length === currentValue.length - fullMonthName.length;
|
106
|
-
return {
|
107
|
-
hasMonthFullName: hasMonthFullName,
|
108
|
-
isValidMonth: isValidMonth,
|
109
|
-
isLengthEqual: isLengthEqual
|
110
|
-
};
|
111
8
|
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { getOriginalDates } from "./getOriginalDates";
|
2
|
+
import { normalizeDates } from "./normalizeDates";
|
3
|
+
export var getFormattedDates = function getFormattedDates(_ref) {
|
4
|
+
var value = _ref.value,
|
5
|
+
lang = _ref.lang,
|
6
|
+
format = _ref.format,
|
7
|
+
includeEdgeDates = _ref.includeEdgeDates,
|
8
|
+
min = _ref.min,
|
9
|
+
max = _ref.max;
|
10
|
+
var _getOriginalDates = getOriginalDates(value, lang, format),
|
11
|
+
formattedDate = _getOriginalDates.formattedDate,
|
12
|
+
isoDate = _getOriginalDates.isoDate,
|
13
|
+
originalDate = _getOriginalDates.originalDate;
|
14
|
+
if (!originalDate) {
|
15
|
+
var innerValue = format && (/M{3,4}/g.test(format) ? formattedDate : formattedDate.slice(0, format.length));
|
16
|
+
return {
|
17
|
+
formattedDate: innerValue || '',
|
18
|
+
isoDate: isoDate,
|
19
|
+
originalDate: originalDate
|
20
|
+
};
|
21
|
+
}
|
22
|
+
var _normalizeDates = normalizeDates({
|
23
|
+
originalDate: originalDate,
|
24
|
+
lang: lang,
|
25
|
+
format: format,
|
26
|
+
includeEdgeDates: includeEdgeDates,
|
27
|
+
min: min,
|
28
|
+
max: max
|
29
|
+
}),
|
30
|
+
normalizedDate = _normalizeDates.normalizedDate,
|
31
|
+
formattedNormalizedDate = _normalizeDates.formattedNormalizedDate;
|
32
|
+
return {
|
33
|
+
formattedDate: formattedNormalizedDate,
|
34
|
+
isoDate: normalizedDate.toISOString(),
|
35
|
+
originalDate: normalizedDate
|
36
|
+
};
|
37
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export var getMaskedDateOnInput = function getMaskedDateOnInput(value, format, delimiter, prevValue) {
|
2
|
+
if (!value) {
|
3
|
+
return '';
|
4
|
+
}
|
5
|
+
if (!format || !delimiter || /M{3,4}/g.test(format)) {
|
6
|
+
return value;
|
7
|
+
}
|
8
|
+
var dateRegExp = new RegExp("[^0-9".concat(delimiter, "]"), 'g');
|
9
|
+
var formattedValue = value.replace(dateRegExp, '');
|
10
|
+
if (formattedValue.length >= format.length) {
|
11
|
+
return formattedValue.slice(0, format.length);
|
12
|
+
}
|
13
|
+
if (prevValue && formattedValue.length < prevValue.length && (prevValue === null || prevValue === void 0 ? void 0 : prevValue[formattedValue.length]) === delimiter) {
|
14
|
+
return formattedValue.slice(0, -1);
|
15
|
+
}
|
16
|
+
if ((format === null || format === void 0 ? void 0 : format[formattedValue.length]) === delimiter) {
|
17
|
+
return formattedValue + delimiter;
|
18
|
+
}
|
19
|
+
return formattedValue;
|
20
|
+
};
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { customDayjs } from "../../../utils/datejs";
|
2
|
+
var initialValueStructure = {
|
3
|
+
isoDate: '',
|
4
|
+
originalDate: undefined,
|
5
|
+
formattedDate: ''
|
6
|
+
};
|
7
|
+
export var getOriginalDates = function getOriginalDates(value, lang, format) {
|
8
|
+
if (!value || !lang) {
|
9
|
+
return initialValueStructure;
|
10
|
+
}
|
11
|
+
customDayjs.locale(lang);
|
12
|
+
if (value instanceof Date) {
|
13
|
+
return {
|
14
|
+
formattedDate: customDayjs(value).format(format),
|
15
|
+
isoDate: new Date(value).toISOString(),
|
16
|
+
originalDate: new Date(value)
|
17
|
+
};
|
18
|
+
}
|
19
|
+
if (!format) {
|
20
|
+
return {
|
21
|
+
formattedDate: value,
|
22
|
+
isoDate: '',
|
23
|
+
originalDate: undefined
|
24
|
+
};
|
25
|
+
}
|
26
|
+
if (customDayjs(value, format).isValid()) {
|
27
|
+
var isoDate = customDayjs(value, format).toISOString();
|
28
|
+
var originalDate = customDayjs(value, format).toDate();
|
29
|
+
var formattedDate = customDayjs(value, format).format(format);
|
30
|
+
return {
|
31
|
+
formattedDate: formattedDate,
|
32
|
+
isoDate: isoDate,
|
33
|
+
originalDate: originalDate
|
34
|
+
};
|
35
|
+
}
|
36
|
+
return {
|
37
|
+
formattedDate: value,
|
38
|
+
isoDate: '',
|
39
|
+
originalDate: undefined
|
40
|
+
};
|
41
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { customDayjs } from "../../../utils/datejs";
|
2
|
+
export var normalizeDates = function normalizeDates(_ref) {
|
3
|
+
var originalDate = _ref.originalDate,
|
4
|
+
lang = _ref.lang,
|
5
|
+
format = _ref.format,
|
6
|
+
includeEdgeDates = _ref.includeEdgeDates,
|
7
|
+
min = _ref.min,
|
8
|
+
max = _ref.max;
|
9
|
+
var dateCandidate = originalDate;
|
10
|
+
customDayjs.locale(lang);
|
11
|
+
if (min && includeEdgeDates && min > originalDate) {
|
12
|
+
dateCandidate = min;
|
13
|
+
} else if (min && !includeEdgeDates && min >= originalDate) {
|
14
|
+
dateCandidate = customDayjs(min).add(1, 'd').toDate();
|
15
|
+
} else if (max && includeEdgeDates && max < originalDate) {
|
16
|
+
dateCandidate = max;
|
17
|
+
} else if (max && !includeEdgeDates && max <= originalDate) {
|
18
|
+
dateCandidate = customDayjs(max).subtract(1, 'd').toDate();
|
19
|
+
}
|
20
|
+
var formattedDateCandidate = format ? customDayjs(dateCandidate).format(format) : dateCandidate.toString();
|
21
|
+
return {
|
22
|
+
normalizedDate: dateCandidate,
|
23
|
+
formattedNormalizedDate: formattedDateCandidate
|
24
|
+
};
|
25
|
+
};
|