@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
57 lines (56 loc) • 1.79 kB
JavaScript
import { FieldView as e } from "../FieldView/FieldView.js";
import { accepts as t } from "../../../kit/accepts.js";
import { useFieldBinding as n } from "../../../hooks/useFieldBinding.js";
import { defineField as r } from "../../../kit/contracts.js";
import { formatDate as i, formatDateTimeIn as a } from "../internal/formatTemporal.js";
import { jsx as o } from "react/jsx-runtime";
import { DateRangeField as s, DateRangePickerField as c } from "@mitcsutt/kiln-ui";
//#region src/components/fields/FormDateRangeField/FormDateRangeField.tsx
var l = {
start: "",
end: ""
}, u = (e, { timeZone: t, locale: n, hourCycle: r }) => e.includes("T") ? a(e, t, n, r) : i(e, n), d = r()(function({ warn: r, excluded: i, onBlur: a, picker: d, granularity: f, presets: p, clearable: m, isDateDisabled: h, firstDayOfWeek: g, locale: _, timeZone: v, hourCycle: y, labels: b, ...x }) {
let S = n({
...x,
warn: r,
excluded: i,
accepts: t.dateRange,
empty: l
}), C = S.value ?? l;
if (S.mode === "view") {
let t = {
timeZone: v,
locale: _,
hourCycle: y
}, n = [u(C.start, t), u(C.end, t)].filter((e) => e !== "");
return /* @__PURE__ */ o(e, {
label: x.label,
children: n.length === 0 ? void 0 : n.join(" – ")
});
}
let w = {
...x,
...S.fieldProps,
ref: S.ref,
value: C,
onValueChange: S.setValue,
onBlur: (e) => {
a?.(e), S.onBlur();
}
};
return d !== "calendar" && (d !== void 0 || p === void 0 && (f ?? "day") === "day") ? /* @__PURE__ */ o(s, { ...w }) : /* @__PURE__ */ o(c, {
...w,
granularity: f,
presets: p,
clearable: m,
isDateDisabled: h,
firstDayOfWeek: g,
locale: _,
timeZone: v,
hourCycle: y,
labels: b
});
});
//#endregion
export { d as FormDateRangeField };
//# sourceMappingURL=FormDateRangeField.js.map