tdesign-pro-component
Version:
ProComponents tdesign-vue-next + Vue3 + TS
70 lines (69 loc) • 2.31 kB
JavaScript
import { a as h, i as x, w as g } from "./utils-DU1amZow.js";
import { defineComponent as _, ref as v, useSlots as V, onMounted as k, watch as y, resolveComponent as r, openBlock as P, createBlock as C, mergeProps as s, withCtx as N, createVNode as w, unref as A, isRef as B } from "vue";
import { u as F } from "./hooks-9GWkbKry.js";
const W = /* @__PURE__ */ _({
name: "ProFormCheckbox",
__name: "ProFormCheckbox",
props: {
name: {},
modelValue: { type: [String, Number, Boolean, null, Array] },
data: {},
label: {},
formItemProps: {},
rules: {},
labelWidth: {},
labelAlign: { default: "left" },
labelName: { default: "label" },
valueName: { default: "value" },
disabled: { type: Boolean },
readonly: { type: Boolean },
max: {},
checkboxProps: {}
},
emits: ["update:modelValue", "change"],
setup(d, { expose: u, emit: i }) {
const t = i, e = d, o = F(e, "modelValue", t, e.modelValue || []), n = v([]);
V(), k(() => {
e.name || h("name is empty"), m();
});
function m() {
x(e.data) ? e.data().then((a) => {
n.value = a.map((l) => ({ label: l[e.labelName], value: l[e.valueName], disabled: l.disabled }));
}) : n.value = e.data.map((a) => ({ label: a[e.labelName], value: a[e.valueName], disabled: a.disabled }));
}
function b(a, l) {
t("change", a, l);
}
return y(() => e.data, () => {
m();
}), u({
getValue: () => o.value
}), (a, l) => {
const p = r("t-checkbox-group"), c = r("t-form-item");
return P(), C(c, s({
labelWidth: e.labelWidth,
labelAlign: e.labelAlign,
label: e.label,
name: e.name
}, e.formItemProps, {
rules: e.rules
}), {
default: N(() => [
w(p, s({
modelValue: A(o),
"onUpdate:modelValue": l[0] || (l[0] = (f) => B(o) ? o.value = f : null),
onChange: b,
max: e.max,
disabled: e.disabled,
readonly: e.readonly,
options: n.value
}, e.checkboxProps), null, 16, ["modelValue", "max", "disabled", "readonly", "options"])
]),
_: 1
}, 16, ["labelWidth", "labelAlign", "label", "name", "rules"]);
};
}
}), D = g(W);
export {
D as P
};