Modal

Modal allows you to add dialogs to your site for lightboxes, user notifications, or completely custom content.

Angular grayed logo
Angular coming soon

Example

Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.

<button type="button" class="nj-btn nj-btn--primary" data-toggle="modal" data-target="#exampleModal">
  Info modal
</button>

<div class="nj-modal fade" tabindex="-1" id="exampleModal" role="dialog">
  <div class="nj-modal__dialog" role="document">
    <div class="nj-modal__content">
      <div class="nj-modal__header">
        <h4 class="nj-modal__title" id="exampleModalLabel">Info modal</h4>
        <button type="button" class="nj-modal__close" data-dismiss="modal" aria-label="Close">
          <i class="material-icons close-icon">close</i>
        </button>
      </div>
      <div class="nj-modal__body">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.</p>
      </div>
      <div class="nj-modal__footer">
        <button type="button" class="nj-btn nj-btn--outline-primary" data-dismiss="modal">Cancel</button>
        <button type="button" class="nj-btn nj-btn--primary">Submit</button>
      </div>
    </div>
  </div>
</div>

Optional sizes

Modals have two optional sizes, available via modifier classes to be placed on a .nj-modal-dialog. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.

Size Class Modal max-width
Small .nj-modal--sm 440px
Default None 560px
<button type="button" class="nj-btn nj-btn--primary" data-toggle="modal" data-target="#exampleModalSmall">
  Small modal
</button>
<button type="button" class="nj-btn nj-btn--primary" data-toggle="modal" data-target="#exampleModalDefault">
  Default modal
</button>
<button type="button" class="nj-btn nj-btn--warning" data-toggle="modal" data-target="#exampleModalWarning">
  Warning information modal
</button>
<button type="button" class="nj-btn nj-btn--danger" data-toggle="modal" data-target="#exampleErrorModal">
  Error information modal
</button>

<div class="nj-modal fade" tabindex="-1" id="exampleModalSmall" role="dialog">
  <div class="nj-modal__dialog nj-modal--sm" role="document">
    <div class="nj-modal__content">
      <div class="nj-modal__header">
        <h4 class="nj-modal__title" id="exampleModalSmallLabel">Small modal</h4>
        <button type="button" class="nj-modal__close" data-dismiss="modal" aria-label="Close">
          <i class="material-icons close-icon">close</i>
        </button>
      </div>
      <div class="nj-modal__body">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.</p>
      </div>
      <div class="nj-modal__footer">
        <button type="button" class="nj-btn nj-btn--outline-primary" data-dismiss="modal">Cancel</button>
        <button type="button" class="nj-btn nj-btn--primary">Submit</button>
      </div>
    </div>
  </div>
</div>


<div class="nj-modal fade" tabindex="-1" id="exampleModalDefault" role="dialog">
  <div class="nj-modal__dialog" role="document">
    <div class="nj-modal__content">
      <div class="nj-modal__header">
        <h4 class="nj-modal__title" id="exampleModalDefaultLabel">Default modal</h4>
        <button type="button" class="nj-modal__close" data-dismiss="modal" aria-label="Close">
          <i class="material-icons close-icon">close</i>
        </button>
      </div>
      <div class="nj-modal__body">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor. Cras elementum ultrices diam.</p>
      </div>
      <div class="nj-modal__footer">
        <button type="button" class="nj-btn nj-btn--outline-primary" data-dismiss="modal">Cancel</button>
        <button type="button" class="nj-btn nj-btn--primary">Submit</button>
      </div>
    </div>
  </div>
</div>

        <div class="nj-modal nj-modal--information fade" tabindex="-1" id="exampleModalWarning" role="dialog">
          <div class="nj-modal__dialog" role="document">
            <div class="nj-modal__content">
              <button type="button" class="nj-modal__close" data-dismiss="modal" aria-label="Close">
                <i class="material-icons close-icon">close</i>
              </button>
              <div class="nj-modal__body">
                <i class="material-icons md--warning md-64 nj-modal__icon">info</i>
                <h4 class="nj-modal__title" id="exampleModalLabel">
                  Warning modal
                </h4>
                <p class="text-center">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet</p>
              </div>
              <div class="nj-modal__footer nj-modal__footer--centered">
                <button type="button" class="nj-btn nj-btn--outline-primary" data-dismiss="modal">Cancel</button>
                <button type="button" class="nj-btn nj-btn--primary">Confirm</button>
              </div>
            </div>
          </div>
        </div>


        <div class="nj-modal nj-modal--information fade" tabindex="-1" id="exampleErrorModal" role="dialog">
          <div class="nj-modal__dialog" role="document">
            <div class="nj-modal__content">
              <button type="button" class="nj-modal__close" data-dismiss="modal" aria-label="Close">
                <i class="material-icons close-icon">close</i>
              </button>
              <div class="nj-modal__body">
                <i class="material-icons md--danger md-64 nj-modal__icon">report_problem</i>
                <h4 class="nj-modal__title" id="exampleModalLabel">
                  Failure modal
                </h4>
                <p class="nj-modal__description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet</p>
              </div>
              <div class="nj-modal__footer nj-modal__footer--centered">
                <button type="button" class="nj-btn nj-btn--primary">Retry</button>
              </div>
            </div>
          </div>
        </div>

Methods

Method Description
toggle Shows or hides the modal, according to his current state.
show Shows the modal.
hide Hides the modal.
getInstance Static method which allows you to get the modal instance associated to a DOM element. You can use it like this: Alert.getInstance(domElement)

Events

ENGIE’s modal component exposes a few events for hooking into modal functionality.

Event Description
show.nj.modal This event fires immediately when the show instance method is called.
shown.nj.modal This event is fired when the alert has been closed (will wait for CSS transitions to complete).
hide.nj.modal This event fires immediately when the hide instance method is called.
hidden.nj.modal This event is fired when the alert has been closed (will wait for CSS transitions to complete).
document.querySelector('.my-modal').addEventListener('show.nj.modal', () => {
// do something...
});
document.querySelector('.my-modal').addEventListene('shown.nj.modal', () => {
// do something...
});
document.querySelector('.my-modal').addEventListener('hide.nj.modal', () => {
// do something...
});
document.querySelector('.my-modal').addEventListener('hidden.nj.modal', () => {
// do something...
});