@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
121 lines (120 loc) • 2.9 kB
JavaScript
import { radioCheckboxCommonProps as h, useGuid as V, RADIOGROUP_CONTEXT as C, withInstall as R } from "../common/index.esm.js";
import { computed as v, defineComponent as p, ref as f, provide as x, watch as F, createVNode as i } from "vue";
const k = {
...h,
/**
* 组件标识
*/
id: String,
/**
* 禁用组件,不允许切换单选值
*/
disabled: { type: Boolean, default: !1 },
/**
* 功能同disabled
*/
readonly: { type: Boolean, default: !1 },
/**
* 单选组枚举数组----废弃
*/
enumData: {
type: Array
},
/**
* 单选组枚举数组
*/
data: {
type: Array
},
/**
* 组件值
*/
modelValue: { type: String, default: "" },
/**
* 组件名称
*/
name: { type: String, default: "" },
/**
* 输入框Tab键索引
*/
tabIndex: { type: Number, default: -1 },
/**
* 枚举数组中展示文本的key值。
*/
textField: { type: String, default: "name" },
/**
* 枚举数组中枚举值的key值。
*/
valueField: { type: String, default: "value" }
};
function D(e, t, u) {
const r = v(() => !e.disabled), d = v(() => e.data || e.enumData || e.options || []);
function n(a) {
return a[e.valueField];
}
function c(a) {
return a[e.textField];
}
function s(a, m) {
if (r.value) {
const o = n(a);
u.value !== o && (u.value = o, t.emit("changeValue", o), t.emit("update:modelValue", o));
}
m.stopPropagation();
}
return {
enumData: d,
getValue: n,
getText: c,
onClickRadio: s
};
}
const G = /* @__PURE__ */ p({
name: "FRadioGroup",
props: k,
emits: ["changeValue", "update:modelValue"],
setup(e, t) {
const {
guid: u
} = V(), r = `radio_${u().slice(0, 8)}`, d = f(e.name || r), n = f(e.modelValue), {
enumData: c,
onClickRadio: s,
getValue: a,
getText: m
} = D(e, t, n), o = v(() => ({
"farris-checkradio-hor": e.direction === "horizontal"
})), y = f([]);
return x(C, {
radios: y,
parentProps: e,
parentContext: t
}), F(() => e.modelValue, (l) => {
n.value = l;
}), () => i("div", {
class: ["farris-input-wrap", "btn-group", o.value]
}, [t.slots.default ? t.slots.default() : c.value.map((l, P) => {
const g = "radio_" + e.id + d.value + l[e.valueField];
return i("div", {
class: "custom-control custom-radio"
}, [i("input", {
type: "radio",
class: "custom-control-input",
name: d.value,
id: g,
value: a(l),
checked: a(l) === n.value,
disabled: e.readonly || e.disabled,
tabindex: e.tabIndex,
onClick: (b) => s(l, b)
}, null), i("label", {
class: "custom-control-label",
for: g
}, [m(l)])]);
})]);
}
}), I = R(G);
export {
G as FRadioGroup,
I as default,
k as radioGroupProps
};