@bikariya/modals 0.0.3 → 0.0.5
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/README.md
CHANGED
|
@@ -33,7 +33,7 @@ pnpm i -D @bikariya/modals
|
|
|
33
33
|
```vue
|
|
34
34
|
<script lang="ts" setup>
|
|
35
35
|
defineProps<{
|
|
36
|
-
|
|
36
|
+
open?: boolean;
|
|
37
37
|
}>();
|
|
38
38
|
|
|
39
39
|
defineEmits<{
|
|
@@ -43,7 +43,7 @@ pnpm i -D @bikariya/modals
|
|
|
43
43
|
|
|
44
44
|
<template>
|
|
45
45
|
<transition>
|
|
46
|
-
<div v-if="
|
|
46
|
+
<div v-if="open">
|
|
47
47
|
<span>I'm a modal.</span>
|
|
48
48
|
<button @click="$emit(`close`)">Close</button>
|
|
49
49
|
</div>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver,
|
|
1
|
+
import { defineNuxtModule, createResolver, addImportsSources, addComponent } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const name = "@bikariya/modals";
|
|
4
4
|
const packageJson = {
|
|
@@ -14,7 +14,12 @@ const module$1 = defineNuxtModule({
|
|
|
14
14
|
},
|
|
15
15
|
setup() {
|
|
16
16
|
const resolver = createResolver(import.meta.url);
|
|
17
|
-
|
|
17
|
+
addImportsSources({
|
|
18
|
+
from: resolver.resolve("runtime/store"),
|
|
19
|
+
imports: [
|
|
20
|
+
"useModalStore"
|
|
21
|
+
]
|
|
22
|
+
});
|
|
18
23
|
addComponent({
|
|
19
24
|
name: "BikariyaModals",
|
|
20
25
|
filePath: resolver.resolve("runtime/modals.vue")
|
package/dist/runtime/modals.vue
CHANGED
|
@@ -5,15 +5,15 @@ const { modals } = storeToRefs(modalStore);
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<template>
|
|
8
|
-
<template v-for="{ vnode, zIndex,
|
|
8
|
+
<template v-for="{ vnode, zIndex, open, close } in modals" :key="zIndex">
|
|
9
9
|
<transition>
|
|
10
10
|
<div
|
|
11
|
-
v-if="
|
|
11
|
+
v-if="open.value"
|
|
12
12
|
class="bikariya-overlay"
|
|
13
13
|
:style="{ zIndex: zIndex - 1 }"
|
|
14
14
|
@click="close.value()"
|
|
15
15
|
></div>
|
|
16
16
|
</transition>
|
|
17
|
-
<component :is="vnode.value" :
|
|
17
|
+
<component :is="vnode.value" :open="open.value" :style="{ zIndex }"/>
|
|
18
18
|
</template>
|
|
19
19
|
</template>
|
|
@@ -3,9 +3,10 @@ interface ModalContext {
|
|
|
3
3
|
vnode: ComputedRef<VNode>;
|
|
4
4
|
zIndex: number;
|
|
5
5
|
duration: number;
|
|
6
|
-
|
|
6
|
+
open: Ref<boolean>;
|
|
7
7
|
close: ComputedRef<() => void>;
|
|
8
8
|
}
|
|
9
|
+
type ModalStatus = "closed" | "open" | "closing";
|
|
9
10
|
interface UseModalOptions {
|
|
10
11
|
duration?: number;
|
|
11
12
|
immediate?: boolean;
|
|
@@ -16,18 +17,21 @@ export declare const useModalStore: import("pinia").StoreDefinition<"modal", Pic
|
|
|
16
17
|
use: (render: () => VNode, options?: UseModalOptions) => {
|
|
17
18
|
open: () => void;
|
|
18
19
|
close: () => Promise<void>;
|
|
20
|
+
status: Ref<ModalStatus, ModalStatus>;
|
|
19
21
|
};
|
|
20
22
|
}, "modals">, Pick<{
|
|
21
23
|
modals: import("vue").ShallowReactive<ModalContext[]>;
|
|
22
24
|
use: (render: () => VNode, options?: UseModalOptions) => {
|
|
23
25
|
open: () => void;
|
|
24
26
|
close: () => Promise<void>;
|
|
27
|
+
status: Ref<ModalStatus, ModalStatus>;
|
|
25
28
|
};
|
|
26
29
|
}, never>, Pick<{
|
|
27
30
|
modals: import("vue").ShallowReactive<ModalContext[]>;
|
|
28
31
|
use: (render: () => VNode, options?: UseModalOptions) => {
|
|
29
32
|
open: () => void;
|
|
30
33
|
close: () => Promise<void>;
|
|
34
|
+
status: Ref<ModalStatus, ModalStatus>;
|
|
31
35
|
};
|
|
32
36
|
}, "use">>;
|
|
33
37
|
export {};
|
|
@@ -9,7 +9,7 @@ export const useModalStore = defineStore("modal", () => {
|
|
|
9
9
|
unique = false
|
|
10
10
|
} = options;
|
|
11
11
|
let ctx;
|
|
12
|
-
const
|
|
12
|
+
const status = ref("closed");
|
|
13
13
|
immediate && open();
|
|
14
14
|
function open() {
|
|
15
15
|
if (unique && indexOf() !== -1) {
|
|
@@ -20,7 +20,7 @@ export const useModalStore = defineStore("modal", () => {
|
|
|
20
20
|
vnode.value.props = {
|
|
21
21
|
onClose: close,
|
|
22
22
|
onVnodeMounted() {
|
|
23
|
-
|
|
23
|
+
status.value = "open";
|
|
24
24
|
},
|
|
25
25
|
...vnode.value.props
|
|
26
26
|
};
|
|
@@ -31,14 +31,15 @@ export const useModalStore = defineStore("modal", () => {
|
|
|
31
31
|
vnode,
|
|
32
32
|
zIndex,
|
|
33
33
|
duration,
|
|
34
|
-
|
|
34
|
+
open: computed(() => status.value === "open"),
|
|
35
35
|
close: computed(() => vnode.value.props?.onClose)
|
|
36
36
|
};
|
|
37
37
|
modals.push(ctx);
|
|
38
38
|
}
|
|
39
39
|
async function close() {
|
|
40
|
-
|
|
40
|
+
status.value = "closing";
|
|
41
41
|
await promiseTimeout(duration);
|
|
42
|
+
status.value = "closed";
|
|
42
43
|
const i = indexOf();
|
|
43
44
|
if (i !== -1) {
|
|
44
45
|
modals.splice(i, 1);
|
|
@@ -49,7 +50,8 @@ export const useModalStore = defineStore("modal", () => {
|
|
|
49
50
|
}
|
|
50
51
|
return {
|
|
51
52
|
open,
|
|
52
|
-
close
|
|
53
|
+
close,
|
|
54
|
+
status
|
|
53
55
|
};
|
|
54
56
|
}
|
|
55
57
|
return {
|