Handle for interaction outside of the ViewportDialog (default to cancel)
This commit is contained in:
parent
9403a091d9
commit
a0b0f365dd
@ -50,6 +50,10 @@ function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
|
|||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick: () => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(RESPONSE.CANCEL);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,6 +63,10 @@ function _askShouldAddMeasurements(UIViewportDialogService, viewportIndex) {
|
|||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick: () => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(RESPONSE.CANCEL);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -91,10 +95,14 @@ function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
|
|||||||
|
|
||||||
UIViewportDialogService.show({
|
UIViewportDialogService.show({
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
type: 'info', // TODO: warn
|
type: 'warning',
|
||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick: () => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(RESPONSE.CANCEL);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,10 @@ function _askTrackMeasurements(UIViewportDialogService, viewportIndex) {
|
|||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick: () => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(RESPONSE.CANCEL);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -85,10 +89,14 @@ function _askSaveDiscardOrCancel(UIViewportDialogService, viewportIndex) {
|
|||||||
|
|
||||||
UIViewportDialogService.show({
|
UIViewportDialogService.show({
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
type: 'info', // TODO: warn
|
type: 'warning',
|
||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick: () => {
|
||||||
|
UIViewportDialogService.hide();
|
||||||
|
resolve(RESPONSE.CANCEL);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -277,6 +277,7 @@ function TrackedCornerstoneViewport({
|
|||||||
type={viewportDialogState.type}
|
type={viewportDialogState.type}
|
||||||
actions={viewportDialogState.actions}
|
actions={viewportDialogState.actions}
|
||||||
onSubmit={viewportDialogState.onSubmit}
|
onSubmit={viewportDialogState.onSubmit}
|
||||||
|
onOutsideClick={viewportDialogState.onOutsideClick}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -26,13 +26,21 @@ const serviceImplementation = {
|
|||||||
*
|
*
|
||||||
* @param {ViewportDialogProps} props { content, contentProps, viewportIndex }
|
* @param {ViewportDialogProps} props { content, contentProps, viewportIndex }
|
||||||
*/
|
*/
|
||||||
function _show({ viewportIndex, type, message, actions, onSubmit }) {
|
function _show({
|
||||||
|
viewportIndex,
|
||||||
|
type,
|
||||||
|
message,
|
||||||
|
actions,
|
||||||
|
onSubmit,
|
||||||
|
onOutsideClick,
|
||||||
|
}) {
|
||||||
return serviceImplementation._show({
|
return serviceImplementation._show({
|
||||||
viewportIndex,
|
viewportIndex,
|
||||||
type,
|
type,
|
||||||
message,
|
message,
|
||||||
actions,
|
actions,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onOutsideClick,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,35 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Button, Icon } from '@ohif/ui';
|
import { Button, Icon } from '@ohif/ui';
|
||||||
|
|
||||||
const Notification = ({ type, message, actions, onSubmit }) => {
|
const Notification = ({ type, message, actions, onSubmit, onOutsideClick }) => {
|
||||||
|
const notificationRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const notificationElement = notificationRef.current;
|
||||||
|
const handleClick = function(event) {
|
||||||
|
const isClickInside = notificationElement.contains(event.target);
|
||||||
|
|
||||||
|
if (!isClickInside) {
|
||||||
|
onOutsideClick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener('mousedown', handleClick);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener('mousedown', handleClick);
|
||||||
|
};
|
||||||
|
}, [onOutsideClick]);
|
||||||
|
|
||||||
const iconsByType = {
|
const iconsByType = {
|
||||||
error: {
|
error: {
|
||||||
icon: 'info',
|
icon: 'info',
|
||||||
color: 'text-red-700',
|
color: 'text-red-700',
|
||||||
},
|
},
|
||||||
warning: {
|
warning: {
|
||||||
icon: 'info',
|
icon: 'notificationwarning-diamond',
|
||||||
color: 'text-yellow-500',
|
color: 'text-yellow-500',
|
||||||
},
|
},
|
||||||
info: {
|
info: {
|
||||||
@ -35,7 +54,10 @@ const Notification = ({ type, message, actions, onSubmit }) => {
|
|||||||
const { icon, color } = getIconData();
|
const { icon, color } = getIconData();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col p-2 mx-2 mt-2 rounded bg-common-bright">
|
<div
|
||||||
|
ref={notificationRef}
|
||||||
|
className="flex flex-col p-2 mx-2 mt-2 rounded bg-common-bright"
|
||||||
|
>
|
||||||
<div className="flex flex-grow">
|
<div className="flex flex-grow">
|
||||||
<Icon name={icon} className={classnames('w-5', color)} />
|
<Icon name={icon} className={classnames('w-5', color)} />
|
||||||
<span className="ml-2 text-base text-black">{message}</span>
|
<span className="ml-2 text-base text-black">{message}</span>
|
||||||
@ -65,6 +87,7 @@ const Notification = ({ type, message, actions, onSubmit }) => {
|
|||||||
|
|
||||||
Notification.defaultProps = {
|
Notification.defaultProps = {
|
||||||
type: 'info',
|
type: 'info',
|
||||||
|
onOutsideClick: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
Notification.propTypes = {
|
Notification.propTypes = {
|
||||||
@ -78,6 +101,8 @@ Notification.propTypes = {
|
|||||||
})
|
})
|
||||||
).isRequired,
|
).isRequired,
|
||||||
onSubmit: PropTypes.func.isRequired,
|
onSubmit: PropTypes.func.isRequired,
|
||||||
|
/** Can be used as a callback to dismiss the notification for clicks that occur outside of it */
|
||||||
|
onOutsideClick: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Notification;
|
export default Notification;
|
||||||
|
|||||||
@ -18,6 +18,9 @@ const DEFAULT_STATE = {
|
|||||||
onSubmit: () => {
|
onSubmit: () => {
|
||||||
console.log('btn value?');
|
console.log('btn value?');
|
||||||
},
|
},
|
||||||
|
onOutsideClick: () => {
|
||||||
|
console.warn('default: onOutsideClick')
|
||||||
|
},
|
||||||
onDismiss: () => {
|
onDismiss: () => {
|
||||||
console.log('dismiss? -1');
|
console.log('dismiss? -1');
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user