@nutui/nutui-react-taro
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
783 lines (782 loc) • 29 kB
JavaScript
import React__default, { useState, useRef, useEffect } from "react";
import classNames from "classnames";
import { ScrollView } from "@tarojs/components";
import Taro, { nextTick } from "@tarojs/taro";
import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
import { a as getNumTwoBit, b as getMonthDays, c as getMonthPreDay, d as date2Str, e as getWhatDay, i as isEqual, g as getDateString, f as compareDate } from "./date-C7eJqrqk.js";
import { r as requestAniFrame } from "./raf-Di10dXPS.js";
import { u as useConfig } from "./configprovider.taro-DpK4IiCE.js";
import { u as usePropsValue } from "./use-props-value-SH9krhkx.js";
const getCurrMonthData = (type, year, month) => {
{
month === 12 && (year += 1);
month = month === 12 ? 1 : ++month;
}
return [year, getNumTwoBit(month), getMonthDays(String(year), String(month))];
};
const getDaysStatus = (type, year, month) => {
let days = getMonthDays(`${year}`, `${month}`);
return Array.from(Array(days), (v, k) => {
return {
day: k + 1,
type,
year,
month
};
});
};
const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
let preMonth = +month - 1;
let preYear = year;
if (preMonth <= 0) {
preMonth = 12;
preYear += 1;
}
let days = getMonthPreDay(+year, +month);
days -= firstDayOfWeek;
if (days >= 7) {
days -= 7;
}
const preDates = getMonthDays(`${preYear}`, `${preMonth}`);
const months = Array.from(Array(preDates), (v, k) => {
return {
day: k + 1,
type,
preYear,
preMonth
};
});
return months.slice(preDates - days);
};
const getWeekDate = (year, month, date, firstDayOfWeek = 0) => {
const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
const nowTime = dateNow.getTime();
let day = dateNow.getDay();
if (firstDayOfWeek === 0) {
const oneDayTime2 = 24 * 60 * 60 * 1e3;
const SundayTime2 = nowTime - day * oneDayTime2;
const SaturdayTime = nowTime + (6 - day) * oneDayTime2;
const sunday2 = date2Str(new Date(SundayTime2));
const saturday = date2Str(new Date(SaturdayTime));
return [sunday2, saturday];
}
day = day === 0 ? 7 : day;
const oneDayTime = 24 * 60 * 60 * 1e3;
const MondayTime = nowTime - (day - 1) * oneDayTime;
const SundayTime = nowTime + (7 - day) * oneDayTime;
const monday = date2Str(new Date(MondayTime));
const sunday = date2Str(new Date(SundayTime));
return [monday, sunday];
};
const formatResultDate = (date) => {
const [year, month, day] = [...date.split("-")];
const formatterDay = getNumTwoBit(Number(day));
const formatterDate = `${year}-${month}-${day}`;
const dayOfWeek = getWhatDay(Number(year), Number(month), Number(day));
return [year, month, formatterDay, formatterDate, dayOfWeek];
};
const getWeekOfYearByYMD = (year, month, date, firstDayOfWeek = 0) => {
const MILLISECONDS_PER_DAY = 864e5;
const dateNow = new Date(year, month - 1, date);
const dateFirst = new Date(year, 0, 1);
const dayOfYear = Math.round((dateNow.valueOf() - dateFirst.valueOf()) / MILLISECONDS_PER_DAY);
const DAYS_OF_FIRST_WEEK = 3;
let dayOfWeek = dateNow.getDay();
let remainder = 6 - dayOfWeek - DAYS_OF_FIRST_WEEK;
if (firstDayOfWeek !== 0) {
dayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
remainder = 7 - dayOfWeek - DAYS_OF_FIRST_WEEK;
}
let weekNo = Math.ceil((dayOfYear + remainder + 1) / 7);
if (weekNo === 0) {
weekNo = getWeekOfYearByYMD(year - 1, 12, 31, firstDayOfWeek);
} else if (weekNo === 53) {
const remainder2 = 7 - dayOfWeek - DAYS_OF_FIRST_WEEK;
weekNo = remainder2 > 0 ? 1 : weekNo;
}
return weekNo;
};
const getWeekNosOfYear = (year, month, firstDayOfWeek) => {
const startWeekNo = getWeekOfYearByYMD(year, month, 1, firstDayOfWeek);
const endWeekNo = getWeekOfYearByYMD(year, month, getMonthDays(`${year}`, `${month}`), firstDayOfWeek);
return Array.from({
length: (endWeekNo === 1 ? 53 : endWeekNo) - (startWeekNo === 53 || startWeekNo === 52 ? 0 : startWeekNo) + 1
}, (_, i) => {
const lastIndex = (endWeekNo === 1 ? 53 : endWeekNo) - startWeekNo;
return `${endWeekNo === 1 && i === lastIndex ? 1 : ((startWeekNo === 53 || startWeekNo === 52) && i !== 0 ? 0 : startWeekNo) + i}`;
});
};
const splitDate = (date) => {
const split = date.indexOf("-") !== -1 ? "-" : "/";
return date.split(split);
};
const isMultiple = (day, days) => {
if (days.length > 0) {
return days.some((item) => {
return isEqual(item, day);
});
}
return false;
};
const isCurrDay = (month, day) => {
const date = `${month.curData[0]}/${month.curData[1]}/${day}`;
return isEqual(date, date2Str(/* @__PURE__ */ new Date(), "/"));
};
const getCurrDate = (day, month) => {
return `${month.curData[0]}/${month.curData[1]}/${getNumTwoBit(+day.day)}`;
};
const isStart = (day, days) => {
return isEqual(days[0], day);
};
const isEnd = (day, days) => {
return isEqual(days[1], day);
};
const isStartAndEnd = (days) => {
return days.length >= 2 && isEqual(days[0], days[1]);
};
const getPreMonths = (type, year, month) => {
const preMonth = +month - 1;
const months = Array.from(Array(preMonth), (v, k) => {
return {
year,
month: k + 1,
yearAndMonth: formatMonth(year, k + 1),
type
};
});
return months;
};
const getMonths = (type, year, month, endMonth = 12) => {
const nextMonth = endMonth - month + 1;
const months = Array.from(Array(nextMonth), (v, k) => {
return {
year,
month: k + month,
yearAndMonth: formatMonth(year, k + month),
type
};
});
return months;
};
const formatMonth = (year, month) => {
return `${year}-${String(month).padStart(2, "0")}`;
};
const formatQuarter = (year, quarter) => {
return `${year}-Q${quarter}`;
};
const getQuarter = (month) => {
if (month < 1 || month > 12) {
throw new Error("月份必须在 1 到 12 之间");
}
const quarter = Math.floor((month - 1) / 3) + 1;
return quarter;
};
const getQuarters = (type, year, month, endMonth = 12) => {
const quarters = [];
const startIndex = month;
const endIndex = endMonth;
for (let index = startIndex; index <= endIndex; index += 3) {
const quarter = getQuarter(index);
quarters.push({
year,
quarter,
yearAndQuarter: formatQuarter(year, quarter),
type
});
}
return quarters;
};
const getPreQuarters = (type, year, month) => {
const quarters = [];
const startIndex = 1;
const endIndex = month - 3;
for (let index = startIndex; index <= endIndex; index += 3) {
const quarter = getQuarter(index);
quarters.push({
year,
quarter,
yearAndQuarter: formatQuarter(year, quarter),
type
});
}
return quarters;
};
const getNextQuarters = (type, year, month, endMonth = 12) => {
const quarters = [];
const startIndex = month + 3;
const endIndex = endMonth;
for (let index = startIndex; index <= endIndex; index += 3) {
const quarter = getQuarter(index);
quarters.push({
year,
quarter,
yearAndQuarter: formatQuarter(year, quarter),
type
});
}
return quarters;
};
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, title: "", startDate: getDateString(0), endDate: getDateString(365), showToday: true, startText: "", endText: "", confirmText: "", showTitle: true, showSubTitle: true, showMonthNumber: false, scrollAnimation: true, firstDayOfWeek: 0, disableDate: (date) => false, renderHeaderButtons: void 0, renderDay: void 0, renderDayTop: void 0, renderDayBottom: void 0, onConfirm: (data) => {
}, onUpdate: () => {
}, onDayClick: (data) => {
}, onPageChange: (data) => {
} });
const CalendarItem = React__default.forwardRef((props, ref) => {
const { locale } = useConfig();
const { style, className, children, popup, type, autoBackfill, title, value, defaultValue, startDate, endDate, showToday, startText, endText, confirmText, showTitle, showSubTitle, showMonthNumber, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderBottomButton, renderDay, renderDayTop, renderDayBottom, onConfirm, onUpdate, onDayClick, onPageChange } = Object.assign(Object.assign({}, defaultProps), props);
const classPrefix = "nut-calendar";
const dayPrefix = "nut-calendar-day";
const weekdays = locale.calendaritem.weekdays;
const weeks = [
...weekdays.slice(firstDayOfWeek, 7),
...weekdays.slice(0, firstDayOfWeek)
];
const monthTitle = locale.calendaritem.monthTitle;
const [yearMonthTitle, setYearMonthTitle] = useState("");
const [monthsData, setMonthsData] = useState([]);
const [monthsNum, setMonthsNum] = useState(0);
const [translateY, setTranslateY] = useState(0);
const [monthDefaultRange, setMonthDefaultRange] = useState([]);
const [scrollTop, setScrollTop] = useState(0);
const [scrollWithAnimation, setScrollWithAnimation] = useState(false);
const propStartDate = startDate || getDateString(0);
const propEndDate = endDate || getDateString(365);
const startDates = splitDate(propStartDate);
const endDates = splitDate(propEndDate);
const [state] = useState({
currDateArray: []
});
const resetDefaultValue = () => {
if (defaultValue || Array.isArray(defaultValue) && defaultValue.length > 0) {
return type !== "single" ? [...defaultValue] : defaultValue;
}
return type === "single" ? "" : [];
};
const [currentDate, setCurrentDate] = usePropsValue({
value,
defaultValue: resetDefaultValue(),
finalValue: [],
onChange: (val) => {
}
});
const weeksPanel = useRef(null);
const monthsRef = useRef(null);
const monthsPanel = useRef(null);
const viewAreaRef = useRef(null);
const [avgHeight, setAvgHeight] = useState(0);
let viewHeight = 0;
const getMonthData = (curData, monthNum) => {
let i = 0;
let date = curData;
const monthData = monthsData;
do {
const y = parseInt(date[0], 10);
const m = parseInt(date[1], 10);
const days = [
...getPreMonthDates("prev", y, m, firstDayOfWeek),
...getDaysStatus("active", y, m)
];
let scrollTop2 = 0;
if (monthData.length > 0) {
const monthEle = monthData[monthData.length - 1];
scrollTop2 = monthEle.scrollTop + monthEle.cssHeight;
}
const cssHeight = 39 + (days.length > 35 ? 384 : 320);
const monthInfo = {
curData: date,
title: monthTitle(y, m),
weekNo: getWeekNosOfYear(y, m, firstDayOfWeek),
monthData: days,
cssHeight,
scrollTop: scrollTop2
};
if (!endDates || !compareDate(`${endDates[0]}/${endDates[1]}/${getMonthDays(endDates[0], endDates[1])}`, `${curData[0]}/${curData[1]}/${curData[2]}`)) {
monthData.push(monthInfo);
}
date = getCurrMonthData("next", y, m);
} while (i++ < monthNum);
setMonthsData(monthData);
};
const setReachedYearMonthInfo = (current) => {
const currentMonthsData = monthsData[current];
if (currentMonthsData.title === yearMonthTitle)
return;
const [year, month] = currentMonthsData.curData;
onPageChange === null || onPageChange === void 0 ? void 0 : onPageChange([year, month, `${year}-${month}`]);
setYearMonthTitle(currentMonthsData.title);
};
const setDefaultRange = (monthNum, current) => {
let start = 0;
let end = 0;
if (monthNum >= 3) {
if (current > 0 && current < monthNum) {
start = current - 1;
end = current + 3;
} else if (current === 0) {
start = current;
end = current + 4;
} else if (current === monthNum) {
start = current - 2;
end = current + 2;
}
} else {
start = 0;
end = monthNum + 2;
}
setMonthDefaultRange([start, end]);
setTranslateY(monthsData[start].scrollTop);
setReachedYearMonthInfo(current);
};
const setDefaultDate = () => {
let defaultData = [];
if (type === "single" && typeof currentDate === "string") {
if (!currentDate.length) {
return defaultData;
}
if (compareDate(currentDate, propStartDate)) {
defaultData = [...splitDate(propStartDate)];
} else if (!compareDate(currentDate, propEndDate)) {
defaultData = [...splitDate(propEndDate)];
} else {
defaultData = [...splitDate(currentDate)];
}
return defaultData;
}
if (Array.isArray(currentDate) && currentDate.length) {
switch (type) {
case "range": {
if (compareDate(currentDate[0], propStartDate)) {
currentDate[0] = propStartDate;
}
if (compareDate(propEndDate, currentDate[1])) {
currentDate[1] = propEndDate;
}
defaultData = [
...splitDate(currentDate[0]),
...splitDate(currentDate[1])
];
break;
}
case "multiple": {
const defaultArr = [];
const obj = {};
currentDate.forEach((item) => {
if (!compareDate(item, propStartDate) && !compareDate(propEndDate, item)) {
if (!Object.hasOwnProperty.call(obj, item)) {
defaultArr.push(item);
obj[item] = item;
}
}
});
currentDate.splice(0, currentDate.length, ...defaultArr);
defaultData = [...splitDate(defaultArr[0])];
break;
}
case "week": {
const [y, m, d] = splitDate(currentDate[0]);
const weekArr = getWeekDate(y, m, d, firstDayOfWeek);
currentDate.splice(0, currentDate.length, ...weekArr);
if (compareDate(currentDate[0], propStartDate)) {
currentDate.splice(0, 1, propStartDate);
}
if (compareDate(propEndDate, currentDate[1])) {
currentDate.splice(1, 1, propEndDate);
}
defaultData = [
...splitDate(currentDate[0]),
...splitDate(currentDate[1])
];
break;
}
}
}
return defaultData;
};
const getCurrentIndex = (defaultData) => {
let current = 0;
let lastCurrent = 0;
if (defaultData.length > 0) {
monthsData.forEach((item, index) => {
if (item.title === monthTitle(defaultData[0], defaultData[1])) {
current = index;
}
if (type === "range" || type === "week") {
if (item.title === monthTitle(defaultData[3], defaultData[4])) {
lastCurrent = index;
}
}
});
} else {
const date = /* @__PURE__ */ new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1;
const index = monthsData.findIndex((item) => +item.curData[0] === year && +item.curData[1] === month);
if (index > -1)
current = index;
}
return {
current,
lastCurrent
};
};
const renderCurrentDate = (defaultData, current) => {
if (!defaultData.length)
return;
const date = monthsData[current.current];
switch (type) {
case "range": {
handleDayClick({ day: defaultData[2], type: "active" }, date);
handleDayClick({ day: defaultData[5], type: "active" }, monthsData[current.lastCurrent]);
break;
}
case "week": {
handleDayClick({ day: defaultData[2], type: "curr" }, date);
break;
}
case "multiple": {
[...currentDate].forEach((item) => {
const dateArr = splitDate(item);
let currentIndex = current.current;
currentIndex = monthsData.findIndex((item2) => item2.title === monthTitle(dateArr[0], dateArr[1]));
handleDayClick({ day: dateArr[2], type: "active" }, monthsData[currentIndex]);
});
break;
}
default: {
handleDayClick({ day: defaultData[2], type: "active" }, date);
break;
}
}
};
const getMonthsPanel = () => {
return monthsPanel.current;
};
const getMonthsRef = () => {
return monthsRef.current;
};
const requestAniFrameFunc = (current, monthNum) => {
const lastItem = monthsData[monthsData.length - 1];
const containerHeight = lastItem.cssHeight + lastItem.scrollTop;
requestAniFrame(() => {
if (monthsRef && monthsPanel && viewAreaRef) {
viewHeight = getMonthsRef().clientHeight;
getMonthsPanel().style.height = `${containerHeight}px`;
const currTop = monthsData[current].scrollTop;
getMonthsRef().scrollTop = currTop;
setScrollTop(currTop);
nextTick(() => setScrollWithAnimation(true));
}
});
setAvgHeight(Math.floor(containerHeight / (monthNum + 1)));
};
const getMonthNum = () => {
let monthNum = Number(endDates[1]) - Number(startDates[1]);
const yearNum = Number(endDates[0]) - Number(startDates[0]);
if (yearNum > 0)
monthNum += 12 * yearNum;
if (monthNum <= 0)
monthNum = 1;
setMonthsNum(monthNum);
return monthNum;
};
const initData = () => {
const monthNum = getMonthNum();
getMonthData(startDates, monthNum);
const defaultData = setDefaultDate();
const current = getCurrentIndex(defaultData);
const currentIndex = current.current;
renderCurrentDate(defaultData, current);
setDefaultRange(monthNum, currentIndex);
requestAniFrameFunc(currentIndex, monthNum);
};
useEffect(() => {
initData();
}, []);
const resetRender = () => {
state.currDateArray.splice(0);
monthsData.splice(0);
initData();
};
useEffect(() => {
setCurrentDate(resetDefaultValue());
}, [defaultValue]);
useEffect(() => {
popup && resetRender();
}, [currentDate]);
const scrollToDate = (date) => {
if (compareDate(date, propStartDate)) {
date = propStartDate;
} else if (!compareDate(date, propEndDate)) {
date = propEndDate;
}
const dateArr = splitDate(date);
monthsData.forEach((item, index) => {
if (item.title === monthTitle(dateArr[0], dateArr[1])) {
const currTop = monthsData[index].scrollTop;
if (monthsRef.current) {
const distance = currTop - monthsRef.current.scrollTop;
if (scrollAnimation) {
let flag = 0;
const interval = setInterval(() => {
flag++;
if (monthsRef.current) {
const offset = distance / 10;
monthsRef.current.scrollTop += offset;
}
if (flag >= 10) {
clearInterval(interval);
if (monthsRef.current) {
monthsRef.current.scrollTop = currTop;
setScrollTop(currTop);
}
}
}, 40);
} else {
monthsRef.current.scrollTop = currTop;
setScrollTop(currTop);
}
}
}
});
};
const monthsViewScroll = (e) => {
if (monthsData.length <= 1)
return;
const scrollTop2 = e.target.scrollTop;
Taro.getEnv() === "WEB" && setScrollTop(scrollTop2);
let current = Math.floor(scrollTop2 / avgHeight);
if (current < 0)
return;
if (!monthsData[current + 1])
return;
const nextTop = monthsData[current + 1].scrollTop;
const nextHeight = monthsData[current + 1].cssHeight;
if (current === 0) {
if (scrollTop2 >= nextTop)
current += 1;
} else if (current > 0 && current < monthsNum - 1) {
if (scrollTop2 >= nextTop)
current += 1;
if (scrollTop2 < monthsData[current].scrollTop)
current -= 1;
} else {
const viewPosition = Math.round(scrollTop2 + viewHeight);
if (current + 1 <= monthsNum && viewPosition >= nextTop + nextHeight) {
current += 1;
}
if (current >= 1 && scrollTop2 < monthsData[current - 1].scrollTop) {
current -= 1;
}
}
setDefaultRange(monthsNum, current);
};
React__default.useImperativeHandle(ref, () => ({
scrollToDate
}));
const isDisable = (day, month) => {
if (day.type !== "active")
return true;
const dateStr = getCurrDate(day, month);
if (compareDate(dateStr, propStartDate))
return true;
if (compareDate(propEndDate, dateStr))
return true;
return false;
};
const getClasses = (day, month) => {
const dateStr = getCurrDate(day, month);
if (isDisable(day, month))
return `${dayPrefix}-disabled`;
const activeCls = `${dayPrefix}-active`;
if (type === "range" || type === "week") {
if (isStart(dateStr, currentDate))
return `${activeCls} active-start`;
if (isEnd(dateStr, currentDate)) {
return `${activeCls} active-end`;
}
if (currentDate.length === 2 && compareDate(currentDate[0], dateStr) && compareDate(dateStr, currentDate[1])) {
return disableDate(day) ? `${dayPrefix}-choose-disabled` : `${dayPrefix}-choose`;
}
} else if (type === "multiple" && isMultiple(dateStr, currentDate) || !Array.isArray(currentDate) && isEqual(currentDate, dateStr)) {
return activeCls;
}
if (disableDate(day))
return `${dayPrefix}-disabled`;
return null;
};
const handleDayClick = (day, month, isFirst = true) => {
if (isDisable(day, month) || disableDate(day))
return;
const days = [...month.curData];
const [y, m] = month.curData;
days[2] = typeof day.day === "number" ? getNumTwoBit(day.day) : day.day;
days[3] = `${days[0]}/${days[1]}/${days[2]}`;
days[4] = getWhatDay(+days[0], +days[1], +days[2]);
const newDate = days[3];
switch (type) {
case "multiple": {
if (Array.isArray(currentDate)) {
if (currentDate.length > 0) {
const hasIndex = currentDate.findIndex((item) => item === newDate);
if (isFirst) {
state.currDateArray.push([...days]);
} else if (hasIndex > -1) {
currentDate.splice(hasIndex, 1);
state.currDateArray.splice(hasIndex, 1);
} else {
currentDate.push(newDate);
state.currDateArray.push([...days]);
}
} else {
currentDate.push(newDate);
state.currDateArray = [[...days]];
}
}
break;
}
case "range": {
if (Array.isArray(currentDate)) {
if (currentDate.length === 2 || currentDate.length === 0) {
currentDate.splice(0, currentDate.length, newDate);
state.currDateArray = [[...days]];
} else if (compareDate(currentDate[0], newDate)) {
currentDate.push(newDate);
state.currDateArray = [...state.currDateArray, [...days]];
} else {
currentDate.unshift(newDate);
state.currDateArray = [[...days], ...state.currDateArray];
}
}
break;
}
case "week": {
const weekArr = getWeekDate(y, m, `${day.day}`, firstDayOfWeek);
if (compareDate(weekArr[0], propStartDate)) {
weekArr[0] = propStartDate;
}
if (compareDate(propEndDate, weekArr[1])) {
weekArr[1] = propEndDate;
}
currentDate.splice(0, currentDate.length, ...weekArr);
state.currDateArray = [
formatResultDate(weekArr[0]),
formatResultDate(weekArr[1])
];
break;
}
default: {
setCurrentDate(newDate);
state.currDateArray = [...days];
break;
}
}
if (!isFirst) {
onDayClick === null || onDayClick === void 0 ? void 0 : onDayClick(state.currDateArray);
if (autoBackfill || !popup) {
confirm();
}
}
setMonthsData(monthsData.slice());
};
const confirm = () => {
if (type === "range" && state.currDateArray.length === 2 || type !== "range") {
const chooseData = state.currDateArray.slice(0);
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(chooseData);
if (popup) {
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
}
}
};
const classes = classNames(classPrefix, {
[`${classPrefix}-title`]: !popup,
[`${classPrefix}-nofooter`]: !!autoBackfill
}, className);
const headerClasses = classNames({
[`${classPrefix}-header`]: true,
[`${classPrefix}-header-title`]: !popup
});
const isStartTip = (day, month) => {
return (type === "range" || type === "week") && day.type === "active" && isStart(getCurrDate(day, month), currentDate);
};
const isEndTip = (day, month) => {
return currentDate.length >= 2 && (type === "range" || type === "week") && day.type === "active" && isEnd(getCurrDate(day, month), currentDate);
};
const renderHeader = () => {
return React__default.createElement(
"div",
{ className: headerClasses },
showTitle && React__default.createElement("div", { className: `${classPrefix}-title` }, title || locale.calendaritem.title),
renderHeaderButtons && React__default.createElement("div", { className: `${classPrefix}-header-buttons` }, renderHeaderButtons()),
showSubTitle && React__default.createElement("div", { className: `${classPrefix}-sub-title` }, yearMonthTitle),
React__default.createElement("div", { className: `${classPrefix}-weeks ${showMonthNumber ? `${classPrefix}-weeks-shrink` : ""}`, ref: weeksPanel }, weeks.map((item) => React__default.createElement("div", { className: `${classPrefix}-week-item`, key: item }, item)))
);
};
const renderItem = (month, day, index) => {
const startTip = isStartTip(day, month);
const endTip = isEndTip(day, month);
const noStartNorEnd = !startTip && !endTip;
return React__default.createElement(
"div",
{ className: classNames("nut-calendar-day", getClasses(day, month)), onClick: () => handleDayClick(day, month, false), key: index },
React__default.createElement("div", { className: `${classPrefix}-day-day` }, renderDay ? renderDay(day) : day.day),
!startTip && renderDayTop && React__default.createElement("div", { className: `${classPrefix}-day-info-top` }, renderDayTop(day)),
noStartNorEnd && renderDayBottom && React__default.createElement("div", { className: `${classPrefix}-day-info-bottom` }, renderDayBottom(day)),
noStartNorEnd && !renderDayBottom && showToday && isCurrDay(month, day.day) && React__default.createElement("div", { className: `${classPrefix}-day-info-curr` }, locale.calendaritem.today),
startTip && React__default.createElement("div", { className: classNames("nut-calendar-day-info", {
"nut-calendar-day-info-top": isStartAndEnd(currentDate)
}) }, startText || locale.calendaritem.start),
endTip && React__default.createElement("div", { className: `${classPrefix}-day-info` }, endText || locale.calendaritem.end)
);
};
const renderPanel = (month, key) => {
return React__default.createElement(
"div",
{ className: `${classPrefix}-month`, key },
React__default.createElement("div", { className: `${classPrefix}-month-title` }, month.title),
React__default.createElement(
"div",
{ className: `${showMonthNumber ? "shrink" : ""}` },
showMonthNumber && React__default.createElement("div", { className: `${classPrefix}-weeknumber` }, month.weekNo.map((item, index) => React__default.createElement("div", { className: `${classPrefix}-weeknumber-index`, key: index }, item))),
React__default.createElement("div", { className: `${classPrefix}-days` }, month.monthData.map((day, i) => renderItem(month, day, i)))
)
);
};
const renderContent = () => {
return React__default.createElement(
ScrollView,
{ scrollTop, scrollY: true, type: "list", scrollWithAnimation, className: `${classPrefix}-content`, onScroll: monthsViewScroll, ref: monthsRef },
React__default.createElement(
"div",
{ className: `${classPrefix}-pannel`, ref: monthsPanel },
React__default.createElement("div", { ref: viewAreaRef, style: { transform: `translateY(${translateY}px)` } }, monthsData.slice(monthDefaultRange[0], monthDefaultRange[1]).map((month, key) => {
return renderPanel(month, key);
}))
)
);
};
const renderFooter = () => {
return React__default.createElement(
"div",
{ className: "nut-calendar-footer" },
children,
React__default.createElement("div", { onClick: confirm }, renderBottomButton ? renderBottomButton() : React__default.createElement("div", { className: "calendar-confirm-btn" }, confirmText || locale.confirm))
);
};
return React__default.createElement(
"div",
{ className: classes, style },
renderHeader(),
renderContent(),
popup && !autoBackfill ? renderFooter() : ""
);
});
CalendarItem.displayName = "NutCalendarItem";
export {
CalendarItem as C,
getMonths as a,
getPreQuarters as b,
getQuarters as c,
getNextQuarters as d,
getPreMonths as g,
splitDate as s
};