Sha256: c8050039b284d4ab74bb5bdd46add96cc976b6a06478d285f858eadc92d2b1f3

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

import tippy from "~/app/assets/lookbook/js/lib/tippy";
import { initTooltip } from "~/app/assets/lookbook/js/components/tooltip";

export default function buttonComponent() {
  let tooltip = null;
  let dropdown = null;

  return {
    init() {
      if (this.$refs.tooltip) {
        tooltip = initTooltip(this, {
          target: this.$refs.icon,
        });
      }

      if (this.dropdownContent) {
        dropdown = tippy(this.$el, {
          content: this.dropdownContent,
          trigger: "click",
          theme: "menu",
          triggerTarget: this.$el,
          interactive: true,
          zIndex: 99999,
          onShow: () => {
            if (!this.$store.settings.showTooltips) {
              return false;
            }
            this.$dispatch("dropdown:show", { dropdown: this });
          },
          onHide: () => this.$dispatch("dropdown:hide", { dropdown: this }),
        });
      }
    },

    get dropdownContent() {
      if (this.$root && this.$root.id) {
        const dropdown = document.querySelector(
          `[data-dropdown-id="${this.$root.id}"]`
        );
        return dropdown ? dropdown.innerHTML : null;
      }
      return null;
    },

    hideDropdown() {
      if (dropdown) {
        dropdown.hide();
      }
    },

    updateDropdown() {
      if (dropdown) {
        dropdown.hide();
        this.$nextTick(() => {
          dropdown.setContent(this.dropdownContent);
        });
      }
    },

    startSpin() {
      this._spinning = true;
    },

    stopSpin(delay = 0) {
      setTimeout(() => (this._spinning = false), delay);
    },

    get _tooltip() {
      return tooltip;
    },

    _spinning: false,
  };
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lookbook-2.0.0.beta.5 app/components/lookbook/button/component.js
lookbook-2.0.0.beta.4 app/components/lookbook/button/component.js
lookbook-2.0.0.beta.3 app/components/lookbook/button/component.js
lookbook-2.0.0.beta.2 app/components/lookbook/button/component.js
lookbook-2.0.0.beta.1 app/components/lookbook/button/component.js
lookbook-2.0.0.beta.0 app/components/lookbook/button/component.js