UNPKG

fui-fancyui

Version:
106 lines (105 loc) 3.29 kB
"use client"; import { jsx as o } from "react/jsx-runtime"; import { useRef as L, useMemo as C, useState as c, useEffect as P } from "react"; import { StyledCalendar as q, MonthContainer as z } from "./Calendar.style.js"; import G from "../MonthWithDays/MonthWithDays.js"; import J from "./utils/useSelectedDates/useSelectedDates.js"; import K from "../../shared/FancyVirtualScroll/FancyVirtualScroll.js"; import I from "../../../utils/hooks/useDebounce/useDebounce.js"; import { generateArrayWithMonthYearRange as N } from "./utils/generateArrayWithMonthYearRange/generateArrayWithMonthYearRange.js"; function te(w) { const { selectedYearMonth: t = { year: (/* @__PURE__ */ new Date()).getFullYear() + 5, month: (/* @__PURE__ */ new Date()).getMonth() }, startCalendarDate: u = { year: (/* @__PURE__ */ new Date()).getFullYear(), month: 0 }, endCalendarDate: m = { year: (/* @__PURE__ */ new Date()).getFullYear() + 5, month: (/* @__PURE__ */ new Date()).getMonth() }, handleDates: x, selectFromTo: M, currentInViewhandler: a, handleSwitchFromTo: F, disabledDateSetting: b, externalMonthsWithDays: l, rangeCalendar: d = !0, themeType: H, startWeekOnDay: R = 1, layer: T } = w, V = L(null), { selectedDates: k, handleDateClick: v } = J({ selectFromTo: M, handleSwitchFromTo: F, handleDates: x, rangeCalendar: d }), n = C( () => N( { year: u.year, month: u.month }, { year: m.year, month: m.month } ), // eslint-disable-next-line react-hooks/exhaustive-deps [] ), h = C(() => n.findIndex((e) => e.month === (t == null ? void 0 : t.month) && e.year === t.year), [t, n]), [f, E] = c(h), [s, i] = c(!1), [r, y] = c(!1), [g, O] = I(() => { i(!1); }, 200), D = () => { O(), i(!0), y(!0); }, S = () => { g(), y(!1); }, $ = (e) => { if (e && r) { i(!0); return; } e && !r && g(); }; P(() => { r || j(); }, [f, r, s]); const [j] = I(() => { a == null || a(n[f]); }, 100); return /* @__PURE__ */ o(q, { ref: V, children: /* @__PURE__ */ o( K, { containerHeight: "300px", itemHeight: 300, scrollSnap: s ? "mandatory" : "proximity", firstItemIndexInView: h, currentFirstItemsInViewHandler: (e) => E(e), onScrollingStateChange: (e) => $(e), attributesContainer: { onTouchStart: D, onTouchEnd: S, onMouseEnter: D, onMouseLeave: S, $externalStyle: { scrollBehavior: s ? "smooth" : "auto" } }, children: n.map((e, A) => { var p; return /* @__PURE__ */ o(z, { "data-month": e.month, "data-year": e.year, children: /* @__PURE__ */ o( G, { disabledDateSetting: b, monthIdx: e.month, startWeekOn: R, externalMonthWithDays: (p = l == null ? void 0 : l[`${e.year}`]) == null ? void 0 : p.find( (B) => B.monthIdx === e.month ), year: e.year, themeType: H, layer: T, handleDateClick: v, isRangePicking: d, selectedDates: k } ) }, A); }) } ) }); } export { te as default };