feat(ui): Add support for Custom Modal component in Modal Service (#4752)
This commit is contained in:
parent
8788dae6a4
commit
2c183aa4a7
@ -9,7 +9,7 @@ export const useAppConfig = () => useContext(appConfigContext);
|
|||||||
export function AppConfigProvider({ children, value: initAppConfig }) {
|
export function AppConfigProvider({ children, value: initAppConfig }) {
|
||||||
const [appConfig, setAppConfig] = useState(initAppConfig);
|
const [appConfig, setAppConfig] = useState(initAppConfig);
|
||||||
|
|
||||||
return <Provider value={[appConfig]}>{children}</Provider>;
|
return <Provider value={[appConfig, setAppConfig]}>{children}</Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppConfigProvider.propTypes = {
|
AppConfigProvider.propTypes = {
|
||||||
|
|||||||
@ -16,6 +16,7 @@ const name = 'uiModalService';
|
|||||||
const serviceImplementation = {
|
const serviceImplementation = {
|
||||||
_hide: () => console.warn('hide() NOT IMPLEMENTED'),
|
_hide: () => console.warn('hide() NOT IMPLEMENTED'),
|
||||||
_show: () => console.warn('show() NOT IMPLEMENTED'),
|
_show: () => console.warn('show() NOT IMPLEMENTED'),
|
||||||
|
_customComponent: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
class UIModalService {
|
class UIModalService {
|
||||||
@ -45,6 +46,8 @@ class UIModalService {
|
|||||||
movable = false,
|
movable = false,
|
||||||
containerDimensions = null,
|
containerDimensions = null,
|
||||||
contentDimensions = null,
|
contentDimensions = null,
|
||||||
|
shouldCloseOnOverlayClick = true,
|
||||||
|
shouldCloseImmediately = false,
|
||||||
}) {
|
}) {
|
||||||
return serviceImplementation._show({
|
return serviceImplementation._show({
|
||||||
content,
|
content,
|
||||||
@ -57,6 +60,8 @@ class UIModalService {
|
|||||||
movable,
|
movable,
|
||||||
containerDimensions,
|
containerDimensions,
|
||||||
contentDimensions,
|
contentDimensions,
|
||||||
|
shouldCloseOnOverlayClick,
|
||||||
|
shouldCloseImmediately,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +74,15 @@ class UIModalService {
|
|||||||
return serviceImplementation._hide();
|
return serviceImplementation._hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This provides flexibility in customizing the Modal's default component
|
||||||
|
*
|
||||||
|
* @returns {React.Component}
|
||||||
|
*/
|
||||||
|
getCustomComponent() {
|
||||||
|
return serviceImplementation._customComponent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -77,13 +91,20 @@ class UIModalService {
|
|||||||
* show: showImplementation,
|
* show: showImplementation,
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
setServiceImplementation({ hide: hideImplementation, show: showImplementation }) {
|
setServiceImplementation({
|
||||||
|
hide: hideImplementation,
|
||||||
|
show: showImplementation,
|
||||||
|
customComponent: customComponentImplementation,
|
||||||
|
}) {
|
||||||
if (hideImplementation) {
|
if (hideImplementation) {
|
||||||
serviceImplementation._hide = hideImplementation;
|
serviceImplementation._hide = hideImplementation;
|
||||||
}
|
}
|
||||||
if (showImplementation) {
|
if (showImplementation) {
|
||||||
serviceImplementation._show = showImplementation;
|
serviceImplementation._show = showImplementation;
|
||||||
}
|
}
|
||||||
|
if (customComponentImplementation) {
|
||||||
|
serviceImplementation._customComponent = customComponentImplementation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,8 @@ be centered, and not draggable. They're commonly used when:
|
|||||||
If you're curious about the DOs and DON'Ts of dialogs and modals, check out this
|
If you're curious about the DOs and DON'Ts of dialogs and modals, check out this
|
||||||
article: ["Best Practices for Modals / Overlays / Dialog Windows"][ux-article]
|
article: ["Best Practices for Modals / Overlays / Dialog Windows"][ux-article]
|
||||||
|
|
||||||
|
customComponent: The modal service allows users to provide their own Modal UI using the customComponents.
|
||||||
|
|
||||||
|
|
||||||
<div style={{padding:"56.25% 0 0 0", position:"relative"}}>
|
<div style={{padding:"56.25% 0 0 0", position:"relative"}}>
|
||||||
<iframe src="https://player.vimeo.com/video/843233754?badge=0&autopause=0&player_id=0&app_id=58479" frameBorder="0" allow="autoplay; fullscreen; picture-in-picture" allowFullScreen style= {{ position:"absolute",top:0,left:0,width:"100%",height:"100%"}} title="measurement-report"></iframe>
|
<iframe src="https://player.vimeo.com/video/843233754?badge=0&autopause=0&player_id=0&app_id=58479" frameBorder="0" allow="autoplay; fullscreen; picture-in-picture" allowFullScreen style= {{ position:"absolute",top:0,left:0,width:"100%",height:"100%"}} title="measurement-report"></iframe>
|
||||||
@ -29,12 +31,14 @@ is expected to support, [check out it's interface in `@ohif/core`][interface]
|
|||||||
| ---------- | ------------------------------------- |
|
| ---------- | ------------------------------------- |
|
||||||
| `hide()` | Hides the open modal |
|
| `hide()` | Hides the open modal |
|
||||||
| `show()` | Shows the provided content in a modal |
|
| `show()` | Shows the provided content in a modal |
|
||||||
|
| `customComponent()` | Overrides the default Modal component |
|
||||||
|
|
||||||
## Implementations
|
## Implementations
|
||||||
|
|
||||||
| Implementation | Consumer |
|
| Implementation | Consumer |
|
||||||
| ---------------------------------- | --------- |
|
| ---------------------------------- | --------- |
|
||||||
| [Modal Provider][modal-provider]\* | Modal.jsx |
|
| [Modal Provider][modal-provider]\* | Modal.jsx |
|
||||||
|
| customComponent | user extensions via setServiceImplementation({customComponent: Modal}) |
|
||||||
|
|
||||||
`*` - Denotes maintained by OHIF
|
`*` - Denotes maintained by OHIF
|
||||||
|
|
||||||
|
|||||||
@ -39,6 +39,8 @@ const ModalProvider = ({ children, modal: Modal, service = null }) => {
|
|||||||
|
|
||||||
const [options, setOptions] = useState(DEFAULT_OPTIONS);
|
const [options, setOptions] = useState(DEFAULT_OPTIONS);
|
||||||
|
|
||||||
|
const CustomModal = service.getCustomComponent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the modal and override its configuration props.
|
* Show the modal and override its configuration props.
|
||||||
*
|
*
|
||||||
@ -81,10 +83,12 @@ const ModalProvider = ({ children, modal: Modal, service = null }) => {
|
|||||||
contentDimensions,
|
contentDimensions,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
const ModalComp = CustomModal ? CustomModal : Modal;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Provider value={{ show, hide }}>
|
<Provider value={{ show, hide }}>
|
||||||
{ModalContent && (
|
{ModalContent && (
|
||||||
<Modal
|
<ModalComp
|
||||||
className={classNames(customClassName, ModalContent.className)}
|
className={classNames(customClassName, ModalContent.className)}
|
||||||
shouldCloseOnEsc={shouldCloseOnEsc}
|
shouldCloseOnEsc={shouldCloseOnEsc}
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
@ -101,7 +105,7 @@ const ModalProvider = ({ children, modal: Modal, service = null }) => {
|
|||||||
show={show}
|
show={show}
|
||||||
hide={hide}
|
hide={hide}
|
||||||
/>
|
/>
|
||||||
</Modal>
|
</ModalComp>
|
||||||
)}
|
)}
|
||||||
{children}
|
{children}
|
||||||
</Provider>
|
</Provider>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user