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-09-02 14:11:59 +00:00
|
|
|
import { resolveWidgetFieldValue, resolveReferences } from '../../_helpers/utils';
|
2021-05-09 18:06:11 +00:00
|
|
|
|
|
|
|
|
export const Modal = function Modal({
|
|
|
|
|
id,
|
|
|
|
|
component,
|
|
|
|
|
height,
|
2021-05-10 11:36:33 +00:00
|
|
|
mode,
|
2021-09-02 14:11:59 +00:00
|
|
|
containerProps,
|
|
|
|
|
currentState
|
2021-05-09 18:06:11 +00:00
|
|
|
}) {
|
|
|
|
|
const [show, showModal] = useState(false);
|
|
|
|
|
const parentRef = useRef(null);
|
|
|
|
|
|
2021-05-10 07:59:17 +00:00
|
|
|
const titleProp = component.definition.properties.title;
|
|
|
|
|
const title = titleProp ? titleProp.value : '';
|
|
|
|
|
|
|
|
|
|
const sizeProp = component.definition.properties.size;
|
|
|
|
|
const size = sizeProp ? sizeProp.value : 'lg';
|
|
|
|
|
|
2021-09-02 14:11:59 +00:00
|
|
|
const disabledState = component.definition.styles?.disabledState?.value ?? false;
|
|
|
|
|
|
|
|
|
|
const parsedDisabledState = typeof disabledState !== 'boolean' ? resolveWidgetFieldValue(disabledState, currentState) : disabledState;
|
|
|
|
|
|
2021-05-09 18:06:11 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
const componentState = containerProps.currentState.components[component.name];
|
|
|
|
|
const canShowModel = componentState ? componentState.show : false;
|
|
|
|
|
showModal(canShowModel);
|
|
|
|
|
}, [containerProps.currentState.components[component.name]]);
|
|
|
|
|
|
|
|
|
|
function hideModal() {
|
|
|
|
|
containerProps.onComponentOptionChanged(component, 'show', false);
|
|
|
|
|
showModal(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2021-09-02 14:11:59 +00:00
|
|
|
<div data-disabled={parsedDisabledState}>
|
2021-05-10 07:59:17 +00:00
|
|
|
<BootstrapModal
|
2021-05-09 18:06:11 +00:00
|
|
|
contentClassName="modal-component"
|
2021-05-10 07:59:17 +00:00
|
|
|
show={show}
|
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}
|
|
|
|
|
onEscapeKeyDown={() => showModal(false)}
|
|
|
|
|
>
|
2021-05-10 14:31:14 +00:00
|
|
|
{containerProps.mode === 'edit' &&
|
|
|
|
|
<ConfigHandle
|
|
|
|
|
id={id}
|
|
|
|
|
component={component}
|
|
|
|
|
configHandleClicked={containerProps.onComponentClick}
|
|
|
|
|
/>
|
|
|
|
|
}
|
2021-05-09 18:06:11 +00:00
|
|
|
<BootstrapModal.Header>
|
2021-05-10 07:59:17 +00:00
|
|
|
<BootstrapModal.Title>
|
|
|
|
|
{title}
|
|
|
|
|
</BootstrapModal.Title>
|
2021-05-09 18:06:11 +00:00
|
|
|
<div>
|
|
|
|
|
<Button variant="light" size="sm" onClick={hideModal}>
|
|
|
|
|
x
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</BootstrapModal.Header>
|
|
|
|
|
|
2021-05-10 07:59:17 +00:00
|
|
|
<BootstrapModal.Body style={{ height }} ref={parentRef}>
|
2021-05-09 18:06:11 +00:00
|
|
|
<SubContainer
|
|
|
|
|
parent={id}
|
|
|
|
|
{...containerProps}
|
|
|
|
|
parentRef={parentRef}
|
|
|
|
|
/>
|
2021-05-10 07:59:17 +00:00
|
|
|
<SubCustomDragLayer
|
|
|
|
|
snapToGrid={true}
|
2021-05-09 18:06:11 +00:00
|
|
|
parentRef={parentRef}
|
2021-05-11 16:23:01 +00:00
|
|
|
parent={id}
|
2021-08-20 10:27:22 +00:00
|
|
|
currentLayout={containerProps.currentLayout}
|
2021-05-09 18:06:11 +00:00
|
|
|
/>
|
|
|
|
|
</BootstrapModal.Body>
|
|
|
|
|
</BootstrapModal>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|