Sha256: e86a076b131d1ffd08738b7cf523317c0178d5439d96b25279fcaa68a0f47eac

Contents?: true

Size: 1.12 KB

Versions: 22

Compression:

Stored size: 1.12 KB

Contents

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

export default CocoComponent("alertMessage", () => {
  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", "dismissAfterAction"]',
      ":class": "{'force-multi-line': forceMultiLine}",
    },
  };
});

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
coveragebook_components-0.19.8 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.7 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.6 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.5 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.4 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.3 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.2 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.1 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.19.0 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.18.8 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.18.7 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.18.0 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.7 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.6 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.5 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.4 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.3 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.2 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.1 app/components/coco/messaging/alert/alert.js
coveragebook_components-0.17.0 app/components/coco/messaging/alert/alert.js