Sha256: a1b125a58a1aba83b3a5cedcc779dd347b548fd940b8d6767f06da81fc529bca

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

import { CocoComponent } from "@js/coco";

export default CocoComponent("appAlert", () => {
  return {
    alert: null,
    dismissed: false,
    forceMultiLine: false,
    dismissDuration: 300,

    init() {
      this.checkSingleLineWrap = Alpine.throttle(
        this.checkSingleLineWrap.bind(this),
        200
      );
    },

    dismiss() {
      if (this.$options.dismissable) {
        this.$dispatch("alert:dismiss", {
          alert: this,
          duration: this.dismissDuration,
        });

        this.dismissed = true;

        setTimeout(() => this.remove(), this.dismissDuration);
      }
    },

    remove() {
      this.$nextTick(() => this.$dispatch("alert:removed", { alert: this }));
      this.$root.remove();
    },

    checkSingleLineWrap({ height }) {
      this.forceMultiLine = false;
      if (height > 24 && this.$options.singleLine) {
        this.$nextTick(() => {
          this.forceMultiLine = true;
        });
      }
    },

    root: {
      "x-options": '["dismissable", "singleLine"]',
      ":class": "{'force-multi-line': forceMultiLine}",
    },
  };
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
coveragebook_components-0.8.6 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.5 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.4 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.3 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.2 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.1 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.0 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.0.beta.3 app/components/coco/app/elements/alert/alert.js
coveragebook_components-0.8.0.beta.2 app/components/coco/app/elements/alert/alert.js