@openshift-console/dynamic-plugin-sdk
Version:
Provides core APIs, types and utilities used by dynamic plugins at runtime.
28 lines (27 loc) • 955 B
JavaScript
import * as React from 'react';
import { ModalContext } from './ModalProvider';
/**
* A hook to launch Modals.
*
* Additional props can be passed to `useModal` and they will be passed through to the modal component.
* An optional ID can also be passed to `useModal`. If provided, this distinguishes the modal from
* other modals to allow multiple modals to be displayed at the same time.
* @example
*```tsx
* const AppPage: React.FC = () => {
* const launchModal = useModal();
* const onClick1 = () => launchModal(ModalComponent);
* const onClick2 = () => launchModal(ModalComponent, { title: 'Test modal' }, 'TEST_MODAL_ID');
* return (
* <>
* <Button onClick={onClick1}>Launch basic modal</Button>
* <Button onClick={onClick2}>Launch modal with props and an ID</Button>
* </>
* )
* }
* ```
*/
export const useModal = () => {
const { launchModal } = React.useContext(ModalContext);
return launchModal;
};