Sha256: b3427b9bd85c7eb245810f656eba2d8c4cb2cdc1d366d9ac19e06c0c9e70ec80

Contents?: true

Size: 1.5 KB

Versions: 9

Compression:

Stored size: 1.5 KB

Contents

export default function navItemComponent({ id, matchers }) {
  matchers = matchers.map((matcher) =>
    matcher.replace(/\s/g, "").toLowerCase()
  );

  return {
    filteredOut: false,

    get open() {
      return this.isCollection && this.isOpen(id);
    },

    get active() {
      if (this.$refs.link) {
        return (
          this.location &&
          this.location.pathname === this.$refs.link.getAttribute("href")
        );
      }
      return false;
    },

    get children() {
      return this.$refs.items ? Array.from(this.$refs.items.children) : [];
    },

    get isCollection() {
      return !this.$refs.link;
    },

    toggle() {
      this.toggleOpen(id);
    },

    async filter(text) {
      if (this.isCollection) {
        this.filteredOut = true;
        this.children.forEach(async (child) => {
          const data = Alpine.$data(child);
          await data.filter(text);
          if (!data.filteredOut) {
            this.filteredOut = false;
          }
        });
      } else {
        this.filteredOut = !this.match(text);
      }
      return this;
    },

    match(text) {
      if (text.length) {
        const matched = (matchers || []).map((m) => m.includes(text));
        return matched.filter((m) => m).length;
      }
      return true;
    },

    bindings: {
      toggle: {
        ["x-on:click.stop"]: "toggle",
        ["x-ref"]: "toggle",
      },
      link: {
        [":class"]: "{'!bg-lookbook-nav-item-active':active}",
        ["x-ref"]: "link",
      },
    },
  };
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lookbook-2.3.0 app/components/lookbook/nav/item/component.js
lookbook-2.2.2 app/components/lookbook/nav/item/component.js
lookbook-2.2.1 app/components/lookbook/nav/item/component.js
lookbook-2.2.0 app/components/lookbook/nav/item/component.js
lookbook-2.1.1 app/components/lookbook/nav/item/component.js
lookbook-2.1.0 app/components/lookbook/nav/item/component.js
lookbook-2.0.5 app/components/lookbook/nav/item/component.js
lookbook-2.0.4 app/components/lookbook/nav/item/component.js
lookbook-2.0.3 app/components/lookbook/nav/item/component.js