@douyinfe/semi-foundation 2.24.0 → 2.24.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/datePicker/yearAndMonthFoundation.ts +26 -2
- package/lib/cjs/datePicker/yearAndMonthFoundation.d.ts +5 -1
- package/lib/cjs/datePicker/yearAndMonthFoundation.js +56 -1
- package/lib/es/datePicker/yearAndMonthFoundation.d.ts +5 -1
- package/lib/es/datePicker/yearAndMonthFoundation.js +55 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setMonth, setYear } from 'date-fns';
|
|
1
2
|
import BaseFoundation, { DefaultAdapter } from '../base/foundation';
|
|
2
3
|
import { PresetPosition } from './foundation';
|
|
3
4
|
|
|
@@ -26,7 +27,7 @@ export interface YearAndMonthFoundationState {
|
|
|
26
27
|
currentMonth: number
|
|
27
28
|
}
|
|
28
29
|
export interface YearAndMonthAdapter extends DefaultAdapter<YearAndMonthFoundationProps, YearAndMonthFoundationState> {
|
|
29
|
-
setCurrentYear: (currentYear: number) => void;
|
|
30
|
+
setCurrentYear: (currentYear: number, cb?: () => void) => void;
|
|
30
31
|
setCurrentMonth: (currentMonth: number) => void;
|
|
31
32
|
notifySelectYear: (year: number) => void;
|
|
32
33
|
notifySelectMonth: (month: number) => void;
|
|
@@ -61,7 +62,7 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
|
|
|
61
62
|
|
|
62
63
|
selectYear(item: YearScrollItem) {
|
|
63
64
|
const year = item.value;
|
|
64
|
-
this._adapter.setCurrentYear(year);
|
|
65
|
+
this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item));
|
|
65
66
|
this._adapter.notifySelectYear(year);
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -71,6 +72,29 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
|
|
|
71
72
|
this._adapter.notifySelectMonth(month);
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/**
|
|
76
|
+
* After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
|
|
77
|
+
*/
|
|
78
|
+
autoSelectMonth(item: YearScrollItem) {
|
|
79
|
+
const { disabledDate, locale } = this._adapter.getProps();
|
|
80
|
+
const { months, currentMonth } = this._adapter.getStates();
|
|
81
|
+
|
|
82
|
+
const currentDate = setYear(Date.now(), item.year);
|
|
83
|
+
const isCurrentMonthDisabled = disabledDate(setMonth(currentDate, currentMonth - 1));
|
|
84
|
+
if (isCurrentMonthDisabled) {
|
|
85
|
+
const currentIndex = months.findIndex(({ month }) => month === currentMonth);
|
|
86
|
+
let validMonth: typeof months[number];
|
|
87
|
+
// First look in the back, if you can't find it in the back, then look in the front
|
|
88
|
+
validMonth = months.slice(currentIndex).find(({ month }) => !disabledDate(setMonth(currentDate, month - 1)));
|
|
89
|
+
if (!validMonth) {
|
|
90
|
+
validMonth = months.slice(0, currentIndex).find(({ month }) => !disabledDate(setMonth(currentDate, month - 1)));
|
|
91
|
+
}
|
|
92
|
+
if (validMonth) {
|
|
93
|
+
this.selectMonth({ month: validMonth.month, value: locale.fullMonths[validMonth.month], disabled: false });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
74
98
|
backToMain() {
|
|
75
99
|
this._adapter.notifyBackToMain();
|
|
76
100
|
}
|
|
@@ -33,7 +33,7 @@ export interface YearAndMonthFoundationState {
|
|
|
33
33
|
currentMonth: number;
|
|
34
34
|
}
|
|
35
35
|
export interface YearAndMonthAdapter extends DefaultAdapter<YearAndMonthFoundationProps, YearAndMonthFoundationState> {
|
|
36
|
-
setCurrentYear: (currentYear: number) => void;
|
|
36
|
+
setCurrentYear: (currentYear: number, cb?: () => void) => void;
|
|
37
37
|
setCurrentMonth: (currentMonth: number) => void;
|
|
38
38
|
notifySelectYear: (year: number) => void;
|
|
39
39
|
notifySelectMonth: (month: number) => void;
|
|
@@ -57,5 +57,9 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
|
|
|
57
57
|
destroy(): void;
|
|
58
58
|
selectYear(item: YearScrollItem): void;
|
|
59
59
|
selectMonth(item: MonthScrollItem): void;
|
|
60
|
+
/**
|
|
61
|
+
* After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
|
|
62
|
+
*/
|
|
63
|
+
autoSelectMonth(item: YearScrollItem): void;
|
|
60
64
|
backToMain(): void;
|
|
61
65
|
}
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _dateFns = require("date-fns");
|
|
9
|
+
|
|
8
10
|
var _foundation = _interopRequireDefault(require("../base/foundation"));
|
|
9
11
|
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -23,7 +25,7 @@ class YearAndMonthFoundation extends _foundation.default {
|
|
|
23
25
|
selectYear(item) {
|
|
24
26
|
const year = item.value;
|
|
25
27
|
|
|
26
|
-
this._adapter.setCurrentYear(year);
|
|
28
|
+
this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item));
|
|
27
29
|
|
|
28
30
|
this._adapter.notifySelectYear(year);
|
|
29
31
|
}
|
|
@@ -37,6 +39,59 @@ class YearAndMonthFoundation extends _foundation.default {
|
|
|
37
39
|
|
|
38
40
|
this._adapter.notifySelectMonth(month);
|
|
39
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
autoSelectMonth(item) {
|
|
48
|
+
const {
|
|
49
|
+
disabledDate,
|
|
50
|
+
locale
|
|
51
|
+
} = this._adapter.getProps();
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
months,
|
|
55
|
+
currentMonth
|
|
56
|
+
} = this._adapter.getStates();
|
|
57
|
+
|
|
58
|
+
const currentDate = (0, _dateFns.setYear)(Date.now(), item.year);
|
|
59
|
+
const isCurrentMonthDisabled = disabledDate((0, _dateFns.setMonth)(currentDate, currentMonth - 1));
|
|
60
|
+
|
|
61
|
+
if (isCurrentMonthDisabled) {
|
|
62
|
+
const currentIndex = months.findIndex(_ref => {
|
|
63
|
+
let {
|
|
64
|
+
month
|
|
65
|
+
} = _ref;
|
|
66
|
+
return month === currentMonth;
|
|
67
|
+
});
|
|
68
|
+
let validMonth; // First look in the back, if you can't find it in the back, then look in the front
|
|
69
|
+
|
|
70
|
+
validMonth = months.slice(currentIndex).find(_ref2 => {
|
|
71
|
+
let {
|
|
72
|
+
month
|
|
73
|
+
} = _ref2;
|
|
74
|
+
return !disabledDate((0, _dateFns.setMonth)(currentDate, month - 1));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (!validMonth) {
|
|
78
|
+
validMonth = months.slice(0, currentIndex).find(_ref3 => {
|
|
79
|
+
let {
|
|
80
|
+
month
|
|
81
|
+
} = _ref3;
|
|
82
|
+
return !disabledDate((0, _dateFns.setMonth)(currentDate, month - 1));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (validMonth) {
|
|
87
|
+
this.selectMonth({
|
|
88
|
+
month: validMonth.month,
|
|
89
|
+
value: locale.fullMonths[validMonth.month],
|
|
90
|
+
disabled: false
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
40
95
|
|
|
41
96
|
backToMain() {
|
|
42
97
|
this._adapter.notifyBackToMain();
|
|
@@ -33,7 +33,7 @@ export interface YearAndMonthFoundationState {
|
|
|
33
33
|
currentMonth: number;
|
|
34
34
|
}
|
|
35
35
|
export interface YearAndMonthAdapter extends DefaultAdapter<YearAndMonthFoundationProps, YearAndMonthFoundationState> {
|
|
36
|
-
setCurrentYear: (currentYear: number) => void;
|
|
36
|
+
setCurrentYear: (currentYear: number, cb?: () => void) => void;
|
|
37
37
|
setCurrentMonth: (currentMonth: number) => void;
|
|
38
38
|
notifySelectYear: (year: number) => void;
|
|
39
39
|
notifySelectMonth: (month: number) => void;
|
|
@@ -57,5 +57,9 @@ export default class YearAndMonthFoundation extends BaseFoundation<YearAndMonthA
|
|
|
57
57
|
destroy(): void;
|
|
58
58
|
selectYear(item: YearScrollItem): void;
|
|
59
59
|
selectMonth(item: MonthScrollItem): void;
|
|
60
|
+
/**
|
|
61
|
+
* After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
|
|
62
|
+
*/
|
|
63
|
+
autoSelectMonth(item: YearScrollItem): void;
|
|
60
64
|
backToMain(): void;
|
|
61
65
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setMonth, setYear } from 'date-fns';
|
|
1
2
|
import BaseFoundation from '../base/foundation';
|
|
2
3
|
export default class YearAndMonthFoundation extends BaseFoundation {
|
|
3
4
|
constructor(adapter) {
|
|
@@ -13,7 +14,7 @@ export default class YearAndMonthFoundation extends BaseFoundation {
|
|
|
13
14
|
selectYear(item) {
|
|
14
15
|
const year = item.value;
|
|
15
16
|
|
|
16
|
-
this._adapter.setCurrentYear(year);
|
|
17
|
+
this._adapter.setCurrentYear(year, () => this.autoSelectMonth(item));
|
|
17
18
|
|
|
18
19
|
this._adapter.notifySelectYear(year);
|
|
19
20
|
}
|
|
@@ -27,6 +28,59 @@ export default class YearAndMonthFoundation extends BaseFoundation {
|
|
|
27
28
|
|
|
28
29
|
this._adapter.notifySelectMonth(month);
|
|
29
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* After selecting a year, if the currentMonth is disabled, automatically select a non-disabled month
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
autoSelectMonth(item) {
|
|
37
|
+
const {
|
|
38
|
+
disabledDate,
|
|
39
|
+
locale
|
|
40
|
+
} = this._adapter.getProps();
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
months,
|
|
44
|
+
currentMonth
|
|
45
|
+
} = this._adapter.getStates();
|
|
46
|
+
|
|
47
|
+
const currentDate = setYear(Date.now(), item.year);
|
|
48
|
+
const isCurrentMonthDisabled = disabledDate(setMonth(currentDate, currentMonth - 1));
|
|
49
|
+
|
|
50
|
+
if (isCurrentMonthDisabled) {
|
|
51
|
+
const currentIndex = months.findIndex(_ref => {
|
|
52
|
+
let {
|
|
53
|
+
month
|
|
54
|
+
} = _ref;
|
|
55
|
+
return month === currentMonth;
|
|
56
|
+
});
|
|
57
|
+
let validMonth; // First look in the back, if you can't find it in the back, then look in the front
|
|
58
|
+
|
|
59
|
+
validMonth = months.slice(currentIndex).find(_ref2 => {
|
|
60
|
+
let {
|
|
61
|
+
month
|
|
62
|
+
} = _ref2;
|
|
63
|
+
return !disabledDate(setMonth(currentDate, month - 1));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!validMonth) {
|
|
67
|
+
validMonth = months.slice(0, currentIndex).find(_ref3 => {
|
|
68
|
+
let {
|
|
69
|
+
month
|
|
70
|
+
} = _ref3;
|
|
71
|
+
return !disabledDate(setMonth(currentDate, month - 1));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (validMonth) {
|
|
76
|
+
this.selectMonth({
|
|
77
|
+
month: validMonth.month,
|
|
78
|
+
value: locale.fullMonths[validMonth.month],
|
|
79
|
+
disabled: false
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
30
84
|
|
|
31
85
|
backToMain() {
|
|
32
86
|
this._adapter.notifyBackToMain();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douyinfe/semi-foundation",
|
|
3
|
-
"version": "2.24.
|
|
3
|
+
"version": "2.24.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build:lib": "node ./scripts/compileLib.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"*.scss",
|
|
24
24
|
"*.css"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "cdd012ac90665b020133f4b01c4c07c8399e4296",
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@babel/plugin-transform-runtime": "^7.15.8",
|
|
29
29
|
"@babel/preset-env": "^7.15.8",
|