@nutui/nutui-react 2.7.7 → 2.7.8
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/CHANGELOG.md +19 -10
- package/dist/esm/Animate/style/style.css +1 -1
- package/dist/esm/Animate.js +6 -9
- package/dist/esm/Calendar/style/style.css +1 -1
- package/dist/esm/Calendar.js +2 -2
- package/dist/esm/CalendarCard.js +4 -4
- package/dist/esm/CalendarItem.js +177 -180
- package/dist/esm/date.js +109 -181
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +311 -418
- package/dist/nutui.react.umd.js +311 -418
- package/dist/packages/animate/animate.scss +63 -105
- package/dist/packages/calendar/calendar.scss +9 -9
- package/dist/style.css +1 -1
- package/dist/types/packages/animate/animate.taro.d.ts +2 -1
- package/dist/types/utils/date.d.ts +54 -52
- package/package.json +1 -1
package/dist/esm/CalendarItem.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useState, useRef, useEffect } from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
3
|
import { C as ComponentDefaults } from "./typings.js";
|
|
4
|
-
import {
|
|
4
|
+
import { i as isEqual, d as date2Str, a as getNumTwoBit, g as getDateString, c as compareDate, b as getPreMonthDates, e as getDaysStatus, f as getMonthDays, h as getCurrMonthData, j as getWeekDate, k as getWhatDay, l as formatResultDate } from "./date.js";
|
|
5
5
|
import { r as requestAniFrame } from "./raf.js";
|
|
6
6
|
import { useConfig } from "./ConfigProvider.js";
|
|
7
7
|
import { u as usePropsValue } from "./use-props-value.js";
|
|
@@ -12,28 +12,28 @@ const splitDate = (date) => {
|
|
|
12
12
|
const isMultiple = (day, days) => {
|
|
13
13
|
if (days.length > 0) {
|
|
14
14
|
return days.some((item) => {
|
|
15
|
-
return
|
|
15
|
+
return isEqual(item, day);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
return false;
|
|
19
19
|
};
|
|
20
20
|
const isCurrDay = (month, day) => {
|
|
21
21
|
const date = `${month.curData[0]}/${month.curData[1]}/${day}`;
|
|
22
|
-
return
|
|
22
|
+
return isEqual(date, date2Str(/* @__PURE__ */ new Date(), "/"));
|
|
23
23
|
};
|
|
24
24
|
const getCurrDate = (day, month) => {
|
|
25
|
-
return `${month.curData[0]}/${month.curData[1]}/${
|
|
25
|
+
return `${month.curData[0]}/${month.curData[1]}/${getNumTwoBit(+day.day)}`;
|
|
26
26
|
};
|
|
27
27
|
const isStart = (day, days) => {
|
|
28
|
-
return
|
|
28
|
+
return isEqual(days[0], day);
|
|
29
29
|
};
|
|
30
30
|
const isEnd = (day, days) => {
|
|
31
|
-
return
|
|
31
|
+
return isEqual(days[1], day);
|
|
32
32
|
};
|
|
33
33
|
const isStartAndEnd = (days) => {
|
|
34
|
-
return days.length >= 2 &&
|
|
34
|
+
return days.length >= 2 && isEqual(days[0], days[1]);
|
|
35
35
|
};
|
|
36
|
-
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, title: "", startDate:
|
|
36
|
+
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, title: "", startDate: getDateString(0), endDate: getDateString(365), showToday: true, startText: "", endText: "", confirmText: "", showTitle: true, showSubTitle: true, scrollAnimation: true, firstDayOfWeek: 0, disableDate: (date) => false, renderHeaderButtons: void 0, renderDay: void 0, renderDayTop: void 0, renderDayBottom: void 0, onConfirm: (data) => {
|
|
37
37
|
}, onUpdate: () => {
|
|
38
38
|
}, onDayClick: (data) => {
|
|
39
39
|
}, onPageChange: (data) => {
|
|
@@ -41,6 +41,8 @@ const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type:
|
|
|
41
41
|
const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
42
42
|
const { locale } = useConfig();
|
|
43
43
|
const { style, className, children, popup, type, autoBackfill, title, defaultValue, startDate, endDate, showToday, startText, endText, confirmText, showTitle, showSubTitle, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderBottomButton, renderDay, renderDayTop, renderDayBottom, value, onConfirm, onUpdate, onDayClick, onPageChange } = Object.assign(Object.assign({}, defaultProps), props);
|
|
44
|
+
const classPrefix = "nut-calendar";
|
|
45
|
+
const dayPrefix = "nut-calendar-day";
|
|
44
46
|
const weekdays = locale.calendaritem.weekdays;
|
|
45
47
|
const weeks = [
|
|
46
48
|
...weekdays.slice(firstDayOfWeek, 7),
|
|
@@ -52,19 +54,13 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
52
54
|
const [monthsNum, setMonthsNum] = useState(0);
|
|
53
55
|
const [translateY, setTranslateY] = useState(0);
|
|
54
56
|
const [monthDefaultRange, setMonthDefaultRange] = useState([]);
|
|
55
|
-
const propStartDate = startDate ||
|
|
56
|
-
const propEndDate = endDate ||
|
|
57
|
+
const propStartDate = startDate || getDateString(0);
|
|
58
|
+
const propEndDate = endDate || getDateString(365);
|
|
57
59
|
const startDates = splitDate(propStartDate);
|
|
58
60
|
const endDates = splitDate(propEndDate);
|
|
59
61
|
const [state] = useState({
|
|
60
62
|
currDateArray: []
|
|
61
63
|
});
|
|
62
|
-
const getMonthsPanel = () => {
|
|
63
|
-
return monthsPanel.current;
|
|
64
|
-
};
|
|
65
|
-
const getMonthsRef = () => {
|
|
66
|
-
return monthsRef.current;
|
|
67
|
-
};
|
|
68
64
|
const resetDefaultValue = () => {
|
|
69
65
|
if (defaultValue || Array.isArray(defaultValue) && defaultValue.length > 0) {
|
|
70
66
|
return type !== "single" ? [...defaultValue] : defaultValue;
|
|
@@ -84,9 +80,7 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
84
80
|
const viewAreaRef = useRef(null);
|
|
85
81
|
const [avgHeight, setAvgHeight] = useState(0);
|
|
86
82
|
let viewHeight = 0;
|
|
87
|
-
const
|
|
88
|
-
const dayPrefix = "nut-calendar-day";
|
|
89
|
-
const getMonthData = (curData, monthNum, type2) => {
|
|
83
|
+
const getMonthData = (curData, monthNum) => {
|
|
90
84
|
let i = 0;
|
|
91
85
|
let date = curData;
|
|
92
86
|
const monthData = monthsData;
|
|
@@ -110,10 +104,8 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
110
104
|
cssHeight,
|
|
111
105
|
scrollTop
|
|
112
106
|
};
|
|
113
|
-
{
|
|
114
|
-
|
|
115
|
-
monthData.push(monthInfo);
|
|
116
|
-
}
|
|
107
|
+
if (!endDates || !compareDate(`${endDates[0]}/${endDates[1]}/${getMonthDays(endDates[0], endDates[1])}`, `${curData[0]}/${curData[1]}/${curData[2]}`)) {
|
|
108
|
+
monthData.push(monthInfo);
|
|
117
109
|
}
|
|
118
110
|
date = getCurrMonthData("next", y, m);
|
|
119
111
|
} while (i++ < monthNum);
|
|
@@ -121,9 +113,9 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
121
113
|
};
|
|
122
114
|
const setReachedYearMonthInfo = (current) => {
|
|
123
115
|
const currentMonthsData = monthsData[current];
|
|
124
|
-
const [year, month] = currentMonthsData.curData;
|
|
125
116
|
if (currentMonthsData.title === yearMonthTitle)
|
|
126
117
|
return;
|
|
118
|
+
const [year, month] = currentMonthsData.curData;
|
|
127
119
|
onPageChange && onPageChange([year, month, `${year}-${month}`]);
|
|
128
120
|
setYearMonthTitle(currentMonthsData.title);
|
|
129
121
|
};
|
|
@@ -149,57 +141,54 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
149
141
|
setTranslateY(monthsData[start].scrollTop);
|
|
150
142
|
setReachedYearMonthInfo(current);
|
|
151
143
|
};
|
|
152
|
-
const getMonthNum = () => {
|
|
153
|
-
let monthNum = Number(endDates[1]) - Number(startDates[1]);
|
|
154
|
-
const yearNum = Number(endDates[0]) - Number(startDates[0]);
|
|
155
|
-
if (yearNum > 0) {
|
|
156
|
-
monthNum += 12 * yearNum;
|
|
157
|
-
}
|
|
158
|
-
if (monthNum <= 0) {
|
|
159
|
-
monthNum = 1;
|
|
160
|
-
}
|
|
161
|
-
setMonthsNum(monthNum);
|
|
162
|
-
return monthNum;
|
|
163
|
-
};
|
|
164
144
|
const setDefaultDate = () => {
|
|
165
145
|
let defaultData = [];
|
|
166
|
-
if (type === "
|
|
167
|
-
if (currentDate.length
|
|
168
|
-
|
|
169
|
-
|
|
146
|
+
if (type === "single" && typeof currentDate === "string") {
|
|
147
|
+
if (!currentDate.length) {
|
|
148
|
+
return defaultData;
|
|
149
|
+
}
|
|
150
|
+
if (compareDate(currentDate, propStartDate)) {
|
|
151
|
+
defaultData = [...splitDate(propStartDate)];
|
|
152
|
+
} else if (!compareDate(currentDate, propEndDate)) {
|
|
153
|
+
defaultData = [...splitDate(propEndDate)];
|
|
154
|
+
} else {
|
|
155
|
+
defaultData = [...splitDate(currentDate)];
|
|
156
|
+
}
|
|
157
|
+
return defaultData;
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(currentDate) && currentDate.length) {
|
|
160
|
+
if (type === "range") {
|
|
161
|
+
if (compareDate(currentDate[0], propStartDate)) {
|
|
162
|
+
currentDate[0] = propStartDate;
|
|
170
163
|
}
|
|
171
|
-
if (
|
|
172
|
-
currentDate
|
|
164
|
+
if (compareDate(propEndDate, currentDate[1])) {
|
|
165
|
+
currentDate[1] = propEndDate;
|
|
173
166
|
}
|
|
174
167
|
defaultData = [
|
|
175
168
|
...splitDate(currentDate[0]),
|
|
176
169
|
...splitDate(currentDate[1])
|
|
177
170
|
];
|
|
178
|
-
}
|
|
179
|
-
} else if (type === "multiple" && Array.isArray(currentDate)) {
|
|
180
|
-
if (currentDate.length > 0) {
|
|
171
|
+
} else if (type === "multiple") {
|
|
181
172
|
const defaultArr = [];
|
|
182
173
|
const obj = {};
|
|
183
174
|
currentDate.forEach((item) => {
|
|
184
|
-
if (
|
|
175
|
+
if (!compareDate(item, propStartDate) && !compareDate(propEndDate, item)) {
|
|
185
176
|
if (!Object.hasOwnProperty.call(obj, item)) {
|
|
186
177
|
defaultArr.push(item);
|
|
187
178
|
obj[item] = item;
|
|
188
179
|
}
|
|
189
180
|
}
|
|
190
181
|
});
|
|
191
|
-
currentDate.splice(0
|
|
182
|
+
currentDate.splice(0, currentDate.length, ...defaultArr);
|
|
192
183
|
defaultData = [...splitDate(defaultArr[0])];
|
|
193
|
-
}
|
|
194
|
-
} else if (type === "week" && Array.isArray(currentDate)) {
|
|
195
|
-
if (currentDate.length > 0) {
|
|
184
|
+
} else if (type === "week") {
|
|
196
185
|
const [y, m, d] = splitDate(currentDate[0]);
|
|
197
|
-
const weekArr =
|
|
198
|
-
currentDate.splice(0
|
|
199
|
-
if (
|
|
186
|
+
const weekArr = getWeekDate(y, m, d, firstDayOfWeek);
|
|
187
|
+
currentDate.splice(0, currentDate.length, ...weekArr);
|
|
188
|
+
if (compareDate(currentDate[0], propStartDate)) {
|
|
200
189
|
currentDate.splice(0, 1, propStartDate);
|
|
201
190
|
}
|
|
202
|
-
if (
|
|
191
|
+
if (compareDate(propEndDate, currentDate[1])) {
|
|
203
192
|
currentDate.splice(1, 1, propEndDate);
|
|
204
193
|
}
|
|
205
194
|
defaultData = [
|
|
@@ -207,18 +196,6 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
207
196
|
...splitDate(currentDate[1])
|
|
208
197
|
];
|
|
209
198
|
}
|
|
210
|
-
} else if (currentDate) {
|
|
211
|
-
if (currentDate.length > 0) {
|
|
212
|
-
if (propStartDate && Utils.compareDate(currentDate, propStartDate)) {
|
|
213
|
-
defaultData = [...splitDate(propStartDate)];
|
|
214
|
-
} else if (propEndDate && !Utils.compareDate(currentDate, propEndDate)) {
|
|
215
|
-
defaultData = [...splitDate(propEndDate)];
|
|
216
|
-
} else {
|
|
217
|
-
defaultData = [...splitDate(currentDate)];
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
defaultData = [];
|
|
221
|
-
}
|
|
222
199
|
}
|
|
223
200
|
return defaultData;
|
|
224
201
|
};
|
|
@@ -252,31 +229,31 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
252
229
|
lastCurrent
|
|
253
230
|
};
|
|
254
231
|
};
|
|
255
|
-
const renderCurrentDate = () => {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
chooseDay({ day: dateArr[2], type: "active" }, monthsData[currentIndex], true);
|
|
274
|
-
});
|
|
275
|
-
} else {
|
|
276
|
-
chooseDay({ day: defaultData[2], type: "active" }, monthsData[current.current], true);
|
|
277
|
-
}
|
|
232
|
+
const renderCurrentDate = (defaultData, current) => {
|
|
233
|
+
if (!defaultData.length)
|
|
234
|
+
return;
|
|
235
|
+
const date = monthsData[current.current];
|
|
236
|
+
if (type === "range") {
|
|
237
|
+
handleDayClick({ day: defaultData[2], type: "active" }, date);
|
|
238
|
+
handleDayClick({ day: defaultData[5], type: "active" }, monthsData[current.lastCurrent]);
|
|
239
|
+
} else if (type === "week") {
|
|
240
|
+
handleDayClick({ day: defaultData[2], type: "curr" }, date);
|
|
241
|
+
} else if (type === "multiple") {
|
|
242
|
+
[...currentDate].forEach((item) => {
|
|
243
|
+
const dateArr = splitDate(item);
|
|
244
|
+
let currentIndex = current.current;
|
|
245
|
+
currentIndex = monthsData.findIndex((item2) => item2.title === monthTitle(dateArr[0], dateArr[1]));
|
|
246
|
+
handleDayClick({ day: dateArr[2], type: "active" }, monthsData[currentIndex]);
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
handleDayClick({ day: defaultData[2], type: "active" }, date);
|
|
278
250
|
}
|
|
279
|
-
|
|
251
|
+
};
|
|
252
|
+
const getMonthsPanel = () => {
|
|
253
|
+
return monthsPanel.current;
|
|
254
|
+
};
|
|
255
|
+
const getMonthsRef = () => {
|
|
256
|
+
return monthsRef.current;
|
|
280
257
|
};
|
|
281
258
|
const requestAniFrameFunc = (current, monthNum) => {
|
|
282
259
|
const lastItem = monthsData[monthsData.length - 1];
|
|
@@ -290,12 +267,27 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
290
267
|
});
|
|
291
268
|
setAvgHeight(Math.floor(containerHeight / (monthNum + 1)));
|
|
292
269
|
};
|
|
270
|
+
const getMonthNum = () => {
|
|
271
|
+
let monthNum = Number(endDates[1]) - Number(startDates[1]);
|
|
272
|
+
const yearNum = Number(endDates[0]) - Number(startDates[0]);
|
|
273
|
+
if (yearNum > 0) {
|
|
274
|
+
monthNum += 12 * yearNum;
|
|
275
|
+
}
|
|
276
|
+
if (monthNum <= 0) {
|
|
277
|
+
monthNum = 1;
|
|
278
|
+
}
|
|
279
|
+
setMonthsNum(monthNum);
|
|
280
|
+
return monthNum;
|
|
281
|
+
};
|
|
293
282
|
const initData = () => {
|
|
294
283
|
const monthNum = getMonthNum();
|
|
295
284
|
getMonthData(startDates, monthNum);
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
285
|
+
const defaultData = setDefaultDate();
|
|
286
|
+
const current = getCurrentIndex(defaultData);
|
|
287
|
+
const currentIndex = current.current;
|
|
288
|
+
renderCurrentDate(defaultData, current);
|
|
289
|
+
setDefaultRange(monthNum, currentIndex);
|
|
290
|
+
requestAniFrameFunc(currentIndex, monthNum);
|
|
299
291
|
};
|
|
300
292
|
useEffect(() => {
|
|
301
293
|
initData();
|
|
@@ -312,9 +304,9 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
312
304
|
popup && resetRender();
|
|
313
305
|
}, [currentDate]);
|
|
314
306
|
const scrollToDate = (date) => {
|
|
315
|
-
if (
|
|
307
|
+
if (compareDate(date, propStartDate)) {
|
|
316
308
|
date = propStartDate;
|
|
317
|
-
} else if (!
|
|
309
|
+
} else if (!compareDate(date, propEndDate)) {
|
|
318
310
|
date = propEndDate;
|
|
319
311
|
}
|
|
320
312
|
const dateArr = splitDate(date);
|
|
@@ -358,16 +350,13 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
358
350
|
const nextTop = monthsData[current + 1].scrollTop;
|
|
359
351
|
const nextHeight = monthsData[current + 1].cssHeight;
|
|
360
352
|
if (current === 0) {
|
|
361
|
-
if (scrollTop >= nextTop)
|
|
353
|
+
if (scrollTop >= nextTop)
|
|
362
354
|
current += 1;
|
|
363
|
-
}
|
|
364
355
|
} else if (current > 0 && current < monthsNum - 1) {
|
|
365
|
-
if (scrollTop >= nextTop)
|
|
356
|
+
if (scrollTop >= nextTop)
|
|
366
357
|
current += 1;
|
|
367
|
-
|
|
368
|
-
if (scrollTop < monthsData[current].scrollTop) {
|
|
358
|
+
if (scrollTop < monthsData[current].scrollTop)
|
|
369
359
|
current -= 1;
|
|
370
|
-
}
|
|
371
360
|
} else {
|
|
372
361
|
const viewPosition = Math.round(scrollTop + viewHeight);
|
|
373
362
|
if (current + 1 <= monthsNum && viewPosition >= nextTop + nextHeight) {
|
|
@@ -382,86 +371,90 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
382
371
|
React__default.useImperativeHandle(ref, () => ({
|
|
383
372
|
scrollToDate
|
|
384
373
|
}));
|
|
374
|
+
const isDisable = (day, month) => {
|
|
375
|
+
if (day.type !== "active")
|
|
376
|
+
return true;
|
|
377
|
+
const dateStr = getCurrDate(day, month);
|
|
378
|
+
if (compareDate(dateStr, propStartDate))
|
|
379
|
+
return true;
|
|
380
|
+
if (compareDate(propEndDate, dateStr))
|
|
381
|
+
return true;
|
|
382
|
+
return false;
|
|
383
|
+
};
|
|
385
384
|
const getClasses = (day, month) => {
|
|
386
385
|
const dateStr = getCurrDate(day, month);
|
|
387
|
-
if (day
|
|
388
|
-
|
|
389
|
-
|
|
386
|
+
if (isDisable(day, month))
|
|
387
|
+
return `${dayPrefix}-disabled`;
|
|
388
|
+
const activeCls = `${dayPrefix}-active`;
|
|
389
|
+
if (type === "range" || type === "week") {
|
|
390
|
+
if (isStart(dateStr, currentDate))
|
|
391
|
+
return `${activeCls} active-start`;
|
|
392
|
+
if (isEnd(dateStr, currentDate)) {
|
|
393
|
+
return `${activeCls} active-end`;
|
|
390
394
|
}
|
|
391
|
-
if (
|
|
392
|
-
|
|
393
|
-
return `${dayPrefix}-active ${isStart(dateStr, currentDate) ? "active-start" : ""} ${isEnd(dateStr, currentDate) ? "active-end" : ""}`;
|
|
394
|
-
}
|
|
395
|
-
if (Array.isArray(currentDate) && Object.values(currentDate).length === 2 && Utils.compareDate(currentDate[0], dateStr) && Utils.compareDate(dateStr, currentDate[1])) {
|
|
396
|
-
if (disableDate(day)) {
|
|
397
|
-
return `${dayPrefix}-choose-disabled`;
|
|
398
|
-
}
|
|
399
|
-
return `${dayPrefix}-choose`;
|
|
400
|
-
}
|
|
401
|
-
} else if (type === "multiple" && isMultiple(dateStr, currentDate) || !Array.isArray(currentDate) && Utils.isEqual(currentDate, dateStr)) {
|
|
402
|
-
return `${dayPrefix}-active`;
|
|
395
|
+
if (currentDate.length === 2 && compareDate(currentDate[0], dateStr) && compareDate(dateStr, currentDate[1])) {
|
|
396
|
+
return disableDate(day) ? `${dayPrefix}-choose-disabled` : `${dayPrefix}-choose`;
|
|
403
397
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
return null;
|
|
398
|
+
} else if (type === "multiple" && isMultiple(dateStr, currentDate) || type === "single" && isEqual(currentDate, dateStr)) {
|
|
399
|
+
return activeCls;
|
|
408
400
|
}
|
|
409
|
-
|
|
401
|
+
if (disableDate(day))
|
|
402
|
+
return `${dayPrefix}-disabled`;
|
|
403
|
+
return null;
|
|
410
404
|
};
|
|
411
|
-
const
|
|
405
|
+
const handleDayClick = (day, month, isFirst = true) => {
|
|
412
406
|
if (getClasses(day, month) === `${dayPrefix}-disabled`) {
|
|
413
407
|
return;
|
|
414
408
|
}
|
|
415
409
|
const days = [...month.curData];
|
|
416
410
|
const [y, m] = month.curData;
|
|
417
|
-
days[2] = typeof day.day === "number" ?
|
|
411
|
+
days[2] = typeof day.day === "number" ? getNumTwoBit(day.day) : day.day;
|
|
418
412
|
days[3] = `${days[0]}/${days[1]}/${days[2]}`;
|
|
419
|
-
days[4] =
|
|
413
|
+
days[4] = getWhatDay(+days[0], +days[1], +days[2]);
|
|
414
|
+
const newDate = days[3];
|
|
420
415
|
if (type === "multiple") {
|
|
421
|
-
if (currentDate
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
if (
|
|
425
|
-
|
|
416
|
+
if (Array.isArray(currentDate)) {
|
|
417
|
+
if (currentDate.length > 0) {
|
|
418
|
+
const hasIndex = currentDate.findIndex((item) => item === newDate);
|
|
419
|
+
if (isFirst) {
|
|
420
|
+
state.currDateArray.push([...days]);
|
|
421
|
+
} else if (hasIndex > -1) {
|
|
422
|
+
currentDate.splice(hasIndex, 1);
|
|
423
|
+
state.currDateArray.splice(hasIndex, 1);
|
|
424
|
+
} else {
|
|
425
|
+
currentDate.push(newDate);
|
|
426
|
+
state.currDateArray.push([...days]);
|
|
426
427
|
}
|
|
427
|
-
});
|
|
428
|
-
if (isFirst) {
|
|
429
|
-
state.currDateArray.push([...days]);
|
|
430
|
-
} else if (hasIndex !== "") {
|
|
431
|
-
currentDate.splice(hasIndex, 1);
|
|
432
|
-
state.currDateArray.splice(hasIndex, 1);
|
|
433
428
|
} else {
|
|
434
|
-
currentDate.push(
|
|
435
|
-
state.currDateArray
|
|
429
|
+
currentDate.push(newDate);
|
|
430
|
+
state.currDateArray = [[...days]];
|
|
436
431
|
}
|
|
437
|
-
} else {
|
|
438
|
-
currentDate.push(days[3]);
|
|
439
|
-
state.currDateArray = [[...days]];
|
|
440
432
|
}
|
|
441
433
|
} else if (type === "range") {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
434
|
+
if (Array.isArray(currentDate)) {
|
|
435
|
+
if (currentDate.length === 2 || currentDate.length === 0) {
|
|
436
|
+
currentDate.splice(0, currentDate.length, newDate);
|
|
437
|
+
state.currDateArray = [[...days]];
|
|
438
|
+
} else if (compareDate(currentDate[0], newDate)) {
|
|
439
|
+
currentDate.push(newDate);
|
|
440
|
+
state.currDateArray = [...state.currDateArray, [...days]];
|
|
441
|
+
} else {
|
|
442
|
+
currentDate.unshift(newDate);
|
|
443
|
+
state.currDateArray = [[...days], ...state.currDateArray];
|
|
444
|
+
}
|
|
452
445
|
}
|
|
453
446
|
} else if (type === "week") {
|
|
454
|
-
const weekArr =
|
|
455
|
-
if (
|
|
456
|
-
weekArr
|
|
447
|
+
const weekArr = getWeekDate(y, m, `${day.day}`, firstDayOfWeek);
|
|
448
|
+
if (compareDate(weekArr[0], propStartDate)) {
|
|
449
|
+
weekArr[0] = propStartDate;
|
|
457
450
|
}
|
|
458
|
-
if (
|
|
459
|
-
weekArr
|
|
451
|
+
if (compareDate(propEndDate, weekArr[1])) {
|
|
452
|
+
weekArr[1] = propEndDate;
|
|
460
453
|
}
|
|
461
|
-
|
|
454
|
+
currentDate.splice(0, currentDate.length, ...weekArr);
|
|
462
455
|
state.currDateArray = [
|
|
463
|
-
|
|
464
|
-
|
|
456
|
+
formatResultDate(weekArr[0]),
|
|
457
|
+
formatResultDate(weekArr[1])
|
|
465
458
|
];
|
|
466
459
|
} else {
|
|
467
460
|
setCurrentDate(days[3]);
|
|
@@ -484,10 +477,10 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
484
477
|
}
|
|
485
478
|
}
|
|
486
479
|
};
|
|
487
|
-
const classes = classNames({
|
|
480
|
+
const classes = classNames(classPrefix, {
|
|
488
481
|
[`${classPrefix}-title`]: !popup,
|
|
489
482
|
[`${classPrefix}-nofooter`]: !!autoBackfill
|
|
490
|
-
},
|
|
483
|
+
}, className);
|
|
491
484
|
const headerClasses = classNames({
|
|
492
485
|
[`${classPrefix}-header`]: true,
|
|
493
486
|
[`${classPrefix}-header-title`]: !popup
|
|
@@ -508,6 +501,29 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
508
501
|
React__default.createElement("div", { className: `${classPrefix}-weeks`, ref: weeksPanel }, weeks.map((item) => React__default.createElement("div", { className: `${classPrefix}-week-item`, key: item }, item)))
|
|
509
502
|
);
|
|
510
503
|
};
|
|
504
|
+
const renderItem = (month, day, index) => {
|
|
505
|
+
const startTip = isStartTip(day, month);
|
|
506
|
+
const endTip = isEndTip(day, month);
|
|
507
|
+
const noStartNorEnd = !startTip && !endTip;
|
|
508
|
+
return React__default.createElement(
|
|
509
|
+
"div",
|
|
510
|
+
{ className: [`${classPrefix}-day`, getClasses(day, month)].join(" "), onClick: () => handleDayClick(day, month, false), key: index },
|
|
511
|
+
React__default.createElement("div", { className: `${classPrefix}-day-day` }, renderDay ? renderDay(day) : day.day),
|
|
512
|
+
!startTip && renderDayTop && React__default.createElement("div", { className: `${classPrefix}-day-info-top` }, renderDayTop(day)),
|
|
513
|
+
noStartNorEnd && renderDayBottom && React__default.createElement("div", { className: `${classPrefix}-day-info-bottom` }, renderDayBottom(day)),
|
|
514
|
+
noStartNorEnd && !renderDayBottom && showToday && isCurrDay(month, day.day) && React__default.createElement("div", { className: `${classPrefix}-day-info-curr` }, locale.calendaritem.today),
|
|
515
|
+
startTip && React__default.createElement("div", { className: `${classPrefix}-day-info ${isStartAndEnd(currentDate) ? `${classPrefix}-day-info-top` : ""}` }, startText || locale.calendaritem.start),
|
|
516
|
+
endTip && React__default.createElement("div", { className: `${classPrefix}-day-info` }, endText || locale.calendaritem.end)
|
|
517
|
+
);
|
|
518
|
+
};
|
|
519
|
+
const renderPanel = (month, key) => {
|
|
520
|
+
return React__default.createElement(
|
|
521
|
+
"div",
|
|
522
|
+
{ className: `${classPrefix}-month`, key },
|
|
523
|
+
React__default.createElement("div", { className: `${classPrefix}-month-title` }, month.title),
|
|
524
|
+
React__default.createElement("div", { className: `${classPrefix}-days` }, month.monthData.map((day, i) => renderItem(month, day, i)))
|
|
525
|
+
);
|
|
526
|
+
};
|
|
511
527
|
const renderContent = () => {
|
|
512
528
|
return React__default.createElement(
|
|
513
529
|
"div",
|
|
@@ -516,26 +532,7 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
516
532
|
"div",
|
|
517
533
|
{ className: `${classPrefix}-pannel`, ref: monthsPanel },
|
|
518
534
|
React__default.createElement("div", { className: "viewArea", ref: viewAreaRef, style: { transform: `translateY(${translateY}px)` } }, monthsData.slice(monthDefaultRange[0], monthDefaultRange[1]).map((month, key) => {
|
|
519
|
-
return
|
|
520
|
-
"div",
|
|
521
|
-
{ className: `${classPrefix}-month`, key },
|
|
522
|
-
React__default.createElement("div", { className: `${classPrefix}-month-title` }, month.title),
|
|
523
|
-
React__default.createElement("div", { className: `${classPrefix}-days` }, month.monthData.map((day, i) => React__default.createElement(
|
|
524
|
-
"div",
|
|
525
|
-
{ className: [
|
|
526
|
-
`${classPrefix}-day`,
|
|
527
|
-
getClasses(day, month)
|
|
528
|
-
].join(" "), onClick: () => {
|
|
529
|
-
chooseDay(day, month);
|
|
530
|
-
}, key: i },
|
|
531
|
-
React__default.createElement("div", { className: `${classPrefix}-day-day` }, renderDay ? renderDay(day) : day.day),
|
|
532
|
-
!isStartTip(day, month) && renderDayTop && React__default.createElement("div", { className: `${classPrefix}-day-info-top` }, renderDayTop(day)),
|
|
533
|
-
!isStartTip(day, month) && !isEndTip(day, month) && renderDayBottom && React__default.createElement("div", { className: `${classPrefix}-day-info-bottom` }, renderDayBottom(day)),
|
|
534
|
-
!isStartTip(day, month) && !isEndTip(day, month) && !renderDayBottom && showToday && isCurrDay(month, day.day) && React__default.createElement("div", { className: `${classPrefix}-day-info-curr` }, locale.calendaritem.today),
|
|
535
|
-
isStartTip(day, month) && React__default.createElement("div", { className: `${classPrefix}-day-info ${isStartAndEnd(currentDate) ? `${classPrefix}-day-info-top` : ""}` }, startText || locale.calendaritem.start),
|
|
536
|
-
isEndTip(day, month) && React__default.createElement("div", { className: `${classPrefix}-day-info` }, endText || locale.calendaritem.end)
|
|
537
|
-
)))
|
|
538
|
-
);
|
|
535
|
+
return renderPanel(month, key);
|
|
539
536
|
}))
|
|
540
537
|
)
|
|
541
538
|
);
|