@douyinfe/semi-foundation 2.1.6-alpha.0 → 2.2.1
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/cascader/cascader.scss +1 -1
- package/cascader/constants.ts +4 -0
- package/cascader/foundation.ts +29 -15
- package/cascader/util.ts +13 -0
- package/datePicker/_utils/parser.ts +4 -3
- package/datePicker/datePicker.scss +29 -0
- package/datePicker/foundation.ts +31 -11
- package/datePicker/inputFoundation.ts +2 -0
- package/datePicker/monthsGridFoundation.ts +101 -8
- package/datePicker/rtl.scss +15 -1
- package/datePicker/variables.scss +2 -0
- package/gulpfile.js +3 -1
- package/lib/cjs/cascader/cascader.css +2 -2
- package/lib/cjs/cascader/cascader.scss +1 -1
- package/lib/cjs/cascader/constants.d.ts +3 -0
- package/lib/cjs/cascader/constants.js +6 -1
- package/lib/cjs/cascader/foundation.d.ts +4 -1
- package/lib/cjs/cascader/foundation.js +24 -11
- package/lib/cjs/cascader/util.d.ts +1 -0
- package/lib/cjs/cascader/util.js +17 -0
- package/lib/cjs/datePicker/_utils/parser.d.ts +6 -1
- package/lib/cjs/datePicker/_utils/parser.js +3 -1
- package/lib/cjs/datePicker/datePicker.css +32 -3
- package/lib/cjs/datePicker/datePicker.scss +29 -0
- package/lib/cjs/datePicker/foundation.d.ts +6 -3
- package/lib/cjs/datePicker/foundation.js +40 -14
- package/lib/cjs/datePicker/inputFoundation.js +3 -0
- package/lib/cjs/datePicker/monthsGridFoundation.d.ts +35 -3
- package/lib/cjs/datePicker/monthsGridFoundation.js +139 -6
- package/lib/cjs/datePicker/rtl.scss +15 -1
- package/lib/cjs/datePicker/variables.scss +2 -0
- package/lib/cjs/navigation/navigation.css +0 -1
- package/lib/cjs/notification/notification.css +8 -4
- package/lib/cjs/notification/notification.scss +9 -5
- package/lib/cjs/notification/variables.scss +1 -0
- package/lib/cjs/select/foundation.d.ts +10 -1
- package/lib/cjs/select/foundation.js +11 -9
- package/lib/cjs/table/table.css +0 -2
- package/lib/cjs/table/table.scss +0 -2
- package/lib/cjs/tree/treeUtil.js +14 -14
- package/lib/cjs/upload/foundation.d.ts +1 -0
- package/lib/cjs/upload/foundation.js +106 -0
- package/lib/cjs/upload/rtl.scss +0 -4
- package/lib/cjs/upload/upload.css +30 -18
- package/lib/cjs/upload/upload.scss +31 -8
- package/lib/cjs/upload/variables.scss +5 -1
- package/lib/es/cascader/cascader.css +2 -2
- package/lib/es/cascader/cascader.scss +1 -1
- package/lib/es/cascader/constants.d.ts +3 -0
- package/lib/es/cascader/constants.js +6 -1
- package/lib/es/cascader/foundation.d.ts +4 -1
- package/lib/es/cascader/foundation.js +24 -12
- package/lib/es/cascader/util.d.ts +1 -0
- package/lib/es/cascader/util.js +14 -0
- package/lib/es/datePicker/_utils/parser.d.ts +6 -1
- package/lib/es/datePicker/_utils/parser.js +3 -1
- package/lib/es/datePicker/datePicker.css +32 -3
- package/lib/es/datePicker/datePicker.scss +29 -0
- package/lib/es/datePicker/foundation.d.ts +6 -3
- package/lib/es/datePicker/foundation.js +40 -14
- package/lib/es/datePicker/inputFoundation.js +3 -0
- package/lib/es/datePicker/monthsGridFoundation.d.ts +35 -3
- package/lib/es/datePicker/monthsGridFoundation.js +139 -6
- package/lib/es/datePicker/rtl.scss +15 -1
- package/lib/es/datePicker/variables.scss +2 -0
- package/lib/es/navigation/navigation.css +0 -1
- package/lib/es/notification/notification.css +8 -4
- package/lib/es/notification/notification.scss +9 -5
- package/lib/es/notification/variables.scss +1 -0
- package/lib/es/select/foundation.d.ts +10 -1
- package/lib/es/select/foundation.js +12 -9
- package/lib/es/table/table.css +0 -2
- package/lib/es/table/table.scss +0 -2
- package/lib/es/tree/treeUtil.js +13 -12
- package/lib/es/upload/foundation.d.ts +1 -0
- package/lib/es/upload/foundation.js +107 -0
- package/lib/es/upload/rtl.scss +0 -4
- package/lib/es/upload/upload.css +30 -18
- package/lib/es/upload/upload.scss +31 -8
- package/lib/es/upload/variables.scss +5 -1
- package/notification/notification.scss +9 -5
- package/notification/variables.scss +1 -0
- package/package.json +4 -4
- package/select/foundation.ts +11 -9
- package/table/table.scss +0 -2
- package/tree/treeUtil.ts +6 -2
- package/upload/foundation.ts +81 -0
- package/upload/rtl.scss +0 -4
- package/upload/upload.scss +31 -8
- package/upload/variables.scss +5 -1
|
@@ -62,6 +62,8 @@ var _treeUtil = require("../tree/treeUtil");
|
|
|
62
62
|
|
|
63
63
|
var _util = require("./util");
|
|
64
64
|
|
|
65
|
+
var _constants = require("./constants");
|
|
66
|
+
|
|
65
67
|
// eslint-disable-next-line max-len
|
|
66
68
|
class CascaderFoundation extends _foundation.default {
|
|
67
69
|
constructor(adapter) {
|
|
@@ -568,10 +570,12 @@ class CascaderFoundation extends _foundation.default {
|
|
|
568
570
|
}
|
|
569
571
|
|
|
570
572
|
_defaultRenderText(path, displayRender) {
|
|
573
|
+
const separator = this.getProp('separator');
|
|
574
|
+
|
|
571
575
|
if (displayRender && typeof displayRender === 'function') {
|
|
572
576
|
return displayRender(path);
|
|
573
577
|
} else {
|
|
574
|
-
return path.join(
|
|
578
|
+
return path.join(separator);
|
|
575
579
|
}
|
|
576
580
|
}
|
|
577
581
|
|
|
@@ -645,7 +649,8 @@ class CascaderFoundation extends _foundation.default {
|
|
|
645
649
|
const {
|
|
646
650
|
changeOnSelect: allowChange,
|
|
647
651
|
filterLeafOnly,
|
|
648
|
-
multiple
|
|
652
|
+
multiple,
|
|
653
|
+
enableLeafClick
|
|
649
654
|
} = this.getProps();
|
|
650
655
|
const {
|
|
651
656
|
keyEntities,
|
|
@@ -679,6 +684,10 @@ class CascaderFoundation extends _foundation.default {
|
|
|
679
684
|
this._adapter.updateStates({
|
|
680
685
|
activeKeys: new _set.default(activeKeys)
|
|
681
686
|
});
|
|
687
|
+
|
|
688
|
+
if (isLeaf && enableLeafClick) {
|
|
689
|
+
this.onItemCheckboxClick(item);
|
|
690
|
+
}
|
|
682
691
|
} else {
|
|
683
692
|
this._adapter.notifySelect(data.value);
|
|
684
693
|
|
|
@@ -728,12 +737,13 @@ class CascaderFoundation extends _foundation.default {
|
|
|
728
737
|
const {
|
|
729
738
|
checkedKeys,
|
|
730
739
|
keyEntities,
|
|
731
|
-
|
|
740
|
+
resolvedCheckedKeys
|
|
732
741
|
} = this.getStates();
|
|
733
742
|
const {
|
|
734
743
|
autoMergeValue,
|
|
735
744
|
max,
|
|
736
|
-
disableStrictly
|
|
745
|
+
disableStrictly,
|
|
746
|
+
leafOnly
|
|
737
747
|
} = this.getProps(); // prev checked status
|
|
738
748
|
|
|
739
749
|
const prevCheckedStatus = checkedKeys.has(key); // next checked status
|
|
@@ -744,15 +754,18 @@ class CascaderFoundation extends _foundation.default {
|
|
|
744
754
|
checkedKeys: curCheckedKeys,
|
|
745
755
|
halfCheckedKeys: curHalfCheckedKeys
|
|
746
756
|
} = disableStrictly ? this.calcNonDisabedCheckedKeys(key, curCheckedStatus) : this.calcCheckedKeys(key, curCheckedStatus);
|
|
747
|
-
const
|
|
748
|
-
const
|
|
757
|
+
const mergeType = (0, _util.calcMergeType)(autoMergeValue, leafOnly);
|
|
758
|
+
const isLeafOnlyMerge = mergeType === _constants.strings.LEAF_ONLY_MERGE_TYPE;
|
|
759
|
+
const isNoneMerge = mergeType === _constants.strings.NONE_MERGE_TYPE;
|
|
760
|
+
const curResolvedCheckedKeys = new _set.default((0, _treeUtil.normalizeKeyList)(curCheckedKeys, keyEntities, isLeafOnlyMerge));
|
|
761
|
+
const curRealCheckedKeys = isNoneMerge ? curCheckedKeys : curResolvedCheckedKeys;
|
|
749
762
|
|
|
750
763
|
if ((0, _isNumber2.default)(max)) {
|
|
751
|
-
if (
|
|
764
|
+
if (!isNoneMerge) {
|
|
752
765
|
// When it exceeds max, the quantity is allowed to be reduced, and no further increase is allowed
|
|
753
|
-
if (
|
|
766
|
+
if (resolvedCheckedKeys.size < curResolvedCheckedKeys.size && curResolvedCheckedKeys.size > max) {
|
|
754
767
|
const checkedEntities = [];
|
|
755
|
-
(0, _forEach.default)(
|
|
768
|
+
(0, _forEach.default)(curResolvedCheckedKeys).call(curResolvedCheckedKeys, itemKey => {
|
|
756
769
|
checkedEntities.push(keyEntities[itemKey]);
|
|
757
770
|
});
|
|
758
771
|
|
|
@@ -779,7 +792,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
779
792
|
this._adapter.updateStates({
|
|
780
793
|
checkedKeys: curCheckedKeys,
|
|
781
794
|
halfCheckedKeys: curHalfCheckedKeys,
|
|
782
|
-
|
|
795
|
+
resolvedCheckedKeys: curResolvedCheckedKeys
|
|
783
796
|
});
|
|
784
797
|
} // The click event during multiple selection will definitely cause the checked state of node to change,
|
|
785
798
|
// so there is no need to judge the value to change.
|
|
@@ -935,7 +948,7 @@ class CascaderFoundation extends _foundation.default {
|
|
|
935
948
|
newState.halfCheckedKeys = new _set.default([]);
|
|
936
949
|
newState.selectedKeys = new _set.default([]);
|
|
937
950
|
newState.activeKeys = new _set.default([]);
|
|
938
|
-
newState.
|
|
951
|
+
newState.resolvedCheckedKeys = new _set.default([]);
|
|
939
952
|
|
|
940
953
|
this._adapter.notifyChange([]);
|
|
941
954
|
} else {
|
|
@@ -2,3 +2,4 @@ export declare function isValid(val: any): boolean;
|
|
|
2
2
|
export declare function normalizedArr(val: any): any[];
|
|
3
3
|
export declare function convertDataToEntities(dataNodes: any): any;
|
|
4
4
|
export declare function findKeysForValues(value: any, keyEntities: any): any[];
|
|
5
|
+
export declare function calcMergeType(autoMergeValue: boolean, leafOnly: boolean): string;
|
package/lib/cjs/cascader/util.js
CHANGED
|
@@ -8,6 +8,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
|
8
8
|
value: true
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
exports.calcMergeType = calcMergeType;
|
|
11
12
|
exports.convertDataToEntities = convertDataToEntities;
|
|
12
13
|
exports.findKeysForValues = findKeysForValues;
|
|
13
14
|
exports.isValid = isValid;
|
|
@@ -33,6 +34,8 @@ var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
|
33
34
|
|
|
34
35
|
var _isNull2 = _interopRequireDefault(require("lodash/isNull"));
|
|
35
36
|
|
|
37
|
+
var _constants = require("./constants");
|
|
38
|
+
|
|
36
39
|
function getPosition(level, index) {
|
|
37
40
|
var _context;
|
|
38
41
|
|
|
@@ -111,4 +114,18 @@ function findKeysForValues(value, keyEntities) {
|
|
|
111
114
|
const valuePath = normalizedArr(value);
|
|
112
115
|
const res = (0, _map.default)(_context2 = (0, _filter.default)(_context3 = (0, _values.default)(keyEntities)).call(_context3, item => (0, _isEqual2.default)(item.valuePath, valuePath))).call(_context2, item => item.key);
|
|
113
116
|
return res;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function calcMergeType(autoMergeValue, leafOnly) {
|
|
120
|
+
let mergeType;
|
|
121
|
+
|
|
122
|
+
if (leafOnly) {
|
|
123
|
+
mergeType = _constants.strings.LEAF_ONLY_MERGE_TYPE;
|
|
124
|
+
} else if (autoMergeValue) {
|
|
125
|
+
mergeType = _constants.strings.AUTO_MERGE_VALUE_MERGE_TYPE;
|
|
126
|
+
} else {
|
|
127
|
+
mergeType = _constants.strings.NONE_MERGE_TYPE;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return mergeType;
|
|
114
131
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file
|
|
3
|
+
* Various date-related analysis methods
|
|
4
|
+
*/
|
|
5
|
+
import { Locale } from 'date-fns';
|
|
1
6
|
/**
|
|
2
7
|
* Parsing value to Date object
|
|
3
8
|
*/
|
|
4
|
-
export declare function compatiableParse(value: string, formatToken?: string, baseDate?: Date, locale?:
|
|
9
|
+
export declare function compatiableParse(value: string, formatToken?: string, baseDate?: Date, locale?: Locale): Date | null;
|
|
@@ -37,7 +37,9 @@ function compatiableParse(value, formatToken, baseDate, locale) {
|
|
|
37
37
|
result = new Date(Date.parse(value));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
const yearInvalid = (0, _dateFns.isValid)(result) && String(result.getFullYear()).length > 4;
|
|
41
|
+
|
|
42
|
+
if (!(0, _dateFns.isValid)(result) || yearInvalid) {
|
|
41
43
|
result = null;
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@charset "UTF-8";
|
|
2
1
|
/* shadow */
|
|
3
2
|
/* sizing */
|
|
4
3
|
/* spacing */
|
|
@@ -72,6 +71,9 @@
|
|
|
72
71
|
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
|
73
72
|
min-height: 24px;
|
|
74
73
|
}
|
|
74
|
+
.semi-datepicker-month-grid[x-panel-yearandmonth-open-type=left] .semi-datepicker-weeks, .semi-datepicker-month-grid[x-panel-yearandmonth-open-type=right] .semi-datepicker-weeks {
|
|
75
|
+
min-height: 216px;
|
|
76
|
+
}
|
|
75
77
|
.semi-datepicker-panel-yam {
|
|
76
78
|
max-width: 284px;
|
|
77
79
|
}
|
|
@@ -96,6 +98,12 @@
|
|
|
96
98
|
text-align: right;
|
|
97
99
|
background-color: var(--semi-color-fill-0);
|
|
98
100
|
}
|
|
101
|
+
.semi-datepicker-footer .semi-button:first-of-type {
|
|
102
|
+
margin-right: 12px;
|
|
103
|
+
}
|
|
104
|
+
.semi-datepicker-footer .semi-button:nth-of-type(2) {
|
|
105
|
+
margin-right: 8px;
|
|
106
|
+
}
|
|
99
107
|
.semi-datepicker-yam {
|
|
100
108
|
position: absolute;
|
|
101
109
|
top: 0;
|
|
@@ -561,6 +569,9 @@
|
|
|
561
569
|
.semi-datepicker-compact .semi-datepicker-month-grid .semi-scrolllist-item-wheel .semi-scrolllist-shade-post {
|
|
562
570
|
margin-top: 17px;
|
|
563
571
|
}
|
|
572
|
+
.semi-datepicker-compact .semi-datepicker-month-grid[x-panel-yearandmonth-open-type=left] .semi-datepicker-weeks, .semi-datepicker-compact .semi-datepicker-month-grid[x-panel-yearandmonth-open-type=right] .semi-datepicker-weeks {
|
|
573
|
+
min-height: 168px;
|
|
574
|
+
}
|
|
564
575
|
.semi-datepicker-compact.semi-datepicker-panel-yam .semi-scrolllist {
|
|
565
576
|
font-size: 12px;
|
|
566
577
|
line-height: 16px;
|
|
@@ -700,6 +711,16 @@
|
|
|
700
711
|
padding-left: 8px;
|
|
701
712
|
text-align: left;
|
|
702
713
|
}
|
|
714
|
+
.semi-rtl .semi-datepicker-footer .semi-button:first-of-type,
|
|
715
|
+
.semi-portal-rtl .semi-datepicker-footer .semi-button:first-of-type {
|
|
716
|
+
margin-left: 0;
|
|
717
|
+
margin-right: 0;
|
|
718
|
+
}
|
|
719
|
+
.semi-rtl .semi-datepicker-footer .semi-button:nth-of-type(2),
|
|
720
|
+
.semi-portal-rtl .semi-datepicker-footer .semi-button:nth-of-type(2) {
|
|
721
|
+
margin-right: 12px;
|
|
722
|
+
margin-left: 0;
|
|
723
|
+
}
|
|
703
724
|
.semi-rtl .semi-datepicker-day-offsetrange-start .semi-datepicker-day-main,
|
|
704
725
|
.semi-portal-rtl .semi-datepicker-day-offsetrange-start .semi-datepicker-day-main {
|
|
705
726
|
border-radius: 0 var(--semi-border-radius-small) var(--semi-border-radius-small) 0;
|
|
@@ -735,12 +756,20 @@
|
|
|
735
756
|
margin-right: 8px;
|
|
736
757
|
}
|
|
737
758
|
.semi-rtl .semi-datepicker-navigation .semi-icon-chevron_left,
|
|
738
|
-
.semi-rtl .semi-datepicker-navigation .semi-icon-chevron_right,
|
|
759
|
+
.semi-rtl .semi-datepicker-navigation .semi-icon-chevron_right,
|
|
760
|
+
.semi-rtl .semi-datepicker-navigation .semi-icon-double_chevron_left,
|
|
761
|
+
.semi-rtl .semi-datepicker-navigation .semi-icon-double_chevron_right, .semi-rtl .semi-datepicker-yam .semi-icon-chevron_left,
|
|
739
762
|
.semi-rtl .semi-datepicker-yam .semi-icon-chevron_right,
|
|
763
|
+
.semi-rtl .semi-datepicker-yam .semi-icon-double_chevron_left,
|
|
764
|
+
.semi-rtl .semi-datepicker-yam .semi-icon-double_chevron_right,
|
|
740
765
|
.semi-portal-rtl .semi-datepicker-navigation .semi-icon-chevron_left,
|
|
741
766
|
.semi-portal-rtl .semi-datepicker-navigation .semi-icon-chevron_right,
|
|
767
|
+
.semi-portal-rtl .semi-datepicker-navigation .semi-icon-double_chevron_left,
|
|
768
|
+
.semi-portal-rtl .semi-datepicker-navigation .semi-icon-double_chevron_right,
|
|
742
769
|
.semi-portal-rtl .semi-datepicker-yam .semi-icon-chevron_left,
|
|
743
|
-
.semi-portal-rtl .semi-datepicker-yam .semi-icon-chevron_right
|
|
770
|
+
.semi-portal-rtl .semi-datepicker-yam .semi-icon-chevron_right,
|
|
771
|
+
.semi-portal-rtl .semi-datepicker-yam .semi-icon-double_chevron_left,
|
|
772
|
+
.semi-portal-rtl .semi-datepicker-yam .semi-icon-double_chevron_right {
|
|
744
773
|
transform: scaleX(-1);
|
|
745
774
|
}
|
|
746
775
|
.semi-rtl .semi-datepicker-range-input-prefix,
|
|
@@ -94,6 +94,15 @@ $module: #{$prefix}-datepicker;
|
|
|
94
94
|
min-height: $height-datepicker_timepicker_header_min;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
// 为了防止 scrollList 因为 weeks 变化高度发生变化导致年月可能发生滚动
|
|
99
|
+
// In order to prevent scrollList from scrolling due to changes in the height of weeks, the year and month may be scrolled
|
|
100
|
+
&[x-panel-yearandmonth-open-type="left"],
|
|
101
|
+
&[x-panel-yearandmonth-open-type="right"] {
|
|
102
|
+
.#{$module}-weeks {
|
|
103
|
+
min-height: 6 * $width-datepicker_day;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
// 年月选择器
|
|
@@ -131,6 +140,17 @@ $module: #{$prefix}-datepicker;
|
|
|
131
140
|
padding-bottom: $spacing-datepicker_footer-paddingBottom;
|
|
132
141
|
text-align: right;
|
|
133
142
|
background-color: $color-datepicker_footer-bg-default;
|
|
143
|
+
|
|
144
|
+
.#{$prefix}-button {
|
|
145
|
+
// cancel button
|
|
146
|
+
&:first-of-type {
|
|
147
|
+
margin-right: $spacing-datepicker_footer_cancel_button-marginRight;
|
|
148
|
+
}
|
|
149
|
+
// confirm button
|
|
150
|
+
&:nth-of-type(2) {
|
|
151
|
+
margin-right: $spacing-datepicker_footer_confirm_button-marginRight;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
134
154
|
}
|
|
135
155
|
|
|
136
156
|
// 年月选择
|
|
@@ -833,6 +853,15 @@ $module: #{$prefix}-datepicker;
|
|
|
833
853
|
}
|
|
834
854
|
}
|
|
835
855
|
}
|
|
856
|
+
|
|
857
|
+
// 为了防止 scrollList 因为 weeks 变化高度发生变化导致年月可能发生滚动
|
|
858
|
+
// In order to prevent scrollList from scrolling due to changes in the height of weeks, the year and month may be scrolled
|
|
859
|
+
&[x-panel-yearandmonth-open-type="left"],
|
|
860
|
+
&[x-panel-yearandmonth-open-type="right"] {
|
|
861
|
+
.#{$module}-weeks {
|
|
862
|
+
min-height: 6 * $width-datepicker_day_compact;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
836
865
|
}
|
|
837
866
|
|
|
838
867
|
// 年月选择器
|
|
@@ -201,10 +201,13 @@ export default class DatePickerFoundation extends BaseFoundation<DatePickerAdapt
|
|
|
201
201
|
* 2. set cachedSelectedValue using given dates(in needConfirm mode)
|
|
202
202
|
* - directly closePanel without click confirm will set cachedSelectedValue to state value
|
|
203
203
|
* - select one date(which means that the selection value is incomplete) and click confirm also set cachedSelectedValue to state value
|
|
204
|
-
* @param {String} inputValue
|
|
205
|
-
* @param {Date[]} dates
|
|
206
204
|
*/
|
|
207
|
-
rangeTypeSideEffectsWhenClosePanel(inputValue: string,
|
|
205
|
+
rangeTypeSideEffectsWhenClosePanel(inputValue: string, willUpdateDates: Date[]): void;
|
|
206
|
+
/**
|
|
207
|
+
* clear input value when selected date is not confirmed
|
|
208
|
+
*/
|
|
209
|
+
needConfirmSideEffectsWhenClosePanel(willUpdateDates: Date[] | null | undefined): void;
|
|
210
|
+
resetCachedSelectedValue(willUpdateDates?: Date[]): void;
|
|
208
211
|
/**
|
|
209
212
|
* timing to call closePanel
|
|
210
213
|
* 1. click confirm button
|
|
@@ -250,12 +250,10 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
250
250
|
* 2. set cachedSelectedValue using given dates(in needConfirm mode)
|
|
251
251
|
* - directly closePanel without click confirm will set cachedSelectedValue to state value
|
|
252
252
|
* - select one date(which means that the selection value is incomplete) and click confirm also set cachedSelectedValue to state value
|
|
253
|
-
* @param {String} inputValue
|
|
254
|
-
* @param {Date[]} dates
|
|
255
253
|
*/
|
|
256
254
|
|
|
257
255
|
|
|
258
|
-
rangeTypeSideEffectsWhenClosePanel(inputValue,
|
|
256
|
+
rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates) {
|
|
259
257
|
if (this._isRangeType()) {
|
|
260
258
|
this._adapter.setRangeInputFocus(false);
|
|
261
259
|
/**
|
|
@@ -265,17 +263,36 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
265
263
|
|
|
266
264
|
|
|
267
265
|
this.handleInputBlur(inputValue);
|
|
266
|
+
this.resetCachedSelectedValue(willUpdateDates);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* clear input value when selected date is not confirmed
|
|
271
|
+
*/
|
|
268
272
|
|
|
269
|
-
const {
|
|
270
|
-
value,
|
|
271
|
-
cachedSelectedValue
|
|
272
|
-
} = this._adapter.getStates();
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
needConfirmSideEffectsWhenClosePanel(willUpdateDates) {
|
|
275
|
+
if (this._adapter.needConfirm() && !this._isRangeType()) {
|
|
276
|
+
/**
|
|
277
|
+
* if `null` input element will show `cachedSelectedValue` formatted value(format in DateInput render)
|
|
278
|
+
* if `` input element will show `` directly
|
|
279
|
+
*/
|
|
280
|
+
this._adapter.updateInputValue(null);
|
|
275
281
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
282
|
+
this.resetCachedSelectedValue(willUpdateDates);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
resetCachedSelectedValue(willUpdateDates) {
|
|
287
|
+
const {
|
|
288
|
+
value,
|
|
289
|
+
cachedSelectedValue
|
|
290
|
+
} = this._adapter.getStates();
|
|
291
|
+
|
|
292
|
+
const newCachedSelectedValue = (0, _isArray.default)(willUpdateDates) ? willUpdateDates : value;
|
|
293
|
+
|
|
294
|
+
if (!(0, _isEqual2.default)(newCachedSelectedValue, cachedSelectedValue)) {
|
|
295
|
+
this._adapter.updateCachedSelectedValue(newCachedSelectedValue);
|
|
279
296
|
}
|
|
280
297
|
}
|
|
281
298
|
/**
|
|
@@ -294,7 +311,14 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
294
311
|
|
|
295
312
|
closePanel(e) {
|
|
296
313
|
let inputValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
297
|
-
let dates = arguments.length > 2
|
|
314
|
+
let dates = arguments.length > 2 ? arguments[2] : undefined;
|
|
315
|
+
|
|
316
|
+
const {
|
|
317
|
+
value,
|
|
318
|
+
cachedSelectedValue
|
|
319
|
+
} = this._adapter.getStates();
|
|
320
|
+
|
|
321
|
+
const willUpdateDates = (0, _isNullOrUndefined.default)(dates) ? this._adapter.needConfirm() ? value : cachedSelectedValue : dates;
|
|
298
322
|
|
|
299
323
|
if (!this._isControlledComponent('open')) {
|
|
300
324
|
this._adapter.togglePanel(false);
|
|
@@ -303,7 +327,8 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
303
327
|
} // range type picker, closing panel requires the following side effects
|
|
304
328
|
|
|
305
329
|
|
|
306
|
-
this.rangeTypeSideEffectsWhenClosePanel(inputValue,
|
|
330
|
+
this.rangeTypeSideEffectsWhenClosePanel(inputValue, willUpdateDates);
|
|
331
|
+
this.needConfirmSideEffectsWhenClosePanel(willUpdateDates);
|
|
307
332
|
|
|
308
333
|
this._adapter.notifyOpenChange(false);
|
|
309
334
|
|
|
@@ -365,7 +390,8 @@ class DatePickerFoundation extends _foundation.default {
|
|
|
365
390
|
if (parsedResult && parsedResult.length) {
|
|
366
391
|
this._updateValueAndInput(parsedResult, input === '');
|
|
367
392
|
} else if (input === '') {
|
|
368
|
-
|
|
393
|
+
// if clear input, set input to `''`
|
|
394
|
+
this._updateValueAndInput('', true, '');
|
|
369
395
|
} else {
|
|
370
396
|
this._updateValueAndInput(stateValue);
|
|
371
397
|
}
|
|
@@ -13,6 +13,7 @@ interface MonthsGridElementProps {
|
|
|
13
13
|
renderFullDate?: () => React.ReactNode;
|
|
14
14
|
}
|
|
15
15
|
export declare type PanelType = 'left' | 'right';
|
|
16
|
+
export declare type YearMonthChangeType = 'prevMonth' | 'nextMonth' | 'prevYear' | 'nextYear';
|
|
16
17
|
export interface MonthsGridFoundationProps extends MonthsGridElementProps {
|
|
17
18
|
type?: Type;
|
|
18
19
|
defaultValue?: ValueType;
|
|
@@ -104,11 +105,34 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
104
105
|
_initDateTimePickerFromValue(values: BaseValueType[]): void;
|
|
105
106
|
_initDateTimeRangePickerFormValue(values: BaseValueType[]): void;
|
|
106
107
|
destroy(): void;
|
|
108
|
+
/**
|
|
109
|
+
* sync change another panel month when change months from the else yam panel
|
|
110
|
+
* call it when
|
|
111
|
+
* - current change panel targe date month is same with another panel date
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* - panelType=right, target=new Date('2022-09-01') and left panel is in '2022-09' => call it, left panel minus one month to '2022-08'
|
|
115
|
+
* - panelType=left, target=new Date('2021-12-01') and right panel is in '2021-12' => call it, right panel add one month to '2021-01'
|
|
116
|
+
*/
|
|
117
|
+
handleSyncChangeMonths(options: {
|
|
118
|
+
panelType: PanelType;
|
|
119
|
+
target: Date;
|
|
120
|
+
}): void;
|
|
121
|
+
/**
|
|
122
|
+
* Get the target date based on the panel type and switch type
|
|
123
|
+
*/
|
|
124
|
+
getTargetChangeDate(options: {
|
|
125
|
+
panelType: PanelType;
|
|
126
|
+
switchType: YearMonthChangeType;
|
|
127
|
+
}): Date;
|
|
128
|
+
/**
|
|
129
|
+
* Change month by yam panel
|
|
130
|
+
*/
|
|
107
131
|
toMonth(panelType: PanelType, target: Date): void;
|
|
108
132
|
toYear(panelType: PanelType, target: Date): void;
|
|
109
133
|
toYearMonth(panelType: PanelType, target: Date): void;
|
|
110
134
|
isRangeType(type?: Type): boolean;
|
|
111
|
-
|
|
135
|
+
handleSwitchMonthOrYear(switchType: YearMonthChangeType, panelType: PanelType): void;
|
|
112
136
|
prevMonth(panelType: PanelType): void;
|
|
113
137
|
nextMonth(panelType: PanelType): void;
|
|
114
138
|
prevYear(panelType: PanelType): void;
|
|
@@ -158,13 +182,13 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
158
182
|
notifyValue: any;
|
|
159
183
|
notifyDate: any;
|
|
160
184
|
};
|
|
161
|
-
handleYearOrMonthChange(type:
|
|
185
|
+
handleYearOrMonthChange(type: YearMonthChangeType, panelType?: PanelType, step?: number, notSeparateInRange?: boolean): void;
|
|
162
186
|
/**
|
|
163
187
|
* You have chosen to switch the year and month in the future to directly update the Date without closing the date panel
|
|
164
188
|
* @param {*} type
|
|
165
189
|
* @param {*} targetDate
|
|
166
190
|
*/
|
|
167
|
-
updateDateAfterChangeYM(type:
|
|
191
|
+
updateDateAfterChangeYM(type: YearMonthChangeType, targetDate: Date): void;
|
|
168
192
|
_isMultiple(): boolean;
|
|
169
193
|
_isRange(): void;
|
|
170
194
|
handleDayClick(day: MonthDayInfo, panelType: PanelType): void;
|
|
@@ -214,5 +238,13 @@ export default class MonthsGridFoundation extends BaseFoundation<MonthsGridAdapt
|
|
|
214
238
|
showYearPicker(panelType: PanelType): void;
|
|
215
239
|
showTimePicker(panelType: PanelType, opt?: boolean): void;
|
|
216
240
|
showDatePanel(panelType: PanelType): void;
|
|
241
|
+
/**
|
|
242
|
+
* Get year and month panel open type
|
|
243
|
+
*
|
|
244
|
+
* It is useful info to set minHeight of weeks.
|
|
245
|
+
* - When yam open type is 'left' or 'right', weeks minHeight should be set
|
|
246
|
+
* If the minHeight is not set, the change of the number of weeks will cause the scrollList to be unstable
|
|
247
|
+
*/
|
|
248
|
+
getYAMOpenType(): "left" | "right" | "none" | "both";
|
|
217
249
|
}
|
|
218
250
|
export {};
|
|
@@ -241,11 +241,99 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
destroy() {}
|
|
244
|
+
/**
|
|
245
|
+
* sync change another panel month when change months from the else yam panel
|
|
246
|
+
* call it when
|
|
247
|
+
* - current change panel targe date month is same with another panel date
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* - panelType=right, target=new Date('2022-09-01') and left panel is in '2022-09' => call it, left panel minus one month to '2022-08'
|
|
251
|
+
* - panelType=left, target=new Date('2021-12-01') and right panel is in '2021-12' => call it, right panel add one month to '2021-01'
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
handleSyncChangeMonths(options) {
|
|
256
|
+
const {
|
|
257
|
+
panelType,
|
|
258
|
+
target
|
|
259
|
+
} = options;
|
|
260
|
+
|
|
261
|
+
const {
|
|
262
|
+
type
|
|
263
|
+
} = this._adapter.getProps();
|
|
264
|
+
|
|
265
|
+
const {
|
|
266
|
+
monthLeft,
|
|
267
|
+
monthRight
|
|
268
|
+
} = this._adapter.getStates();
|
|
269
|
+
|
|
270
|
+
if (this.isRangeType(type)) {
|
|
271
|
+
if (panelType === 'right' && (0, _dateFns.differenceInCalendarMonths)(target, monthLeft.pickerDate) === 0) {
|
|
272
|
+
this.handleYearOrMonthChange('prevMonth', 'left', 1, true);
|
|
273
|
+
} else if (panelType === 'left' && (0, _dateFns.differenceInCalendarMonths)(monthRight.pickerDate, target) === 0) {
|
|
274
|
+
this.handleYearOrMonthChange('nextMonth', 'right', 1, true);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get the target date based on the panel type and switch type
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
getTargetChangeDate(options) {
|
|
284
|
+
const {
|
|
285
|
+
panelType,
|
|
286
|
+
switchType
|
|
287
|
+
} = options;
|
|
288
|
+
|
|
289
|
+
const {
|
|
290
|
+
monthRight,
|
|
291
|
+
monthLeft
|
|
292
|
+
} = this._adapter.getStates();
|
|
293
|
+
|
|
294
|
+
const currentDate = panelType === 'left' ? monthLeft.pickerDate : monthRight.pickerDate;
|
|
295
|
+
let target;
|
|
296
|
+
|
|
297
|
+
switch (switchType) {
|
|
298
|
+
case 'prevMonth':
|
|
299
|
+
target = (0, _dateFns.addMonths)(currentDate, -1);
|
|
300
|
+
break;
|
|
301
|
+
|
|
302
|
+
case 'nextMonth':
|
|
303
|
+
target = (0, _dateFns.addMonths)(currentDate, 1);
|
|
304
|
+
break;
|
|
305
|
+
|
|
306
|
+
case 'prevYear':
|
|
307
|
+
target = (0, _dateFns.addYears)(currentDate, -1);
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
case 'nextYear':
|
|
311
|
+
target = (0, _dateFns.addYears)(currentDate, 1);
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return target;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Change month by yam panel
|
|
319
|
+
*/
|
|
320
|
+
|
|
244
321
|
|
|
245
322
|
toMonth(panelType, target) {
|
|
323
|
+
const {
|
|
324
|
+
type
|
|
325
|
+
} = this._adapter.getProps();
|
|
326
|
+
|
|
246
327
|
const diff = this._getDiff('month', target, panelType);
|
|
247
328
|
|
|
248
329
|
this.handleYearOrMonthChange(diff < 0 ? 'prevMonth' : 'nextMonth', panelType, Math.abs(diff), false);
|
|
330
|
+
|
|
331
|
+
if (this.isRangeType(type)) {
|
|
332
|
+
this.handleSyncChangeMonths({
|
|
333
|
+
panelType,
|
|
334
|
+
target
|
|
335
|
+
});
|
|
336
|
+
}
|
|
249
337
|
}
|
|
250
338
|
|
|
251
339
|
toYear(panelType, target) {
|
|
@@ -267,34 +355,51 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
267
355
|
return typeof realType === 'string' && /range/i.test(realType);
|
|
268
356
|
}
|
|
269
357
|
|
|
270
|
-
|
|
358
|
+
handleSwitchMonthOrYear(switchType, panelType) {
|
|
271
359
|
const {
|
|
272
360
|
type,
|
|
273
361
|
syncSwitchMonth
|
|
274
362
|
} = this.getProps();
|
|
363
|
+
const rangeType = this.isRangeType(type); // range type and syncSwitchMonth, we should change panels at same time
|
|
275
364
|
|
|
276
|
-
if (
|
|
365
|
+
if (rangeType && syncSwitchMonth) {
|
|
277
366
|
this.handleYearOrMonthChange(switchType, 'left', 1, true);
|
|
278
367
|
this.handleYearOrMonthChange(switchType, 'right', 1, true);
|
|
279
368
|
} else {
|
|
280
369
|
this.handleYearOrMonthChange(switchType, panelType);
|
|
370
|
+
/**
|
|
371
|
+
* default behavior (v2.2.0)
|
|
372
|
+
* In order to prevent the two panels from being the same month, this will confuse the user when selecting the range
|
|
373
|
+
* https://github.com/DouyinFE/semi-design/issues/260
|
|
374
|
+
*/
|
|
375
|
+
|
|
376
|
+
if (rangeType) {
|
|
377
|
+
const target = this.getTargetChangeDate({
|
|
378
|
+
panelType,
|
|
379
|
+
switchType
|
|
380
|
+
});
|
|
381
|
+
this.handleSyncChangeMonths({
|
|
382
|
+
panelType,
|
|
383
|
+
target
|
|
384
|
+
});
|
|
385
|
+
}
|
|
281
386
|
}
|
|
282
387
|
}
|
|
283
388
|
|
|
284
389
|
prevMonth(panelType) {
|
|
285
|
-
this.
|
|
390
|
+
this.handleSwitchMonthOrYear('prevMonth', panelType);
|
|
286
391
|
}
|
|
287
392
|
|
|
288
393
|
nextMonth(panelType) {
|
|
289
|
-
this.
|
|
394
|
+
this.handleSwitchMonthOrYear('nextMonth', panelType);
|
|
290
395
|
}
|
|
291
396
|
|
|
292
397
|
prevYear(panelType) {
|
|
293
|
-
this.
|
|
398
|
+
this.handleSwitchMonthOrYear('prevYear', panelType);
|
|
294
399
|
}
|
|
295
400
|
|
|
296
401
|
nextYear(panelType) {
|
|
297
|
-
this.
|
|
402
|
+
this.handleSwitchMonthOrYear('nextYear', panelType);
|
|
298
403
|
}
|
|
299
404
|
/**
|
|
300
405
|
* Calculate the year and month difference
|
|
@@ -948,6 +1053,34 @@ class MonthsGridFoundation extends _foundation.default {
|
|
|
948
1053
|
isYearPickerOpen: false
|
|
949
1054
|
});
|
|
950
1055
|
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Get year and month panel open type
|
|
1058
|
+
*
|
|
1059
|
+
* It is useful info to set minHeight of weeks.
|
|
1060
|
+
* - When yam open type is 'left' or 'right', weeks minHeight should be set
|
|
1061
|
+
* If the minHeight is not set, the change of the number of weeks will cause the scrollList to be unstable
|
|
1062
|
+
*/
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
getYAMOpenType() {
|
|
1066
|
+
const {
|
|
1067
|
+
monthLeft,
|
|
1068
|
+
monthRight
|
|
1069
|
+
} = this._adapter.getStates();
|
|
1070
|
+
|
|
1071
|
+
const leftYearPickerOpen = monthLeft.isYearPickerOpen;
|
|
1072
|
+
const rightYearPickerOpen = monthRight.isYearPickerOpen;
|
|
1073
|
+
|
|
1074
|
+
if (leftYearPickerOpen && rightYearPickerOpen) {
|
|
1075
|
+
return 'both';
|
|
1076
|
+
} else if (leftYearPickerOpen) {
|
|
1077
|
+
return 'left';
|
|
1078
|
+
} else if (rightYearPickerOpen) {
|
|
1079
|
+
return 'right';
|
|
1080
|
+
} else {
|
|
1081
|
+
return 'none';
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
951
1084
|
|
|
952
1085
|
}
|
|
953
1086
|
|