import { h, onUnmounted, inject, ref, Ref, onMounted, PropType } from 'vue' import { defineVxeComponent } from '../../ui/src/comp' import { XEOptionProvide, createOption, watchOption, destroyOption, assembleOption } from './util' import type { VxeSelectConstructor, VxeOptionEmits, VxeOptionPropTypes } from '../../../types' export default /* define-vxe-component start */ defineVxeComponent({ name: 'VxeOption', props: { value: [String, Number, Boolean] as PropType, label: { type: [String, Number, Boolean] as PropType, default: '' }, visible: { type: Boolean as PropType, default: null }, className: [String, Function] as PropType, disabled: Boolean as PropType }, emits: [] as VxeOptionEmits, setup(props, context) { const { slots } = context const elem = ref() as Ref const $xeSelect = inject('$xeSelect', {} as VxeSelectConstructor) const $xeOptgroup = inject('$xeOptgroup', null) const optionConfig = createOption($xeSelect, props) optionConfig.slots = slots watchOption(props, optionConfig) onMounted(() => { const el = elem.value assembleOption($xeSelect, el, optionConfig, $xeOptgroup) }) onUnmounted(() => { destroyOption($xeSelect, optionConfig) }) return () => { return h('div', { ref: elem }) } } }) /* define-vxe-component end */