UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

50 lines (49 loc) • 1.4 kB
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 { jsx as i } from "react/jsx-runtime"; import { Amount as a, AmountField as o } from "@mitcsutt/kiln-ui"; //#region src/components/fields/FormAmountField/FormAmountField.tsx function s(e, t) { try { return new Intl.NumberFormat(t, { style: "currency", currency: e }).resolvedOptions().maximumFractionDigits ?? 2; } catch { return 2; } } function c(e, t, n, r) { return t === "minor" ? Number(`${String(e)}e-${String(s(n, r))}`) : e; } var l = r()(function({ warn: r, excluded: s, onBlur: l, ...u }) { let d = n({ ...u, warn: r, excluded: s, accepts: t.numberOrNull, empty: null }); return d.mode === "view" ? /* @__PURE__ */ i(e, { label: u.label, children: d.value === null ? void 0 : /* @__PURE__ */ i(a, { value: c(d.value, u.unit, u.currency, u.locale), currency: u.currency, ...u.locale === void 0 ? {} : { locale: u.locale } }) }) : /* @__PURE__ */ i(o, { ...u, ...d.fieldProps, ref: d.ref, value: d.value, onValueChange: d.setValue, onBlur: (e) => { l?.(e), d.onBlur(); } }); }); //#endregion export { l as FormAmountField }; //# sourceMappingURL=FormAmountField.js.map