dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
164 lines (163 loc) • 5 kB
JavaScript
import { j as o } from "./jsx-runtime-C5mzlN2N.js";
import { useState as h, useEffect as g, useMemo as v } from "react";
import { n as k, G as y } from "./timepicker-CVwZY2bQ-6XH6bbfh.js";
import { d as r } from "./dayjs.min-DQzb66fB.js";
import { u as p } from "./check-DE-1lGDl-24KCJ29m.js";
import { O as N, _ as w, u as M } from "./popover-DDxpKohG-BbuLlzlz.js";
import { m as x } from "./utils-D0f6bOsw-HrLsble-.js";
import { u as L } from "./useTranslation-dH-uwymc.js";
import { c as T } from "./createLucideIcon-B950nf2d.js";
/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/
const C = [
["path", { d: "M11 14h1v4", key: "fy54vd" }],
["path", { d: "M16 2v4", key: "4m81vk" }],
["path", { d: "M3 10h18", key: "8toen8" }],
["path", { d: "M8 2v4", key: "1cmpym" }],
["rect", { x: "3", y: "4", width: "18", height: "18", rx: "2", key: "12vinp" }]
], S = T("calendar-1", C), q = ({
className: b,
format: n = k,
selected: c,
timezone: i,
onRangeSelected: D = () => {
},
placeholder: u
}) => {
const { t: s } = L(), [j, f] = h(!1), [t, m] = h();
g(() => {
m(c);
}, [c]);
const O = v(() => {
const e = r().endOf("day");
return [
{
from: e.startOf("week").toDate(),
to: e.endOf("week").toDate(),
label: s("This week")
},
{
from: e.startOf("month").toDate(),
to: e.endOf("month").toDate(),
label: s("This month")
},
{
from: e.startOf("year").toDate(),
to: e.endOf("year").toDate(),
label: s("This year")
},
{
from: e.subtract(7, "day").startOf("day").toDate(),
to: e.toDate(),
label: s("Last 7 days")
},
{
from: e.subtract(30, "day").startOf("day").toDate(),
to: e.toDate(),
label: s("Last 30 days")
},
{
from: e.subtract(3, "month").startOf("day").toDate(),
to: e.toDate(),
label: s("Last 3 months")
},
{
from: e.subtract(6, "month").startOf("day").toDate(),
to: e.toDate(),
label: s("Last 6 months")
},
{
from: e.subtract(12, "month").startOf("day").toDate(),
to: e.toDate(),
label: s("Last 12 months")
}
];
}, [s]), d = (e) => {
const { from: a, to: l } = e;
m({ from: a, to: l }), a && l && (D({ from: a, to: l }), f(!1));
};
return /* @__PURE__ */ o.jsx("div", { className: x("grid gap-2", b), children: /* @__PURE__ */ o.jsxs(N, { open: j, onOpenChange: f, children: [
/* @__PURE__ */ o.jsx(w, { asChild: !0, children: /* @__PURE__ */ o.jsxs(
p,
{
id: "date",
size: "sm",
variant: "secondary",
className: x(
"min-w-[170px] text-body-xs-regular justify-between",
!t && "text-primary"
),
children: [
t != null && t.from ? t.to ? /* @__PURE__ */ o.jsxs(o.Fragment, { children: [
r(t.from).format(n),
" -",
" ",
r(t.to).format(n)
] }) : r(t.from).format(n) : /* @__PURE__ */ o.jsx("span", { className: "text-secondary", children: u }),
/* @__PURE__ */ o.jsx(S, { className: "text-secondary" })
]
}
) }),
/* @__PURE__ */ o.jsxs(M, { className: "w-auto p-0 flex", align: "end", side: "bottom", children: [
/* @__PURE__ */ o.jsx(
"div",
{
className: "space-y-1 flex flex-col p-2 border-e border-border-alpha-light",
children: O.map((e, a) => /* @__PURE__ */ o.jsx(
p,
{
size: "xs",
variant: "ghost",
className: "justify-start",
onClick: () => d(e),
children: e.label
},
a
))
}
),
/* @__PURE__ */ o.jsx(
y,
{
className: "border-e border-border-alpha-light",
mode: "single",
endMonth: t == null ? void 0 : t.to,
selected: t == null ? void 0 : t.from,
selectedToDate: t == null ? void 0 : t.to,
selectedFromDate: t == null ? void 0 : t.from,
timeZone: i,
disabled: t != null && t.to ? {
after: t.to
} : void 0,
onSelect: (e) => {
m({ ...t, from: e });
}
}
),
/* @__PURE__ */ o.jsx(
y,
{
mode: "single",
startMonth: t == null ? void 0 : t.from,
selected: t == null ? void 0 : t.to,
timeZone: i,
disabled: t != null && t.from ? {
before: t.from
} : void 0,
selectedToDate: t == null ? void 0 : t.to,
selectedFromDate: t == null ? void 0 : t.from,
onSelect: (e) => {
t && d({ ...t, to: e });
}
}
)
] })
] }) });
};
export {
q as D
};