Sha256: 27719cfeed374fc86d33e668b3ed24632c40f7ecce134b246271a3428e0a1953

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

import { Views } from "loco-js";

class Flash extends Views.Base {
  constructor(opts = {}) {
    super(opts);
    this.notice = opts.notice;
    this.alert = opts.alert;
    this.warning = opts.warning;
    this.hide = opts.hide;
  }

  setNotice(text) {
    this.notice = text;
  }
  setAlert(text) {
    this.alert = text;
  }
  setWarning(text) {
    this.warning = text;
  }

  render() {
    const node = document.querySelector(".flash");
    node.classList.remove("notice");
    node.classList.remove("alert");
    node.classList.remove("warning");
    if (this.notice != null) {
      node.classList.add("notice");
      document.querySelector(".flash p").textContent = this.notice;
    } else if (this.alert != null) {
      node.classList.add("alert");
      document.querySelector(".flash p").textContent = this.alert;
    } else if (this.warning != null) {
      node.classList.add("warning");
      document.querySelector(".flash p").textContent = this.warning;
    }
    node.classList.remove("none"); // slideDown initially
    if (this.hide) this.hideAfterTime();
  }

  hideAfterTime(time = 4000) {
    setTimeout(() => {
      document.querySelector(".flash").classList.add("none"); // slideUp initially
    }, time);
  }
}

export default Flash;

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
loco-rails-3.0.5 test/dummy/frontend/js/views/shared/Flash.js
loco-rails-3.0.4 test/dummy/frontend/js/views/shared/Flash.js