UNPKG

dgz-ui-shared

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library

179 lines (178 loc) 5.18 kB
import { jsxs as c, jsx as e } from "react/jsx-runtime"; import { Button as w } from "dgz-ui/button"; import { DATE as A, Calendar as d } from "dgz-ui/calendar"; import { Input as M } from "dgz-ui/form"; import { Popover as P, PopoverTrigger as z, PopoverContent as E } from "dgz-ui/popover"; import { dayjs as l, cn as h } from "dgz-ui/utils"; import { XIcon as F, Calendar1 as I } from "lucide-react"; import { useState as T, useEffect as Z, useMemo as $ } from "react"; import { useTranslation as g } from "react-i18next"; const V = ({ className: x, format: n = A, selected: r, timezone: p, onRangeSelected: m = () => { }, placeholder: N, defaultPresets: D, disabled: i, error: C, inputProps: k, ...b }) => { const { t: a } = g(), [L, u] = T(!1), [o, f] = T(); Z(() => { f(r); }, [r]); const j = $(() => { const t = l().endOf("day"); return (D ?? [ { from: t.startOf("week").toDate(), to: t.endOf("week").toDate(), label: a("This week") }, { from: t.startOf("month").toDate(), to: t.endOf("month").toDate(), label: a("This month") }, { from: t.startOf("year").toDate(), to: t.endOf("year").toDate(), label: a("This year") }, { from: t.subtract(7, "day").startOf("day").toDate(), to: t.toDate(), label: a("Last 7 days") }, { from: t.subtract(30, "day").startOf("day").toDate(), to: t.toDate(), label: a("Last 30 days") }, { from: t.subtract(3, "month").startOf("day").toDate(), to: t.toDate(), label: a("Last 3 months") }, { from: t.subtract(6, "month").startOf("day").toDate(), to: t.toDate(), label: a("Last 6 months") }, { from: t.subtract(12, "month").startOf("day").toDate(), to: t.toDate(), label: a("Last 12 months") } ]).map((s) => { var v, O; return { ...s, isActive: ((v = r == null ? void 0 : r.from) == null ? void 0 : v.getTime()) === s.from.getTime() && ((O = r == null ? void 0 : r.to) == null ? void 0 : O.getTime()) === s.to.getTime() }; }); }, [a, r, D]), y = (t) => { f(t), t != null && t.from && (t != null && t.to) && (m(t), u(!1)); }; return /* @__PURE__ */ c(P, { open: L, onOpenChange: u, children: [ /* @__PURE__ */ e(z, { asChild: !0, className: "m-0!", disabled: i, children: /* @__PURE__ */ c("div", { className: "relative", children: [ /* @__PURE__ */ e( M, { variant: C ? "failure" : "default", ...k, readOnly: !0, value: o != null && o.from ? o.to ? `${l(o.from).format(n)}-${l(o.to).format(n)}` : l(o.from).format(n) : "", placeholder: N, disabled: i, className: h(x) } ), o && /* @__PURE__ */ e( F, { onClick: () => { f(void 0), m == null || m(void 0); }, className: h( "text-secondary absolute top-3 right-8 size-4 cursor-pointer", i && "pointer-events-none opacity-50" ) } ), /* @__PURE__ */ e( I, { className: h( "text-secondary absolute top-2.5 right-2 size-5", i && "pointer-events-none opacity-50" ) } ) ] }) }), /* @__PURE__ */ c(E, { className: "flex w-auto p-0", align: "end", side: "bottom", children: [ /* @__PURE__ */ e( "div", { className: "border-border-alpha-light flex flex-col space-y-1 border-e p-2", children: j.map((t, s) => /* @__PURE__ */ e( w, { size: "xs", variant: t.isActive ? "default" : "ghost", className: "justify-start", onClick: () => y(t), children: t.label }, s )) } ), /* @__PURE__ */ e( d, { ...b, className: "border-border-alpha-light border-e", mode: "single", endMonth: o == null ? void 0 : o.to, selected: o == null ? void 0 : o.from, selectedToDate: o == null ? void 0 : o.to, selectedFromDate: o == null ? void 0 : o.from, timeZone: p, disabled: o != null && o.to ? { after: o.to } : void 0, onSelect: (t) => { f({ ...o, from: t }); } } ), /* @__PURE__ */ e( d, { ...b, mode: "single", startMonth: o == null ? void 0 : o.from, selected: o == null ? void 0 : o.to, timeZone: p, disabled: o != null && o.from ? { before: o.from } : void 0, selectedToDate: o == null ? void 0 : o.to, selectedFromDate: o == null ? void 0 : o.from, onSelect: (t) => { o && y({ ...o, to: t }); } } ) ] }) ] }); }; export { V as D }; //# sourceMappingURL=DateRangePicker-C2ZYbgXb.es.js.map