antd-mobile 5.37.0 → 5.37.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/2x/bundle/antd-mobile.cjs.development.js +923 -873
- package/2x/bundle/antd-mobile.cjs.js +7 -7
- package/2x/bundle/antd-mobile.es.development.js +923 -873
- package/2x/bundle/antd-mobile.es.js +4924 -4897
- package/2x/bundle/antd-mobile.umd.development.js +923 -873
- package/2x/bundle/antd-mobile.umd.js +7 -7
- package/2x/bundle/style.css +45 -45
- package/2x/cjs/components/calendar-picker/calendar-picker.js +12 -6
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +3 -0
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.js +41 -19
- package/2x/cjs/components/calendar-picker-view/useSyncScroll.d.ts +2 -0
- package/2x/cjs/components/calendar-picker-view/useSyncScroll.js +39 -0
- package/2x/cjs/components/nav-bar/nav-bar.js +6 -6
- package/2x/es/components/calendar-picker/calendar-picker.js +11 -5
- package/2x/es/components/calendar-picker-view/calendar-picker-view.d.ts +3 -0
- package/2x/es/components/calendar-picker-view/calendar-picker-view.js +40 -19
- package/2x/es/components/calendar-picker-view/useSyncScroll.d.ts +2 -0
- package/2x/es/components/calendar-picker-view/useSyncScroll.js +33 -0
- package/2x/es/components/nav-bar/nav-bar.js +7 -7
- package/2x/package.json +1 -1
- package/bundle/antd-mobile.cjs.development.js +923 -873
- package/bundle/antd-mobile.cjs.js +7 -7
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +923 -873
- package/bundle/antd-mobile.es.js +4924 -4897
- package/bundle/antd-mobile.umd.development.js +923 -873
- package/bundle/antd-mobile.umd.js +7 -7
- package/bundle/style.css +1 -1
- package/cjs/components/calendar-picker/calendar-picker.js +12 -6
- package/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +3 -0
- package/cjs/components/calendar-picker-view/calendar-picker-view.js +41 -19
- package/cjs/components/calendar-picker-view/useSyncScroll.d.ts +2 -0
- package/cjs/components/calendar-picker-view/useSyncScroll.js +39 -0
- package/cjs/components/nav-bar/nav-bar.js +6 -6
- package/es/components/calendar-picker/calendar-picker.js +11 -5
- package/es/components/calendar-picker-view/calendar-picker-view.d.ts +3 -0
- package/es/components/calendar-picker-view/calendar-picker-view.js +40 -19
- package/es/components/calendar-picker-view/useSyncScroll.d.ts +2 -0
- package/es/components/calendar-picker-view/useSyncScroll.js +33 -0
- package/es/components/nav-bar/nav-bar.js +7 -7
- package/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
package/2x/bundle/style.css
CHANGED
|
@@ -661,51 +661,6 @@ div.adm-px-tester {
|
|
|
661
661
|
text-align: center;
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
.adm-divider-horizontal {
|
|
665
|
-
display: flex;
|
|
666
|
-
align-items: center;
|
|
667
|
-
margin: 32px 0;
|
|
668
|
-
border-width: 0;
|
|
669
|
-
border-color: var(--adm-color-border);
|
|
670
|
-
border-style: solid;
|
|
671
|
-
color: var(--adm-color-weak);
|
|
672
|
-
font-size: 28px;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
.adm-divider-left.adm-divider-horizontal:before {
|
|
676
|
-
max-width: 10%;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
.adm-divider-right.adm-divider-horizontal:after {
|
|
680
|
-
max-width: 10%;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
.adm-divider-horizontal:after,
|
|
684
|
-
.adm-divider-horizontal:before {
|
|
685
|
-
flex: auto;
|
|
686
|
-
display: block;
|
|
687
|
-
content: "";
|
|
688
|
-
border-style: inherit;
|
|
689
|
-
border-color: inherit;
|
|
690
|
-
border-width: 2px 0 0;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
.adm-divider-horizontal .adm-divider-content {
|
|
694
|
-
flex: none;
|
|
695
|
-
padding: 0 32px;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
.adm-divider-vertical {
|
|
699
|
-
position: relative;
|
|
700
|
-
top: -.06em;
|
|
701
|
-
display: inline-block;
|
|
702
|
-
height: .9em;
|
|
703
|
-
margin: 0 32px;
|
|
704
|
-
vertical-align: middle;
|
|
705
|
-
border-top: 0;
|
|
706
|
-
border-left: 2px solid var(--adm-color-border);
|
|
707
|
-
}
|
|
708
|
-
|
|
709
664
|
.adm-calendar-picker .adm-calendar-picker-title,
|
|
710
665
|
.adm-calendar-picker .adm-calendar-picker-view-title,
|
|
711
666
|
.adm-calendar-picker .adm-calendar-picker-popup-title,
|
|
@@ -1321,6 +1276,51 @@ div.adm-px-tester {
|
|
|
1321
1276
|
text-align: center;
|
|
1322
1277
|
}
|
|
1323
1278
|
|
|
1279
|
+
.adm-divider-horizontal {
|
|
1280
|
+
display: flex;
|
|
1281
|
+
align-items: center;
|
|
1282
|
+
margin: 32px 0;
|
|
1283
|
+
border-width: 0;
|
|
1284
|
+
border-color: var(--adm-color-border);
|
|
1285
|
+
border-style: solid;
|
|
1286
|
+
color: var(--adm-color-weak);
|
|
1287
|
+
font-size: 28px;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
.adm-divider-left.adm-divider-horizontal:before {
|
|
1291
|
+
max-width: 10%;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
.adm-divider-right.adm-divider-horizontal:after {
|
|
1295
|
+
max-width: 10%;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
.adm-divider-horizontal:after,
|
|
1299
|
+
.adm-divider-horizontal:before {
|
|
1300
|
+
flex: auto;
|
|
1301
|
+
display: block;
|
|
1302
|
+
content: "";
|
|
1303
|
+
border-style: inherit;
|
|
1304
|
+
border-color: inherit;
|
|
1305
|
+
border-width: 2px 0 0;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
.adm-divider-horizontal .adm-divider-content {
|
|
1309
|
+
flex: none;
|
|
1310
|
+
padding: 0 32px;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
.adm-divider-vertical {
|
|
1314
|
+
position: relative;
|
|
1315
|
+
top: -.06em;
|
|
1316
|
+
display: inline-block;
|
|
1317
|
+
height: .9em;
|
|
1318
|
+
margin: 0 32px;
|
|
1319
|
+
vertical-align: middle;
|
|
1320
|
+
border-top: 0;
|
|
1321
|
+
border-left: 2px solid var(--adm-color-border);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
1324
|
.adm-capsule-tabs {
|
|
1325
1325
|
position: relative;
|
|
1326
1326
|
min-width: 0;
|
|
@@ -5,18 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.CalendarPicker = void 0;
|
|
7
7
|
var _tslib = require("tslib");
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
10
|
var _nativeProps = require("../../utils/native-props");
|
|
10
|
-
var
|
|
11
|
+
var _withDefaultProps = require("../../utils/with-default-props");
|
|
11
12
|
var _button = _interopRequireDefault(require("../button"));
|
|
13
|
+
var _calendarPickerView = _interopRequireDefault(require("../calendar-picker-view"));
|
|
14
|
+
var _calendarPickerView2 = require("../calendar-picker-view/calendar-picker-view");
|
|
15
|
+
var _configProvider = require("../config-provider");
|
|
12
16
|
var _divider = _interopRequireDefault(require("../divider"));
|
|
13
17
|
var _popup = _interopRequireDefault(require("../popup"));
|
|
14
|
-
var _withDefaultProps = require("../../utils/with-default-props");
|
|
15
|
-
var _configProvider = require("../config-provider");
|
|
16
|
-
var _calendarPickerView = _interopRequireDefault(require("../calendar-picker-view"));
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
const classPrefix = 'adm-calendar-picker';
|
|
21
22
|
const defaultProps = {
|
|
22
23
|
weekStartsOn: 'Sunday',
|
|
@@ -45,6 +46,9 @@ const CalendarPicker = (0, _react.forwardRef)((p, ref) => {
|
|
|
45
46
|
getContainer
|
|
46
47
|
} = props,
|
|
47
48
|
calendarViewProps = (0, _tslib.__rest)(props, ["visible", "confirmText", "popupClassName", "popupStyle", "popupBodyStyle", "forceRender", "closeOnMaskClick", "onClose", "onConfirm", "onMaskClick", "getContainer"]);
|
|
49
|
+
const viewContext = _react.default.useMemo(() => ({
|
|
50
|
+
visible: !!visible
|
|
51
|
+
}), [visible]);
|
|
48
52
|
const footer = _react.default.createElement("div", {
|
|
49
53
|
className: `${classPrefix}-footer`
|
|
50
54
|
}, _react.default.createElement(_divider.default, null), _react.default.createElement("div", {
|
|
@@ -84,8 +88,10 @@ const CalendarPicker = (0, _react.forwardRef)((p, ref) => {
|
|
|
84
88
|
}
|
|
85
89
|
},
|
|
86
90
|
getContainer: getContainer
|
|
91
|
+
}, _react.default.createElement(_calendarPickerView2.Context.Provider, {
|
|
92
|
+
value: viewContext
|
|
87
93
|
}, _react.default.createElement(_calendarPickerView.default, Object.assign({
|
|
88
94
|
ref: calendarRef
|
|
89
|
-
}, calendarViewProps)), footer)));
|
|
95
|
+
}, calendarViewProps))), footer)));
|
|
90
96
|
});
|
|
91
97
|
exports.CalendarPicker = CalendarPicker;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
import { DateRange, Page } from './convert';
|
|
4
|
+
export declare const Context: React.Context<{
|
|
5
|
+
visible: boolean;
|
|
6
|
+
}>;
|
|
4
7
|
export declare type CalendarPickerViewRef = {
|
|
5
8
|
jumpTo: (page: Page | ((page: Page) => Page)) => void;
|
|
6
9
|
jumpToToday: () => void;
|
|
@@ -3,23 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.CalendarPickerView = void 0;
|
|
6
|
+
exports.Context = exports.CalendarPickerView = void 0;
|
|
7
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
9
|
+
var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
10
|
+
var _isoWeek = _interopRequireDefault(require("dayjs/plugin/isoWeek"));
|
|
7
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
12
|
var _nativeProps = require("../../utils/native-props");
|
|
9
|
-
var
|
|
10
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
|
+
var _usePropsValue = require("../../utils/use-props-value");
|
|
11
14
|
var _withDefaultProps = require("../../utils/with-default-props");
|
|
12
15
|
var _configProvider = require("../config-provider");
|
|
13
|
-
var _isoWeek = _interopRequireDefault(require("dayjs/plugin/isoWeek"));
|
|
14
|
-
var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
15
|
-
var _usePropsValue = require("../../utils/use-props-value");
|
|
16
16
|
var _convert = require("./convert");
|
|
17
|
-
|
|
17
|
+
var _useSyncScroll = _interopRequireDefault(require("./useSyncScroll"));
|
|
18
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
_dayjs.default.extend(_isoWeek.default);
|
|
21
22
|
_dayjs.default.extend(_isSameOrBefore.default);
|
|
22
23
|
const classPrefix = 'adm-calendar-picker-view';
|
|
24
|
+
const Context = _react.default.createContext({
|
|
25
|
+
visible: false
|
|
26
|
+
});
|
|
27
|
+
exports.Context = Context;
|
|
23
28
|
const defaultProps = {
|
|
24
29
|
weekStartsOn: 'Sunday',
|
|
25
30
|
defaultValue: null,
|
|
@@ -29,6 +34,7 @@ const defaultProps = {
|
|
|
29
34
|
};
|
|
30
35
|
const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
31
36
|
var _a;
|
|
37
|
+
const bodyRef = (0, _react.useRef)(null);
|
|
32
38
|
const today = (0, _dayjs.default)();
|
|
33
39
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
34
40
|
const {
|
|
@@ -53,6 +59,13 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
53
59
|
});
|
|
54
60
|
const [intermediate, setIntermediate] = (0, _react.useState)(false);
|
|
55
61
|
const [current, setCurrent] = (0, _react.useState)(() => (0, _dayjs.default)(dateRange ? dateRange[0] : today).date(1));
|
|
62
|
+
// =============================== Scroll ===============================
|
|
63
|
+
const context = (0, _react.useContext)(Context);
|
|
64
|
+
const scrollTo = (0, _useSyncScroll.default)(current, context.visible, bodyRef);
|
|
65
|
+
// ============================== Boundary ==============================
|
|
66
|
+
const maxDay = (0, _react.useMemo)(() => props.max ? (0, _dayjs.default)(props.max) : current.add(6, 'month'), [props.max, current]);
|
|
67
|
+
const minDay = (0, _react.useMemo)(() => props.min ? (0, _dayjs.default)(props.min) : current, [props.min, current]);
|
|
68
|
+
// ================================ Refs ================================
|
|
56
69
|
(0, _react.useImperativeHandle)(ref, () => ({
|
|
57
70
|
jumpTo: pageOrPageGenerator => {
|
|
58
71
|
let page;
|
|
@@ -64,20 +77,23 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
64
77
|
} else {
|
|
65
78
|
page = pageOrPageGenerator;
|
|
66
79
|
}
|
|
67
|
-
|
|
80
|
+
const next = (0, _convert.convertPageToDayjs)(page);
|
|
81
|
+
setCurrent(next);
|
|
82
|
+
scrollTo(next);
|
|
68
83
|
},
|
|
69
84
|
jumpToToday: () => {
|
|
70
|
-
|
|
85
|
+
const next = (0, _dayjs.default)().date(1);
|
|
86
|
+
setCurrent(next);
|
|
87
|
+
scrollTo(next);
|
|
71
88
|
},
|
|
72
89
|
getDateRange: () => dateRange
|
|
73
90
|
}));
|
|
91
|
+
// =============================== Render ===============================
|
|
74
92
|
const header = _react.default.createElement("div", {
|
|
75
93
|
className: `${classPrefix}-header`
|
|
76
94
|
}, _react.default.createElement("div", {
|
|
77
95
|
className: `${classPrefix}-title`
|
|
78
96
|
}, (_a = props.title) !== null && _a !== void 0 ? _a : locale.Calendar.title));
|
|
79
|
-
const maxDay = (0, _react.useMemo)(() => props.max ? (0, _dayjs.default)(props.max) : current.add(6, 'month'), [props.max, current]);
|
|
80
|
-
const minDay = (0, _react.useMemo)(() => props.min ? (0, _dayjs.default)(props.min) : current, [props.min, current]);
|
|
81
97
|
function renderBody() {
|
|
82
98
|
var _a;
|
|
83
99
|
const cells = [];
|
|
@@ -85,13 +101,21 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
85
101
|
// 遍历月份
|
|
86
102
|
while (monthIterator.isSameOrBefore(maxDay, 'month')) {
|
|
87
103
|
const year = monthIterator.year();
|
|
88
|
-
const month = monthIterator.month();
|
|
104
|
+
const month = monthIterator.month() + 1;
|
|
89
105
|
const renderMap = {
|
|
90
106
|
year,
|
|
91
|
-
month
|
|
107
|
+
month
|
|
92
108
|
};
|
|
109
|
+
const yearMonth = `${year}-${month}`;
|
|
110
|
+
// 获取需要预先填充的空格,如果是 7 天则不需要填充
|
|
111
|
+
const presetEmptyCellCount = props.weekStartsOn === 'Monday' ? monthIterator.date(1).isoWeekday() - 1 : monthIterator.date(1).isoWeekday();
|
|
112
|
+
const presetEmptyCells = presetEmptyCellCount == 7 ? null : Array(presetEmptyCellCount).fill(null).map((_, index) => _react.default.createElement("div", {
|
|
113
|
+
key: index,
|
|
114
|
+
className: `${classPrefix}-cell`
|
|
115
|
+
}));
|
|
93
116
|
cells.push(_react.default.createElement("div", {
|
|
94
|
-
key:
|
|
117
|
+
key: yearMonth,
|
|
118
|
+
"data-year-month": yearMonth
|
|
95
119
|
}, _react.default.createElement("div", {
|
|
96
120
|
className: `${classPrefix}-title`
|
|
97
121
|
}, (_a = locale.Calendar.yearAndMonth) === null || _a === void 0 ? void 0 : _a.replace(/\${(.*?)}/g, (_, variable) => {
|
|
@@ -99,10 +123,7 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
99
123
|
return (_a = renderMap[variable]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
100
124
|
})), _react.default.createElement("div", {
|
|
101
125
|
className: `${classPrefix}-cells`
|
|
102
|
-
}, Array(
|
|
103
|
-
key: index,
|
|
104
|
-
className: `${classPrefix}-cell`
|
|
105
|
-
})), Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
|
|
126
|
+
}, presetEmptyCells, Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
|
|
106
127
|
var _a;
|
|
107
128
|
const d = monthIterator.date(index + 1);
|
|
108
129
|
let isSelect = false;
|
|
@@ -200,7 +221,8 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
200
221
|
return cells;
|
|
201
222
|
}
|
|
202
223
|
const body = _react.default.createElement("div", {
|
|
203
|
-
className: `${classPrefix}-body
|
|
224
|
+
className: `${classPrefix}-body`,
|
|
225
|
+
ref: bodyRef
|
|
204
226
|
}, renderBody());
|
|
205
227
|
const mark = _react.default.createElement("div", {
|
|
206
228
|
className: `${classPrefix}-mark`
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useSyncScroll;
|
|
7
|
+
var _rcUtil = require("rc-util");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
function useSyncScroll(current, visible, bodyRef) {
|
|
10
|
+
const rafRef = (0, _react.useRef)();
|
|
11
|
+
const clean = () => {
|
|
12
|
+
if (rafRef.current) {
|
|
13
|
+
cancelAnimationFrame(rafRef.current);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const scrollTo = (0, _rcUtil.useEvent)(date => {
|
|
17
|
+
clean();
|
|
18
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
19
|
+
if (bodyRef.current) {
|
|
20
|
+
const yearMonth = date.format('YYYY-M');
|
|
21
|
+
const target = bodyRef.current.querySelector(`[data-year-month="${yearMonth}"]`);
|
|
22
|
+
if (target) {
|
|
23
|
+
// Scroll to the top of view
|
|
24
|
+
target.scrollIntoView({
|
|
25
|
+
block: 'start',
|
|
26
|
+
inline: 'nearest'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
(0, _react.useEffect)(() => {
|
|
33
|
+
if (visible && current) {
|
|
34
|
+
scrollTo(current);
|
|
35
|
+
return clean;
|
|
36
|
+
}
|
|
37
|
+
}, [current, visible]);
|
|
38
|
+
return scrollTo;
|
|
39
|
+
}
|
|
@@ -12,19 +12,19 @@ var _withDefaultProps = require("../../utils/with-default-props");
|
|
|
12
12
|
var _configProvider = require("../config-provider");
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
const classPrefix = `adm-nav-bar`;
|
|
15
|
-
const
|
|
16
|
-
backIcon: true
|
|
17
|
-
};
|
|
15
|
+
const defaultBackIcon = _react.default.createElement(_antdMobileIcons.LeftOutline, null);
|
|
18
16
|
const NavBar = props => {
|
|
19
17
|
const {
|
|
20
18
|
navBar: componentConfig = {}
|
|
21
19
|
} = (0, _configProvider.useConfig)();
|
|
22
|
-
const mergedProps = (0, _withDefaultProps.mergeProps)(
|
|
20
|
+
const mergedProps = (0, _withDefaultProps.mergeProps)(componentConfig, props);
|
|
23
21
|
const {
|
|
24
22
|
back,
|
|
25
23
|
backIcon,
|
|
26
24
|
backArrow
|
|
27
25
|
} = mergedProps;
|
|
26
|
+
const mergedDefaultBackIcon = componentConfig.backIcon || defaultBackIcon;
|
|
27
|
+
const mergedBackIcon = (0, _withDefaultProps.mergeProp)(defaultBackIcon, componentConfig.backIcon, backArrow === true ? mergedDefaultBackIcon : backArrow, backIcon === true ? mergedDefaultBackIcon : backIcon);
|
|
28
28
|
return (0, _nativeProps.withNativeProps)(mergedProps, _react.default.createElement("div", {
|
|
29
29
|
className: (0, _classnames.default)(classPrefix)
|
|
30
30
|
}, _react.default.createElement("div", {
|
|
@@ -33,9 +33,9 @@ const NavBar = props => {
|
|
|
33
33
|
}, back !== null && _react.default.createElement("div", {
|
|
34
34
|
className: `${classPrefix}-back`,
|
|
35
35
|
onClick: mergedProps.onBack
|
|
36
|
-
},
|
|
36
|
+
}, mergedBackIcon && _react.default.createElement("span", {
|
|
37
37
|
className: `${classPrefix}-back-arrow`
|
|
38
|
-
},
|
|
38
|
+
}, mergedBackIcon), _react.default.createElement("span", {
|
|
39
39
|
"aria-hidden": 'true'
|
|
40
40
|
}, back)), mergedProps.left), _react.default.createElement("div", {
|
|
41
41
|
className: `${classPrefix}-title`
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
+
import classNames from 'classnames';
|
|
2
3
|
import React, { forwardRef, useRef } from 'react';
|
|
3
4
|
import { withNativeProps } from '../../utils/native-props';
|
|
4
|
-
import
|
|
5
|
+
import { mergeProps } from '../../utils/with-default-props';
|
|
5
6
|
import Button from '../button';
|
|
7
|
+
import CalendarPickerView from '../calendar-picker-view';
|
|
8
|
+
import { Context } from '../calendar-picker-view/calendar-picker-view';
|
|
9
|
+
import { useConfig } from '../config-provider';
|
|
6
10
|
import Divider from '../divider';
|
|
7
11
|
import Popup from '../popup';
|
|
8
|
-
import { mergeProps } from '../../utils/with-default-props';
|
|
9
|
-
import { useConfig } from '../config-provider';
|
|
10
|
-
import CalendarPickerView from '../calendar-picker-view';
|
|
11
12
|
const classPrefix = 'adm-calendar-picker';
|
|
12
13
|
const defaultProps = {
|
|
13
14
|
weekStartsOn: 'Sunday',
|
|
@@ -36,6 +37,9 @@ export const CalendarPicker = forwardRef((p, ref) => {
|
|
|
36
37
|
getContainer
|
|
37
38
|
} = props,
|
|
38
39
|
calendarViewProps = __rest(props, ["visible", "confirmText", "popupClassName", "popupStyle", "popupBodyStyle", "forceRender", "closeOnMaskClick", "onClose", "onConfirm", "onMaskClick", "getContainer"]);
|
|
40
|
+
const viewContext = React.useMemo(() => ({
|
|
41
|
+
visible: !!visible
|
|
42
|
+
}), [visible]);
|
|
39
43
|
const footer = React.createElement("div", {
|
|
40
44
|
className: `${classPrefix}-footer`
|
|
41
45
|
}, React.createElement(Divider, null), React.createElement("div", {
|
|
@@ -75,7 +79,9 @@ export const CalendarPicker = forwardRef((p, ref) => {
|
|
|
75
79
|
}
|
|
76
80
|
},
|
|
77
81
|
getContainer: getContainer
|
|
82
|
+
}, React.createElement(Context.Provider, {
|
|
83
|
+
value: viewContext
|
|
78
84
|
}, React.createElement(CalendarPickerView, Object.assign({
|
|
79
85
|
ref: calendarRef
|
|
80
|
-
}, calendarViewProps)), footer)));
|
|
86
|
+
}, calendarViewProps))), footer)));
|
|
81
87
|
});
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
import { DateRange, Page } from './convert';
|
|
4
|
+
export declare const Context: React.Context<{
|
|
5
|
+
visible: boolean;
|
|
6
|
+
}>;
|
|
4
7
|
export declare type CalendarPickerViewRef = {
|
|
5
8
|
jumpTo: (page: Page | ((page: Page) => Page)) => void;
|
|
6
9
|
jumpToToday: () => void;
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import React, { forwardRef, useState, useImperativeHandle, useMemo } from 'react';
|
|
2
|
-
import { withNativeProps } from '../../utils/native-props';
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
1
|
import classNames from 'classnames';
|
|
5
|
-
import
|
|
6
|
-
import { useConfig } from '../config-provider';
|
|
7
|
-
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
8
3
|
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
4
|
+
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
5
|
+
import React, { forwardRef, useContext, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { withNativeProps } from '../../utils/native-props';
|
|
9
7
|
import { usePropsValue } from '../../utils/use-props-value';
|
|
10
|
-
import {
|
|
8
|
+
import { mergeProps } from '../../utils/with-default-props';
|
|
9
|
+
import { useConfig } from '../config-provider';
|
|
10
|
+
import { convertPageToDayjs, convertValueToRange } from './convert';
|
|
11
|
+
import useSyncScroll from './useSyncScroll';
|
|
11
12
|
dayjs.extend(isoWeek);
|
|
12
13
|
dayjs.extend(isSameOrBefore);
|
|
13
14
|
const classPrefix = 'adm-calendar-picker-view';
|
|
15
|
+
export const Context = React.createContext({
|
|
16
|
+
visible: false
|
|
17
|
+
});
|
|
14
18
|
const defaultProps = {
|
|
15
19
|
weekStartsOn: 'Sunday',
|
|
16
20
|
defaultValue: null,
|
|
@@ -20,6 +24,7 @@ const defaultProps = {
|
|
|
20
24
|
};
|
|
21
25
|
export const CalendarPickerView = forwardRef((p, ref) => {
|
|
22
26
|
var _a;
|
|
27
|
+
const bodyRef = useRef(null);
|
|
23
28
|
const today = dayjs();
|
|
24
29
|
const props = mergeProps(defaultProps, p);
|
|
25
30
|
const {
|
|
@@ -44,6 +49,13 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
44
49
|
});
|
|
45
50
|
const [intermediate, setIntermediate] = useState(false);
|
|
46
51
|
const [current, setCurrent] = useState(() => dayjs(dateRange ? dateRange[0] : today).date(1));
|
|
52
|
+
// =============================== Scroll ===============================
|
|
53
|
+
const context = useContext(Context);
|
|
54
|
+
const scrollTo = useSyncScroll(current, context.visible, bodyRef);
|
|
55
|
+
// ============================== Boundary ==============================
|
|
56
|
+
const maxDay = useMemo(() => props.max ? dayjs(props.max) : current.add(6, 'month'), [props.max, current]);
|
|
57
|
+
const minDay = useMemo(() => props.min ? dayjs(props.min) : current, [props.min, current]);
|
|
58
|
+
// ================================ Refs ================================
|
|
47
59
|
useImperativeHandle(ref, () => ({
|
|
48
60
|
jumpTo: pageOrPageGenerator => {
|
|
49
61
|
let page;
|
|
@@ -55,20 +67,23 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
55
67
|
} else {
|
|
56
68
|
page = pageOrPageGenerator;
|
|
57
69
|
}
|
|
58
|
-
|
|
70
|
+
const next = convertPageToDayjs(page);
|
|
71
|
+
setCurrent(next);
|
|
72
|
+
scrollTo(next);
|
|
59
73
|
},
|
|
60
74
|
jumpToToday: () => {
|
|
61
|
-
|
|
75
|
+
const next = dayjs().date(1);
|
|
76
|
+
setCurrent(next);
|
|
77
|
+
scrollTo(next);
|
|
62
78
|
},
|
|
63
79
|
getDateRange: () => dateRange
|
|
64
80
|
}));
|
|
81
|
+
// =============================== Render ===============================
|
|
65
82
|
const header = React.createElement("div", {
|
|
66
83
|
className: `${classPrefix}-header`
|
|
67
84
|
}, React.createElement("div", {
|
|
68
85
|
className: `${classPrefix}-title`
|
|
69
86
|
}, (_a = props.title) !== null && _a !== void 0 ? _a : locale.Calendar.title));
|
|
70
|
-
const maxDay = useMemo(() => props.max ? dayjs(props.max) : current.add(6, 'month'), [props.max, current]);
|
|
71
|
-
const minDay = useMemo(() => props.min ? dayjs(props.min) : current, [props.min, current]);
|
|
72
87
|
function renderBody() {
|
|
73
88
|
var _a;
|
|
74
89
|
const cells = [];
|
|
@@ -76,13 +91,21 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
76
91
|
// 遍历月份
|
|
77
92
|
while (monthIterator.isSameOrBefore(maxDay, 'month')) {
|
|
78
93
|
const year = monthIterator.year();
|
|
79
|
-
const month = monthIterator.month();
|
|
94
|
+
const month = monthIterator.month() + 1;
|
|
80
95
|
const renderMap = {
|
|
81
96
|
year,
|
|
82
|
-
month
|
|
97
|
+
month
|
|
83
98
|
};
|
|
99
|
+
const yearMonth = `${year}-${month}`;
|
|
100
|
+
// 获取需要预先填充的空格,如果是 7 天则不需要填充
|
|
101
|
+
const presetEmptyCellCount = props.weekStartsOn === 'Monday' ? monthIterator.date(1).isoWeekday() - 1 : monthIterator.date(1).isoWeekday();
|
|
102
|
+
const presetEmptyCells = presetEmptyCellCount == 7 ? null : Array(presetEmptyCellCount).fill(null).map((_, index) => React.createElement("div", {
|
|
103
|
+
key: index,
|
|
104
|
+
className: `${classPrefix}-cell`
|
|
105
|
+
}));
|
|
84
106
|
cells.push(React.createElement("div", {
|
|
85
|
-
key:
|
|
107
|
+
key: yearMonth,
|
|
108
|
+
"data-year-month": yearMonth
|
|
86
109
|
}, React.createElement("div", {
|
|
87
110
|
className: `${classPrefix}-title`
|
|
88
111
|
}, (_a = locale.Calendar.yearAndMonth) === null || _a === void 0 ? void 0 : _a.replace(/\${(.*?)}/g, (_, variable) => {
|
|
@@ -90,10 +113,7 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
90
113
|
return (_a = renderMap[variable]) === null || _a === void 0 ? void 0 : _a.toString();
|
|
91
114
|
})), React.createElement("div", {
|
|
92
115
|
className: `${classPrefix}-cells`
|
|
93
|
-
}, Array(
|
|
94
|
-
key: index,
|
|
95
|
-
className: `${classPrefix}-cell`
|
|
96
|
-
})), Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
|
|
116
|
+
}, presetEmptyCells, Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
|
|
97
117
|
var _a;
|
|
98
118
|
const d = monthIterator.date(index + 1);
|
|
99
119
|
let isSelect = false;
|
|
@@ -191,7 +211,8 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
191
211
|
return cells;
|
|
192
212
|
}
|
|
193
213
|
const body = React.createElement("div", {
|
|
194
|
-
className: `${classPrefix}-body
|
|
214
|
+
className: `${classPrefix}-body`,
|
|
215
|
+
ref: bodyRef
|
|
195
216
|
}, renderBody());
|
|
196
217
|
const mark = React.createElement("div", {
|
|
197
218
|
className: `${classPrefix}-mark`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEvent } from 'rc-util';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
export default function useSyncScroll(current, visible, bodyRef) {
|
|
4
|
+
const rafRef = useRef();
|
|
5
|
+
const clean = () => {
|
|
6
|
+
if (rafRef.current) {
|
|
7
|
+
cancelAnimationFrame(rafRef.current);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
const scrollTo = useEvent(date => {
|
|
11
|
+
clean();
|
|
12
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
13
|
+
if (bodyRef.current) {
|
|
14
|
+
const yearMonth = date.format('YYYY-M');
|
|
15
|
+
const target = bodyRef.current.querySelector(`[data-year-month="${yearMonth}"]`);
|
|
16
|
+
if (target) {
|
|
17
|
+
// Scroll to the top of view
|
|
18
|
+
target.scrollIntoView({
|
|
19
|
+
block: 'start',
|
|
20
|
+
inline: 'nearest'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (visible && current) {
|
|
28
|
+
scrollTo(current);
|
|
29
|
+
return clean;
|
|
30
|
+
}
|
|
31
|
+
}, [current, visible]);
|
|
32
|
+
return scrollTo;
|
|
33
|
+
}
|
|
@@ -2,22 +2,22 @@ import { LeftOutline } from 'antd-mobile-icons';
|
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { withNativeProps } from '../../utils/native-props';
|
|
5
|
-
import { mergeProps } from '../../utils/with-default-props';
|
|
5
|
+
import { mergeProp, mergeProps } from '../../utils/with-default-props';
|
|
6
6
|
import { useConfig } from '../config-provider';
|
|
7
7
|
const classPrefix = `adm-nav-bar`;
|
|
8
|
-
const
|
|
9
|
-
backIcon: true
|
|
10
|
-
};
|
|
8
|
+
const defaultBackIcon = React.createElement(LeftOutline, null);
|
|
11
9
|
export const NavBar = props => {
|
|
12
10
|
const {
|
|
13
11
|
navBar: componentConfig = {}
|
|
14
12
|
} = useConfig();
|
|
15
|
-
const mergedProps = mergeProps(
|
|
13
|
+
const mergedProps = mergeProps(componentConfig, props);
|
|
16
14
|
const {
|
|
17
15
|
back,
|
|
18
16
|
backIcon,
|
|
19
17
|
backArrow
|
|
20
18
|
} = mergedProps;
|
|
19
|
+
const mergedDefaultBackIcon = componentConfig.backIcon || defaultBackIcon;
|
|
20
|
+
const mergedBackIcon = mergeProp(defaultBackIcon, componentConfig.backIcon, backArrow === true ? mergedDefaultBackIcon : backArrow, backIcon === true ? mergedDefaultBackIcon : backIcon);
|
|
21
21
|
return withNativeProps(mergedProps, React.createElement("div", {
|
|
22
22
|
className: classNames(classPrefix)
|
|
23
23
|
}, React.createElement("div", {
|
|
@@ -26,9 +26,9 @@ export const NavBar = props => {
|
|
|
26
26
|
}, back !== null && React.createElement("div", {
|
|
27
27
|
className: `${classPrefix}-back`,
|
|
28
28
|
onClick: mergedProps.onBack
|
|
29
|
-
},
|
|
29
|
+
}, mergedBackIcon && React.createElement("span", {
|
|
30
30
|
className: `${classPrefix}-back-arrow`
|
|
31
|
-
},
|
|
31
|
+
}, mergedBackIcon), React.createElement("span", {
|
|
32
32
|
"aria-hidden": 'true'
|
|
33
33
|
}, back)), mergedProps.left), React.createElement("div", {
|
|
34
34
|
className: `${classPrefix}-title`
|