@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
40 lines (39 loc) • 1.3 kB
JavaScript
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 { defineOptionsField as i } from "../../../kit/contracts.js";
import { optionTags as a, withSwatchIcons as o } from "../internal/optionSwatches.js";
import { useMemo as s } from "react";
import { jsx as c } from "react/jsx-runtime";
import { ChipGroupField as l } from "@mitcsutt/kiln-ui";
//#region src/components/fields/FormChipsField/FormChipsField.tsx
var u = i()(function({ warn: i, excluded: u, onBlur: d, options: f, ...p }) {
let m = r({
...p,
warn: i,
excluded: u,
accepts: n.arrayOfPrimitive,
empty: []
}), h = t(f), g = s(() => o(h), [h]);
return m.mode === "view" ? /* @__PURE__ */ c(e, {
label: p.label,
children: a(m.value, h)
}) : /* @__PURE__ */ c(l, {
...p,
...m.fieldProps,
ref: m.ref,
type: "multiple",
options: g,
value: m.value.map(h.toUi),
onValueChange: (e) => {
m.setValue(e.map(h.fromUi).filter((e) => e !== null));
},
onBlur: (e) => {
d?.(e), m.onBlur();
}
});
});
//#endregion
export { u as FormChipsField };
//# sourceMappingURL=FormChipsField.js.map