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>

109 lines (108 loc) 3.55 kB
import { defineComponent, inject, ref, onMounted, computed, watch, provide, createElementBlock, openBlock, normalizeClass, createElementVNode, renderSlot, nextTick } from "vue"; import { radioInjectKey } from "./provide.mjs"; import { radioProps } from "./types.mjs"; import { radioGroupInjectKey } from "../radio-group/provide.mjs"; import { isUndefined } from "../_utils/is.mjs"; import { uniqueId } from "../_utils/helper.mjs"; const _hoisted_1 = ["for"]; const _hoisted_2 = { class: "o-radio-wrap" }; const _hoisted_3 = ["id", "value", "disabled", "checked"]; const _hoisted_4 = { class: "o-radio-label" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "ORadio", props: radioProps, emits: ["update:modelValue", "change"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const radioGroupInjection = inject(radioGroupInjectKey, null); const inputId = ref(props.inputId); onMounted(() => { if (!inputId.value) { inputId.value = uniqueId(); } }); const _checked = ref(props.defaultChecked); const isChecked = computed(() => { if (radioGroupInjection) { return radioGroupInjection.realValue.value === props.value; } if (!isUndefined(props.modelValue)) { return props.modelValue === props.value; } return _checked.value; }); watch( isChecked, (val) => { _checked.value = val; }, { immediate: true } ); __expose({ checked: isChecked }); const isDisabled = computed(() => (radioGroupInjection == null ? void 0 : radioGroupInjection.disabled.value) || props.disabled); const onClick = (ev) => { ev.stopPropagation(); }; const onChange = (ev) => { if (isDisabled.value) { return; } _checked.value = true; const val = props.value ?? true; emits("update:modelValue", val); radioGroupInjection == null ? void 0 : radioGroupInjection.updateModelValue(val); nextTick(() => { emits("change", val, ev); radioGroupInjection == null ? void 0 : radioGroupInjection.onChange(val, ev); }); }; provide(radioInjectKey, { checked: isChecked, disabled: isDisabled }); return (_ctx, _cache) => { return openBlock(), createElementBlock("label", { class: normalizeClass(["o-radio", { "o-radio-checked": isChecked.value, "o-radio-disabled": isDisabled.value }]), for: inputId.value }, [ createElementVNode("div", _hoisted_2, [ createElementVNode("input", { id: inputId.value, type: "radio", value: props.value, disabled: isDisabled.value, checked: isChecked.value, onClick, onChange }, null, 40, _hoisted_3), renderSlot(_ctx.$slots, "radio", { checked: isChecked.value, disabled: isDisabled.value }, () => [ _cache[0] || (_cache[0] = createElementVNode( "div", { class: "o-radio-input-wrap" }, [ createElementVNode("span", { class: "o-radio-input" }) ], -1 /* HOISTED */ )), createElementVNode("span", _hoisted_4, [ renderSlot(_ctx.$slots, "default") ]) ]) ]) ], 10, _hoisted_1); }; } }); export { _sfc_main as default };