@nutui/nutui-react
Version:
京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序
48 lines (47 loc) • 3.03 kB
JavaScript
import React__default, { useRef } from "react";
import Popup__default from "./Popup.js";
import CalendarItem__default from "./CalendarItem.js";
import { U as Utils } from "./date.js";
import { useConfig } from "./ConfigProvider.js";
import { C as ComponentDefaults } from "./typings.js";
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, visible: false, title: "", defaultValue: "", startDate: Utils.getDay(0), endDate: Utils.getDay(365), showToday: true, startText: "", endText: "", confirmText: "", showTitle: true, showSubTitle: true, scrollAnimation: true, firstDayOfWeek: 0, disableDate: (date) => false, renderHeaderButtons: void 0, renderDay: void 0, renderDayTop: void 0, renderDayBottom: void 0, onClose: () => {
}, onConfirm: (param) => {
}, onDayClick: (data) => {
}, onPageChange: (param) => {
} });
const Calendar = React__default.forwardRef((props, ref) => {
const { locale } = useConfig();
const { style, className, children, popup, visible, type, autoBackfill, title, defaultValue, startDate, endDate, showToday, startText, endText, confirmText, showTitle, showSubTitle, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderDay, renderDayTop, renderDayBottom, onClose, onConfirm, onDayClick, onPageChange } = Object.assign(Object.assign({}, defaultProps), props);
const calendarRef = useRef(null);
const close = () => {
onClose && onClose();
};
const choose = (param) => {
close();
onConfirm && onConfirm(param);
};
const closePopup = () => {
close();
};
const select = (param) => {
onDayClick && onDayClick(param);
};
const scrollToDate = (date) => {
var _a;
(_a = calendarRef.current) === null || _a === void 0 ? void 0 : _a.scrollToDate(date);
};
const yearMonthChange = (param) => {
onPageChange && onPageChange(param);
};
React__default.useImperativeHandle(ref, () => ({
scrollToDate
}));
const renderItem = () => {
return React__default.createElement(CalendarItem__default, { ref: calendarRef, style, className, children, type, autoBackfill, popup, title: title || locale.calendaritem.title, defaultValue, startDate, endDate, showToday, startText: startText || locale.calendaritem.start, endText: endText || locale.calendaritem.end, confirmText: confirmText || locale.calendaritem.confirm, showTitle, showSubTitle, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderDay, renderDayTop, renderDayBottom, onConfirm: choose, onDayClick: select, onPageChange: yearMonthChange });
};
return React__default.createElement(React__default.Fragment, null, popup ? React__default.createElement(Popup__default, { className: "nut-calendar-popup", visible, position: "bottom", round: true, closeable: true, destroyOnClose: true, onOverlayClick: closePopup, onCloseIconClick: closePopup, style: { height: "83%" } }, renderItem()) : renderItem());
});
Calendar.displayName = "NutCalendar";
export {
Calendar as default
};