{"version":3,"file":"use-radio.mjs","sources":["../../../../../../packages/components/radio/src/use-radio.ts"],"sourcesContent":["import { computed, inject, ref } from 'vue'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { useFormDisabled, useFormSize } from '@element-plus/components/form'\nimport { useDeprecated } from '@element-plus/hooks'\nimport { isPropAbsent } from '@element-plus/utils'\nimport { radioGroupKey } from './constants'\n\nimport type { RadioButtonProps } from './radio-button'\nimport type { SetupContext } from 'vue'\nimport type { RadioEmits, RadioProps } from './radio'\nexport const useRadio = (\n props: RadioProps | RadioButtonProps,\n emit?: SetupContext['emit']\n) => {\n const radioRef = ref()\n const radioGroup = inject(radioGroupKey, undefined)\n const isGroup = computed(() => !!radioGroup)\n const actualValue = computed(() => {\n // In version 2.x, if there's no props.value, props.label will act as props.value\n // In version 3.x, remove this computed value, use props.value instead.\n if (!isPropAbsent(props.value)) {\n return props.value\n }\n return props.label\n })\n const modelValue = computed({\n get() {\n return isGroup.value ? radioGroup!.modelValue : props.modelValue!\n },\n set(val) {\n if (isGroup.value) {\n radioGroup!.changeEvent(val)\n } else {\n emit && emit(UPDATE_MODEL_EVENT, val)\n }\n radioRef.value!.checked = props.modelValue === actualValue.value\n },\n })\n\n const size = useFormSize(computed(() => radioGroup?.size))\n const disabled = useFormDisabled(computed(() => radioGroup?.disabled))\n const focus = ref(false)\n const tabIndex = computed(() => {\n return disabled.value ||\n (isGroup.value && modelValue.value !== actualValue.value)\n ? -1\n : 0\n })\n\n useDeprecated(\n {\n from: 'label act as value',\n replacement: 'value',\n version: '3.0.0',\n scope: 'el-radio',\n ref: 'https://element-plus.org/en-US/component/radio.html',\n },\n computed(() => isGroup.value && isPropAbsent(props.value))\n )\n\n return {\n radioRef,\n isGroup,\n radioGroup,\n focus,\n size,\n disabled,\n tabIndex,\n modelValue,\n actualValue,\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAMY,MAAC,QAAQ,GAAG,CAAC,KAAK,EAAE,IAAI,KAAK;AACzC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