@artmate/chat
Version:
借鉴字节开源react库AntX,通过vue实现的版本
94 lines (93 loc) • 3.08 kB
JavaScript
import { defineComponent as v, createElementBlock as N, openBlock as V, normalizeClass as t, unref as n, createVNode as c, createElementVNode as r, withCtx as K, renderSlot as l, mergeProps as B } from "vue";
import { ElInput as S } from "element-plus";
import $ from "../collapseTransition/index.vue.js";
/* empty css */
import { useNamespace as k } from "../hooks/useNamespace.js";
const I = /* @__PURE__ */ v({
__name: "index",
props: {
modelValue: {},
classNames: { default: void 0 },
disabled: { type: Boolean, default: !1 },
loading: { type: Boolean, default: !1 },
readOnly: { type: Boolean },
rootClassName: { default: "" },
submitType: { type: [String, Boolean], default: "enter" },
onChange: { type: Function, default: () => {
} },
onKeyPress: { type: Function, default: () => {
} }
},
emits: ["update:modelValue", "onSubmit"],
setup(y, { emit: b }) {
const s = y, d = b, o = k("sender"), g = (e) => {
s != null && s.onChange && s.onChange(e);
}, C = (e) => {
g(e);
}, m = () => {
s.modelValue && !s.loading && d("onSubmit");
}, h = (e) => {
const a = e.key === "Enter";
switch (s.submitType) {
case "enter": {
a && !e.shiftKey && (e.preventDefault(), m());
break;
}
case "shiftEnter": {
a && e.shiftKey && (e.preventDefault(), m());
break;
}
}
s.onKeyPress && s.onKeyPress(e);
};
return (e, a) => {
var u, p;
return V(), N("div", {
class: t([n(o).b(), e.disabled && n(o).b("disabled"), e.rootClassName])
}, [
c($, null, {
default: K(() => [
l(e.$slots, "header")
]),
_: 3
}),
r("div", {
class: t(n(o).b("content"))
}, [
r("div", {
class: t([n(o).b("prefix"), (u = e.classNames) == null ? void 0 : u.prefix])
}, [
l(e.$slots, "prefix")
], 2),
l(e.$slots, "components", {}, () => {
var f;
return [
c(n(S), B({
autosize: { maxRows: 8 },
class: [n(o).b("input"), (f = e.classNames) == null ? void 0 : f.input],
disabled: e.disabled,
"model-value": e.modelValue,
readonly: e.readOnly,
placeholder: "请输入内容",
resize: "none",
type: "textarea"
}, e.$attrs, {
onChange: C,
onKeydown: a[0] || (a[0] = (i) => h(i)),
"onUpdate:modelValue": a[1] || (a[1] = (i) => d("update:modelValue", i))
}), null, 16, ["class", "disabled", "model-value", "readonly"])
];
}),
r("div", {
class: t([n(o).b("actions-list"), (p = e.classNames) == null ? void 0 : p.actions])
}, [
l(e.$slots, "actions")
], 2)
], 2)
], 2);
};
}
});
export {
I as default
};