Cookie policy notification

by Eugene Trounev

HTML

<div class="cookie-policy">
  <aside tabindex="0" role="alertdialog" class="cookie-policy-alert docsie-card" aria-labelledby="cookie-policy-title" aria-describedby="cookie-policy-content">
    <h1 id="cookie-policy-title" class="off-screen">
      Cookie policy notification
    </h1>
    <span class="cookie-policy-content" id="cookie-policy-content" role="document" tabindex="0"> We use cookies to improve your experience. By your continued use of
      this site you accept such use.<br> This notice will disappear by
      itself.
      <button class="cookie-policy-close" aria-label="Close this cookie policy notification">Close</button>
    </span>
  </aside>
</div>

SCSS

.cookie-policy .cookie-policy-alert {
  bottom: 0;
  box-sizing: border-box;
  border: 0;
  display: none;
  padding: 1rem;
  padding-right: 4rem;
  position: fixed;
  z-index: 200;

  @media (min-width: 1030px) {
    left: 50%;
    margin-left: calc(1030px / -2);
    width: 1030px;
  }

  .off-screen {
    height: 1px !important;
    left: -10000px !important;
    overflow: hidden !important;
    position: absolute !important;
    top: auto !important;
    width: 1px !important;
  }

  .cookie-policy-content {
    margin: 0;
    padding-right: 1.5rem;
    text-align: left;
  }

  .cookie-policy-close {
    background-color: rgba(0, 0, 0, 0);
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAaUlEQVQY043RMRLAIAgEwEtqf+Cb6H26rY7+wP5SOGMIUITuYAsYrlprSinnjKjmnGstjDFKKa01utqj3jtOMO4IktCt47R4kXZGfNB2IiIiWpC8w6NI2mz28Hcg3NQ4eOEdQmHc9ectD4HBKCHtwCenAAAAAElFTkSuQmCC);
    background-position: center;
    background-repeat: no-repeat;
    /* background-size: 1rem; */
    border: 0;
    cursor: pointer;
    height: 1rem;
    padding: 1rem;
    position: absolute;
    right: 0.75rem;
    text-indent: -99999px;
    top: 0.25rem;
    width: 1rem;
  }
}

JavaScript

var policyHide = 15000;
var policy = document.querySelector(".cookie-policy-alert");

function hidePolicy() {
  policy.style.display = "none";
  localStorage.setItem("my-cookie-policy", true);
}

if (
  policy &&
  !localStorage.getItem("my-cookie-policy")
) {
  policy
    .querySelector(".cookie-policy-close")
    .addEventListener("click", hidePolicy);
  policy.style.display = "block";
  setTimeout(hidePolicy, policyHide);
}