@anweb/nuxt-ancore 1.15.10 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { v4 } from "uuid";
|
|
3
|
+
import { computed, onMounted, ref, useTemplateRef } from "vue";
|
|
4
|
+
import { onClickOutside } from "@vueuse/core";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
area: { type: String, required: false }
|
|
7
|
+
});
|
|
8
|
+
const id = ref();
|
|
9
|
+
const state = ref(false);
|
|
10
|
+
const refTarget = useTemplateRef("refTarget");
|
|
11
|
+
const toggle = (value) => {
|
|
12
|
+
state.value = value !== void 0 ? value : !state.value;
|
|
13
|
+
};
|
|
14
|
+
const close = () => {
|
|
15
|
+
toggle(false);
|
|
16
|
+
};
|
|
17
|
+
const area = computed(() => {
|
|
18
|
+
return props.area || "bottom span-right";
|
|
19
|
+
});
|
|
20
|
+
const name = computed(() => {
|
|
21
|
+
return id.value ? `--an-dropdown-${id.value}` : "";
|
|
22
|
+
});
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
id.value = v4();
|
|
25
|
+
});
|
|
26
|
+
onClickOutside(refTarget, close);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<div ref="refTarget" class="an-dropdown__button">
|
|
31
|
+
<slot name="button" :toggle="toggle" />
|
|
32
|
+
|
|
33
|
+
<teleport to="body">
|
|
34
|
+
<div v-show="state" class="an-dropdown__menu">
|
|
35
|
+
<slot name="menu" :close="close" />
|
|
36
|
+
</div>
|
|
37
|
+
</teleport>
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<style scoped>
|
|
42
|
+
.an-dropdown__button{anchor-name:v-bind(name)}.an-dropdown__menu{position:fixed;position-anchor:v-bind(name);position-area:v-bind(area);position-try-fallbacks:top span-right,bottom span-left,top span-left;z-index:1000}
|
|
43
|
+
</style>
|