@payfit/unity-components
Version:
63 lines (62 loc) • 2.07 kB
JavaScript
import { Text as e } from "../../../../../core/components/text/Text.js";
import { AIStructuredInputAnswers as t } from "../parts/AIStructuredInputAnswers.js";
import { AIStructuredInputFreeTextAnswer as n } from "../parts/AIStructuredInputFreeTextAnswer.js";
import { useAIKitFieldContext as r } from "../../../hooks/ai-kit-form-context.js";
import { useId as i } from "react";
import { jsx as a, jsxs as o } from "react/jsx-runtime";
//#region src/modules/ai-kit/components/ai-structured-input/form/TanstackAIStructuredInputAnswersField.tsx
function s({ freeText: s, onAnswerChange: c, feedbackMessage: l, ...u }) {
let d = r(), f = i(), p = d.state.value, m = d.state.meta.errors[0], h;
typeof m == "string" ? h = m : typeof m == "object" && m && "message" in m && typeof m.message == "string" && (h = m.message);
let g = l ?? h, _ = (e) => {
d.handleChange(e), c?.(e);
};
return /* @__PURE__ */ o("div", {
role: "group",
"aria-label": u["aria-label"],
"aria-labelledby": u["aria-labelledby"],
"aria-describedby": [u["aria-describedby"], g && f].filter(Boolean).join(" ") || void 0,
children: [
/* @__PURE__ */ a(t, {
...u,
value: new Set(p?.kind === "choices" ? p.keys : []),
"aria-describedby": [u["aria-describedby"], g && f].filter(Boolean).join(" ") || void 0,
onBlur: (e) => {
d.handleBlur(), u.onBlur?.(e);
},
onChange: (e) => {
let t = e === "all" ? u.items.map((e) => e.id) : Array.from(e);
_({
kind: "choices",
keys: t
});
}
}),
s && /* @__PURE__ */ a(n, {
...s,
value: p?.kind === "text" ? p.text : "",
isInvalid: !!g,
feedbackMessage: g,
feedbackId: f,
onChange: (e) => {
_({
kind: "text",
text: e.target.value
});
},
onBlur: (e) => {
d.handleBlur(), s.onBlur?.(e);
}
}),
g && !s && /* @__PURE__ */ a(e, {
id: f,
role: "alert",
variant: "bodySmallStrong",
color: "content.danger",
children: g
})
]
});
}
//#endregion
export { s as TanstackAIStructuredInputAnswersField };