All files / platform/core/src/services/UIModalService index.ts

76.47% Statements 13/17
50% Branches 5/10
62.5% Functions 5/8
75% Lines 12/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 8934x   34x           34x         34x                                       1x                                                   35x                               34x 34x   34x 34x   34x       34x      
const name = 'uiModalService';
 
const serviceImplementation = {
  _hide: () => console.warn('hide() NOT IMPLEMENTED'),
  _show: () => console.warn('show() NOT IMPLEMENTED'),
  _customComponent: null,
};
 
class UIModalService {
  static REGISTRATION = {
    name,
    altName: 'UIModalService',
    create: (): UIModalService => {
      return new UIModalService();
    },
  };
 
  readonly name = name;
 
  /**
   * Show a new UI modal;
   *
   * @param {ModalProps} props { content, contentProps, shouldCloseOnEsc, isOpen, closeButton, title, customClassName }
   */
  show({
    content = null,
    contentProps = null,
    title = null,
    className = null,
    shouldCloseOnEsc = true,
    shouldCloseOnOverlayClick = true,
    containerClassName = null,
  }) {
    return serviceImplementation._show({
      content,
      contentProps,
      shouldCloseOnEsc,
      title,
      className,
      shouldCloseOnOverlayClick,
      containerClassName,
    });
  }
 
  /**
   * Hides/dismisses the modal, if currently shown
   *
   * @returns void
   */
  hide() {
    return serviceImplementation._hide();
  }
 
  /**
   * This provides flexibility in customizing the Modal's default component
   *
   * @returns {React.Component}
   */
  getCustomComponent() {
    return serviceImplementation._customComponent;
  }
 
  /**
   *
   *
   * @param {*} {
   *   hide: hideImplementation,
   *   show: showImplementation,
   * }
   */
  setServiceImplementation({
    hide: hideImplementation,
    show: showImplementation,
    customComponent: customComponentImplementation,
  }) {
    if (hideImplementation) {
      serviceImplementation._hide = hideImplementation;
    }
    if (showImplementation) {
      serviceImplementation._show = showImplementation;
    }
    Iif (customComponentImplementation) {
      serviceImplementation._customComponent = customComponentImplementation;
    }
  }
}
 
export default UIModalService;