UNPKG

@mitcsutt/kiln-forms

Version:

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

39 lines (38 loc) • 1.25 kB
import { FieldView as e } from "../FieldView/FieldView.js"; import { useOptionMapping as t } from "../../../hooks/useOptionMapping.js"; import { accepts as n } from "../../../kit/accepts.js"; import { useFieldBinding as r } from "../../../hooks/useFieldBinding.js"; import { defineOptionField as i } from "../../../kit/contracts.js"; import { withSwatchIcons as a } from "../internal/optionSwatches.js"; import { useMemo as o } from "react"; import { jsx as s } from "react/jsx-runtime"; import { SegmentedField as c } from "@mitcsutt/kiln-ui"; //#region src/components/fields/FormSegmentedField/FormSegmentedField.tsx var l = i()(function({ warn: i, excluded: l, onBlur: u, options: d, ...f }) { let p = r({ ...f, warn: i, excluded: l, accepts: n.primitiveOrNull, empty: null }), m = t(d), h = o(() => a(m), [m]); return p.mode === "view" ? /* @__PURE__ */ s(e, { label: f.label, children: m.labelOf(p.value) }) : /* @__PURE__ */ s(c, { ...f, ...p.fieldProps, ref: p.ref, options: h, value: m.toUi(p.value), onValueChange: (e) => { p.setValue(m.fromUi(e)); }, onBlur: (e) => { u?.(e), p.onBlur(); } }); }); //#endregion export { l as FormSegmentedField }; //# sourceMappingURL=FormSegmentedField.js.map