2021-05-09 18:06:11 +00:00
|
|
|
import React, { useRef, useState, useEffect } from 'react';
|
2021-05-10 07:59:17 +00:00
|
|
|
import { default as BootstrapModal } from 'react-bootstrap/Modal';
|
2021-05-09 18:06:11 +00:00
|
|
|
import Button from 'react-bootstrap/Button';
|
|
|
|
|
import { SubCustomDragLayer } from '../SubCustomDragLayer';
|
|
|
|
|
import { SubContainer } from '../SubContainer';
|
2021-05-10 13:44:58 +00:00
|
|
|
import { ConfigHandle } from '../ConfigHandle';
|
2021-05-09 18:06:11 +00:00
|
|
|
|
2021-12-15 04:23:57 +00:00
|
|
|
export const Modal = function Modal({
|
|
|
|
|
id,
|
|
|
|
|
component,
|
|
|
|
|
height,
|
|
|
|
|
containerProps,
|
|
|
|
|
darkMode,
|
|
|
|
|
properties,
|
|
|
|
|
styles,
|
|
|
|
|
exposedVariables,
|
|
|
|
|
setExposedVariable,
|
|
|
|
|
}) {
|
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
2021-05-09 18:06:11 +00:00
|
|
|
const parentRef = useRef(null);
|
|
|
|
|
|
2021-12-15 04:23:57 +00:00
|
|
|
const title = properties.title ?? '';
|
|
|
|
|
const size = properties.size ?? 'lg';
|
2021-05-10 07:59:17 +00:00
|
|
|
|
2021-12-15 04:23:57 +00:00
|
|
|
const { disabledState } = styles;
|
2021-09-02 14:11:59 +00:00
|
|
|
|
2021-05-09 18:06:11 +00:00
|
|
|
useEffect(() => {
|
2021-12-15 04:23:57 +00:00
|
|
|
const canShowModal = exposedVariables.show ?? false;
|
|
|
|
|
setShowModal(canShowModal);
|
2021-09-21 13:48:28 +00:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2021-12-15 04:23:57 +00:00
|
|
|
}, [exposedVariables.show]);
|
2021-05-09 18:06:11 +00:00
|
|
|
|
|
|
|
|
function hideModal() {
|
2021-12-15 04:23:57 +00:00
|
|
|
setExposedVariable('show', false);
|
|
|
|
|
setShowModal(false);
|
2021-05-09 18:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2021-12-15 04:23:57 +00:00
|
|
|
<div data-disabled={disabledState}>
|
2021-05-10 07:59:17 +00:00
|
|
|
<BootstrapModal
|
2021-05-09 18:06:11 +00:00
|
|
|
contentClassName="modal-component"
|
2021-12-15 04:23:57 +00:00
|
|
|
show={showModal}
|
2021-05-10 09:28:44 +00:00
|
|
|
container={document.getElementsByClassName('canvas-area')[0]}
|
2021-05-10 07:59:17 +00:00
|
|
|
size={size}
|
2021-05-10 09:29:21 +00:00
|
|
|
backdrop={true}
|
2021-05-10 07:59:17 +00:00
|
|
|
keyboard={true}
|
2021-05-10 09:29:21 +00:00
|
|
|
enforceFocus={false}
|
2021-05-09 18:06:11 +00:00
|
|
|
animation={false}
|
2022-02-22 12:52:34 +00:00
|
|
|
onEscapeKeyDown={() => hideModal()}
|
2021-05-09 18:06:11 +00:00
|
|
|
>
|
2021-09-21 13:48:28 +00:00
|
|
|
{containerProps.mode === 'edit' && (
|
2022-02-06 13:15:38 +00:00
|
|
|
<ConfigHandle id={id} component={component} setSelectedComponent={containerProps.onComponentClick} />
|
2021-09-21 13:48:28 +00:00
|
|
|
)}
|
2021-05-09 18:06:11 +00:00
|
|
|
<BootstrapModal.Header>
|
2021-12-15 04:23:57 +00:00
|
|
|
<BootstrapModal.Title>{title}</BootstrapModal.Title>
|
2021-05-09 18:06:11 +00:00
|
|
|
<div>
|
2021-10-07 03:14:47 +00:00
|
|
|
<Button variant={darkMode ? 'secondary' : 'light'} size="sm" onClick={hideModal}>
|
2021-05-09 18:06:11 +00:00
|
|
|
x
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</BootstrapModal.Header>
|
|
|
|
|
|
2021-11-25 08:47:18 +00:00
|
|
|
<BootstrapModal.Body style={{ height }} ref={parentRef} id={id}>
|
2021-09-21 13:48:28 +00:00
|
|
|
<SubContainer parent={id} {...containerProps} parentRef={parentRef} />
|
|
|
|
|
<SubCustomDragLayer
|
|
|
|
|
snapToGrid={true}
|
|
|
|
|
parentRef={parentRef}
|
|
|
|
|
parent={id}
|
|
|
|
|
currentLayout={containerProps.currentLayout}
|
|
|
|
|
/>
|
2021-05-09 18:06:11 +00:00
|
|
|
</BootstrapModal.Body>
|
|
|
|
|
</BootstrapModal>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|