PanelBody.js
3.54 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
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import * as React from 'react';
import classNames from 'classnames';
import PanelContext from '../PanelContext';
import { getLastDay } from '../utils/timeUtil';
export default 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),
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: classNames(cellPrefixCls, _objectSpread((_objectSpread2 = {}, _defineProperty(_objectSpread2, "".concat(cellPrefixCls, "-disabled"), disabled), _defineProperty(_objectSpread2, "".concat(cellPrefixCls, "-start"), getCellText(currentDate) === 1 || picker === 'year' && Number(title) % 10 === 0), _defineProperty(_objectSpread2, "".concat(cellPrefixCls, "-end"), title === 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)));
}