File size: 1,186 Bytes
4d70170 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<script lang="ts">
import type { ComponentInternalInstance, Ref } from 'vue'
import { defineComponent, getCurrentInstance, inject, onMounted, ref } from 'vue'
export default defineComponent({
name: 'VueSelectButton',
props: {
label: {
type: String,
default: null,
},
},
setup() {
const currentInstance = getCurrentInstance()
const groupButton = ref(null)
const { setCurrentChild, getCurrentChild } = inject<{
setCurrentChild: (child: ComponentInternalInstance) => void
getCurrentChild: () => Ref<ComponentInternalInstance | null>
}>('VueSelect')
onMounted(() => {
onSelect(groupButton.value.selected)
})
function onSelect(selected: boolean) {
if (selected) {
setCurrentChild(currentInstance)
}
else if (getCurrentChild()?.value === currentInstance) {
setCurrentChild(null)
}
}
return {
groupButton,
onSelect,
}
},
})
</script>
<template>
<VueGroupButton
ref="groupButton"
v-close-popper="true"
class="vue-ui-select-button"
:label="label"
flat
@selected="onSelect"
>
<slot />
</VueGroupButton>
</template>
|