Skip to content

Commit

Permalink
Modal Popup not applying theme variables (#6559)
Browse files Browse the repository at this point in the history
* work for #6503 Modal Popup not applying theme variables

* work for #6559 Modal Popup not applying theme variables - support Vue3

---------

Co-authored-by: OlgaLarina <olga.larina.dev@gmail.com>
  • Loading branch information
OlgaLarina and OlgaLarina authored Jul 24, 2023
1 parent e1016de commit b583559
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class ModalComponent {

constructor(private popupService: PopupService) {
}
showDialog(dialogOptions: IDialogOptions, container?: HTMLElement): PopupBaseViewModel {
this.model = createPopupModalViewModel(dialogOptions, container);
showDialog(dialogOptions: IDialogOptions, rootElement?: HTMLElement): PopupBaseViewModel {
this.model = createPopupModalViewModel(dialogOptions, rootElement);
this.model.model.onHide = () => {
this.portalHost.detach();
this.model.dispose();
Expand Down Expand Up @@ -52,10 +52,15 @@ export class ModalComponent {
);
return this.showDialog(options);
};

settings.showDialog = (dialogOptions: IDialogOptions, rootElement?: HTMLElement) => {
this.showDialog(dialogOptions, rootElement);
};
}
ngOnDestroy() {
if(this.functionDefined) {
settings.showModal = <any>undefined;
settings.showDialog = <any>undefined;
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions packages/survey-vue3-ui/src/components/popup/PopupModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ function showModal(
}
function showDialog(
dialogOptions: IDialogOptions,
container?: HTMLElement
rootElement?: HTMLElement
): PopupBaseViewModel {
dialogOptions.onHide = () => {
popup.value = undefined;
popupViewModel.dispose();
};
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(
dialogOptions,
container
rootElement
);
popupViewModel.model.isVisible = true;
popup.value = popupViewModel;
Expand All @@ -59,4 +59,10 @@ if (!settings.showModal) {
settings.showModal = undefined as any;
});
}
if (!settings.showDialog) {
settings.showDialog = showDialog;
onUnmounted(() => {
settings.showDialog = undefined as any;
});
}
</script>
5 changes: 3 additions & 2 deletions src/knockout/components/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export function showModal(
);
return showDialog(options, container);
}
export function showDialog(dialogOptions: IDialogOptions, container?: HTMLElement): PopupBaseViewModel {
export function showDialog(dialogOptions: IDialogOptions, rootElement?: HTMLElement): PopupBaseViewModel {
dialogOptions.onHide = () => {
viewModel.dispose();
ko.cleanNode(popupViewModel.container);
popupViewModel.dispose();
};
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, container);
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, rootElement);
var viewModel = new PopupViewModel(popupViewModel);
popupViewModel.container.innerHTML = template;
ko.applyBindings(viewModel, popupViewModel.container);
Expand All @@ -59,6 +59,7 @@ export function showDialog(dialogOptions: IDialogOptions, container?: HTMLElemen
}

settings.showModal = showModal;
settings.showDialog = showDialog;

ko.components.register("sv-popup", {
viewModel: {
Expand Down
12 changes: 9 additions & 3 deletions src/popup-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { IDialogOptions, PopupModel } from "./popup";
import { PopupDropdownViewModel } from "./popup-dropdown-view-model";
import { PopupModalViewModel } from "./popup-modal-view-model";
import { PopupBaseViewModel } from "./popup-view-model";
import { settings } from "./settings";
import { getElement } from "./utils/utils";

export function createPopupModalViewModel(options: IDialogOptions, container?: HTMLElement): PopupBaseViewModel {
export function createPopupModalViewModel(options: IDialogOptions, rootElement?: HTMLElement): PopupBaseViewModel {
const popupModel = new PopupModel(
options.componentName,
options.data,
Expand All @@ -20,8 +22,12 @@ export function createPopupModalViewModel(options: IDialogOptions, container?: H
);
popupModel.displayMode = options.displayMode || "popup";
const popupViewModel: PopupBaseViewModel = new PopupModalViewModel(popupModel);
popupViewModel.setComponentElement(container);
if(!container) {
if(!!rootElement && !!rootElement.appendChild) {
const container: HTMLElement = document.createElement("div");
rootElement.appendChild(container);
popupViewModel.setComponentElement(container);
}
if(!popupViewModel.container) {
popupViewModel.initializePopupContainer();
}
return popupViewModel;
Expand Down
5 changes: 3 additions & 2 deletions src/react/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,17 @@ export function showModal(
);
return showDialog(options);
}
export function showDialog(dialogOptions: IDialogOptions, container?: HTMLElement): PopupBaseViewModel {
export function showDialog(dialogOptions: IDialogOptions, rootElement?: HTMLElement): PopupBaseViewModel {
dialogOptions.onHide = () => {
ReactDOM.unmountComponentAtNode(popupViewModel.container);
popupViewModel.dispose();
};
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, container);
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, rootElement);
ReactDOM.render(<PopupContainer model={popupViewModel} />, popupViewModel.container);
popupViewModel.model.isVisible = true;

return popupViewModel;
}

settings.showModal = showModal;
settings.showDialog = showDialog;
3 changes: 3 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IDialogOptions } from "./popup";

export type ISurveyEnvironment = {
root: Document | ShadowRoot,
rootElement: HTMLElement | ShadowRoot,
Expand Down Expand Up @@ -562,6 +564,7 @@ export var settings = {
displayMode?: "popup" | "overlay"
) => any
>undefined,
showDialog: < (options: IDialogOptions, rootElement?: HTMLElement) => any >undefined,
supportCreatorV2: false,
showDefaultItemsInCreatorV2: true,
/**
Expand Down
5 changes: 3 additions & 2 deletions src/vue/components/popup/popup-container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ export function showModal(
);
return showDialog(options);
}
export function showDialog(dialogOptions: IDialogOptions, container?: HTMLElement): PopupBaseViewModel {
export function showDialog(dialogOptions: IDialogOptions, rootElement?: HTMLElement): PopupBaseViewModel {
dialogOptions.onHide = () => {
popup.$destroy();
popupViewModel.dispose();
};
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, container);
const popupViewModel: PopupBaseViewModel = createPopupModalViewModel(dialogOptions, rootElement);
const popup = new PopupContainer({
el: popupViewModel.container.appendChild(document.createElement("div")),
propsData: { model: popupViewModel },
Expand All @@ -116,6 +116,7 @@ export function showDialog(dialogOptions: IDialogOptions, container?: HTMLElemen
return popupViewModel;
}
settings.showModal = showModal;
settings.showDialog = showDialog;
Vue.component("sv-popup-container", PopupContainer);
export default PopupContainer;
</script>

0 comments on commit b583559

Please sign in to comment.