59 lines
2.1 KiB
JavaScript
59 lines
2.1 KiB
JavaScript
import * as React from 'react';
|
|
import { isSameMonth } from '../../utils/dateUtil';
|
|
import RangeContext from '../../RangeContext';
|
|
import useCellClassName from '../../hooks/useCellClassName';
|
|
import PanelBody from '../PanelBody';
|
|
export var MONTH_COL_COUNT = 3;
|
|
var MONTH_ROW_COUNT = 4;
|
|
|
|
function MonthBody(props) {
|
|
var prefixCls = props.prefixCls,
|
|
locale = props.locale,
|
|
value = props.value,
|
|
viewDate = props.viewDate,
|
|
generateConfig = props.generateConfig,
|
|
monthCellRender = props.monthCellRender;
|
|
|
|
var _React$useContext = React.useContext(RangeContext),
|
|
rangedValue = _React$useContext.rangedValue,
|
|
hoverRangedValue = _React$useContext.hoverRangedValue;
|
|
|
|
var cellPrefixCls = "".concat(prefixCls, "-cell");
|
|
var getCellClassName = useCellClassName({
|
|
cellPrefixCls: cellPrefixCls,
|
|
value: value,
|
|
generateConfig: generateConfig,
|
|
rangedValue: rangedValue,
|
|
hoverRangedValue: hoverRangedValue,
|
|
isSameCell: function isSameCell(current, target) {
|
|
return isSameMonth(generateConfig, current, target);
|
|
},
|
|
isInView: function isInView() {
|
|
return true;
|
|
},
|
|
offsetCell: function offsetCell(date, offset) {
|
|
return generateConfig.addMonth(date, offset);
|
|
}
|
|
});
|
|
var monthsLocale = locale.shortMonths || (generateConfig.locale.getShortMonths ? generateConfig.locale.getShortMonths(locale.locale) : []);
|
|
var baseMonth = generateConfig.setMonth(viewDate, 0);
|
|
var getCellNode = monthCellRender ? function (date) {
|
|
return monthCellRender(date, locale);
|
|
} : undefined;
|
|
return React.createElement(PanelBody, Object.assign({}, props, {
|
|
rowNum: MONTH_ROW_COUNT,
|
|
colNum: MONTH_COL_COUNT,
|
|
baseDate: baseMonth,
|
|
getCellNode: getCellNode,
|
|
getCellText: function getCellText(date) {
|
|
return locale.monthFormat ? generateConfig.locale.format(locale.locale, date, locale.monthFormat) : monthsLocale[generateConfig.getMonth(date)];
|
|
},
|
|
getCellClassName: getCellClassName,
|
|
getCellDate: generateConfig.addMonth,
|
|
titleCell: function titleCell(date) {
|
|
return generateConfig.locale.format(locale.locale, date, 'YYYY-MM');
|
|
}
|
|
}));
|
|
}
|
|
|
|
export default MonthBody; |