UNPKG

@opensig/opendesign

Version:

<p align="center"><img src="../docs/public/opendesign-logo-light.png"/></p> <h1 align="center">opendesign</h1> <p align="center">一个 Vue 3 组件库</p> <p align="center"><b>皮肤可定制,使用 TypeScript</b></p>

56 lines (55 loc) 1.69 kB
import { defineComponent, ref, inject, watch, provide, toRef, createElementBlock, openBlock, normalizeClass, renderSlot } from "vue"; import { radioGroupProps } from "./types.mjs"; import { radioGroupInjectKey } from "./provide.mjs"; import { isUndefined } from "../_utils/is.mjs"; import { formItemInjectKey } from "../form/provide.mjs"; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "ORadioGroup", props: radioGroupProps, emits: ["update:modelValue", "change"], setup(__props, { emit: __emit }) { const props = __props; const emits = __emit; const realValue = ref(props.modelValue ?? props.defaultValue); const formItemInjection = inject(formItemInjectKey, null); watch( () => props.modelValue, (val) => { if (!isUndefined(val)) { realValue.value = val; } } ); const updateModelValue = (val) => { realValue.value = val; emits("update:modelValue", val); }; const onChange = (val, ev) => { var _a, _b; emits("change", val, ev); (_b = formItemInjection == null ? void 0 : (_a = formItemInjection.fieldHandlers).onChange) == null ? void 0 : _b.call(_a); }; provide(radioGroupInjectKey, { realValue, disabled: toRef(props, "disabled"), updateModelValue, onChange }); return (_ctx, _cache) => { return openBlock(), createElementBlock( "div", { class: normalizeClass(["o-radio-group", [`o-radio-group-${props.direction}`]]) }, [ renderSlot(_ctx.$slots, "default") ], 2 /* CLASS */ ); }; } }); export { _sfc_main as default };