UNPKG

@rnwonder/react-date-picker

Version:

A lightweight, customizable, and accessible date picker component for React applications.

131 lines (130 loc) 3.35 kB
"use client"; import { jsx as u, Fragment as N } from "react/jsx-runtime"; import { a as I, b as P } from "./index-C-0w3u6j.js"; import B, { memo as O, useState as o, useCallback as d, useEffect as j } from "react"; import { j as k, P as E, R as x } from "./general-DZqASQRm-DXQPvh4C.js"; import { b as F, g as U } from "./format-CMbjATj9-B6oamtiF.js"; const G = O( B.forwardRef((e, A) => { var g, T; const [S, h] = o(""), [f, R] = o([]), [a, i] = o(), [r, m] = o(), [n, V] = o( e.yearSelectorCount ? Math.abs(e.yearSelectorCount) : 20 ), l = d(() => { if (!a || !r) return; const t = r; i(t + 1), m(t + n); }, [n, r, a]), c = d(() => { if (!a || !r) return; const t = a; m(t - 1), i(t - n); }, [n, r, a]), b = d(() => { var t, y; (t = e.setSelectorTwoProps) == null || t.call(e, { ...e, optionsArray: [], locale: e.locale || "en-US", yearArray: f, option: e.year, setOption: e.setYear, attributes: { "data-year": "true" }, handleNext: l, handlePrev: c, range: S, className: "year-selector-option", zIndex: e.zIndex, primaryTextColor: e.primaryTextColor, primaryColor: e.primaryColor, useValueAsName: !0, startYear: a, endYear: r, count: n }), (y = e.setShowSelectorTwo) == null || y.call(e, !0); }, [ n, r, l, c, e, S, a, f, e.locale ]); return j(() => { var C; if (e.yearSelectorType === "compact-dropdown" || !e.year) return; const { range: t, array: y, endYear: w, startYear: Y } = F({ startYear: a, endYear: r, count: n, year: e.year, yearRange: e.yearRange, locale: e.locale || "en-US" }); e.showSelectorTwo || (i(Y), m(w)); const s = k(y, 4); h(t), R(s), (C = e.setSelectorTwoProps) == null || C.call(e, (z) => ({ ...z, yearArray: s, range: t, startYear: Y, endYear: w, count: n, handleNext: l, handlePrev: c })); }, [ n, r, l, c, e.locale, e.showSelectorTwo, e.year, e.yearRange, e.yearSelectorType, a ]), /* @__PURE__ */ u(N, { children: e.yearSelectorType === "compact-dropdown" ? /* @__PURE__ */ u( I, { ...e, optionsArray: E( ((g = e.yearRange) == null ? void 0 : g.start) || x - 51, ((T = e.yearRange) == null ? void 0 : T.end) || x + 20 ).map((t) => t.toString()), option: e.year, setOption: e.setYear, ref: A, attributes: { "data-year": "true" }, useValueAsName: !0, className: "year-selector-option", zIndex: e.zIndex, primaryColor: e.primaryColor, primaryTextColor: e.primaryTextColor } ) : /* @__PURE__ */ u( P, { option: e.year, optionsArray: [], type: "full-size", isOpen: e.showSelectorTwo || !1, onClick: b, noButtonAnimation: e.noButtonAnimation, children: U(e.year, e.locale) } ) }); }) ); export { G as Y };