PanelBody.js
4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = PanelBody;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var React = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _PanelContext = _interopRequireDefault(require("../PanelContext"));
var _timeUtil = require("../utils/timeUtil");
function PanelBody(_ref) {
var prefixCls = _ref.prefixCls,
disabledDate = _ref.disabledDate,
onSelect = _ref.onSelect,
picker = _ref.picker,
rowNum = _ref.rowNum,
colNum = _ref.colNum,
prefixColumn = _ref.prefixColumn,
rowClassName = _ref.rowClassName,
baseDate = _ref.baseDate,
getCellClassName = _ref.getCellClassName,
getCellText = _ref.getCellText,
getCellNode = _ref.getCellNode,
getCellDate = _ref.getCellDate,
generateConfig = _ref.generateConfig,
titleCell = _ref.titleCell,
headerCells = _ref.headerCells;
var _React$useContext = React.useContext(_PanelContext.default),
onDateMouseEnter = _React$useContext.onDateMouseEnter,
onDateMouseLeave = _React$useContext.onDateMouseLeave;
var cellPrefixCls = "".concat(prefixCls, "-cell"); // =============================== Body ===============================
var rows = [];
for (var i = 0; i < rowNum; i += 1) {
var row = [];
var rowStartDate = void 0;
var _loop = function _loop(j) {
var _objectSpread2;
var offset = i * colNum + j;
var currentDate = getCellDate(baseDate, offset);
var disabled = disabledDate && disabledDate(currentDate);
if (j === 0) {
rowStartDate = currentDate;
if (prefixColumn) {
row.push(prefixColumn(rowStartDate));
}
}
var title = titleCell && titleCell(currentDate);
row.push( /*#__PURE__*/React.createElement("td", {
key: j,
title: title,
className: (0, _classnames.default)(cellPrefixCls, (0, _objectSpread3.default)((_objectSpread2 = {}, (0, _defineProperty2.default)(_objectSpread2, "".concat(cellPrefixCls, "-disabled"), disabled), (0, _defineProperty2.default)(_objectSpread2, "".concat(cellPrefixCls, "-start"), getCellText(currentDate) === 1 || picker === 'year' && Number(title) % 10 === 0), (0, _defineProperty2.default)(_objectSpread2, "".concat(cellPrefixCls, "-end"), title === (0, _timeUtil.getLastDay)(generateConfig, currentDate) || picker === 'year' && Number(title) % 10 === 9), _objectSpread2), getCellClassName(currentDate))),
onClick: function onClick() {
if (!disabled) {
onSelect(currentDate);
}
},
onMouseEnter: function onMouseEnter() {
if (!disabled && onDateMouseEnter) {
onDateMouseEnter(currentDate);
}
},
onMouseLeave: function onMouseLeave() {
if (!disabled && onDateMouseLeave) {
onDateMouseLeave(currentDate);
}
}
}, getCellNode ? getCellNode(currentDate) : /*#__PURE__*/React.createElement("div", {
className: "".concat(cellPrefixCls, "-inner")
}, getCellText(currentDate))));
};
for (var j = 0; j < colNum; j += 1) {
_loop(j);
}
rows.push( /*#__PURE__*/React.createElement("tr", {
key: i,
className: rowClassName && rowClassName(rowStartDate)
}, row));
}
return /*#__PURE__*/React.createElement("div", {
className: "".concat(prefixCls, "-body")
}, /*#__PURE__*/React.createElement("table", {
className: "".concat(prefixCls, "-content")
}, headerCells && /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, headerCells)), /*#__PURE__*/React.createElement("tbody", null, rows)));
}