UNPKG

@payfit/unity-components

Version:

53 lines (52 loc) • 1.65 kB
import { AIComposerContextProvider as e } from "./AIComposer.context.js"; import { aiComposer as t } from "./AIComposer.variants.js"; import { forwardRef as n, useCallback as r, useImperativeHandle as i, useRef as a, useState as o } from "react"; import { mergeProps as s, useFocusWithin as c } from "react-aria"; import { jsx as l, jsxs as u } from "react/jsx-runtime"; //#region src/modules/ai-kit/components/ai-composer/AIComposer.tsx var d = n(({ children: n, enterKeyBehavior: d = "submit", state: f = "enabled", onSubmit: p, onStop: m, ...h }, g) => { let _ = t({ state: f }), v = a(null), [y, b] = o(!1), [x, S] = o(!1), { focusWithinProps: C } = c({ isDisabled: f === "disabled", onFocusWithinChange: S }), w = s(h, C); i(g, () => { if (!v.current) throw Error("Expected the AI Composer form to be mounted"); return v.current; }, []); let T = r(() => { v.current?.requestSubmit(); }, []), E = (e) => { e.preventDefault(), p?.(e); }; return /* @__PURE__ */ l(e, { value: { enterKeyBehavior: d, state: f, hasValue: y, setHasValue: b, onStop: m, requestSubmit: T }, children: /* @__PURE__ */ u("form", { ref: v, ...w, onSubmit: E, className: _.base(), "data-focus-within": x || void 0, "data-has-value": y || void 0, "data-state": f, "data-unity-component": "ai.composer", children: [/* @__PURE__ */ l("span", { "aria-hidden": "true", className: _.surface(), "data-unity-slot": "ai.surface" }), /* @__PURE__ */ l("div", { className: _.content(), children: n })] }) }); }); d.displayName = "AIComposer"; //#endregion export { d as AIComposer };