@douyinfe/semi-foundation 2.31.2 → 2.32.0-beta.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.
Files changed (67) hide show
  1. package/cascader/foundation.ts +8 -1
  2. package/datePicker/_utils/getDefaultFormatToken.ts +1 -0
  3. package/datePicker/_utils/getInsetInputFormatToken.ts +1 -0
  4. package/datePicker/_utils/getInsetInputValueFromInsetInputStr.ts +1 -0
  5. package/datePicker/constants.ts +1 -1
  6. package/datePicker/datePicker.scss +33 -6
  7. package/datePicker/foundation.ts +132 -74
  8. package/datePicker/inputFoundation.ts +8 -2
  9. package/datePicker/variables.scss +6 -4
  10. package/datePicker/yearAndMonthFoundation.ts +65 -18
  11. package/lib/cjs/cascader/foundation.d.ts +2 -0
  12. package/lib/cjs/datePicker/_utils/getDefaultFormatToken.d.ts +1 -0
  13. package/lib/cjs/datePicker/_utils/getDefaultFormatToken.js +2 -1
  14. package/lib/cjs/datePicker/_utils/getInsetInputFormatToken.js +1 -0
  15. package/lib/cjs/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +1 -0
  16. package/lib/cjs/datePicker/constants.d.ts +1 -1
  17. package/lib/cjs/datePicker/constants.js +1 -1
  18. package/lib/cjs/datePicker/datePicker.css +29 -11
  19. package/lib/cjs/datePicker/datePicker.scss +33 -6
  20. package/lib/cjs/datePicker/foundation.d.ts +34 -6
  21. package/lib/cjs/datePicker/foundation.js +145 -69
  22. package/lib/cjs/datePicker/inputFoundation.d.ts +1 -1
  23. package/lib/cjs/datePicker/inputFoundation.js +13 -1
  24. package/lib/cjs/datePicker/variables.scss +6 -4
  25. package/lib/cjs/datePicker/yearAndMonthFoundation.d.ts +66 -13
  26. package/lib/cjs/datePicker/yearAndMonthFoundation.js +55 -14
  27. package/lib/cjs/modal/modal.css +1 -0
  28. package/lib/cjs/modal/modal.scss +1 -0
  29. package/lib/cjs/modal/variables.scss +1 -0
  30. package/lib/cjs/sideSheet/sideSheet.css +10 -0
  31. package/lib/cjs/sideSheet/sideSheet.scss +15 -0
  32. package/lib/cjs/sideSheet/variables.scss +6 -0
  33. package/lib/cjs/switch/foundation.js +0 -3
  34. package/lib/cjs/treeSelect/foundation.d.ts +3 -0
  35. package/lib/cjs/treeSelect/foundation.js +3 -2
  36. package/lib/es/cascader/foundation.d.ts +2 -0
  37. package/lib/es/datePicker/_utils/getDefaultFormatToken.d.ts +1 -0
  38. package/lib/es/datePicker/_utils/getDefaultFormatToken.js +2 -1
  39. package/lib/es/datePicker/_utils/getInsetInputFormatToken.js +1 -0
  40. package/lib/es/datePicker/_utils/getInsetInputValueFromInsetInputStr.js +1 -0
  41. package/lib/es/datePicker/constants.d.ts +1 -1
  42. package/lib/es/datePicker/constants.js +1 -1
  43. package/lib/es/datePicker/datePicker.css +29 -11
  44. package/lib/es/datePicker/datePicker.scss +33 -6
  45. package/lib/es/datePicker/foundation.d.ts +34 -6
  46. package/lib/es/datePicker/foundation.js +145 -69
  47. package/lib/es/datePicker/inputFoundation.d.ts +1 -1
  48. package/lib/es/datePicker/inputFoundation.js +13 -1
  49. package/lib/es/datePicker/variables.scss +6 -4
  50. package/lib/es/datePicker/yearAndMonthFoundation.d.ts +66 -13
  51. package/lib/es/datePicker/yearAndMonthFoundation.js +58 -14
  52. package/lib/es/modal/modal.css +1 -0
  53. package/lib/es/modal/modal.scss +1 -0
  54. package/lib/es/modal/variables.scss +1 -0
  55. package/lib/es/sideSheet/sideSheet.css +10 -0
  56. package/lib/es/sideSheet/sideSheet.scss +15 -0
  57. package/lib/es/sideSheet/variables.scss +6 -0
  58. package/lib/es/switch/foundation.js +0 -3
  59. package/lib/es/treeSelect/foundation.d.ts +3 -0
  60. package/lib/es/treeSelect/foundation.js +3 -2
  61. package/modal/modal.scss +1 -0
  62. package/modal/variables.scss +1 -0
  63. package/package.json +2 -2
  64. package/sideSheet/sideSheet.scss +15 -0
  65. package/sideSheet/variables.scss +6 -0
  66. package/switch/foundation.ts +2 -3
  67. package/treeSelect/foundation.ts +6 -3
@@ -127,9 +127,7 @@ class DatePickerFoundation extends _foundation.default {
127
127
  this._adapter.updatePrevTimezone(prevTimeZone); // reset input value when value update
128
128
 
129
129
 
130
- this._adapter.updateInputValue(null);
131
-
132
- this._adapter.updateInsetInputValue(null);
130
+ this.clearInputValue();
133
131
 
134
132
  this._adapter.updateValue(result);
135
133
 
@@ -216,7 +214,8 @@ class DatePickerFoundation extends _foundation.default {
216
214
 
217
215
  destroy() {
218
216
  // Ensure that event listeners will be uninstalled and users may not trigger closePanel
219
- // this._adapter.togglePanel(false);
217
+ this._adapter.togglePanel(false);
218
+
220
219
  this._adapter.unregisterClickOutSide();
221
220
  }
222
221
 
@@ -235,52 +234,47 @@ class DatePickerFoundation extends _foundation.default {
235
234
  openPanel() {
236
235
  if (!this.getProp('disabled')) {
237
236
  if (!this._isControlledComponent('open')) {
238
- this._adapter.togglePanel(true);
239
-
240
- this._adapter.registerClickOutSide();
237
+ this.open();
241
238
  }
242
239
 
243
240
  this._adapter.notifyOpenChange(true);
244
241
  }
245
242
  }
246
243
  /**
244
+ * @deprecated
247
245
  * do these side effects when type is dateRange or dateTimeRange
248
246
  * 1. trigger input blur, if input value is invalid, set input value and state value to previous status
249
247
  * 2. set cachedSelectedValue using given dates(in needConfirm mode)
250
248
  * - directly closePanel without click confirm will set cachedSelectedValue to state value
251
249
  * - select one date(which means that the selection value is incomplete) and click confirm also set cachedSelectedValue to state value
252
250
  */
251
+ // rangeTypeSideEffectsWhenClosePanel(inputValue: string, willUpdateDates: Date[]) {
252
+ // if (this._isRangeType()) {
253
+ // this._adapter.setRangeInputFocus(false);
254
+ // /**
255
+ // * inputValue is string when it is not disabled or can't parsed
256
+ // * when inputValue is null, picker value will back to last selected value
257
+ // */
258
+ // this.handleInputBlur(inputValue);
259
+ // this.resetCachedSelectedValue(willUpdateDates);
260
+ // }
261
+ // }
253
262
 
254
-
255
- rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates) {
256
- if (this._isRangeType()) {
257
- this._adapter.setRangeInputFocus(false);
258
- /**
259
- * inputValue is string when it is not disabled or can't parsed
260
- * when inputValue is null, picker value will back to last selected value
261
- */
262
-
263
-
264
- this.handleInputBlur(inputValue);
265
- this.resetCachedSelectedValue(willUpdateDates);
266
- }
267
- }
268
263
  /**
264
+ * @deprecated
269
265
  * clear input value when selected date is not confirmed
270
266
  */
267
+ // needConfirmSideEffectsWhenClosePanel(willUpdateDates: Date[] | null | undefined) {
268
+ // if (this._adapter.needConfirm() && !this._isRangeType()) {
269
+ // /**
270
+ // * if `null` input element will show `cachedSelectedValue` formatted value(format in DateInput render)
271
+ // * if `` input element will show `` directly
272
+ // */
273
+ // this._adapter.updateInputValue(null);
274
+ // this.resetCachedSelectedValue(willUpdateDates);
275
+ // }
276
+ // }
271
277
 
272
-
273
- needConfirmSideEffectsWhenClosePanel(willUpdateDates) {
274
- if (this._adapter.needConfirm() && !this._isRangeType()) {
275
- /**
276
- * if `null` input element will show `cachedSelectedValue` formatted value(format in DateInput render)
277
- * if `` input element will show `` directly
278
- */
279
- this._adapter.updateInputValue(null);
280
-
281
- this.resetCachedSelectedValue(willUpdateDates);
282
- }
283
- }
284
278
  /**
285
279
  * clear inset input value when close panel
286
280
  */
@@ -337,20 +331,114 @@ class DatePickerFoundation extends _foundation.default {
337
331
  const willUpdateDates = (0, _isNullOrUndefined.default)(dates) ? value : dates;
338
332
 
339
333
  if (!this._isControlledComponent('open')) {
340
- this._adapter.togglePanel(false);
334
+ this.close();
335
+ } else {
336
+ this.resetInnerSelectedStates(willUpdateDates);
337
+ }
341
338
 
342
- this._adapter.unregisterClickOutSide();
343
- } // range type picker, closing panel requires the following side effects
339
+ this._adapter.notifyOpenChange(false);
340
+ }
344
341
 
342
+ open() {
343
+ this._adapter.togglePanel(true);
345
344
 
346
- this.rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates);
347
- this.needConfirmSideEffectsWhenClosePanel(willUpdateDates);
348
- this.clearInsetInputValue();
345
+ this._adapter.registerClickOutSide();
346
+ }
349
347
 
350
- this._adapter.notifyOpenChange(false);
348
+ close() {
349
+ this._adapter.togglePanel(false, () => this.resetInnerSelectedStates());
350
+
351
+ this._adapter.unregisterClickOutSide();
352
+ }
353
+
354
+ focus(focusType) {
355
+ if (this._isRangeType()) {
356
+ const rangeInputFocus = focusType !== null && focusType !== void 0 ? focusType : 'rangeStart';
357
+
358
+ this._adapter.setRangeInputFocus(rangeInputFocus);
359
+ } else {
360
+ this._adapter.setInputFocus();
361
+ }
362
+ }
363
+
364
+ blur() {
365
+ if (this._isRangeType()) {
366
+ this._adapter.setRangeInputBlur();
367
+ } else {
368
+ this._adapter.setInputBlur();
369
+ }
370
+ }
371
+ /**
372
+ * reset cachedSelectedValue, inputValue when close panel
373
+ */
374
+
375
+
376
+ resetInnerSelectedStates(willUpdateDates) {
377
+ const {
378
+ value
379
+ } = this._adapter.getStates();
380
+
381
+ const needResetCachedSelectedValue = !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
382
+
383
+ if (needResetCachedSelectedValue) {
384
+ this.resetCachedSelectedValue(value);
385
+ }
386
+
387
+ this.resetFocus();
388
+ this.clearInputValue();
389
+ this.clickConfirmButton = false;
390
+ }
391
+
392
+ resetFocus(e) {
393
+ this._adapter.setRangeInputFocus(false);
351
394
 
352
395
  this._adapter.notifyBlur(e);
353
396
  }
397
+ /**
398
+ * cachedSelectedValue can be `(Date|null)[]` or `null`
399
+ */
400
+
401
+
402
+ isCachedSelectedValueValid(dates) {
403
+ const cachedSelectedValue = dates || this._adapter.getState('cachedSelectedValue');
404
+
405
+ const {
406
+ type
407
+ } = this._adapter.getProps();
408
+
409
+ let isValid = true;
410
+
411
+ switch (true) {
412
+ case type === 'dateRange':
413
+ case type === 'dateTimeRange':
414
+ if (!this._isRangeValueComplete(cachedSelectedValue)) {
415
+ isValid = false;
416
+ }
417
+
418
+ break;
419
+
420
+ default:
421
+ const value = cachedSelectedValue === null || cachedSelectedValue === void 0 ? void 0 : cachedSelectedValue.filter(item => item);
422
+
423
+ if (!(Array.isArray(value) && value.length)) {
424
+ isValid = false;
425
+ }
426
+
427
+ break;
428
+ }
429
+
430
+ return isValid;
431
+ }
432
+ /**
433
+ * 将输入框内容置空
434
+ */
435
+
436
+
437
+ clearInputValue() {
438
+ this._adapter.updateInputValue(null);
439
+
440
+ this._adapter.updateInsetInputValue(null);
441
+ }
354
442
  /**
355
443
  * Callback when the content of the input box changes
356
444
  * Update the date panel if the changed value is a legal date, otherwise only update the input box
@@ -453,36 +541,12 @@ class DatePickerFoundation extends _foundation.default {
453
541
  * @param {String} input
454
542
  * @param {Event} e
455
543
  */
544
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
456
545
 
457
546
 
458
547
  handleInputBlur() {
459
548
  let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
460
549
  let e = arguments.length > 1 ? arguments[1] : undefined;
461
- const parsedResult = input ? this._isMultiple() ? this.parseMultipleInput(input, ',', true) : this.parseInput(input) : [];
462
- const stateValue = this.getState('value'); // console.log(input, parsedResult);
463
-
464
- if (parsedResult && parsedResult.length) {
465
- this._updateValueAndInput(parsedResult, input === '');
466
- } else if (input === '') {
467
- // if clear input, set input to `''`
468
- this._updateValueAndInput('', true, '');
469
- } else {
470
- this._updateValueAndInput(stateValue);
471
- }
472
- /**
473
- * 当不是范围类型且不需要确认时,使用 stateValue 重置 cachedSelectedValue
474
- * 这样做的目的是,在输入非法值时,使用上次选中的值作为已选值
475
- * needConfirm 或者 range type 时,我们在 close panel 时调用 resetCachedSelectedValue,这里不用重复调用
476
- *
477
- * Use stateValue to reset cachedSelectedValue when it is not a range type and does not require confirmation
478
- * The purpose of this is to use the last selected value as the selected value when an invalid value is entered
479
- * When needConfirm or range type, we call resetCachedSelectedValue when close panel, no need to call repeatedly here
480
- */
481
-
482
-
483
- if (!this._adapter.needConfirm() && !this._isRangeType()) {
484
- this.resetCachedSelectedValue(stateValue);
485
- }
486
550
  }
487
551
  /**
488
552
  * called when range type rangeEnd input tab press
@@ -617,6 +681,7 @@ class DatePickerFoundation extends _foundation.default {
617
681
 
618
682
  case 'dateRange':
619
683
  case 'dateTimeRange':
684
+ case 'monthRange':
620
685
  const separator = rangeSeparator;
621
686
  const values = input.split(separator);
622
687
  parsedResult = values && values.reduce((arr, cur) => {
@@ -840,6 +905,7 @@ class DatePickerFoundation extends _foundation.default {
840
905
 
841
906
  case 'dateRange':
842
907
  case 'dateTimeRange':
908
+ case 'monthRange':
843
909
  const startIsTruthy = !(0, _isNullOrUndefined.default)(dates[0]);
844
910
  const endIsTruthy = !(0, _isNullOrUndefined.default)(dates[1]);
845
911
 
@@ -888,6 +954,7 @@ class DatePickerFoundation extends _foundation.default {
888
954
 
889
955
  case 'dateRange':
890
956
  case 'dateTimeRange':
957
+ case 'monthRange':
891
958
  for (let i = 0; i < dates.length; i += 2) {
892
959
  strs.push(this.formatDates(dates.slice(i, i + 2), customFormat));
893
960
  }
@@ -1034,7 +1101,7 @@ class DatePickerFoundation extends _foundation.default {
1034
1101
  }
1035
1102
  }
1036
1103
  /**
1037
- * when changing the year and month through the panel when the type is year or month
1104
+ * when changing the year and month through the panel when the type is year or month or monthRange
1038
1105
  * @param {*} item
1039
1106
  */
1040
1107
 
@@ -1046,15 +1113,23 @@ class DatePickerFoundation extends _foundation.default {
1046
1113
  currentMonth,
1047
1114
  currentYear
1048
1115
  } = item;
1116
+ const {
1117
+ type
1118
+ } = this.getProps();
1049
1119
 
1050
- if (typeof currentMonth === 'number' && typeof currentYear === 'number') {
1051
- // Strings with only dates (e.g. "1970-01-01") will be treated as UTC instead of local time #1460
1052
- const date = new Date(currentYear, currentMonth - 1);
1120
+ if (type === 'month') {
1121
+ const date = new Date(currentYear['left'], currentMonth['left'] - 1);
1053
1122
  this.handleSelectedChange([date]);
1123
+ } else {
1124
+ const dateLeft = new Date(currentYear['left'], currentMonth['left'] - 1);
1125
+ const dateRight = new Date(currentYear['right'], currentMonth['right'] - 1);
1126
+ this.handleSelectedChange([dateLeft, dateRight]);
1054
1127
  }
1055
1128
  }
1056
1129
 
1057
1130
  handleConfirm() {
1131
+ this.clickConfirmButton = true;
1132
+
1058
1133
  const {
1059
1134
  cachedSelectedValue,
1060
1135
  value
@@ -1180,6 +1255,7 @@ class DatePickerFoundation extends _foundation.default {
1180
1255
 
1181
1256
  case 'dateRange':
1182
1257
  case 'dateTimeRange':
1258
+ case 'monthRange':
1183
1259
  notifyValue = _value.map(v => v && this.localeFormat(v, formatToken));
1184
1260
  notifyDate = [..._value];
1185
1261
  break;
@@ -1,7 +1,7 @@
1
1
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
2
2
  import { BaseValueType, ValidateStatus, ValueType } from './foundation';
3
3
  import { strings } from './constants';
4
- export declare type Type = 'date' | 'dateRange' | 'year' | 'month' | 'dateTime' | 'dateTimeRange';
4
+ export declare type Type = 'date' | 'dateRange' | 'year' | 'month' | 'dateTime' | 'dateTimeRange' | 'monthRange';
5
5
  export declare type RangeType = 'rangeStart' | 'rangeEnd';
6
6
  export declare type PanelType = 'left' | 'right';
7
7
  export interface DateInputEventHandlerProps {
@@ -132,6 +132,13 @@ class InputFoundation extends _foundation.default {
132
132
  text = (0, _formatter.formatDateValues)(value, formatToken, undefined, dateFnsLocale);
133
133
  break;
134
134
 
135
+ case 'monthRange':
136
+ text = (0, _formatter.formatDateValues)(value, formatToken, {
137
+ groupSize: 2,
138
+ groupInnerSeparator: rangeSeparator
139
+ }, dateFnsLocale);
140
+ break;
141
+
135
142
  default:
136
143
  break;
137
144
  }
@@ -248,7 +255,8 @@ class InputFoundation extends _foundation.default {
248
255
  getInsetInputPlaceholder() {
249
256
  const {
250
257
  type,
251
- format
258
+ format,
259
+ rangeSeparator
252
260
  } = this._adapter.getProps();
253
261
 
254
262
  const insetInputFormat = (0, _getInsetInputFormatToken.default)({
@@ -267,6 +275,9 @@ class InputFoundation extends _foundation.default {
267
275
  case 'dateTime':
268
276
  case 'dateTimeRange':
269
277
  [datePlaceholder, timePlaceholder] = insetInputFormat.split(' ');
278
+
279
+ case 'monthRange':
280
+ datePlaceholder = insetInputFormat + rangeSeparator + insetInputFormat;
270
281
  break;
271
282
  }
272
283
 
@@ -351,6 +362,7 @@ class InputFoundation extends _foundation.default {
351
362
  switch (type) {
352
363
  case 'date':
353
364
  case 'month':
365
+ case 'monthRange':
354
366
  inputValue = insetInputValue.monthLeft.dateInput;
355
367
  break;
356
368
 
@@ -9,6 +9,7 @@ $height-datepicker_timeType_tpk: calc(100% - 54px); // 时间面板高度
9
9
  $height-datepicker_panel_yam_scrolllist: 266px; // 时间滚动内容高度
10
10
 
11
11
  $width-datepicker_monthPanel_max: 284px; // 年月选择器最大宽度
12
+ $width-datepicker_monthRangePanel_max: 384px; // 年月选择器最大宽度
12
13
  $height-datepicker_timepicker_header_min: 24px; // 年月选择 header 最小高度
13
14
  $width-datepicker_navigation_button_min: 32px; // header 按钮最小宽度
14
15
  $height-datepicker_yamShowing_min: 378px; // 日期时间选择器菜单最小高度
@@ -30,7 +31,8 @@ $height-datepicker_timeType_insetInput_yam: 100%; // 时间面板高度 - 内嵌
30
31
  $height-datepicker_timeType_insetInput_tpk: 100%; // 时间面板高度 - 内嵌输入框
31
32
  $width-datepicker_insetInput_date_type_wrapper: 284px; // 日期类型内嵌输入框宽度
32
33
  $width-datepicker_insetInput_date_range_type_wrapper: $width-datepicker_insetInput_date_type_wrapper * 2; // 范围选择内嵌输入框宽度
33
- $width-datepicker_insetInput_month_type_wrapper: 204px; // 月份类型内嵌输入框宽度
34
+ $width-datepicker_insetInput_month_type_wrapper: 165px; // 月份类型内嵌输入框宽度
35
+ $width-datepicker_insetInput_month_range_type_wrapper: 331px; // 年月范围类型内嵌输入框宽度
34
36
  $height-datepicker_insetInput_separator: 32px;
35
37
  $height-datepicker_month_grid_yearType_insetInput: 317px;
36
38
  $height-datepicker_month_grid_timeType_insetInput: 317px;
@@ -222,7 +224,7 @@ $transition-datepicker_range_input: background-color .16s ease-in-out;
222
224
  $width-datepicker_presetPanel_left_and_right_content: $width-datepicker_presetPanel_left_and_right - $spacing-datepicker_quick_control_content-paddingX * 2; // 左右方位快捷选择面板,内容宽度
223
225
  $width-datepicker_presetPanel_top_and_bottom_content_date: $width-datepicker_day * 7 + $spacing-datepicker_month-padding * 2 - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2; // date/dateTime下, 上下方位快捷选择面板内容宽度, 默认(284 - 40)px
224
226
  $width-datepicker_presetPanel_top_and_bottom_content_range: ($width-datepicker_day * 7 + $spacing-datepicker_month-padding * 2) * 2 - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2; // dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认528px
225
- $width-datepicker_presetPanel_top_and_bottom_content_month: 194px - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2; // month下,上下方位快捷选择内容面板宽度, 默认154px
227
+ $width-datepicker_presetPanel_top_and_bottom_content_month: 165px - $spacing-datepicker_quick_control_top_and_bottom_content-paddingX * 2; // month下,上下方位快捷选择内容面板宽度, 默认154px
226
228
 
227
229
  $height-datepicker_month_max: $width-datepicker_day * 7 + 1px; // 年月面板最大高度, 最多6 + 1行,再加上一个border宽度, 默认253px
228
230
  $height-datepicker_month_max_compact: $width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-paddingTop + $spacing-datepicker_weeks_compact-padding + $spacing-datepicker_weekday_compact-paddingBottom; // 年月面板最大高度, 最多6 + 1行,再加上padding,默认220px
@@ -233,7 +235,7 @@ $height-datepicker_presetPanel_left_and_right_except_content: 20px + $spacing-da
233
235
  // compact
234
236
  $width-datepicker_presetPanel_top_and_bottom_content_date_compact: $width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-padding * 2 - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2; // date/dateTime下, 上下方位快捷选择面板内容宽度, 默认(216 - 20)px
235
237
  $width-datepicker_presetPanel_top_and_bottom_content_range_compact: ($width-datepicker_day_compact * 7 + $spacing-datepicker_weeks_compact-padding * 2) * 2 - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2; // dateRange/dateTimeRange下, 上下方位快捷选择内容面板宽度,默认412px
236
- $width-datepicker_presetPanel_top_and_bottom_content_month_compact: 194px - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2; // month下,上下方位快捷选择内容面板宽度, 默认174px
238
+ $width-datepicker_presetPanel_top_and_bottom_content_month_compact: 165px - $spacing-datepicker_quick_control_top_and_bottom_content_compact-paddingX * 2; // month下,上下方位快捷选择内容面板宽度, 默认174px
237
239
 
238
240
  $height-datepicker_date_panel_compact: $height-datepicker_month_max_compact + $width-datepicker_nav_compact + $spacing-datepicker_nav_compact-padding; // compact,date/dateRange,面板渲染最大高度,默认256px
239
241
  $height-datepicker_date_time_panel_compact: $height-datepicker_date_panel_compact + $height-datepicker_switch_compact; // compact,dateTime/dateTImeRange,面板渲染最大高度,默认288px
@@ -242,7 +244,7 @@ $height-datepicker_presetPanel_left_and_right_except_content_compact: 20px + $sp
242
244
  $width-datepicker_presetPanel_left_and_right_two_col_button: ($width-datepicker_presetPanel_left_and_right_content - $spacing-datepicker_quick_control_item-margin) * 0.5; // 左右方位快捷选择面板,固定两列,按钮宽度
243
245
  $width-datepicker_presetPanel_top_and_bottom_three_col_button: ($width-datepicker_presetPanel_top_and_bottom_content_date - $spacing-datepicker_quick_control_item-margin * 2) * 0.333; // 上下方位快捷选择面板,固定三列,按钮宽度
244
246
  $width-datepicker_presetPanel_top_and_bottom_five_col_button: ($width-datepicker_presetPanel_top_and_bottom_content_range - $spacing-datepicker_quick_control_item-margin * 4) * 0.2; // 上下方位快捷选择面板,固定五列,按钮宽度
245
- $width-datepicker_presetPanel_top_and_bottom_two_col_button:($width-datepicker_presetPanel_top_and_bottom_content_month - $spacing-datepicker_quick_control_item-margin) * 0.5; // 上下方位快捷选择面板,固定两列,按钮宽度
247
+ $width-datepicker_presetPanel_top_and_bottom_two_col_button: ($width-datepicker_presetPanel_top_and_bottom_content_month - $spacing-datepicker_quick_control_item-margin) * 0.5; // 上下方位快捷选择面板,固定两列,按钮宽度
246
248
 
247
249
  // compact
248
250
  $width-datepicker_presetPanel_top_and_bottom_three_col_button_compact: ($width-datepicker_presetPanel_top_and_bottom_content_date_compact - $spacing-datepicker_quick_control_item-margin * 2) * 0.333; // 上下方位快捷选择面板,固定三列,按钮宽度
@@ -1,11 +1,27 @@
1
1
  import BaseFoundation, { DefaultAdapter } from '../base/foundation';
2
2
  import { PresetPosition } from './foundation';
3
+ import { ArrayElement } from '../utils/type';
4
+ import { strings } from './constants';
5
+ import { PanelType } from './monthsGridFoundation';
6
+ declare type Type = ArrayElement<typeof strings.TYPE_SET>;
3
7
  export interface YearAndMonthFoundationProps {
4
- currentYear?: number;
5
- currentMonth?: number;
8
+ currentYear: {
9
+ left: number;
10
+ right: number;
11
+ };
12
+ currentMonth: {
13
+ left: number;
14
+ right: number;
15
+ };
6
16
  onSelect?: (obj: {
7
- currentMonth: number;
8
- currentYear: number;
17
+ currentMonth: {
18
+ left: number;
19
+ right: number;
20
+ };
21
+ currentYear: {
22
+ left: number;
23
+ right: number;
24
+ };
9
25
  }) => void;
10
26
  onBackToMain?: () => void;
11
27
  locale?: any;
@@ -18,6 +34,7 @@ export interface YearAndMonthFoundationProps {
18
34
  presetPosition?: PresetPosition;
19
35
  renderQuickControls?: any;
20
36
  renderDateInput?: any;
37
+ type?: Type;
21
38
  yearAndMonthOpts?: any;
22
39
  }
23
40
  export interface YearAndMonthFoundationState {
@@ -29,14 +46,46 @@ export interface YearAndMonthFoundationState {
29
46
  value: number;
30
47
  month: number;
31
48
  }>;
32
- currentYear: number;
33
- currentMonth: number;
49
+ currentYear: {
50
+ left: number;
51
+ right: number;
52
+ };
53
+ currentMonth: {
54
+ left: number;
55
+ right: number;
56
+ };
34
57
  }
35
58
  export interface YearAndMonthAdapter extends DefaultAdapter<YearAndMonthFoundationProps, YearAndMonthFoundationState> {
36
- setCurrentYear: (currentYear: number, cb?: () => void) => void;
37
- setCurrentMonth: (currentMonth: number) => void;
38
- notifySelectYear: (year: number) => void;
39
- notifySelectMonth: (month: number) => void;
59
+ setCurrentYear: (currentYear: {
60
+ left: number;
61
+ right: number;
62
+ }, cb?: () => void) => void;
63
+ setCurrentMonth: (currentMonth: {
64
+ left: number;
65
+ right: number;
66
+ }) => void;
67
+ setCurrentYearAndMonth: (currentYear: {
68
+ left: number;
69
+ right: number;
70
+ }, currentMonth: {
71
+ left: number;
72
+ right: number;
73
+ }) => void;
74
+ notifySelectYear: (year: {
75
+ left: number;
76
+ right: number;
77
+ }) => void;
78
+ notifySelectMonth: (month: {
79
+ left: number;
80
+ right: number;
81
+ }) => void;
82
+ notifySelectYearAndMonth: (year: {
83
+ left: number;
84
+ right: number;
85
+ }, month: {
86
+ left: number;
87
+ right: number;
88
+ }) => void;
40
89
  notifyBackToMain: () => void;
41
90
  }
42
91
  export interface MonthScrollItem {
@@ -55,11 +104,15 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
55
104
  constructor(adapter: YearAndMonthAdapter);
56
105
  init(): void;
57
106
  destroy(): void;
58
- selectYear(item: YearScrollItem): void;
59
- selectMonth(item: MonthScrollItem): void;
107
+ selectYear(item: YearScrollItem, panelType?: PanelType): void;
108
+ selectMonth(item: MonthScrollItem, panelType?: PanelType): void;
60
109
  /**
61
110
  * After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
62
111
  */
63
- autoSelectMonth(item: YearScrollItem): void;
112
+ autoSelectMonth(item: YearScrollItem, panelType: PanelType, year: {
113
+ left: number;
114
+ right: number;
115
+ }): void;
64
116
  backToMain(): void;
65
117
  }
118
+ export {};
@@ -5,10 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
9
+
8
10
  var _dateFns = require("date-fns");
9
11
 
10
12
  var _foundation = _interopRequireDefault(require("../base/foundation"));
11
13
 
14
+ var _constants = require("./constants");
15
+
12
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
17
 
14
18
  class YearAndMonthFoundation extends _foundation.default {
@@ -22,18 +26,54 @@ class YearAndMonthFoundation extends _foundation.default {
22
26
 
23
27
  destroy() {}
24
28
 
25
- selectYear(item) {
26
- const year = item.value;
29
+ selectYear(item, panelType) {
30
+ // const year = item.value;
31
+ const {
32
+ currentYear,
33
+ currentMonth
34
+ } = this.getStates();
35
+ const {
36
+ type
37
+ } = this.getProps();
38
+ const left = _constants.strings.PANEL_TYPE_LEFT;
39
+ const right = _constants.strings.PANEL_TYPE_RIGHT;
40
+ const year = (0, _cloneDeep2.default)(currentYear);
41
+ year[panelType] = item.value; // make sure the right panel time is always less than the left panel time
42
+
43
+ if (type === 'monthRange') {
44
+ const isSameYearIllegalDate = year[left] === year[right] && currentMonth[left] > currentMonth[right];
45
+
46
+ if (panelType === left && item.value > year[right] || panelType === left && isSameYearIllegalDate) {
47
+ // 1. select left year and left year > right year
48
+ // 2. select left year, left year = right year, but left date > right date
49
+ year[right] = item.value + 1;
50
+ } else if (panelType === right && isSameYearIllegalDate) {
51
+ // 1. select right year, left year = right year, but left date > right date
52
+ year[left] = item.value - 1;
53
+ }
54
+ }
27
55
 
28
- this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item));
56
+ this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item, panelType, year));
29
57
 
30
58
  this._adapter.notifySelectYear(year);
31
59
  }
32
60
 
33
- selectMonth(item) {
61
+ selectMonth(item, panelType) {
62
+ const {
63
+ currentMonth,
64
+ currentYear
65
+ } = this.getStates();
34
66
  const {
35
- month
36
- } = item;
67
+ type
68
+ } = this.getProps();
69
+ const left = _constants.strings.PANEL_TYPE_LEFT;
70
+ const right = _constants.strings.PANEL_TYPE_RIGHT;
71
+ const month = (0, _cloneDeep2.default)(currentMonth);
72
+ month[panelType] = item.month; // make sure the right panel time is always less than the left panel time
73
+
74
+ if (type === 'monthRange' && panelType === left && currentYear[left] === currentYear[right] && item.value > month[right]) {
75
+ month[right] = item.month + 1;
76
+ }
37
77
 
38
78
  this._adapter.setCurrentMonth(month);
39
79
 
@@ -44,7 +84,7 @@ class YearAndMonthFoundation extends _foundation.default {
44
84
  */
45
85
 
46
86
 
47
- autoSelectMonth(item) {
87
+ autoSelectMonth(item, panelType, year) {
48
88
  const {
49
89
  disabledDate,
50
90
  locale
@@ -56,14 +96,14 @@ class YearAndMonthFoundation extends _foundation.default {
56
96
  } = this._adapter.getStates();
57
97
 
58
98
  const currentDate = (0, _dateFns.setYear)(Date.now(), item.year);
59
- const isCurrentMonthDisabled = disabledDate((0, _dateFns.setMonth)(currentDate, currentMonth - 1));
99
+ const isCurrentMonthDisabled = disabledDate((0, _dateFns.setMonth)(currentDate, currentMonth[panelType] - 1));
60
100
 
61
101
  if (isCurrentMonthDisabled) {
62
102
  const currentIndex = months.findIndex(_ref => {
63
103
  let {
64
104
  month
65
105
  } = _ref;
66
- return month === currentMonth;
106
+ return month === currentMonth[panelType];
67
107
  });
68
108
  let validMonth; // First look in the back, if you can't find it in the back, then look in the front
69
109
 
@@ -84,11 +124,12 @@ class YearAndMonthFoundation extends _foundation.default {
84
124
  }
85
125
 
86
126
  if (validMonth) {
87
- this.selectMonth({
88
- month: validMonth.month,
89
- value: locale.fullMonths[validMonth.month],
90
- disabled: false
91
- });
127
+ const month = (0, _cloneDeep2.default)(currentMonth);
128
+ month[panelType] = validMonth.month; // change year and month same time
129
+
130
+ this._adapter.setCurrentYearAndMonth(year, month);
131
+
132
+ this._adapter.notifySelectYearAndMonth(year, month);
92
133
  }
93
134
  }
94
135
  }
@@ -67,6 +67,7 @@
67
67
  .semi-modal-content-fullScreen {
68
68
  border-radius: 0;
69
69
  border: none;
70
+ top: 0px;
70
71
  }
71
72
  .semi-modal-header {
72
73
  display: flex;
@@ -76,6 +76,7 @@ $module: #{$prefix}-modal;
76
76
  &-content-fullScreen {
77
77
  border-radius: $radius-modal_content_fullscreen;
78
78
  border: none;
79
+ top: $spacing-modal_content_fullscreen-top;
79
80
  }
80
81
 
81
82
  // &-close {
@@ -43,6 +43,7 @@ $spacing-modal_footer_button-marginLeft: $spacing-base-tight; // 模态框 foote
43
43
  $spacing-modal_footer_button-marginRight: 0; // 模态框 footer 按钮右侧外边距
44
44
  $spacing-modal_confirm_header-marginBottom: 8px; // 命令式调用模态框 header 底部外边距
45
45
  $spacing-modal_confirm_icon_wrapper-marginRight: $spacing-base-tight; // 命令式调用模态框图标右侧外边距
46
+ $spacing-modal_content_fullscreen-top: 0px; // 模态框内容全屏顶部位置
46
47
 
47
48
  // Width/Height
48
49
  $width-modal_title: 100%; // 模态框标题宽度