comic-plus
Version:
<p align="center"> <img width="200px" src="./logo.png"/> </p>
36 lines (35 loc) • 1.19 kB
JavaScript
import { inject, computed } from "vue";
import { useGlobal } from "../../../utils/config.mjs";
import "@vueuse/core";
import { useItemValidate } from "../../../hooks/validate.mjs";
import { FORM_PROVIDE } from "../../form/src/type.mjs";
import { RADIOGROUP_PROVIDE } from "./type.mjs";
const useRadio = (props, emit) => {
const { itemValidate } = useItemValidate();
const { globalSize } = useGlobal();
const radioGroup = inject(RADIOGROUP_PROVIDE, void 0);
const form = inject(FORM_PROVIDE, void 0);
const currentSize = computed(() => {
return props.size ?? (radioGroup == null ? void 0 : radioGroup.props.size) ?? (form == null ? void 0 : form.props.size) ?? (globalSize == null ? void 0 : globalSize.value);
});
const isCheck = computed(() => {
return radioGroup ? radioGroup.props.modelValue === props.value : props.modelValue === props.value;
});
function changeValue() {
if (radioGroup) {
radioGroup.changeItemCheck(props.value);
return;
}
emit("update:modelValue", props.value);
emit("change", isCheck.value);
itemValidate("change");
}
return {
currentSize,
isCheck,
changeValue
};
};
export {
useRadio
};