@@ -12,6 +12,7 @@ import RawModal from '../../atoms/modal/RawModal';
|
||||
function Dialog({
|
||||
className, isOpen, title, onAfterOpen, onAfterClose,
|
||||
contentOptions, onRequestClose, closeFromOutside, children,
|
||||
invisibleScroll,
|
||||
}) {
|
||||
return (
|
||||
<RawModal
|
||||
@@ -36,7 +37,7 @@ function Dialog({
|
||||
{contentOptions}
|
||||
</Header>
|
||||
<div className="dialog__content__wrapper">
|
||||
<ScrollView autoHide>
|
||||
<ScrollView autoHide invisible={invisibleScroll}>
|
||||
<div className="dialog__content-container">
|
||||
{children}
|
||||
</div>
|
||||
@@ -55,6 +56,7 @@ Dialog.defaultProps = {
|
||||
onAfterClose: null,
|
||||
onRequestClose: null,
|
||||
closeFromOutside: true,
|
||||
invisibleScroll: false,
|
||||
};
|
||||
|
||||
Dialog.propTypes = {
|
||||
@@ -67,6 +69,7 @@ Dialog.propTypes = {
|
||||
onRequestClose: PropTypes.func,
|
||||
closeFromOutside: PropTypes.bool,
|
||||
children: PropTypes.node.isRequired,
|
||||
invisibleScroll: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default Dialog;
|
||||
|
||||
@@ -21,8 +21,3 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.dialog__content-container {
|
||||
padding-top: var(--sp-extra-tight);
|
||||
padding-bottom: var(--sp-extra-loose);
|
||||
}
|
||||
49
src/app/molecules/dialog/ReusableDialog.jsx
Normal file
49
src/app/molecules/dialog/ReusableDialog.jsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
import cons from '../../../client/state/cons';
|
||||
|
||||
import navigation from '../../../client/state/navigation';
|
||||
import IconButton from '../../atoms/button/IconButton';
|
||||
import Dialog from './Dialog';
|
||||
|
||||
import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
|
||||
|
||||
function ReusableDialog() {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [data, setData] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOpen = (title, render, afterClose) => {
|
||||
setIsOpen(true);
|
||||
setData({ title, render, afterClose });
|
||||
};
|
||||
navigation.on(cons.events.navigation.REUSABLE_DIALOG_OPENED, handleOpen);
|
||||
return () => {
|
||||
navigation.removeListener(cons.events.navigation.REUSABLE_DIALOG_OPENED, handleOpen);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleAfterClose = () => {
|
||||
data.afterClose();
|
||||
setData(null);
|
||||
};
|
||||
|
||||
const handleRequestClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
isOpen={isOpen}
|
||||
title={data?.title || ''}
|
||||
onAfterClose={handleAfterClose}
|
||||
onRequestClose={handleRequestClose}
|
||||
contentOptions={<IconButton src={CrossIC} onClick={handleRequestClose} tooltip="Close" />}
|
||||
invisibleScroll
|
||||
>
|
||||
{data?.render(handleRequestClose) || <div />}
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default ReusableDialog;
|
||||
Reference in New Issue
Block a user