From 2c183aa4a777d7b5a0417ebcc8576a0fc2631ad2 Mon Sep 17 00:00:00 2001 From: Abhijith Sb <105038248+abhijith-trenser@users.noreply.github.com> Date: Tue, 4 Feb 2025 19:21:23 +0530 Subject: [PATCH] feat(ui): Add support for Custom Modal component in Modal Service (#4752) --- platform/app/src/state/appConfig.tsx | 2 +- .../core/src/services/UIModalService/index.ts | 23 ++++++++++++++++++- .../platform/services/ui/ui-modal-service.md | 4 ++++ .../ui/src/contextProviders/ModalProvider.tsx | 8 +++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/platform/app/src/state/appConfig.tsx b/platform/app/src/state/appConfig.tsx index 8d7388153..ce7eaf726 100644 --- a/platform/app/src/state/appConfig.tsx +++ b/platform/app/src/state/appConfig.tsx @@ -9,7 +9,7 @@ export const useAppConfig = () => useContext(appConfigContext); export function AppConfigProvider({ children, value: initAppConfig }) { const [appConfig, setAppConfig] = useState(initAppConfig); - return {children}; + return {children}; } AppConfigProvider.propTypes = { diff --git a/platform/core/src/services/UIModalService/index.ts b/platform/core/src/services/UIModalService/index.ts index eb56bb7ee..73aa5651a 100644 --- a/platform/core/src/services/UIModalService/index.ts +++ b/platform/core/src/services/UIModalService/index.ts @@ -16,6 +16,7 @@ const name = 'uiModalService'; const serviceImplementation = { _hide: () => console.warn('hide() NOT IMPLEMENTED'), _show: () => console.warn('show() NOT IMPLEMENTED'), + _customComponent: null, }; class UIModalService { @@ -45,6 +46,8 @@ class UIModalService { movable = false, containerDimensions = null, contentDimensions = null, + shouldCloseOnOverlayClick = true, + shouldCloseImmediately = false, }) { return serviceImplementation._show({ content, @@ -57,6 +60,8 @@ class UIModalService { movable, containerDimensions, contentDimensions, + shouldCloseOnOverlayClick, + shouldCloseImmediately, }); } @@ -69,6 +74,15 @@ class UIModalService { 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, * } */ - setServiceImplementation({ hide: hideImplementation, show: showImplementation }) { + setServiceImplementation({ + hide: hideImplementation, + show: showImplementation, + customComponent: customComponentImplementation, + }) { if (hideImplementation) { serviceImplementation._hide = hideImplementation; } if (showImplementation) { serviceImplementation._show = showImplementation; } + if (customComponentImplementation) { + serviceImplementation._customComponent = customComponentImplementation; + } } } diff --git a/platform/docs/docs/platform/services/ui/ui-modal-service.md b/platform/docs/docs/platform/services/ui/ui-modal-service.md index e78bc9c01..fe5de8ceb 100644 --- a/platform/docs/docs/platform/services/ui/ui-modal-service.md +++ b/platform/docs/docs/platform/services/ui/ui-modal-service.md @@ -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 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. +
@@ -29,12 +31,14 @@ is expected to support, [check out it's interface in `@ohif/core`][interface] | ---------- | ------------------------------------- | | `hide()` | Hides the open modal | | `show()` | Shows the provided content in a modal | +| `customComponent()` | Overrides the default Modal component | ## Implementations | Implementation | Consumer | | ---------------------------------- | --------- | | [Modal Provider][modal-provider]\* | Modal.jsx | +| customComponent | user extensions via setServiceImplementation({customComponent: Modal}) | `*` - Denotes maintained by OHIF diff --git a/platform/ui/src/contextProviders/ModalProvider.tsx b/platform/ui/src/contextProviders/ModalProvider.tsx index 19f31982d..fa9b98aee 100644 --- a/platform/ui/src/contextProviders/ModalProvider.tsx +++ b/platform/ui/src/contextProviders/ModalProvider.tsx @@ -39,6 +39,8 @@ const ModalProvider = ({ children, modal: Modal, service = null }) => { const [options, setOptions] = useState(DEFAULT_OPTIONS); + const CustomModal = service.getCustomComponent(); + /** * Show the modal and override its configuration props. * @@ -81,10 +83,12 @@ const ModalProvider = ({ children, modal: Modal, service = null }) => { contentDimensions, } = options; + const ModalComp = CustomModal ? CustomModal : Modal; + return ( {ModalContent && ( - { show={show} hide={hide} /> - + )} {children}