@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
@@ -103,9 +103,7 @@ export default class DatePickerFoundation extends BaseFoundation {
103
103
  this._adapter.updatePrevTimezone(prevTimeZone); // reset input value when value update
104
104
 
105
105
 
106
- this._adapter.updateInputValue(null);
107
-
108
- this._adapter.updateInsetInputValue(null);
106
+ this.clearInputValue();
109
107
 
110
108
  this._adapter.updateValue(result);
111
109
 
@@ -192,7 +190,8 @@ export default class DatePickerFoundation extends BaseFoundation {
192
190
 
193
191
  destroy() {
194
192
  // Ensure that event listeners will be uninstalled and users may not trigger closePanel
195
- // this._adapter.togglePanel(false);
193
+ this._adapter.togglePanel(false);
194
+
196
195
  this._adapter.unregisterClickOutSide();
197
196
  }
198
197
 
@@ -211,52 +210,47 @@ export default class DatePickerFoundation extends BaseFoundation {
211
210
  openPanel() {
212
211
  if (!this.getProp('disabled')) {
213
212
  if (!this._isControlledComponent('open')) {
214
- this._adapter.togglePanel(true);
215
-
216
- this._adapter.registerClickOutSide();
213
+ this.open();
217
214
  }
218
215
 
219
216
  this._adapter.notifyOpenChange(true);
220
217
  }
221
218
  }
222
219
  /**
220
+ * @deprecated
223
221
  * do these side effects when type is dateRange or dateTimeRange
224
222
  * 1. trigger input blur, if input value is invalid, set input value and state value to previous status
225
223
  * 2. set cachedSelectedValue using given dates(in needConfirm mode)
226
224
  * - directly closePanel without click confirm will set cachedSelectedValue to state value
227
225
  * - select one date(which means that the selection value is incomplete) and click confirm also set cachedSelectedValue to state value
228
226
  */
227
+ // rangeTypeSideEffectsWhenClosePanel(inputValue: string, willUpdateDates: Date[]) {
228
+ // if (this._isRangeType()) {
229
+ // this._adapter.setRangeInputFocus(false);
230
+ // /**
231
+ // * inputValue is string when it is not disabled or can't parsed
232
+ // * when inputValue is null, picker value will back to last selected value
233
+ // */
234
+ // this.handleInputBlur(inputValue);
235
+ // this.resetCachedSelectedValue(willUpdateDates);
236
+ // }
237
+ // }
229
238
 
230
-
231
- rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates) {
232
- if (this._isRangeType()) {
233
- this._adapter.setRangeInputFocus(false);
234
- /**
235
- * inputValue is string when it is not disabled or can't parsed
236
- * when inputValue is null, picker value will back to last selected value
237
- */
238
-
239
-
240
- this.handleInputBlur(inputValue);
241
- this.resetCachedSelectedValue(willUpdateDates);
242
- }
243
- }
244
239
  /**
240
+ * @deprecated
245
241
  * clear input value when selected date is not confirmed
246
242
  */
243
+ // needConfirmSideEffectsWhenClosePanel(willUpdateDates: Date[] | null | undefined) {
244
+ // if (this._adapter.needConfirm() && !this._isRangeType()) {
245
+ // /**
246
+ // * if `null` input element will show `cachedSelectedValue` formatted value(format in DateInput render)
247
+ // * if `` input element will show `` directly
248
+ // */
249
+ // this._adapter.updateInputValue(null);
250
+ // this.resetCachedSelectedValue(willUpdateDates);
251
+ // }
252
+ // }
247
253
 
248
-
249
- needConfirmSideEffectsWhenClosePanel(willUpdateDates) {
250
- if (this._adapter.needConfirm() && !this._isRangeType()) {
251
- /**
252
- * if `null` input element will show `cachedSelectedValue` formatted value(format in DateInput render)
253
- * if `` input element will show `` directly
254
- */
255
- this._adapter.updateInputValue(null);
256
-
257
- this.resetCachedSelectedValue(willUpdateDates);
258
- }
259
- }
260
254
  /**
261
255
  * clear inset input value when close panel
262
256
  */
@@ -313,20 +307,114 @@ export default class DatePickerFoundation extends BaseFoundation {
313
307
  const willUpdateDates = isNullOrUndefined(dates) ? value : dates;
314
308
 
315
309
  if (!this._isControlledComponent('open')) {
316
- this._adapter.togglePanel(false);
310
+ this.close();
311
+ } else {
312
+ this.resetInnerSelectedStates(willUpdateDates);
313
+ }
317
314
 
318
- this._adapter.unregisterClickOutSide();
319
- } // range type picker, closing panel requires the following side effects
315
+ this._adapter.notifyOpenChange(false);
316
+ }
320
317
 
318
+ open() {
319
+ this._adapter.togglePanel(true);
321
320
 
322
- this.rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates);
323
- this.needConfirmSideEffectsWhenClosePanel(willUpdateDates);
324
- this.clearInsetInputValue();
321
+ this._adapter.registerClickOutSide();
322
+ }
325
323
 
326
- this._adapter.notifyOpenChange(false);
324
+ close() {
325
+ this._adapter.togglePanel(false, () => this.resetInnerSelectedStates());
326
+
327
+ this._adapter.unregisterClickOutSide();
328
+ }
329
+
330
+ focus(focusType) {
331
+ if (this._isRangeType()) {
332
+ const rangeInputFocus = focusType !== null && focusType !== void 0 ? focusType : 'rangeStart';
333
+
334
+ this._adapter.setRangeInputFocus(rangeInputFocus);
335
+ } else {
336
+ this._adapter.setInputFocus();
337
+ }
338
+ }
339
+
340
+ blur() {
341
+ if (this._isRangeType()) {
342
+ this._adapter.setRangeInputBlur();
343
+ } else {
344
+ this._adapter.setInputBlur();
345
+ }
346
+ }
347
+ /**
348
+ * reset cachedSelectedValue, inputValue when close panel
349
+ */
350
+
351
+
352
+ resetInnerSelectedStates(willUpdateDates) {
353
+ const {
354
+ value
355
+ } = this._adapter.getStates();
356
+
357
+ const needResetCachedSelectedValue = !this.isCachedSelectedValueValid(willUpdateDates) || this._adapter.needConfirm() && !this.clickConfirmButton;
358
+
359
+ if (needResetCachedSelectedValue) {
360
+ this.resetCachedSelectedValue(value);
361
+ }
362
+
363
+ this.resetFocus();
364
+ this.clearInputValue();
365
+ this.clickConfirmButton = false;
366
+ }
367
+
368
+ resetFocus(e) {
369
+ this._adapter.setRangeInputFocus(false);
327
370
 
328
371
  this._adapter.notifyBlur(e);
329
372
  }
373
+ /**
374
+ * cachedSelectedValue can be `(Date|null)[]` or `null`
375
+ */
376
+
377
+
378
+ isCachedSelectedValueValid(dates) {
379
+ const cachedSelectedValue = dates || this._adapter.getState('cachedSelectedValue');
380
+
381
+ const {
382
+ type
383
+ } = this._adapter.getProps();
384
+
385
+ let isValid = true;
386
+
387
+ switch (true) {
388
+ case type === 'dateRange':
389
+ case type === 'dateTimeRange':
390
+ if (!this._isRangeValueComplete(cachedSelectedValue)) {
391
+ isValid = false;
392
+ }
393
+
394
+ break;
395
+
396
+ default:
397
+ const value = cachedSelectedValue === null || cachedSelectedValue === void 0 ? void 0 : cachedSelectedValue.filter(item => item);
398
+
399
+ if (!(Array.isArray(value) && value.length)) {
400
+ isValid = false;
401
+ }
402
+
403
+ break;
404
+ }
405
+
406
+ return isValid;
407
+ }
408
+ /**
409
+ * 将输入框内容置空
410
+ */
411
+
412
+
413
+ clearInputValue() {
414
+ this._adapter.updateInputValue(null);
415
+
416
+ this._adapter.updateInsetInputValue(null);
417
+ }
330
418
  /**
331
419
  * Callback when the content of the input box changes
332
420
  * Update the date panel if the changed value is a legal date, otherwise only update the input box
@@ -429,36 +517,12 @@ export default class DatePickerFoundation extends BaseFoundation {
429
517
  * @param {String} input
430
518
  * @param {Event} e
431
519
  */
520
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
432
521
 
433
522
 
434
523
  handleInputBlur() {
435
524
  let input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
436
525
  let e = arguments.length > 1 ? arguments[1] : undefined;
437
- const parsedResult = input ? this._isMultiple() ? this.parseMultipleInput(input, ',', true) : this.parseInput(input) : [];
438
- const stateValue = this.getState('value'); // console.log(input, parsedResult);
439
-
440
- if (parsedResult && parsedResult.length) {
441
- this._updateValueAndInput(parsedResult, input === '');
442
- } else if (input === '') {
443
- // if clear input, set input to `''`
444
- this._updateValueAndInput('', true, '');
445
- } else {
446
- this._updateValueAndInput(stateValue);
447
- }
448
- /**
449
- * 当不是范围类型且不需要确认时,使用 stateValue 重置 cachedSelectedValue
450
- * 这样做的目的是,在输入非法值时,使用上次选中的值作为已选值
451
- * needConfirm 或者 range type 时,我们在 close panel 时调用 resetCachedSelectedValue,这里不用重复调用
452
- *
453
- * Use stateValue to reset cachedSelectedValue when it is not a range type and does not require confirmation
454
- * The purpose of this is to use the last selected value as the selected value when an invalid value is entered
455
- * When needConfirm or range type, we call resetCachedSelectedValue when close panel, no need to call repeatedly here
456
- */
457
-
458
-
459
- if (!this._adapter.needConfirm() && !this._isRangeType()) {
460
- this.resetCachedSelectedValue(stateValue);
461
- }
462
526
  }
463
527
  /**
464
528
  * called when range type rangeEnd input tab press
@@ -593,6 +657,7 @@ export default class DatePickerFoundation extends BaseFoundation {
593
657
 
594
658
  case 'dateRange':
595
659
  case 'dateTimeRange':
660
+ case 'monthRange':
596
661
  const separator = rangeSeparator;
597
662
  const values = input.split(separator);
598
663
  parsedResult = values && values.reduce((arr, cur) => {
@@ -816,6 +881,7 @@ export default class DatePickerFoundation extends BaseFoundation {
816
881
 
817
882
  case 'dateRange':
818
883
  case 'dateTimeRange':
884
+ case 'monthRange':
819
885
  const startIsTruthy = !isNullOrUndefined(dates[0]);
820
886
  const endIsTruthy = !isNullOrUndefined(dates[1]);
821
887
 
@@ -864,6 +930,7 @@ export default class DatePickerFoundation extends BaseFoundation {
864
930
 
865
931
  case 'dateRange':
866
932
  case 'dateTimeRange':
933
+ case 'monthRange':
867
934
  for (let i = 0; i < dates.length; i += 2) {
868
935
  strs.push(this.formatDates(dates.slice(i, i + 2), customFormat));
869
936
  }
@@ -1013,7 +1080,7 @@ export default class DatePickerFoundation extends BaseFoundation {
1013
1080
  }
1014
1081
  }
1015
1082
  /**
1016
- * when changing the year and month through the panel when the type is year or month
1083
+ * when changing the year and month through the panel when the type is year or month or monthRange
1017
1084
  * @param {*} item
1018
1085
  */
1019
1086
 
@@ -1025,15 +1092,23 @@ export default class DatePickerFoundation extends BaseFoundation {
1025
1092
  currentMonth,
1026
1093
  currentYear
1027
1094
  } = item;
1095
+ const {
1096
+ type
1097
+ } = this.getProps();
1028
1098
 
1029
- if (typeof currentMonth === 'number' && typeof currentYear === 'number') {
1030
- // Strings with only dates (e.g. "1970-01-01") will be treated as UTC instead of local time #1460
1031
- const date = new Date(currentYear, currentMonth - 1);
1099
+ if (type === 'month') {
1100
+ const date = new Date(currentYear['left'], currentMonth['left'] - 1);
1032
1101
  this.handleSelectedChange([date]);
1102
+ } else {
1103
+ const dateLeft = new Date(currentYear['left'], currentMonth['left'] - 1);
1104
+ const dateRight = new Date(currentYear['right'], currentMonth['right'] - 1);
1105
+ this.handleSelectedChange([dateLeft, dateRight]);
1033
1106
  }
1034
1107
  }
1035
1108
 
1036
1109
  handleConfirm() {
1110
+ this.clickConfirmButton = true;
1111
+
1037
1112
  const {
1038
1113
  cachedSelectedValue,
1039
1114
  value
@@ -1159,6 +1234,7 @@ export default class DatePickerFoundation extends BaseFoundation {
1159
1234
 
1160
1235
  case 'dateRange':
1161
1236
  case 'dateTimeRange':
1237
+ case 'monthRange':
1162
1238
  notifyValue = _value.map(v => v && this.localeFormat(v, formatToken));
1163
1239
  notifyDate = [..._value];
1164
1240
  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 {
@@ -108,6 +108,13 @@ export default class InputFoundation extends BaseFoundation {
108
108
  text = formatDateValues(value, formatToken, undefined, dateFnsLocale);
109
109
  break;
110
110
 
111
+ case 'monthRange':
112
+ text = formatDateValues(value, formatToken, {
113
+ groupSize: 2,
114
+ groupInnerSeparator: rangeSeparator
115
+ }, dateFnsLocale);
116
+ break;
117
+
111
118
  default:
112
119
  break;
113
120
  }
@@ -229,7 +236,8 @@ export default class InputFoundation extends BaseFoundation {
229
236
  getInsetInputPlaceholder() {
230
237
  const {
231
238
  type,
232
- format
239
+ format,
240
+ rangeSeparator
233
241
  } = this._adapter.getProps();
234
242
 
235
243
  const insetInputFormat = getInsetInputFormatToken({
@@ -248,6 +256,9 @@ export default class InputFoundation extends BaseFoundation {
248
256
  case 'dateTime':
249
257
  case 'dateTimeRange':
250
258
  [datePlaceholder, timePlaceholder] = insetInputFormat.split(' ');
259
+
260
+ case 'monthRange':
261
+ datePlaceholder = insetInputFormat + rangeSeparator + insetInputFormat;
251
262
  break;
252
263
  }
253
264
 
@@ -332,6 +343,7 @@ export default class InputFoundation extends BaseFoundation {
332
343
  switch (type) {
333
344
  case 'date':
334
345
  case 'month':
346
+ case 'monthRange':
335
347
  inputValue = insetInputValue.monthLeft.dateInput;
336
348
  break;
337
349
 
@@ -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 {};
@@ -1,5 +1,7 @@
1
+ import _cloneDeep from "lodash/cloneDeep";
1
2
  import { setMonth, setYear } from 'date-fns';
2
3
  import BaseFoundation from '../base/foundation';
4
+ import { strings } from './constants';
3
5
  export default class YearAndMonthFoundation extends BaseFoundation {
4
6
  constructor(adapter) {
5
7
  super(Object.assign({}, adapter));
@@ -11,18 +13,58 @@ export default class YearAndMonthFoundation extends BaseFoundation {
11
13
 
12
14
  destroy() {}
13
15
 
14
- selectYear(item) {
15
- const year = item.value;
16
+ selectYear(item, panelType) {
17
+ // const year = item.value;
18
+ const {
19
+ currentYear,
20
+ currentMonth
21
+ } = this.getStates();
22
+ const {
23
+ type
24
+ } = this.getProps();
25
+ const left = strings.PANEL_TYPE_LEFT;
26
+ const right = strings.PANEL_TYPE_RIGHT;
27
+
28
+ const year = _cloneDeep(currentYear);
29
+
30
+ year[panelType] = item.value; // make sure the right panel time is always less than the left panel time
31
+
32
+ if (type === 'monthRange') {
33
+ const isSameYearIllegalDate = year[left] === year[right] && currentMonth[left] > currentMonth[right];
34
+
35
+ if (panelType === left && item.value > year[right] || panelType === left && isSameYearIllegalDate) {
36
+ // 1. select left year and left year > right year
37
+ // 2. select left year, left year = right year, but left date > right date
38
+ year[right] = item.value + 1;
39
+ } else if (panelType === right && isSameYearIllegalDate) {
40
+ // 1. select right year, left year = right year, but left date > right date
41
+ year[left] = item.value - 1;
42
+ }
43
+ }
16
44
 
17
- this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item));
45
+ this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item, panelType, year));
18
46
 
19
47
  this._adapter.notifySelectYear(year);
20
48
  }
21
49
 
22
- selectMonth(item) {
50
+ selectMonth(item, panelType) {
23
51
  const {
24
- month
25
- } = item;
52
+ currentMonth,
53
+ currentYear
54
+ } = this.getStates();
55
+ const {
56
+ type
57
+ } = this.getProps();
58
+ const left = strings.PANEL_TYPE_LEFT;
59
+ const right = strings.PANEL_TYPE_RIGHT;
60
+
61
+ const month = _cloneDeep(currentMonth);
62
+
63
+ month[panelType] = item.month; // make sure the right panel time is always less than the left panel time
64
+
65
+ if (type === 'monthRange' && panelType === left && currentYear[left] === currentYear[right] && item.value > month[right]) {
66
+ month[right] = item.month + 1;
67
+ }
26
68
 
27
69
  this._adapter.setCurrentMonth(month);
28
70
 
@@ -33,7 +75,7 @@ export default class YearAndMonthFoundation extends BaseFoundation {
33
75
  */
34
76
 
35
77
 
36
- autoSelectMonth(item) {
78
+ autoSelectMonth(item, panelType, year) {
37
79
  const {
38
80
  disabledDate,
39
81
  locale
@@ -45,14 +87,14 @@ export default class YearAndMonthFoundation extends BaseFoundation {
45
87
  } = this._adapter.getStates();
46
88
 
47
89
  const currentDate = setYear(Date.now(), item.year);
48
- const isCurrentMonthDisabled = disabledDate(setMonth(currentDate, currentMonth - 1));
90
+ const isCurrentMonthDisabled = disabledDate(setMonth(currentDate, currentMonth[panelType] - 1));
49
91
 
50
92
  if (isCurrentMonthDisabled) {
51
93
  const currentIndex = months.findIndex(_ref => {
52
94
  let {
53
95
  month
54
96
  } = _ref;
55
- return month === currentMonth;
97
+ return month === currentMonth[panelType];
56
98
  });
57
99
  let validMonth; // First look in the back, if you can't find it in the back, then look in the front
58
100
 
@@ -73,11 +115,13 @@ export default class YearAndMonthFoundation extends BaseFoundation {
73
115
  }
74
116
 
75
117
  if (validMonth) {
76
- this.selectMonth({
77
- month: validMonth.month,
78
- value: locale.fullMonths[validMonth.month],
79
- disabled: false
80
- });
118
+ const month = _cloneDeep(currentMonth);
119
+
120
+ month[panelType] = validMonth.month; // change year and month same time
121
+
122
+ this._adapter.setCurrentYearAndMonth(year, month);
123
+
124
+ this._adapter.notifySelectYearAndMonth(year, month);
81
125
  }
82
126
  }
83
127
  }
@@ -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%; // 模态框标题宽度