feat: improve popup
This commit is contained in:
parent
6c113eaca1
commit
92f2e0e214
@ -10,7 +10,7 @@
|
|||||||
class="popup"
|
class="popup"
|
||||||
:class="{
|
:class="{
|
||||||
'is-open': openValue,
|
'is-open': openValue,
|
||||||
'has-overflow': props.hasOverflow && openValue
|
'has-overflow': hasOverflow && openValue
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<slot
|
<slot
|
||||||
@ -23,31 +23,23 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {ref, watch} from 'vue'
|
import {ref, watchEffect} from 'vue'
|
||||||
import {onClickOutside} from '@vueuse/core'
|
import {onClickOutside} from '@vueuse/core'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = withDefaults(defineProps<{
|
||||||
hasOverflow: {
|
hasOverflow?: boolean
|
||||||
type: Boolean,
|
open?: boolean
|
||||||
default: false,
|
}>(), {
|
||||||
},
|
hasOverflow: false,
|
||||||
open: {
|
open: false,
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['close'])
|
const emit = defineEmits(['close'])
|
||||||
|
|
||||||
watch(
|
const openValue = ref(props.open)
|
||||||
() => props.open,
|
watchEffect(() => {
|
||||||
nowOpen => {
|
openValue.value = props.open
|
||||||
openValue.value = nowOpen
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
const openValue = ref(false)
|
|
||||||
const popup = ref<HTMLElement | null>(null)
|
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
openValue.value = false
|
openValue.value = false
|
||||||
@ -58,6 +50,8 @@ function toggle() {
|
|||||||
openValue.value = !openValue.value
|
openValue.value = !openValue.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const popup = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
onClickOutside(popup, () => {
|
onClickOutside(popup, () => {
|
||||||
if (!openValue.value) {
|
if (!openValue.value) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user