UNPKG

tdesign-pro-component

Version:

ProComponents tdesign-vue-next + Vue3 + TS

104 lines (103 loc) 3.67 kB
import { a as F, i as A, w as R } from "./utils-DU1amZow.js"; import { defineComponent as S, ref as W, useSlots as x, onMounted as I, watch as D, resolveComponent as u, openBlock as t, createBlock as b, mergeProps as v, withCtx as d, createVNode as M, unref as $, isRef as E, createElementBlock as s, Fragment as i, renderList as c, renderSlot as _, createTextVNode as y, toDisplayString as g } from "vue"; import { u as L } from "./hooks-9GWkbKry.js"; const T = /* @__PURE__ */ S({ name: "ProFormRadio", __name: "ProFormRadio", props: { name: {}, data: {}, modelValue: { type: [String, Number, Boolean, null] }, label: {}, rules: {}, formItemProps: {}, labelWidth: {}, labelAlign: { default: "left" }, labelName: { default: "label" }, valueName: { default: "value" }, button: { type: Boolean }, radioProps: {}, disabled: { type: Boolean }, readonly: { type: Boolean }, variant: {} }, emits: ["update:modelValue", "change"], setup(h, { expose: V, emit: k }) { const m = k, e = h, n = L(e, "modelValue", m, e.modelValue || ""), r = W([]), p = x(); I(() => { e.name || F("name is empty"), f(); }); function f() { A(e.data) ? e.data().then((l) => { r.value = l.map((o) => ({ label: o[e.labelName], value: o[e.valueName], disabled: o.disabled })); }) : r.value = e.data.map((l) => ({ label: l[e.labelName], value: l[e.valueName], disabled: l.disabled })); } function N(l, o) { m("change", l, o); } return D(() => e.data, () => { f(); }), V({ getValue: () => n.value }), (l, o) => { const P = u("t-radio"), B = u("t-radio-button"), w = u("t-radio-group"), C = u("t-form-item"); return t(), b(C, v({ labelWidth: e.labelWidth, labelAlign: e.labelAlign, rules: e.rules, label: e.label, name: e.name }, e.formItemProps), { default: d(() => [ M(w, v(e.radioProps, { variant: e.variant, disabled: e.disabled, readonly: e.readonly, modelValue: $(n), "onUpdate:modelValue": o[0] || (o[0] = (a) => E(n) ? n.value = a : null), onChange: N }), { default: d(() => [ e.button ? (t(!0), s(i, { key: 1 }, c(r.value, (a) => (t(), b(B, { value: a.value, label: a.label, key: a.label }, { default: d(() => [ p.default ? _(l.$slots, "default", { key: 0, label: a.label, value: a.value }) : (t(), s(i, { key: 1 }, [ y(g(a.label), 1) ], 64)) ]), _: 2 }, 1032, ["value", "label"]))), 128)) : (t(!0), s(i, { key: 0 }, c(r.value, (a) => (t(), b(P, { value: a.value, label: a.label, key: a.label }, { default: d(() => [ p.default ? _(l.$slots, "default", { key: 0, label: a.label, value: a.value }) : (t(), s(i, { key: 1 }, [ y(g(a.label), 1) ], 64)) ]), _: 2 }, 1032, ["value", "label"]))), 128)) ]), _: 3 }, 16, ["variant", "disabled", "readonly", "modelValue"]) ]), _: 3 }, 16, ["labelWidth", "labelAlign", "rules", "label", "name"]); }; } }), z = R(T); export { z as P };