@bagelink/vue 0.0.206 → 0.0.211
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/components/ModalBglForm.vue.d.ts +45 -0
- package/dist/components/ModalBglForm.vue.d.ts.map +1 -0
- package/dist/components/form/index.d.ts +1 -0
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.cjs +167 -60
- package/dist/index.mjs +167 -60
- package/dist/plugins/modal.d.ts +3 -1
- package/dist/plugins/modal.d.ts.map +1 -1
- package/dist/style.css +9 -0
- package/dist/types/BagelForm.d.ts +2 -0
- package/dist/types/BagelForm.d.ts.map +1 -1
- package/dist/types/BtnOptions.d.ts +1 -0
- package/dist/types/BtnOptions.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/ModalBglForm.vue +121 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/plugins/modal.ts +16 -8
- package/src/types/BagelForm.ts +2 -0
- package/src/types/BtnOptions.ts +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="bg-dark"
|
|
4
|
+
:class="{ 'is-side': side, 'is-active': isActive }"
|
|
5
|
+
@click="() => (dismissable ? closeModal() : '')"
|
|
6
|
+
@keydown.esc="closeModal"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="card modal"
|
|
10
|
+
@click.stop
|
|
11
|
+
>
|
|
12
|
+
<header class="tool-bar">
|
|
13
|
+
<slot name="toolbar" />
|
|
14
|
+
<Btn
|
|
15
|
+
:style="{ float: side ? 'left' : 'right' }"
|
|
16
|
+
flat
|
|
17
|
+
icon="close"
|
|
18
|
+
@click="closeModal"
|
|
19
|
+
/>
|
|
20
|
+
<h3 class="modal-title">
|
|
21
|
+
{{ title }}
|
|
22
|
+
</h3>
|
|
23
|
+
</header>
|
|
24
|
+
<BagelForm
|
|
25
|
+
:onDelete="onDelete ? runDelete : undefined"
|
|
26
|
+
:modelValue="modelValue"
|
|
27
|
+
@update:modelValue="handleEmit"
|
|
28
|
+
@submit="runSubmit"
|
|
29
|
+
:schema="computedFormSchema"
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script lang="ts" setup>
|
|
36
|
+
import { onMounted, onUnmounted } from 'vue';
|
|
37
|
+
import {
|
|
38
|
+
Btn, BtnOptions, useEscape, BagelForm,
|
|
39
|
+
} from '@bagelink/vue';
|
|
40
|
+
import '../styles/modal.css';
|
|
41
|
+
import { BglFormSchemaT } from 'dist';
|
|
42
|
+
|
|
43
|
+
const props = defineProps<{
|
|
44
|
+
side?: boolean;
|
|
45
|
+
title?: string;
|
|
46
|
+
dismissable?: boolean;
|
|
47
|
+
actions?: BtnOptions[];
|
|
48
|
+
schema: BglFormSchemaT | (() => BglFormSchemaT);
|
|
49
|
+
modelValue?: Record<string, any>;
|
|
50
|
+
// eslint-disable-next-line no-unused-vars
|
|
51
|
+
onSubmit?: ((formData: any) => Promise<void>);
|
|
52
|
+
// eslint-disable-next-line no-unused-vars
|
|
53
|
+
onDelete?: ((id: string) => void);
|
|
54
|
+
}>();
|
|
55
|
+
|
|
56
|
+
const computedFormSchema = $computed(() => {
|
|
57
|
+
if (typeof props.schema === 'function') {
|
|
58
|
+
return props.schema();
|
|
59
|
+
}
|
|
60
|
+
return props.schema;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
let isActive = $ref<boolean>(false);
|
|
64
|
+
|
|
65
|
+
const emit = defineEmits(['update:isModalVisible', 'update:modelValue']);
|
|
66
|
+
const handleEmit = (value: any) => {
|
|
67
|
+
emit('update:modelValue', value);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const closeModal = () => {
|
|
71
|
+
isActive = false;
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
emit('update:isModalVisible', false);
|
|
74
|
+
}, 200);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const runSubmit = async (formData: any) => {
|
|
78
|
+
try {
|
|
79
|
+
await props.onSubmit?.(formData);
|
|
80
|
+
closeModal();
|
|
81
|
+
} catch (err) {
|
|
82
|
+
console.error(err);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const runDelete = () => {
|
|
87
|
+
props.onDelete?.(props.modelValue?.id);
|
|
88
|
+
closeModal();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const escapeKeyClose = (e: KeyboardEvent) => props?.dismissable && useEscape(e, () => closeModal());
|
|
92
|
+
|
|
93
|
+
onMounted(() => {
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
isActive = true;
|
|
96
|
+
}, 1);
|
|
97
|
+
|
|
98
|
+
document.addEventListener(
|
|
99
|
+
'keydown',
|
|
100
|
+
escapeKeyClose,
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
onUnmounted(() => {
|
|
104
|
+
document.removeEventListener(
|
|
105
|
+
'keydown',
|
|
106
|
+
escapeKeyClose,
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
</script>
|
|
110
|
+
|
|
111
|
+
<style scoped>
|
|
112
|
+
.modal-title {
|
|
113
|
+
margin-top: 0.5rem;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@media screen and (max-width: 910px) {
|
|
117
|
+
.modal-title {
|
|
118
|
+
margin-top: 1rem;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
</style>
|
|
@@ -2,5 +2,6 @@ export { default as ItemRef } from './ItemRef.vue';
|
|
|
2
2
|
export { default as MaterialIcon } from './MaterialIcon.vue';
|
|
3
3
|
export { default as PlainInputField } from './PlainInputField.vue';
|
|
4
4
|
export { default as BglForm } from './BglForm.vue';
|
|
5
|
+
export { default as BagelForm } from './BglForm.vue';
|
|
5
6
|
export { default as BglField } from './BglField.vue';
|
|
6
7
|
export * from './inputs';
|
package/src/components/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { default as MaterialIcon } from './MaterialIcon.vue';
|
|
|
4
4
|
export { default as NavBar } from './NavBar.vue';
|
|
5
5
|
export { default as Btn } from './Btn.vue';
|
|
6
6
|
export { default as Modal } from './Modal.vue';
|
|
7
|
+
export { default as ModalBglForm } from './ModalBglForm.vue';
|
|
7
8
|
export { default as DropDown } from './DropDown.vue';
|
|
8
9
|
export { default as ListView } from './ListView.vue';
|
|
9
10
|
export { default as ListItem } from './ListItem.vue';
|
package/src/plugins/modal.ts
CHANGED
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
} from 'vue';
|
|
4
4
|
import type { Plugin } from 'vue';
|
|
5
5
|
import type { BtnOptions } from '@bagelink/vue';
|
|
6
|
-
import { Modal, ModalForm } from '@bagelink/vue';
|
|
6
|
+
import { Modal, ModalForm, ModalBglForm } from '@bagelink/vue';
|
|
7
7
|
import type { FormKitSchemaDefinition } from '@formkit/core';
|
|
8
|
+
import { BglFormSchemaT } from 'dist/types';
|
|
8
9
|
|
|
9
10
|
interface ModalOptions {
|
|
10
11
|
title?: string;
|
|
@@ -22,13 +23,15 @@ interface ModalFormOptions extends ModalOptions {
|
|
|
22
23
|
onSubmit: (val: any) => void;
|
|
23
24
|
// eslint-disable-next-line no-unused-vars
|
|
24
25
|
onDelete?: (id: string) => void;
|
|
25
|
-
schema: FormKitSchemaDefinition;
|
|
26
|
+
schema: FormKitSchemaDefinition | BglFormSchemaT;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
interface ModalApi {
|
|
29
30
|
// eslint-disable-next-line no-unused-vars
|
|
30
31
|
showModal: (options: ModalOptions, slots?: Record<string, any>) => void;
|
|
31
32
|
// eslint-disable-next-line no-unused-vars
|
|
33
|
+
showModalForm: (options: ModalFormOptions, slots?: Record<string, any>) => void;
|
|
34
|
+
// eslint-disable-next-line no-unused-vars
|
|
32
35
|
modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => void;
|
|
33
36
|
// eslint-disable-next-line no-unused-vars
|
|
34
37
|
hideModal: (index?: number) => void;
|
|
@@ -45,7 +48,7 @@ export const useModal = (): ModalApi => {
|
|
|
45
48
|
|
|
46
49
|
interface ModalComponentProps {
|
|
47
50
|
componentSlots: Record<string, any>,
|
|
48
|
-
|
|
51
|
+
modalType: 0 | 1 | 2,
|
|
49
52
|
modalOptions: ModalOptions | ModalFormOptions
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -59,20 +62,21 @@ export const ModalPlugin: Plugin = {
|
|
|
59
62
|
};
|
|
60
63
|
|
|
61
64
|
const showModal = (
|
|
62
|
-
|
|
65
|
+
modalType: 0 | 1 | 2,
|
|
63
66
|
options: ModalOptions | ModalFormOptions,
|
|
64
67
|
slots: Record<string, any> = {},
|
|
65
68
|
) => {
|
|
66
69
|
modalStack.push({
|
|
67
70
|
modalOptions: options,
|
|
68
|
-
|
|
71
|
+
modalType,
|
|
69
72
|
componentSlots: slots,
|
|
70
73
|
});
|
|
71
74
|
};
|
|
72
75
|
|
|
73
76
|
app.provide(ModalSymbol, {
|
|
74
|
-
modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal(
|
|
75
|
-
showModal: (options: ModalOptions, slots?: Record<string, any>) => showModal(
|
|
77
|
+
modalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal(1, options, slots),
|
|
78
|
+
showModal: (options: ModalOptions, slots?: Record<string, any>) => showModal(0, options, slots),
|
|
79
|
+
showModalForm: (options: ModalFormOptions, slots?: Record<string, any>) => showModal(2, options, slots),
|
|
76
80
|
hideModal: (index = modalStack.length - 1) => hideModal(index),
|
|
77
81
|
// modalOptions,
|
|
78
82
|
});
|
|
@@ -85,7 +89,11 @@ export const ModalPlugin: Plugin = {
|
|
|
85
89
|
},
|
|
86
90
|
render() {
|
|
87
91
|
return modalStack.map((modal, index) => {
|
|
88
|
-
|
|
92
|
+
let renderComponent;
|
|
93
|
+
if (modal.modalType === 1) renderComponent = ModalForm;
|
|
94
|
+
else if (modal.modalType === 2) renderComponent = ModalBglForm;
|
|
95
|
+
else renderComponent = Modal;
|
|
96
|
+
|
|
89
97
|
return h(
|
|
90
98
|
renderComponent,
|
|
91
99
|
{
|
package/src/types/BagelForm.ts
CHANGED
package/src/types/BtnOptions.ts
CHANGED