@via-profit/ui-kit 0.2.5 → 0.2.6
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/Calendar/CalendarComponent.js +35 -15
- package/package.json +1 -1
|
@@ -99,20 +99,38 @@ const computeView = (inputParams) => {
|
|
|
99
99
|
const computeCalendarDate = (params) => {
|
|
100
100
|
const { inputValue, defaultValue } = params;
|
|
101
101
|
const today = new Date();
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
// Проверяем inputValue
|
|
103
|
+
if (inputValue !== null && inputValue !== undefined) {
|
|
104
|
+
if (Array.isArray(inputValue) && inputValue.length > 0) {
|
|
105
|
+
// Для range режима - берем первый элемент, если он есть
|
|
106
|
+
if (inputValue[0] instanceof Date) {
|
|
107
|
+
return inputValue[0];
|
|
108
|
+
}
|
|
109
|
+
// Если первый элемент null, пробуем второй
|
|
110
|
+
if (inputValue[1] instanceof Date) {
|
|
111
|
+
return inputValue[1];
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
114
|
+
else if (inputValue instanceof Date) {
|
|
115
|
+
// Для non-range режима
|
|
116
|
+
return inputValue;
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
// Проверяем defaultValue
|
|
120
|
+
if (defaultValue !== null && defaultValue !== undefined) {
|
|
121
|
+
if (Array.isArray(defaultValue) && defaultValue.length > 0) {
|
|
122
|
+
if (defaultValue[0] instanceof Date) {
|
|
123
|
+
return defaultValue[0];
|
|
124
|
+
}
|
|
125
|
+
if (defaultValue[1] instanceof Date) {
|
|
126
|
+
return defaultValue[1];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (defaultValue instanceof Date) {
|
|
130
|
+
return defaultValue;
|
|
131
|
+
}
|
|
115
132
|
}
|
|
133
|
+
// Возвращаем сегодняшнюю дату, если ничего не подошло
|
|
116
134
|
return today;
|
|
117
135
|
};
|
|
118
136
|
const CalendarComponent = react_1.default.forwardRef((props, ref) => {
|
|
@@ -252,11 +270,13 @@ const CalendarComponent = react_1.default.forwardRef((props, ref) => {
|
|
|
252
270
|
if (JSON.stringify(inputValue) !== JSON.stringify(inputValueRef.current)) {
|
|
253
271
|
inputValueRef.current = inputValue;
|
|
254
272
|
setValue(inputValue);
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
273
|
+
if (inputValue !== null && inputValue !== undefined) {
|
|
274
|
+
if (Array.isArray(inputValue) && inputValue[0] instanceof Date) {
|
|
275
|
+
setCalendarDate(inputValue[0]);
|
|
276
|
+
}
|
|
277
|
+
else if (inputValue instanceof Date) {
|
|
278
|
+
setCalendarDate(inputValue);
|
|
279
|
+
}
|
|
260
280
|
}
|
|
261
281
|
}
|
|
262
282
|
}, [inputValue]);
|