Sha256: e5cf8ba50aa46c67f826c167d5078a7318e5e67845d2401f15298b90b843db42

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

import { tippy, hideOnEsc } from "@libs/tippy";

export default function withDropdown(props = {}) {
  function withDropdownMixin(component) {
    const tippyEl = component.$refs.dropdownTrigger || component.$root;

    const dropdown = tippy(tippyEl, {
      trigger: "click",
      interactive: true,
      animation: false,
      content: component.$refs.dropdownPanel,
      plugins: [hideOnEsc],

      onMount() {
        if (component.onDropdownMount) {
          component.onDropdownMount();
        }
      },

      onCreate() {
        if (component.onDropdownCreate) {
          component.onDropdownCreate();
        }
      },

      onShow: () => {
        component.dropdown.open = true;
        if (component.onDropdownShow) {
          return component.onDropdownShow();
        }

        if (component.setState) {
          component.setState("active");
        }
      },

      onHide: () => {
        component.dropdown.open = false;
        if (component.onDropdownHide) {
          component.onDropdownHide();
        }
        if (component.resetState) {
          component.resetState();
        }
      },

      ...props,
    });

    return Object.assign(component, {
      dropdown: Alpine.reactive({
        instance: dropdown,
        open: false,

        hide() {
          this.instance.hide();
        },

        show() {
          this.instance.show();
        },
      }),
    });
  }

  withDropdownMixin.props = ["dropdown"];

  return withDropdownMixin;
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
coveragebook_components-0.7.1 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.7.0 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.5 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.4 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.3 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.2 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.1 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.6.0 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.7 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.6 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.5 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.4 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.3 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.2 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.1 app/assets/js/base/mixins/dropdown.js
coveragebook_components-0.5.0 app/assets/js/base/mixins/dropdown.js