Custom Popups?

You have interesting examples without Javascript here: https://github.com/you-dont-need/You-Dont-Need-Javascript
Below is one adapted from this one, you can rely on variables in your scope instead of tricks like a hidden input element (so you can have multiple popups on the same page).

<style>
.custom-modal-container {
  background: rgba(0, 0, 0, 0.75);
  opacity: 0;
  color: white;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  visibility: hidden;
  -webkit-transition: opacity 0.5s, visibility 0s linear 0.5s;
  transition: opacity 0.5s, visibility 0s linear 0.5s;
  z-index: 99999;
}
.custom-modal-container.active {
  opacity: 1;
  visibility: visible;
  -webkit-transition: opacity 0.5s;
  transition: opacity 0.5s;
}

.custom-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 2em;
  border-radius: 0.5em;
  -webkit-transform: translateX(-50%) translateY(-50%);
          transform: translateX(-50%) translateY(-50%);
}
.custom-modal.close-modal-area {
  width: 100%;
  height: 100%;
}
.custom-modal.custom-modal-box {
  background: indianred;
  text-align: center;
}
.custom-modal-content .custom-modal {
  width: 100%;
  max-width: 40em;
}

.toggle-modal-button {
  background-color: transparent;
  color: white;
  display: inline-block;
  padding: 1em;
  cursor: pointer;
  border-radius: 0.5em;
  box-shadow: inset 0 0 1px white;
}
.toggle-modal-button:hover, .toggle-modal-button:focus,
    .toggle-modal-button:active {
  background-color: rgba(0, 0, 0, 0.25);
  box-shadow: none;
}
.custom-modal-content .toggle-modal-button {
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 1em;
}

.custom-modal-content {
  color: peru;
  width: 90%;
  max-width: 600px;
  padding-top: 2em;
  margin: 0 auto;
}
</style>
<section class="custom-modal-container" ng-class="{ active: show_modal }">
  <div for="toggler" class="custom-modal close-modal-area" ng-click="show_modal=false"></div>
  <div class="custom-modal custom-modal-box">
    <div>Are you sure?</div>
    <br />
    <div class="toggle-modal-button" ng-click="show_modal=false; sendCmd('Presence_Toggle', 'OFF')">Yes</div>
  </div>
</section>
<section class="custom-modal-content">
  <div class="toggle-modal-button" ng-click="show_modal=true">Show Modal</div>
</section>

Alternatively you could use itemState('SomeItem') instead of the variable in ng-class to add/remove the active class (and also change ng-click to send commands to this item).

Two things when reusing examples with extensive styling:

  • Make sure you don’t copy paste un-preprocessed SASS/SCSS/LESS but the final compiled vanilla CSS;
  • Make the necessary changes so that you don’t use generic classes and broad selectors in your CSS - they might collide with existing ones defined by HABPanel or its dependencies.
2 Likes