UNPKG

hongluan-ui

Version:
76 lines (71 loc) 2.56 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); require('../../../tokens/index.js'); require('../../../constants/index.js'); require('../../../hooks/index.js'); require('../../../utils/index.js'); var radio = require('../../../tokens/radio.js'); var types = require('../../../utils/types.js'); var event = require('../../../constants/event.js'); var index = require('../../../hooks/use-consistent-prop/index.js'); const useRadio = (props, emit) => { const radioRef = vue.ref(); const radioGroup = vue.inject(radio.radioGroupKey, void 0); const isGroup = vue.computed(() => !!radioGroup); const actualValue = vue.computed(() => { if (!types.isPropAbsent(props.value)) { return props.value; } return props.label; }); const modelValue = vue.computed({ get() { return isGroup.value ? radioGroup.modelValue : props.modelValue; }, set(val) { if (isGroup.value) { radioGroup == null ? void 0 : radioGroup.changeEvent(val); } else { emit && emit(event.UPDATE_MODEL_EVENT, val); } radioRef.value.checked = props.modelValue === actualValue.value; } }); const { size: tempRadioSize, disabled: tempRadioDisabled, fill: tempFill } = index.useConsistentProp(); const radioSize = vue.computed(() => { return isGroup.value ? (radioGroup == null ? void 0 : radioGroup.size) || tempRadioSize.value : tempRadioSize.value; }); const radioFill = vue.computed(() => { return isGroup.value ? (radioGroup == null ? void 0 : radioGroup.fill) || tempFill.value : tempFill.value; }); const isDisabled = vue.computed(() => { return isGroup.value ? (radioGroup == null ? void 0 : radioGroup.disabled) || tempRadioDisabled.value : tempRadioDisabled.value; }); const radioType = vue.computed(() => { return isGroup.value ? (radioGroup == null ? void 0 : radioGroup.type) || props.type : props.type; }); const radioCustom = vue.computed(() => { return isGroup.value ? (radioGroup == null ? void 0 : radioGroup.custom) || props.custom : props.custom; }); const focus = vue.ref(false); const tabIndex = vue.computed(() => { return isDisabled.value || isGroup.value && modelValue.value !== actualValue.value ? -1 : 0; }); return { radioRef, isGroup, radioGroup, focus, radioSize, radioFill, isDisabled, radioType, radioCustom, tabIndex, modelValue, actualValue }; }; exports.useRadio = useRadio; //# sourceMappingURL=use-radio.js.map