td2-visualizer/src/components/dialog/DialogManager.js
izawartka b68d4e76c0 Add embedded dialogs
- Extracted DialogManager component selection to utils/getDialogComponent
- Added EmbeddedDialog
- Updated DialogManager to use EmbeddedDialog instead of Dialog if an app is running in embedded mode
2026-07-29 19:47:28 +02:00

34 lines
970 B
JavaScript

import React, { useRef } from 'react';
import './Dialog.css';
import { useDialogs } from '../../hooks/useDialogs';
import { removeDialog } from '../../services/dialogService';
import { getDialogComponent } from './utils/getDialogComponent';
import { useEmbeddedContext } from '../../contexts/EmbeddedContext';
function DialogManager() {
const dialogs = useDialogs();
const currentDialogRef = useRef(null);
const currentDialog = dialogs[dialogs.length - 1];
const { isEmbedded } = useEmbeddedContext();
const onClose = () => {
removeDialog();
};
const onBgClick = (e) => {
if (e.target !== e.currentTarget) return;
currentDialogRef.current?.onBgClick?.();
};
if (!currentDialog) return null;
const DialogComponent = getDialogComponent(currentDialog, onClose, currentDialogRef, isEmbedded);
return (
<div className="dialog-background" onClick={onBgClick}>
{DialogComponent}
</div>
);
}
export default DialogManager;