@payfit/unity-components
Version:
124 lines (123 loc) • 4.11 kB
JavaScript
import { IconButton as e } from "../icon-button/IconButton.js";
import { calendarBase as t } from "./DateCalendar.variants.js";
import { useMonthsList as n } from "./hooks/useMonthsList.js";
import { useYearsList as r } from "./hooks/useYearsList.js";
import { DateSegmentSelect as i } from "./parts/DateSegmentSelect.js";
import { useState as a } from "react";
import { uyTv as o } from "@payfit/unity-themes";
import { jsx as s, jsxs as c } from "react/jsx-runtime";
import { useIntl as l } from "react-intl";
import { getLocalTimeZone as u, isToday as d, today as f } from "@internationalized/date";
import { Calendar as p, CalendarCell as m, CalendarGrid as h, CalendarGridBody as g, CalendarGridHeader as _, CalendarHeaderCell as v, Heading as y } from "react-aria-components/Calendar";
//#region src/components/date-calendar/DateCalendar.tsx
var b = o({
extend: t,
slots: {
calendarGrid: "uy:border-spacing-25",
calendarCell: [
"uy:data-[selected]:bg-surface-form-active",
"",
"",
"uy:data-[selected]:text-content-form-active",
"uy:data-[today]:data-[selected]:after:bg-border-form-active"
]
},
variants: { isDisabled: { true: { calendarCell: "uy:data-[selected]:bg-transparent uy:data-[selected]:text-content-neutral-disabled" } } }
});
function x({ value: t, defaultValue: o, minValue: x, maxValue: S, onChange: C, onFocusChange: w, ...T }) {
let E = l(), D = f(u()), O = n(), k = r({
startYear: x?.year,
endYear: S?.year
}), [A, j] = a(t ?? o ?? null), [M, N] = a(() => {
let e = t ?? o ?? D;
return x && e.compare(x) < 0 ? x : S && e.compare(S) > 0 ? S : e;
}), P = (e) => {
N((t) => t.set({ month: parseInt(e, 10) }));
}, F = (e) => {
N((t) => t.set({ year: parseInt(e, 10) }));
}, { base: I, calendarWrapper: L, dialogHeader: R, dialogHeaderGroup: z, calendarGrid: B, calendarHeaderCell: V, calendarCell: H } = b({
isDisabled: T.isDisabled,
isInteractive: !T.isDisabled && !T.isReadOnly
}), U = "outlined", W = "primary";
return /* @__PURE__ */ s("div", {
className: I(),
"data-dd-privacy": "mask",
children: /* @__PURE__ */ s(p, {
...T,
minValue: x,
maxValue: S,
value: A,
defaultValue: o,
onChange: (e) => {
j(e), C?.(e);
},
focusedValue: M,
onFocusChange: (e) => {
N(e), w?.(e);
},
children: /* @__PURE__ */ c("div", {
className: L(),
children: [/* @__PURE__ */ c("header", {
className: R(),
children: [
/* @__PURE__ */ s(y, { className: "uy:sr-only" }),
/* @__PURE__ */ c("div", {
className: z({ className: "uy:pl-100 uy:gap-200" }),
children: [/* @__PURE__ */ s(i, {
type: "month",
items: O,
value: M.month.toString(),
onChange: P,
isDisabled: T.isDisabled
}), /* @__PURE__ */ s(i, {
type: "year",
items: k,
value: M.year.toString(),
onChange: F,
isDisabled: T.isDisabled
})]
}),
/* @__PURE__ */ c("div", {
className: z({ className: "uy:ml-auto uy:gap-100" }),
children: [/* @__PURE__ */ s(e, {
slot: "previous",
icon: "CaretLeftOutlined",
color: W,
label: E.formatMessage({
id: "unity:component:common:previous",
defaultMessage: "Previous"
}),
variant: U,
isDisabled: T.isDisabled
}), /* @__PURE__ */ s(e, {
slot: "next",
icon: "CaretRightOutlined",
color: W,
label: E.formatMessage({
id: "unity:component:common:next",
defaultMessage: "Next"
}),
variant: U,
isDisabled: T.isDisabled
})]
})
]
}), /* @__PURE__ */ c(h, {
className: B(),
weekdayStyle: "short",
children: [/* @__PURE__ */ s(_, { children: (e) => /* @__PURE__ */ s(v, {
className: V(),
children: e
}) }), /* @__PURE__ */ s(g, { children: (e) => /* @__PURE__ */ s(m, {
date: e,
"data-today": d(e, u()) ? !0 : void 0,
className: H()
}) })]
})]
})
})
});
}
x.displayName = "DateCalendar";
//#endregion
export { x as DateCalendar };