birdpaper-ui
Version:
一个通用的 vue3 UI组件库。A common vue3 UI component library.
69 lines (68 loc) • 1.77 kB
JavaScript
;
const vue = require("vue");
const dom = require("../../utils/dom.js");
const _radioGroup = /* @__PURE__ */ vue.defineComponent({
name: "RadioGroup",
props: {
/** 单选框绑定值 */
modelValue: {
type: [String, Number]
},
/** 是否禁用 */
disabled: {
type: Boolean,
default: false
},
/** 单选框组类型 */
type: {
type: String,
default: "radio"
},
/** 排列方向 */
direction: {
type: String,
default: "horizontal"
}
},
emits: ["update:modelValue", "change"],
setup(props, {
emit,
slots
}) {
const name = "bp-radio-group";
const updateValue = (v) => {
emit("update:modelValue", v);
};
const cls = vue.computed(() => {
let clsName = [name];
clsName.push(`${name}-${props.direction}`);
props.type === "button" && clsName.push(`${name}-button`);
return clsName;
});
const render = () => {
var _a;
const children = dom.getAllElements((_a = slots.default) == null ? void 0 : _a.call(slots), true).filter((item) => item.type !== vue.Comment);
return vue.createVNode("div", {
"class": cls.value
}, [children.map((child, index) => {
const radio = Object.assign({}, child);
radio.props = vue.mergeProps(child.props, {
...props
});
return vue.createVNode(vue.Fragment, {
"key": child.key ?? `item-${index}`
}, [vue.h(radio, {
modelValue: props.modelValue,
onChange(e) {
emit("change", e);
},
"onUpdate:modelValue"(e) {
updateValue(e);
}
})]);
})]);
};
return render;
}
});
module.exports = _radioGroup;