You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.2 KiB
79 lines
2.2 KiB
'use strict';
|
|
|
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
var vue = require('vue');
|
|
var props = require('../../../utils/props.js');
|
|
var constants = require('../../../utils/constants.js');
|
|
var util = require('../../../utils/util.js');
|
|
require('../../../tokens/index.js');
|
|
require('../../../hooks/index.js');
|
|
var index = require('../../../hooks/use-common-props/index.js');
|
|
var shared = require('@vue/shared');
|
|
var radio = require('../../../tokens/radio.js');
|
|
|
|
const radioPropsBase = props.buildProps({
|
|
size: index.useSizeProp,
|
|
disabled: Boolean,
|
|
label: {
|
|
type: [String, Number, Boolean],
|
|
default: ""
|
|
}
|
|
});
|
|
const radioProps = props.buildProps({
|
|
...radioPropsBase,
|
|
modelValue: {
|
|
type: [String, Number, Boolean],
|
|
default: ""
|
|
},
|
|
name: {
|
|
type: String,
|
|
default: ""
|
|
},
|
|
border: Boolean
|
|
});
|
|
const radioEmits = {
|
|
[constants.UPDATE_MODEL_EVENT]: (val) => shared.isString(val) || util.isNumber(val) || util.isBool(val),
|
|
change: (val) => shared.isString(val) || util.isNumber(val) || util.isBool(val)
|
|
};
|
|
const useRadio = (props, emit) => {
|
|
const radioRef = vue.ref();
|
|
const radioGroup = vue.inject(radio.radioGroupKey, void 0);
|
|
const isGroup = vue.computed(() => !!radioGroup);
|
|
const modelValue = vue.computed({
|
|
get() {
|
|
return isGroup.value ? radioGroup.modelValue : props.modelValue;
|
|
},
|
|
set(val) {
|
|
if (isGroup.value) {
|
|
radioGroup.changeEvent(val);
|
|
} else {
|
|
emit(constants.UPDATE_MODEL_EVENT, val);
|
|
}
|
|
radioRef.value.checked = props.modelValue === props.label;
|
|
}
|
|
});
|
|
const size = index.useSize(vue.computed(() => radioGroup == null ? void 0 : radioGroup.size));
|
|
const disabled = index.useDisabled(vue.computed(() => radioGroup == null ? void 0 : radioGroup.disabled));
|
|
const focus = vue.ref(false);
|
|
const tabIndex = vue.computed(() => {
|
|
return disabled.value || isGroup.value && modelValue.value !== props.label ? -1 : 0;
|
|
});
|
|
return {
|
|
radioRef,
|
|
isGroup,
|
|
radioGroup,
|
|
focus,
|
|
size,
|
|
disabled,
|
|
tabIndex,
|
|
modelValue
|
|
};
|
|
};
|
|
|
|
exports.radioEmits = radioEmits;
|
|
exports.radioProps = radioProps;
|
|
exports.radioPropsBase = radioPropsBase;
|
|
exports.useRadio = useRadio;
|
|
//# sourceMappingURL=radio.js.map
|