Skip to content

Commit

Permalink
fix(modal-plugin): add props on modal options (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
smithoo committed Feb 18, 2025
1 parent 78d05cb commit b8acb9a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div v-if="typeof content === 'string'" v-html="content" />
<component v-else :is="toRaw(content)" />
<component v-else :is="toRaw(content)" v-bind="props" />
</template>

<script lang="ts">
Expand All @@ -10,6 +10,7 @@ export default defineComponent({
name: 'VsContentRenderer',
props: {
content: { type: [String, Object, Function] as PropType<string | Component>, required: true },
props: { type: Object as PropType<Record<string, any>>, default: () => ({}) },
},
setup() {
return { toRaw };
Expand Down
12 changes: 5 additions & 7 deletions packages/vlossom/src/components/vs-modal/VsModalView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
:callbacks="modal.callbacks"
>
<template #header v-if="modal.header">
<vs-content-renderer :content="modal.header" />
<vs-content-renderer :content="modal.header" :props="modal.props" />
</template>
<vs-content-renderer v-if="modal.component" :content="modal.component" />
<vs-content-renderer v-if="modal.component" :content="modal.component" :props="modal.props" />
<template #footer v-if="modal.footer">
<vs-content-renderer :content="modal.footer" />
<vs-content-renderer :content="modal.footer" :props="modal.props" />
</template>
</vs-modal-node>
</TransitionGroup>
Expand All @@ -31,7 +31,7 @@
<script lang="ts">
import { computed, ComputedRef, defineComponent, toRefs, watch } from 'vue';
import { store } from '@/stores';
import { useContentRenderer, useScrollLock } from '@/composables';
import { useScrollLock } from '@/composables';
import VsModalNode from '@/components/vs-modal/VsModalNode.vue';
import VsContentRenderer from '@/components/vs-content-renderer/VsContentRenderer.vue';
import { MODAL_DURATION } from '@/declaration';
Expand All @@ -47,8 +47,6 @@ export default defineComponent({
return store.modal.itemsByContainer.value[container.value] || [];
});
const { getRenderedContent } = useContentRenderer();
const wrapperId = computed(() => `vs-modal-${container.value.replace('#', '').replace('.', '')}`);
const isFixed = computed(() => container.value === 'body');
Expand All @@ -73,7 +71,7 @@ export default defineComponent({
}
});
return { modals, getRenderedContent, wrapperId, isFixed, MODAL_DURATION };
return { modals, wrapperId, isFixed, MODAL_DURATION };
},
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Component, h } from 'vue';
import { VsContentRenderer } from '@/components';

export function useContentRenderer() {
function getRenderedContent(content: string | Component) {
return h(VsContentRenderer, { content });
function getRenderedContent(content: string | Component, props: Record<string, any> = {}) {
return h(VsContentRenderer, { content, ...props });
}

return { getRenderedContent };
Expand Down
1 change: 1 addition & 0 deletions packages/vlossom/src/declaration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export type OverlayCallbacks<T = void> = { [eventName: string]: (...args: any[])

export interface ModalOptions<T> {
component: string | Component;
props?: Record<string, any>;
header?: string | Component;
footer?: string | Component;
container?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/vlossom/src/plugins/confirm-plugin/confirm-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useContentRenderer } from '@/composables';
export const confirmPlugin: ConfirmPlugin = {
open: (content: string | Component, confirmOptions: ConfirmOptions = {}): Promise<boolean> => {
return new Promise((resolve) => {
const { okText, cancelText, size = 'xs', callbacks = {}, styleSet } = confirmOptions;
const { okText, cancelText, size = 'xs', callbacks = {}, styleSet, props } = confirmOptions;
const { getRenderedContent } = useContentRenderer();
const modalId = modalPlugin.open({
...confirmOptions,
Expand All @@ -17,7 +17,7 @@ export const confirmPlugin: ConfirmPlugin = {
{ okText, cancelText, styleSet },
{
default: () => {
return getRenderedContent(content);
return getRenderedContent(content, props);
},
},
),
Expand Down

0 comments on commit b8acb9a

Please sign in to comment.