@nutui/nutui-react-taro 1.4.7 → 1.4.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.
Files changed (98) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/esm/Badge.js +2 -2
  3. package/dist/esm/Barrage.js +2 -2
  4. package/dist/esm/Calendar.js +3 -4
  5. package/dist/esm/CalendarItem.js +2 -3
  6. package/dist/esm/Cascader.js +4 -4
  7. package/dist/esm/Checkbox.js +2 -2
  8. package/dist/esm/CheckboxGroup.js +2 -2
  9. package/dist/esm/Col.js +3 -2
  10. package/dist/esm/Dialog.js +3 -2
  11. package/dist/esm/Ellipsis.js +2 -2
  12. package/dist/esm/InputNumber.js +2 -2
  13. package/dist/esm/Popover.js +2 -2
  14. package/dist/esm/Row.js +3 -2
  15. package/dist/esm/ShortPassword.js +2 -2
  16. package/dist/esm/Swipe.js +3 -2
  17. package/dist/esm/TabPane.js +2 -2
  18. package/dist/esm/Tabbar.js +2 -2
  19. package/dist/esm/Tabs.js +2 -2
  20. package/dist/esm/TextArea.js +2 -2
  21. package/dist/esm/Uploader.js +2 -2
  22. package/dist/esm/{badge.taro-11e2ec95.js → badge.taro-116b2521.js} +1 -0
  23. package/dist/esm/barrage.taro-5dbab093.js +94 -0
  24. package/dist/esm/calendar.taro-c95e6998.js +61 -0
  25. package/dist/esm/calendaritem.taro-86412398.js +761 -0
  26. package/dist/esm/{cascader.taro-e6610dd1.js → cascader.taro-e0fb7e63.js} +16 -22
  27. package/dist/esm/{checkbox.taro-04da7151.js → checkbox.taro-b76b1c82.js} +9 -6
  28. package/dist/esm/{col.taro-b61c7cba.js → col.taro-9e4c5cc0.js} +2 -1
  29. package/dist/esm/{dialog.taro-54df2e3f.js → dialog.taro-7608bd26.js} +7 -12
  30. package/dist/esm/{ellipsis.taro-aa39faf7.js → ellipsis.taro-5aa23940.js} +4 -3
  31. package/dist/esm/{inputnumber.taro-e909d932.js → inputnumber.taro-94c75663.js} +11 -21
  32. package/dist/esm/nutui-react.es.js +19 -19
  33. package/dist/esm/{popover.taro-fc7b9a73.js → popover.taro-f144cd02.js} +9 -7
  34. package/dist/esm/{row.taro-37a895de.js → row.taro-4e697aa2.js} +2 -1
  35. package/dist/esm/{shortpassword.taro-02ea4499.js → shortpassword.taro-53b7ee7b.js} +3 -2
  36. package/dist/esm/{swipe.taro-1eb95b21.js → swipe.taro-6532405d.js} +16 -24
  37. package/dist/esm/{tabbar.taro-08e48c43.js → tabbar.taro-17d898d9.js} +12 -7
  38. package/dist/esm/{tabpane.taro-91cd6cf4.js → tabpane.taro-9512e308.js} +3 -3
  39. package/dist/esm/{tabs.taro-5030ce68.js → tabs.taro-4629d66c.js} +5 -2
  40. package/dist/esm/{textarea.taro-42600f8c.js → textarea.taro-47addd05.js} +5 -1
  41. package/dist/esm/types/src/packages/calendar/calendar.taro.d.ts +22 -2
  42. package/dist/esm/types/src/packages/calendaritem/calendaritem.taro.d.ts +21 -3
  43. package/dist/esm/types/src/packages/cascader/cascader.d.ts +1 -0
  44. package/dist/esm/types/src/packages/cascader/cascader.taro.d.ts +1 -0
  45. package/dist/esm/types/src/packages/cascader/cascaderItem.d.ts +1 -0
  46. package/dist/esm/types/src/packages/cascader/cascaderItem.taro.d.ts +1 -0
  47. package/dist/esm/types/src/packages/checkbox/demo.d.ts +0 -1
  48. package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.d.ts +5 -0
  49. package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.taro.d.ts +5 -0
  50. package/dist/esm/types/src/packages/dialog/DialogWrap.d.ts +1 -1
  51. package/dist/esm/types/src/packages/dialog/DialogWrapper.taro.d.ts +11 -0
  52. package/dist/esm/types/src/packages/dialog/dialog.taro.d.ts +3 -2
  53. package/dist/esm/types/src/packages/dialog/index.taro.d.ts +2 -2
  54. package/dist/esm/types/src/packages/form/form.d.ts +3 -0
  55. package/dist/esm/types/src/packages/formitem/formitem.d.ts +2 -1
  56. package/dist/esm/types/src/packages/formitem/types.d.ts +1 -1
  57. package/dist/esm/types/src/packages/popover/popover.taro.d.ts +1 -1
  58. package/dist/esm/types/src/packages/shortpassword/shortpassword.d.ts +1 -0
  59. package/dist/esm/types/src/packages/shortpassword/shortpassword.taro.d.ts +1 -0
  60. package/dist/esm/types/src/packages/switch/switch.d.ts +2 -1
  61. package/dist/esm/types/src/packages/tabbar/tabbar.d.ts +1 -1
  62. package/dist/esm/types/src/packages/tabbar/tabbar.taro.d.ts +1 -1
  63. package/dist/esm/types/src/packages/tabbar/use-props-value.d.ts +7 -0
  64. package/dist/esm/types/src/packages/tabpane/tabpane.taro.d.ts +0 -1
  65. package/dist/esm/types/src/packages/tabs/tabs.d.ts +1 -0
  66. package/dist/esm/types/src/packages/tabs/tabs.taro.d.ts +1 -0
  67. package/dist/esm/types/src/packages/uploader/uploader.taro.d.ts +1 -0
  68. package/dist/esm/{uploader.taro-b7b770e6.js → uploader.taro-c830b573.js} +3 -2
  69. package/dist/locales/base.js +1 -1
  70. package/dist/locales/en-US.js +1 -1
  71. package/dist/locales/id-ID.js +1 -1
  72. package/dist/locales/zh-CN.js +1 -1
  73. package/dist/locales/zh-TW.js +1 -1
  74. package/dist/locales/zh-UG.js +1 -1
  75. package/dist/nutui.react.es.js +690 -412
  76. package/dist/nutui.react.umd.js +689 -411
  77. package/dist/packages/badge/badge.scss +11 -5
  78. package/dist/packages/barrage/barrage.scss +3 -3
  79. package/dist/packages/button/button.scss +1 -0
  80. package/dist/packages/cascader/cascader.scss +19 -5
  81. package/dist/packages/checkboxgroup/checkboxgroup.scss +33 -0
  82. package/dist/packages/collapseitem/collapseitem.scss +41 -17
  83. package/dist/packages/form/form.scss +3 -0
  84. package/dist/packages/inputnumber/inputnumber.scss +18 -1
  85. package/dist/packages/popover/popover.scss +71 -46
  86. package/dist/packages/radiogroup/radiogroup.scss +9 -8
  87. package/dist/packages/step/step.scss +135 -98
  88. package/dist/packages/switch/switch.scss +1 -1
  89. package/dist/packages/tabs/tabs.scss +24 -2
  90. package/dist/packages/textarea/textarea.scss +7 -1
  91. package/dist/style.css +1 -1
  92. package/dist/style.es.js +1 -1
  93. package/dist/styles/variables.scss +155 -33
  94. package/dist/types/index.d.ts +57 -33
  95. package/package.json +1 -1
  96. package/dist/esm/barrage.taro-e4fe81ae.js +0 -73
  97. package/dist/esm/calendar.taro-02479e8b.js +0 -38
  98. package/dist/esm/calendaritem.taro-3cfd4186.js +0 -571
@@ -1,38 +0,0 @@
1
- import React__default from 'react';
2
- import { P as Popup } from './popup.taro-4c18f46c.js';
3
- import { U as Utils, C as CalendarItem } from './calendaritem.taro-3cfd4186.js';
4
- import { u as useConfig } from './configprovider.taro-26882dd2.js';
5
-
6
- const defaultProps = {
7
- type: 'one',
8
- isAutoBackFill: false,
9
- poppable: true,
10
- visible: false,
11
- title: '日历选择',
12
- defaultValue: '',
13
- startDate: Utils.getDay(0),
14
- endDate: Utils.getDay(365),
15
- onClose: () => { },
16
- onChoose: (param) => { },
17
- };
18
- const Calendar = (props) => {
19
- const { locale } = useConfig();
20
- const { children, poppable, visible, type, isAutoBackFill, title, defaultValue, startDate, endDate, onClose, onChoose, } = { ...defaultProps, ...props };
21
- const close = () => {
22
- onClose && onClose();
23
- };
24
- const update = () => { };
25
- const choose = (param) => {
26
- close();
27
- onChoose && onChoose(param);
28
- };
29
- const closePopup = () => {
30
- close();
31
- };
32
- return (React__default.createElement(React__default.Fragment, null, poppable ? (React__default.createElement(Popup, { visible: visible, position: "bottom", round: true, duration: 0.5, closeable: true, destroyOnClose: true, onClickOverlay: closePopup, onClickCloseIcon: closePopup, style: { height: '85vh' } },
33
- React__default.createElement(CalendarItem, { type: type, isAutoBackFill: isAutoBackFill, poppable: poppable, title: locale.calendaritem.title || title, defaultValue: defaultValue, startDate: startDate, endDate: endDate, onUpdate: update, onClose: close, onChoose: choose }))) : (React__default.createElement(CalendarItem, { type: type, isAutoBackFill: isAutoBackFill, poppable: poppable, title: locale.calendaritem.title, defaultValue: defaultValue, startDate: startDate, endDate: endDate, onClose: close, onChoose: choose }))));
34
- };
35
- Calendar.defaultProps = defaultProps;
36
- Calendar.displayName = 'NutCalendar';
37
-
38
- export { Calendar as C };
@@ -1,571 +0,0 @@
1
- import React__default, { useState, useRef, useEffect } from 'react';
2
- import classNames from 'classnames';
3
- import { c as cn } from './bem-893ad28d.js';
4
- import { u as useConfig } from './configprovider.taro-26882dd2.js';
5
- import { g as getRectByTaro } from './useClientRect-4506e52f.js';
6
-
7
- const Utils = {
8
- /**
9
- * 是否为闫年
10
- * @return {Boolse} true|false
11
- */
12
- isLeapYear(y) {
13
- return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
14
- },
15
- /**
16
- * 返回星期数
17
- * @return {String}
18
- */
19
- getWhatDay(year, month, day) {
20
- const date = new Date(`${year}/${month}/${day}`);
21
- const index = date.getDay();
22
- const dayNames = [
23
- '星期日',
24
- '星期一',
25
- '星期二',
26
- '星期三',
27
- '星期四',
28
- '星期五',
29
- '星期六',
30
- ];
31
- return dayNames[index];
32
- },
33
- /**
34
- * 返回星期数
35
- * @return {Number}
36
- */
37
- getMonthPreDay(year, month) {
38
- const date = new Date(`${year}/${month}/01`);
39
- let day = date.getDay();
40
- if (day == 0) {
41
- day = 7;
42
- }
43
- return day;
44
- },
45
- /**
46
- * 返回月份天数
47
- * @return {Number}
48
- */
49
- getMonthDays(year, month) {
50
- if (/^0/.test(month)) {
51
- month = month.split('')[1];
52
- }
53
- return [
54
- 0,
55
- 31,
56
- this.isLeapYear(Number(year)) ? 29 : 28,
57
- 31,
58
- 30,
59
- 31,
60
- 30,
61
- 31,
62
- 31,
63
- 30,
64
- 31,
65
- 30,
66
- 31,
67
- ][month];
68
- },
69
- /**
70
- * 补齐数字位数
71
- * @return {string}
72
- */
73
- getNumTwoBit(n) {
74
- n = Number(n);
75
- return (n > 9 ? '' : '0') + n;
76
- },
77
- /**
78
- * 日期对象转成字符串
79
- * @return {string}
80
- */
81
- date2Str(date, split) {
82
- split = split || '-';
83
- const y = date.getFullYear();
84
- const m = this.getNumTwoBit(date.getMonth() + 1);
85
- const d = this.getNumTwoBit(date.getDate());
86
- return [y, m, d].join(split);
87
- },
88
- /**
89
- * 返回日期格式字符串
90
- * @param {Number} 0返回今天的日期、1返回明天的日期,2返回后天得日期,依次类推
91
- * @return {string} '2014-12-31'
92
- */
93
- getDay(i) {
94
- i = i || 0;
95
- let date = new Date();
96
- const diff = i * (1000 * 60 * 60 * 24);
97
- date = new Date(date.getTime() + diff);
98
- return this.date2Str(date);
99
- },
100
- /**
101
- * 时间比较
102
- * @return {Boolean}
103
- */
104
- compareDate(date1, date2) {
105
- const startTime = new Date(date1.replace('-', '/').replace('-', '/'));
106
- const endTime = new Date(date2.replace('-', '/').replace('-', '/'));
107
- if (startTime >= endTime) {
108
- return false;
109
- }
110
- return true;
111
- },
112
- /**
113
- * 时间是否相等
114
- * @return {Boolean}
115
- */
116
- isEqual(date1, date2) {
117
- const startTime = new Date(date1).getTime();
118
- const endTime = new Date(date2).getTime();
119
- if (startTime == endTime) {
120
- return true;
121
- }
122
- return false;
123
- },
124
- };
125
-
126
- function requestAniFrame() {
127
- if (typeof window !== 'undefined') {
128
- return (window.requestAnimationFrame ||
129
- function (callback) {
130
- window.setTimeout(callback, 1000 / 60);
131
- });
132
- }
133
- return function (callback) {
134
- setTimeout(callback, 1000 / 60);
135
- };
136
- }
137
- var requestAniFrame$1 = requestAniFrame();
138
-
139
- const defaultProps = {
140
- type: 'one',
141
- isAutoBackFill: false,
142
- poppable: true,
143
- visible: false,
144
- title: '日历选择',
145
- defaultValue: '',
146
- startDate: Utils.getDay(0),
147
- endDate: Utils.getDay(365),
148
- onChoose: (data) => { },
149
- onUpdate: () => { },
150
- onClose: () => { },
151
- };
152
- const CalendarItem = (props) => {
153
- const { locale } = useConfig();
154
- const { type, isAutoBackFill, poppable, title, defaultValue, startDate, endDate, onChoose, onUpdate, onClose, } = { ...defaultProps, ...props };
155
- const weeks = locale.calendaritem.weekdays;
156
- const [yearMonthTitle, setYearMonthTitle] = useState('');
157
- const [unLoadPrev, setUnLoadPrev] = useState(false);
158
- const [monthsData, setMonthsData] = useState([]);
159
- const [state] = useState({
160
- currDate: '',
161
- touchParams: {
162
- startY: 0,
163
- endY: 0,
164
- startTime: 0,
165
- endTime: 0,
166
- lastY: 0,
167
- lastTime: 0,
168
- },
169
- transformY: 0,
170
- translateY: 0,
171
- scrollDistance: 0,
172
- defaultData: [],
173
- chooseData: [],
174
- monthsData: [],
175
- dayPrefix: 'calendar-month-day',
176
- startData: '',
177
- endData: '',
178
- isRange: type === 'range',
179
- timer: 0,
180
- });
181
- const weeksPanel = useRef(null);
182
- const months = useRef(null);
183
- const monthsPanel = useRef(null);
184
- const b = cn('calendar');
185
- const classes = classNames({
186
- [`${b('')}-tile`]: !poppable,
187
- [`${b('')}-nofooter`]: !!isAutoBackFill,
188
- }, b(''));
189
- const headerClasses = classNames({
190
- [`${b('')}-header`]: true,
191
- [`${b('')}-header-tile`]: !poppable,
192
- });
193
- const monthitemclasses = classNames({
194
- 'calendar-month-item': true,
195
- [`${type === 'range' ? 'month-item-range' : ''}`]: true,
196
- });
197
- const splitDate = (date) => {
198
- return date.split('-');
199
- };
200
- const isStart = (currDate) => {
201
- return Utils.isEqual(state.currDate[0], currDate);
202
- };
203
- const isEnd = (currDate) => {
204
- return Utils.isEqual(state.currDate[1], currDate);
205
- };
206
- const getCurrDate = (day, month, isRange) => {
207
- return isRange
208
- ? `${month.curData[3]}-${month.curData[4]}-${Utils.getNumTwoBit(+day.day)}`
209
- : `${month.curData[0]}-${month.curData[1]}-${Utils.getNumTwoBit(+day.day)}`;
210
- };
211
- const getClass = (day, month, isRange) => {
212
- const currDate = getCurrDate(day, month, isRange);
213
- if (day.type === 'curr') {
214
- if ((!state.isRange && Utils.isEqual(state.currDate, currDate)) ||
215
- (state.isRange && (isStart(currDate) || isEnd(currDate)))) {
216
- return `${state.dayPrefix}-active`;
217
- }
218
- if ((startDate && Utils.compareDate(currDate, startDate)) ||
219
- (endDate && Utils.compareDate(endDate, currDate))) {
220
- return `${state.dayPrefix}-disabled`;
221
- }
222
- if (state.isRange &&
223
- Array.isArray(state.currDate) &&
224
- Object.values(state.currDate).length === 2 &&
225
- Utils.compareDate(state.currDate[0], currDate) &&
226
- Utils.compareDate(currDate, state.currDate[1])) {
227
- return `${state.dayPrefix}-choose`;
228
- }
229
- return null;
230
- }
231
- return `${state.dayPrefix}-disabled`;
232
- };
233
- const isActive = (day, month) => {
234
- return (state.isRange &&
235
- day.type === 'curr' &&
236
- getClass(day, month) === 'calendar-month-day-active');
237
- };
238
- const isCurrDay = (month, day) => {
239
- const date = `${month.curData[0]}-${month.curData[1]}-${day}`;
240
- return Utils.isEqual(date, Utils.date2Str(new Date()));
241
- };
242
- const confirm = () => {
243
- if ((state.isRange && state.chooseData.length === 2) || !state.isRange) {
244
- onChoose && onChoose(state.chooseData);
245
- if (poppable) {
246
- onUpdate && onUpdate();
247
- }
248
- }
249
- };
250
- const chooseDay = (day, month, isFirst, isRange) => {
251
- if (getClass(day, month, isRange) !== `${state.dayPrefix}-disabled`) {
252
- let days = [...month.curData];
253
- days = isRange ? days.splice(3) : days.splice(0, 3);
254
- days[2] =
255
- typeof day.day === 'number' ? Utils.getNumTwoBit(day.day) : day.day;
256
- days[3] = `${days[0]}-${days[1]}-${days[2]}`;
257
- days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
258
- if (!state.isRange) {
259
- state.currDate = days[3];
260
- state.chooseData = [...days];
261
- }
262
- else {
263
- if (Object.values(state.currDate).length === 2) {
264
- state.currDate = [days[3]];
265
- }
266
- else if (Utils.compareDate(state.currDate[0], days[3])) {
267
- Array.isArray(state.currDate) && state.currDate.push(days[3]);
268
- }
269
- else {
270
- Array.isArray(state.currDate) && state.currDate.unshift(days[3]);
271
- }
272
- if (state.chooseData.length === 2 || !state.chooseData.length) {
273
- state.chooseData = [...days];
274
- }
275
- else if (Utils.compareDate(state.chooseData[3], days[3])) {
276
- state.chooseData = [[...state.chooseData], [...days]];
277
- }
278
- else {
279
- state.chooseData = [[...days], [...state.chooseData]];
280
- }
281
- }
282
- if (isAutoBackFill && !isFirst) {
283
- confirm();
284
- }
285
- setMonthsData(state.monthsData.slice());
286
- }
287
- };
288
- const isStartTip = (day, month) => {
289
- if (isActive(day, month)) {
290
- return isStart(getCurrDate(day, month));
291
- }
292
- return false;
293
- };
294
- // 是否有结束提示
295
- const isEndTip = (day, month) => {
296
- if (isStartTip(day, month)) {
297
- return false;
298
- }
299
- return isActive(day, month);
300
- };
301
- // 获取当前月数据
302
- const getCurrData = (type) => {
303
- const monthData = type === 'prev'
304
- ? state.monthsData[0]
305
- : state.monthsData[state.monthsData.length - 1];
306
- let year = parseInt(monthData.curData[0]);
307
- let month = parseInt(monthData.curData[1].toString().replace(/^0/, ''));
308
- switch (type) {
309
- case 'prev':
310
- month === 1 && (year -= 1);
311
- month = month === 1 ? 12 : --month;
312
- break;
313
- case 'next':
314
- month === 12 && (year += 1);
315
- month = month === 12 ? 1 : ++month;
316
- break;
317
- }
318
- return [
319
- year,
320
- Utils.getNumTwoBit(month),
321
- Utils.getMonthDays(String(year), String(month)),
322
- ];
323
- };
324
- // 获取日期状态
325
- const getDaysStatus = (days, type) => {
326
- // 修复:当某个月的1号是周日时,月份下方会空出来一行
327
- if (type === 'prev' && days >= 7) {
328
- days -= 7;
329
- }
330
- return Array.from(Array(days), (v, k) => {
331
- return {
332
- day: k + 1,
333
- type,
334
- };
335
- });
336
- };
337
- // 获取月数据
338
- const getMonth = (curData, type) => {
339
- const preMonthDays = Utils.getMonthPreDay(+curData[0], +curData[1]);
340
- const currMonthDays = Utils.getMonthDays(curData[0], curData[1]);
341
- const title = {
342
- year: curData[0],
343
- month: curData[1],
344
- };
345
- const monthInfo = {
346
- curData,
347
- title: locale.calendaritem.monthTitle(title.year, title.month),
348
- monthData: [
349
- ...getDaysStatus(preMonthDays, 'prev'),
350
- ...getDaysStatus(currMonthDays, 'curr'),
351
- ],
352
- };
353
- if (type === 'next') {
354
- if (!state.endData ||
355
- !Utils.compareDate(`${state.endData[0]}-${state.endData[1]}-${Utils.getMonthDays(state.endData[0], state.endData[1])}`, `${curData[0]}-${curData[1]}-${curData[2]}`)) {
356
- state.monthsData.push(monthInfo);
357
- }
358
- }
359
- else if (!state.startData ||
360
- !Utils.compareDate(`${curData[0]}-${curData[1]}-${curData[2]}`, `${state.startData[0]}-${state.startData[1]}-01`)) {
361
- state.monthsData.unshift(monthInfo);
362
- }
363
- else {
364
- setUnLoadPrev(true);
365
- }
366
- setMonthsData(state.monthsData);
367
- };
368
- // 监听月份滚动,改变月份标题
369
- const loadScroll = () => {
370
- if (!props.poppable) {
371
- return false;
372
- }
373
- requestAniFrame$1(async () => {
374
- if (weeksPanel?.current && monthsPanel?.current) {
375
- const weeksPanelRes = await getRectByTaro(weeksPanel?.current);
376
- weeksPanelRes?.bottom;
377
- const monthsDoms = monthsPanel.current.getElementsByClassName('calendar-month');
378
- for (let i = 0; i < monthsDoms.length; i++) {
379
- }
380
- }
381
- });
382
- };
383
- // 设置月份滚动距离和速度
384
- const setTransform = (translateY = 0, type, time = 1000) => {
385
- if (monthsPanel?.current) {
386
- if (type === 'end') {
387
- monthsPanel.current.style.webkitTransition = `transform ${time}ms cubic-bezier(0.19, 1, 0.22, 1)`;
388
- clearTimeout(state.timer);
389
- state.timer = window.setTimeout(() => {
390
- loadScroll();
391
- }, time);
392
- }
393
- else {
394
- monthsPanel.current.style.webkitTransition = '';
395
- loadScroll();
396
- }
397
- monthsPanel.current.style.webkitTransform = `translateY(${translateY}px)`;
398
- state.scrollDistance = translateY;
399
- }
400
- };
401
- // 计算滚动方向和距离
402
- const setMove = (move, type, time) => {
403
- let updateMove = move + state.transformY;
404
- const h = months.current?.offsetHeight || 0;
405
- const offsetHeight = monthsPanel.current?.offsetHeight || 0;
406
- if (type === 'end') {
407
- // 限定滚动距离
408
- if (updateMove > 0) {
409
- updateMove = 0;
410
- }
411
- if (updateMove < 0 && updateMove < -offsetHeight + h) {
412
- updateMove = -offsetHeight + h;
413
- }
414
- if (offsetHeight <= h && state.monthsData.length === 1) {
415
- updateMove = 0;
416
- }
417
- setTransform(updateMove, type, time);
418
- }
419
- else {
420
- if (updateMove > 0 && updateMove > 100) {
421
- updateMove = 100;
422
- }
423
- if (updateMove < -offsetHeight + h - 100 && state.monthsData.length > 1) {
424
- updateMove = -offsetHeight + h - 100;
425
- }
426
- if (updateMove < 0 &&
427
- updateMove < -100 &&
428
- state.monthsData.length === 1) {
429
- updateMove = -100;
430
- }
431
- setTransform(updateMove);
432
- }
433
- };
434
- const onTouchStart = (event) => {
435
- event.stopPropagation();
436
- const changedTouches = event.changedTouches[0];
437
- state.touchParams.startY = changedTouches.pageY;
438
- state.touchParams.startTime = event.timeStamp || Date.now();
439
- state.transformY = state.scrollDistance;
440
- };
441
- const onTouchMove = (event) => {
442
- event.stopPropagation();
443
- const changedTouches = event.changedTouches[0];
444
- state.touchParams.lastY = changedTouches.pageY;
445
- state.touchParams.lastTime = event.timeStamp || Date.now();
446
- const move = state.touchParams.lastY - state.touchParams.startY;
447
- if (Math.abs(move) < 5) {
448
- return false;
449
- }
450
- setMove(move);
451
- };
452
- const onTouchEnd = (event) => {
453
- event.stopPropagation();
454
- const changedTouches = event.changedTouches[0];
455
- state.touchParams.lastY = changedTouches.pageY;
456
- state.touchParams.lastTime = event.timeStamp || Date.now();
457
- let move = state.touchParams.lastY - state.touchParams.startY;
458
- if (Math.abs(move) < 5) {
459
- return false;
460
- }
461
- const updateMove = move + state.transformY;
462
- const h = months.current?.offsetHeight || 0;
463
- const offsetHeight = monthsPanel.current?.offsetHeight || 0;
464
- if (updateMove > 0) {
465
- getMonth(getCurrData('prev'), 'prev');
466
- }
467
- else if (updateMove < 0 &&
468
- updateMove < -offsetHeight + (Math.abs(move) > h ? Math.abs(move) : h) * 5) {
469
- getMonth(getCurrData('next'), 'next');
470
- if (Math.abs(move) >= 300) {
471
- getMonth(getCurrData('next'), 'next');
472
- }
473
- }
474
- let moveTime = state.touchParams.lastTime - state.touchParams.startTime;
475
- if (moveTime <= 300) {
476
- move *= 2;
477
- moveTime += 1000;
478
- setMove(move, 'end', moveTime);
479
- }
480
- else {
481
- setMove(move, 'end');
482
- }
483
- };
484
- const initData = () => {
485
- // 初始化开始结束数据
486
- state.startData = startDate ? splitDate(startDate) : '';
487
- state.endData = endDate ? splitDate(endDate) : '';
488
- // 初始化当前日期
489
- if (!defaultValue) {
490
- state.currDate = state.isRange
491
- ? [Utils.date2Str(new Date()), Utils.getDay(1)]
492
- : Utils.date2Str(new Date());
493
- }
494
- else {
495
- state.currDate = state.isRange ? [...defaultValue] : defaultValue;
496
- }
497
- // 日期转化为数组
498
- if (state.isRange && Array.isArray(state.currDate)) {
499
- if (startDate &&
500
- Utils.compareDate(state.currDate[0], startDate)) {
501
- state.currDate.splice(0, 1, startDate);
502
- }
503
- if (endDate && Utils.compareDate(endDate, state.currDate[1])) {
504
- state.currDate.splice(1, 1, endDate);
505
- }
506
- state.defaultData = [
507
- ...splitDate(state.currDate[0]),
508
- ...splitDate(state.currDate[1]),
509
- ];
510
- }
511
- else {
512
- if (startDate &&
513
- Utils.compareDate(state.currDate, startDate)) {
514
- state.currDate = startDate;
515
- }
516
- else if (endDate &&
517
- !Utils.compareDate(state.currDate, endDate)) {
518
- state.currDate = endDate;
519
- }
520
- state.defaultData = [...splitDate(state.currDate)];
521
- }
522
- getMonth(state.defaultData, 'next');
523
- setYearMonthTitle(state.monthsData[0].title);
524
- let i = 1;
525
- do {
526
- getMonth(getCurrData('next'), 'next');
527
- } while (i++ < 4);
528
- if (state.isRange) {
529
- chooseDay({ day: state.defaultData[2], type: 'curr' }, state.monthsData[0], true);
530
- chooseDay({ day: state.defaultData[5], type: 'curr' }, state.monthsData[0], true, true);
531
- }
532
- else {
533
- chooseDay({ day: state.defaultData[2], type: 'curr' }, state.monthsData[0], true);
534
- }
535
- };
536
- useEffect(() => {
537
- initData();
538
- }, []);
539
- return (React__default.createElement(React__default.Fragment, null,
540
- React__default.createElement("div", { className: classes },
541
- React__default.createElement("div", { className: headerClasses },
542
- poppable ? (React__default.createElement(React__default.Fragment, null,
543
- React__default.createElement("div", { className: "calendar-title" }, locale.calendaritem.title),
544
- React__default.createElement("div", { className: "calendar-curr-month" }, yearMonthTitle))) : (''),
545
- React__default.createElement("div", { className: "calendar-weeks", ref: weeksPanel }, weeks.map((item) => (React__default.createElement("div", { className: "calendar-week-item", key: item }, item))))),
546
- React__default.createElement("div", { className: "nut-calendar-content", onTouchStart: onTouchStart, onTouchMove: onTouchMove, onTouchEnd: onTouchEnd, ref: months },
547
- React__default.createElement("div", { className: "calendar-months-panel", ref: monthsPanel },
548
- React__default.createElement("div", { className: "calendar-loading-tip" }, !unLoadPrev
549
- ? locale.calendaritem.loadPreviousMonth
550
- : locale.calendaritem.noEarlierMonth),
551
- monthsData.map((month, key) => (React__default.createElement("div", { className: "calendar-month", key: key },
552
- React__default.createElement("div", { className: "calendar-month-title" }, month.title),
553
- React__default.createElement("div", { className: "calendar-month-con" },
554
- React__default.createElement("div", { className: monthitemclasses }, month.monthData &&
555
- month.monthData.map((day, index) => (React__default.createElement("div", { className: [
556
- 'calendar-month-day',
557
- getClass(day, month),
558
- ].join(' '), key: index, onClick: () => {
559
- chooseDay(day, month);
560
- } },
561
- React__default.createElement("div", { className: "calendar-day" }, day.type === 'curr' ? day.day : ''),
562
- isCurrDay(month, day.day) ? (React__default.createElement("div", { className: "calendar-curr-tip-curr" }, locale.calendaritem.today)) : (''),
563
- isStartTip(day, month) ? (React__default.createElement("div", { className: "calendar-day-tip" }, locale.calendaritem.start)) : (''),
564
- isEndTip(day, month) ? (React__default.createElement("div", { className: "calendar-day-tip" }, locale.calendaritem.end)) : (''))))))))))),
565
- poppable && !isAutoBackFill ? (React__default.createElement("div", { className: "nut-calendar-footer" },
566
- React__default.createElement("div", { className: "calendar-confirm-btn", onClick: confirm }, locale.confirm))) : (''))));
567
- };
568
- CalendarItem.defaultProps = defaultProps;
569
- CalendarItem.displayName = 'NutCalendarItem';
570
-
571
- export { CalendarItem as C, Utils as U };